/* app.css — Cortex shell layout + shared components. */
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* authoritative over .app/.graph-empty display */
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); font-size: var(--fs-body); line-height: var(--lh);
  color: var(--t-1); background: var(--bg-1);
  background-image:
    radial-gradient(1200px 700px at 78% -8%, rgba(110,168,254,.10), transparent 60%),
    radial-gradient(900px 600px at 8% 108%, rgba(126,224,184,.08), transparent 60%);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
h1,h2,h3,p { margin: 0; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--stroke-strong); border-radius: var(--r-pill); }

/* ── app frame ── */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: var(--s-4);
  padding: 0 var(--s-4); border-bottom: 1px solid var(--stroke);
  background: var(--bg-glass); backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: var(--s-2); font-weight: 700; }
.brand-mark { width: 18px; height: 18px; border-radius: 6px; background: var(--acc-grad); box-shadow: var(--glow); }
.brand-name { letter-spacing: .2px; }
.topbar-brain { display: flex; align-items: center; gap: var(--s-2); }
.brain-name { color: var(--t-2); font-weight: 600; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--s-2); }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr var(--rail-w); }
.canvas-wrap { position: relative; min-width: 0; overflow: hidden; }
.graph { position: absolute; inset: 0; }
.rail {
  border-left: 1px solid var(--stroke); background: var(--bg-2);
  display: flex; flex-direction: column; min-height: 0;
}

/* ── buttons ── */
.btn-primary, .btn-ghost, .btn-soft {
  border: 1px solid transparent; border-radius: var(--r-md); padding: 9px 14px;
  font-size: var(--fs-cap); font-weight: 600; cursor: pointer; transition: .15s var(--ease);
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: var(--acc-grad); color: #08101f; box-shadow: var(--sh-1); }
.btn-primary:hover { filter: brightness(1.06); box-shadow: var(--glow); }
.btn-ghost { background: transparent; color: var(--t-2); border-color: var(--stroke); }
.btn-ghost:hover { color: var(--t-1); border-color: var(--stroke-strong); background: var(--bg-3); }
.btn-soft { background: var(--bg-3); color: var(--t-1); border-color: var(--stroke); }
.btn-soft:hover { border-color: var(--stroke-strong); }
.btn-primary:disabled, .btn-soft:disabled { opacity: .5; cursor: default; }
/* visible keyboard focus on every interactive control (mouse clicks stay clean) */
.btn-primary:focus-visible, .btn-ghost:focus-visible, .btn-soft:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.tab:focus-visible { outline: 2px solid var(--acc); outline-offset: -2px; }

/* screen-reader-only text — gives color-only indicators an accessible name */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── fields ── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s-3); }
.field > span { font-size: var(--fs-cap); color: var(--t-2); font-weight: 500; }
.input, textarea.input, select.input {
  width: 100%; background: var(--bg-1); color: var(--t-1);
  border: 1px solid var(--stroke); border-radius: var(--r-md); padding: 10px 12px; font-size: var(--fs-body);
}
.input:focus { outline: none; border-color: var(--acc); box-shadow: 0 0 0 3px rgba(110,168,254,.18); }
textarea.input { resize: vertical; min-height: 64px; }

/* ── chips / badges ── */
.badge { font-size: var(--fs-fine); color: var(--t-3); border: 1px solid var(--stroke); border-radius: var(--r-pill); padding: 2px 8px; }
.chip { font-size: var(--fs-fine); color: var(--t-2); background: var(--bg-3); border: 1px solid var(--stroke); border-radius: var(--r-pill); padding: 3px 9px; display: inline-flex; gap: 5px; align-items: center; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; }

/* ── card ── */
.card { background: var(--bg-3); border: 1px solid var(--stroke); border-radius: var(--r-lg); padding: var(--s-4); }
.card + .card { margin-top: var(--s-3); }

/* ── usage hud ── */
.usage-hud { display: flex; align-items: center; gap: 6px; font-size: var(--fs-fine); color: var(--t-3); }
.usage-hud .bar { width: 64px; height: 5px; border-radius: var(--r-pill); background: var(--bg-3); overflow: hidden; }
.usage-hud .bar > i { display: block; height: 100%; background: var(--acc); }

