:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --bg: #f1f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --gray: #6b7280;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); }
.screen { height: 100vh; }
[hidden] { display: none !important; }
.mobile-only { display: none; }

/* ---------- LOGIN ---------- */
.login { display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--card); width: 360px; max-width: 92vw;
  padding: 32px; border-radius: 16px; box-shadow: 0 10px 40px rgba(2,6,23,.12);
}
.login-card h1 { margin: 0 0 4px; font-size: 1.4rem; }
.subtitle { margin: 0 0 20px; color: var(--muted); font-size: .9rem; }
.login-card label { display: block; font-size: .82rem; font-weight: 600; margin: 12px 0 4px; }
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; font-size: .95rem;
}
.login-card input:focus { outline: 2px solid var(--blue); border-color: var(--blue); }
button {
  cursor: pointer; border: 0; border-radius: 8px; font-size: .95rem;
  background: var(--blue); color: #fff; padding: 11px 16px; font-weight: 600;
}
button:hover { background: var(--blue-dark); }
button:disabled { opacity: .55; cursor: default; }
#login-btn { width: 100%; margin-top: 22px; }
.error {
  margin-top: 14px; background: #fee2e2; color: #991b1b;
  padding: 10px 12px; border-radius: 8px; font-size: .85rem;
}

/* ---------- APP ---------- */
.app { display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); padding: 12px 18px; border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.ghost { background: transparent; color: var(--blue); padding: 7px 10px; }
.ghost:hover { background: #eff6ff; }
.muted { color: var(--muted); font-size: .85rem; }
.pad { padding: 14px 16px; }

.layout { flex: 1; display: flex; min-height: 0; }
.list-pane {
  width: 340px; border-right: 1px solid var(--line); background: var(--card);
  overflow-y: auto; flex: 0 0 auto;
}
#ramp-list { list-style: none; margin: 0; padding: 0; }
.ramp-item {
  padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer;
  display: flex; align-items: center; gap: 10px;
}
.ramp-item:hover { background: #f8fafc; }
.ramp-item.active { background: #eff6ff; border-left: 3px solid var(--blue); padding-left: 13px; }
.ramp-item .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.ramp-item .info { min-width: 0; }
.ramp-item .name { font-weight: 600; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ramp-item .sub { color: var(--muted); font-size: .78rem; }

/* Détail : remplit la hauteur dispo, panneaux alignés en bas (PC) */
.detail-pane { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.detail-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); }
#detail { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.detail-header { display: flex; align-items: center; gap: 14px; padding: 16px 22px 12px; flex: 0 0 auto; }
.detail-header h2 { margin: 0; font-size: 1.25rem; }
#map { flex: 1 1 auto; min-height: 220px; margin: 0 22px; border-radius: 12px; border: 1px solid var(--line); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; padding: 18px 22px; flex: 0 0 auto; }
.detail-block { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; max-height: 38vh; overflow: auto; }
.detail-block h3 { margin: 0 0 10px; font-size: .95rem; }
dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .88rem; }
dt { color: var(--muted); }
dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* icônes booléennes des entrées logiques */
.bool { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.bool svg { flex: none; }
.bool.on { color: var(--green); }
.bool.off { color: var(--gray); }
.bool.ok-text { color: var(--green); }

/* statut */
.status-badge { font-size: .8rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; color: #fff; white-space: nowrap; }
.st-moving { background: var(--green); }
.st-stopped { background: var(--amber); }
.st-off { background: var(--gray); }
.st-error { background: var(--red); }
.st-unknown { background: #94a3b8; }
.dot.st-moving { background: var(--green); }
.dot.st-stopped { background: var(--amber); }
.dot.st-off { background: var(--gray); }
.dot.st-error { background: var(--red); }
.dot.st-unknown { background: #94a3b8; }

/* ---------- MOBILE ---------- */
@media (max-width: 820px) {
  html, body { height: auto; min-height: 100%; }
  .screen.app { height: auto; min-height: 100vh; }
  .mobile-only { display: inline-flex; }

  .layout { flex-direction: column; min-height: 0; }
  .list-pane { width: 100%; max-height: 60vh; }

  /* la page défile naturellement : le détail n'a plus de scroll interne */
  .detail-pane { display: block; overflow: visible; }
  #detail { display: block; }
  #map { height: 300px; min-height: 0; flex: none; margin: 0 12px; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-block { max-height: none; overflow: visible; }

  /* quand une rampe est sélectionnée, on replie la liste pour laisser place à la carte */
  body.ramp-selected .list-pane { display: none; }
  .detail-header { padding-top: 14px; }
}
