:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #17202a;
  --muted: #5b6875;
  --border: #d6dde4;
  --accent: #245d86;
  --accent-text: #ffffff;
  --edge: #8aa4b8;
  --tone-neutral-bg: #e7ebef;
  --tone-neutral-fg: #3f4b57;
  --tone-ok-bg: #dcefe8;
  --tone-ok-fg: #1d5c48;
  --tone-warn-bg: #fbecd2;
  --tone-warn-fg: #7a4b08;
  --tone-bad-bg: #f8dcdc;
  --tone-bad-fg: #8a1f1f;
  --tone-info-bg: #dde9f5;
  --tone-info-fg: #1f4c75;
  --radius: 10px;
  --gutter: 16px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720;
    --surface: #17212c;
    --surface-2: #1d2a37;
    --text: #e6ecf1;
    --muted: #9aa9b7;
    --border: #2b3a49;
    --accent: #7fb6d9;
    --accent-text: #0f1720;
    --edge: #4f6b82;
    --tone-neutral-bg: #26323e;
    --tone-neutral-fg: #c3cdd6;
    --tone-ok-bg: #173b31;
    --tone-ok-fg: #9fdcc6;
    --tone-warn-bg: #3d2f12;
    --tone-warn-fg: #f2cf8c;
    --tone-bad-bg: #4a1d1f;
    --tone-bad-fg: #f5b3b3;
    --tone-info-bg: #1b3149;
    --tone-info-fg: #a9cdf0;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-text-size-adjust: 100%;
}
.boot { padding: 2rem var(--gutter); color: var(--muted); }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .98rem; }
p { margin: .25rem 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .85em; overflow-wrap: anywhere; }

button, .button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: .55rem .9rem;
  min-height: 44px;
  cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--tone-bad-fg); border-color: var(--tone-bad-fg); }