/* ── rail tabs/panels ── */
.rail-tabs { display: flex; gap: 2px; padding: var(--s-3) var(--s-3) 0; border-bottom: 1px solid var(--stroke); }
.tab { flex: 1; background: transparent; border: none; color: var(--t-3); font-weight: 600; font-size: var(--fs-cap);
  padding: 9px 8px; border-radius: var(--r-md) var(--r-md) 0 0; cursor: pointer; }
.tab.is-active { color: var(--t-1); background: var(--bg-3); box-shadow: inset 0 -2px 0 var(--acc); }
.rail-body { flex: 1; min-height: 0; position: relative; }
.panel { position: absolute; inset: 0; display: flex; flex-direction: column; min-height: 0; }
.panel[hidden] { display: none; }

/* ── graph type legend (click to filter) ── */
.legend {
  position: absolute; top: var(--s-3); left: var(--s-3); z-index: 5;
  display: flex; flex-wrap: wrap; gap: 6px; max-width: 60%;
}
.legend-item {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-fine); color: var(--t-2);
  background: var(--bg-glass); backdrop-filter: blur(12px);
  border: 1px solid var(--stroke); border-radius: var(--r-pill);
  padding: 3px 10px; cursor: pointer; transition: .14s var(--ease);
}
.legend-item:hover { border-color: var(--stroke-strong); color: var(--t-1); }
.legend-item:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.legend-item.is-off { opacity: .42; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 6px currentColor; }

/* ── graph empty state ── */
.graph-empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: var(--s-3); padding: var(--s-6); }
.graph-empty h2 { font-size: var(--fs-h2); }
.graph-empty p { color: var(--t-3); max-width: 360px; }
.graph-empty .btn-primary { justify-self: center; }

/* ── inspector (floating node panel) ── */
.inspector { position: absolute; top: var(--s-4); left: var(--s-4); width: 320px; max-height: calc(100% - var(--s-7));
  overflow: auto; background: var(--bg-glass); backdrop-filter: blur(16px);
  border: 1px solid var(--stroke-strong); border-radius: var(--r-lg); box-shadow: var(--sh-3); padding: var(--s-4); }

/* ── modal / onboarding ── */
.backdrop { position: fixed; inset: 0; background: rgba(4,6,14,.72); backdrop-filter: blur(8px); display: grid; place-content: center; z-index: 50; padding: var(--s-4); }
.modal { width: min(520px, 94vw); background: var(--bg-2); border: 1px solid var(--stroke-strong); border-radius: var(--r-xl); box-shadow: var(--sh-3); padding: var(--s-6); }
.modal h2 { font-size: var(--fs-h2); margin-bottom: var(--s-2); }
.modal .sub { color: var(--t-3); margin-bottom: var(--s-5); }
.modal-actions { display: flex; gap: var(--s-2); justify-content: flex-end; margin-top: var(--s-4); }
.hero-mark { width: 54px; height: 54px; border-radius: var(--r-lg); background: var(--acc-grad); box-shadow: var(--glow); margin-bottom: var(--s-4); }

/* ── toast ── */
.toast-host { position: fixed; bottom: var(--s-5); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: var(--s-2); z-index: 80; }
.toast { background: var(--bg-3); border: 1px solid var(--stroke-strong); color: var(--t-1); padding: 10px 16px; border-radius: var(--r-pill); box-shadow: var(--sh-2); font-size: var(--fs-cap); }
.toast.is-good { border-color: rgba(126,224,184,.5); }
.toast.is-warn { border-color: rgba(255,212,121,.5); }
.toast.is-bad { border-color: rgba(255,138,155,.5); }

.muted { color: var(--t-3); }
.row { display: flex; gap: var(--s-2); align-items: center; }
.spread { display: flex; gap: var(--s-2); align-items: center; justify-content: space-between; }
.scroll { overflow: auto; min-height: 0; }
.empty-note { color: var(--t-3); text-align: center; padding: var(--s-6) var(--s-4); font-size: var(--fs-cap); }

/* ── responsive ── */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 1fr 46vh; }
  .rail { border-left: none; border-top: 1px solid var(--stroke); }
  :root { --rail-w: 100%; }
  /* WCAG 2.5.5 — comfortable touch targets on phones */
  .btn-primary, .btn-ghost, .btn-soft, .tab { min-height: 44px; }
}