button:disabled { opacity: .55; cursor: progress; }
button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input {
  font: inherit;
  width: 100%;
  padding: .6rem .7rem;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
label { display: block; font-weight: 600; margin: .75rem 0 .35rem; }

/* ---- authentication ---- */
.auth { max-width: 460px; margin: 8vh auto; padding: 0 var(--gutter); }
.auth .card { padding: 1.5rem; }
.auth .brand { display: flex; gap: .75rem; align-items: center; margin-bottom: 1rem; }
.auth .brand img { width: 40px; height: 40px; }
.auth .actions { display: grid; gap: .6rem; margin-top: 1rem; }
.notice { border-radius: 8px; padding: .6rem .8rem; margin: .75rem 0; font-size: .92rem; }
.notice.bad { background: var(--tone-bad-bg); color: var(--tone-bad-fg); }
.notice.info { background: var(--tone-info-bg); color: var(--tone-info-fg); }
.notice.warn { background: var(--tone-warn-bg); color: var(--tone-warn-fg); }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .6rem var(--gutter);
  padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .title { display: flex; align-items: center; gap: .5rem; margin-right: auto; min-width: 0; }
.topbar .title img { width: 28px; height: 28px; flex: none; }
.topbar .title h1 { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .who { font-size: .85rem; color: var(--muted); }
@media (max-width: 520px) { .topbar .who { display: none; } .topbar .title h1 { font-size: 1rem; } }
.topbar button { min-height: 38px; padding: .35rem .7rem; }
.topbar .app-link {
  display: inline-flex; align-items: center; min-height: 38px; padding: .35rem .7rem;
  border: 1px solid var(--accent); border-radius: 8px; color: var(--accent); text-decoration: none; font-weight: 600;
}
.topbar .app-link::after { content: ' ↗'; }
main { padding: var(--gutter); padding-bottom: calc(84px + env(safe-area-inset-bottom)); max-width: 1500px; width: 100%; margin: 0 auto; min-width: 0; }
nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 58px; text-decoration: none; color: var(--muted); font-size: .72rem; padding: 4px 2px;
}
nav.tabs a .glyph { font-size: 1.15rem; line-height: 1; }
nav.tabs a[aria-current='page'] { color: var(--accent); font-weight: 700; }

@media (min-width: 900px) {
  .shell { grid-template-columns: 210px 1fr; grid-template-rows: auto 1fr; }
  .topbar { grid-column: 1 / -1; }
  nav.tabs {
    position: sticky; top: 57px; align-self: start; height: calc(100vh - 57px);
    display: flex; flex-direction: column; gap: 2px;
    border-top: 0; border-right: 1px solid var(--border); padding: .75rem .5rem;
  }
  nav.tabs a { flex-direction: row; justify-content: flex-start; gap: .6rem; min-height: 42px; font-size: .95rem; padding: 0 .75rem; border-radius: 8px; }
  nav.tabs a[aria-current='page'] { background: var(--surface-2); }
  main { padding: 1.25rem 1.5rem 2rem; }
}

/* ---- generic blocks ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; min-width: 0; }
.stack { display: grid; gap: var(--gutter); }
.grid { display: grid; gap: var(--gutter); grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-bottom: .25rem; }
.kv { display: grid; grid-template-columns: minmax(110px, max-content) 1fr; gap: .3rem .9rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.headline { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.metric { font-size: 1.6rem; font-weight: 700; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.list > li { border: 1px solid var(--border); border-radius: 8px; padding: .7rem .8rem; background: var(--surface); min-width: 0; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spacer { margin-left: auto; }

.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  border-radius: 999px; padding: .1rem .55rem; font-size: .78rem; font-weight: 600;
  white-space: nowrap; max-width: 100%;
}
.badge::before { content: ''; width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; opacity: .8; }
.tone-neutral { background: var(--tone-neutral-bg); color: var(--tone-neutral-fg); }
.tone-ok { background: var(--tone-ok-bg); color: var(--tone-ok-fg); }
.tone-warn { background: var(--tone-warn-bg); color: var(--tone-warn-fg); }
.tone-bad { background: var(--tone-bad-bg); color: var(--tone-bad-fg); }
.tone-info { background: var(--tone-info-bg); color: var(--tone-info-fg); }

/* tables become cards on phones */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .8rem; color: var(--muted); font-weight: 600; }
@media (max-width: 760px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid var(--border); border-radius: 8px; margin-bottom: .6rem; padding: .3rem .2rem; background: var(--surface); }
  .table td { border: 0; padding: .3rem .6rem; display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); gap: .5rem; justify-items: start; align-items: start; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; }
}

/* ---- Carte ---- */
.map-wrap { position: relative; }
.map-edges { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; display: none; }
.map-edges path { fill: none; stroke: var(--edge); stroke-width: 1.5; }
.map-edges path.inactive { stroke-dasharray: 5 5; }
.lanes { display: grid; gap: var(--gutter); grid-template-columns: 1fr; position: relative; }
.lane h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 .5rem; }
.lane .nodes { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); }
.node { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .65rem .7rem; position: relative; z-index: 1; min-width: 0; }
.node .name { font-weight: 700; overflow-wrap: anywhere; }
.node .sub { font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
.node .dims { display: grid; gap: .25rem; margin-top: .45rem; }
.node .dim { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .15rem .4rem; align-items: center; font-size: .78rem; }
.node .dim .badge { white-space: normal; }
.node .dim > span:first-child { color: var(--muted); }
.node details { margin-top: .4rem; font-size: .8rem; }
.node details summary { cursor: pointer; color: var(--accent); min-height: 32px; display: flex; align-items: center; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0 1rem; }

@media (min-width: 760px) and (max-width: 1279px) {
  .lanes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1280px) {
  .lanes { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 28px; }
  .lane .nodes { grid-template-columns: 1fr; }
  .map-edges { display: block; }
}
input[type="checkbox"] { width: auto; min-height: 0; margin: 0 .4rem 0 0; }
label.row { font-weight: 400; }
