/* Shared tokens and components. Follows the CISAI brand guidelines: Axion for
   headings and navigation, Lato for everything else, 1px ink rules instead of
   shadows, blue for anything interactive and red for active states. */

@font-face { font-family: Axion; src: url("../fonts/Axion.otf") format("opentype"); font-weight: 400; font-display: swap; }
@font-face { font-family: Lato; src: url("../fonts/Lato-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: Lato; src: url("../fonts/Lato-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }
@font-face { font-family: Lato; src: url("../fonts/Lato-Italic.ttf") format("truetype"); font-weight: 400; font-style: italic; font-display: swap; }

:root {
  color-scheme: light;
  --page: #F4F7FB;
  --surface: #FFFFFF;
  --ink: #111111;
  --muted: #494949;
  --subtle: #5F6673;
  --faint: #F4F4F2;
  --mist: #E8F3FD;
  --blue: #0E4FE8;        /* fills: buttons, selection */
  --blue-ink: #0E4FE8;    /* text, links and outlines */
  --on-blue: #FFFFFF;
  --red: #D40A12;
  --alert-fill: #D40A12;  /* red fills behind white text */
  --rule: #111111;        /* 1px structural rules */
  --hair: #D9DEE6;        /* quiet internal lines */
  --busy: #8A93A3;
  --hex: #7EB0E7;
  --series: #0E4FE8;      /* single-series charts */
  --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5;
  --seq-5: #256abf; --seq-6: #184f95; --seq-7: #0d366b;

  --display: Axion, Lato, sans-serif;
  --body: Lato, system-ui, sans-serif;
  --gutter: clamp(16px, 3vw, 32px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0A1020; --surface: #101829; --ink: #EEF2F8; --muted: #B4BDCC; --subtle: #8D98AB;
    --faint: #172136; --mist: #13284F; --blue-ink: #7EAEFF; --red: #FF6B6F; --alert-fill: #B3141B;
    --rule: #6F7E98; --hair: #223050; --busy: #6F7E98; --series: #5B8CFF;
    --seq-1: #0d366b; --seq-2: #184f95; --seq-3: #256abf; --seq-4: #3987e5;
    --seq-5: #6da7ec; --seq-6: #9ec5f4; --seq-7: #cde2fb;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0A1020; --surface: #101829; --ink: #EEF2F8; --muted: #B4BDCC; --subtle: #8D98AB;
  --faint: #172136; --mist: #13284F; --blue-ink: #7EAEFF; --red: #FF6B6F; --alert-fill: #B3141B;
  --rule: #6F7E98; --hair: #223050; --busy: #6F7E98; --series: #5B8CFF;
  --seq-1: #0d366b; --seq-2: #184f95; --seq-3: #256abf; --seq-4: #3987e5;
  --seq-5: #6da7ec; --seq-6: #9ec5f4; --seq-7: #cde2fb;
}

*, *::before, *::after { box-sizing: border-box; }
[x-cloak] { display: none !important; }

html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--rule) var(--page); }
* { scrollbar-color: var(--hair) transparent; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font: 400 16px/1.5 var(--body);
}
/* Hex pattern frames the page: strongest at the edges, gone by the centre. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: url("../img/hex.svg") 0 0 / 54px 31.177px;
  -webkit-mask-image: radial-gradient(ellipse 75% 70% at 50% 45%, transparent 45%, #000 100%);
  mask-image: radial-gradient(ellipse 75% 70% at 50% 45%, transparent 45%, #000 100%);
  opacity: .9;
  pointer-events: none;
}

h1, h2, h3, h4 { font-family: var(--display); font-weight: 400; margin: 0; line-height: 1.15; }
h1 { font-size: clamp(26px, 2.6vw, 34px); letter-spacing: -.01em; }
h2 { font-size: 21px; }
h3 { font-size: 17px; }
p { margin: 0; }
a { color: var(--blue-ink); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--blue-ink); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.subtle { color: var(--subtle); }
.num, .tnum { font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------- Header ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 28px;
  height: 64px;
  padding: 0 var(--gutter);
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; height: 100%; }
.brand img { height: 44px; width: auto; display: block; }
.brand .logo-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand .logo-light { display: none; }
  :root:not([data-theme="light"]) .brand .logo-dark { display: block; }
}
:root[data-theme="dark"] .brand .logo-light { display: none; }
:root[data-theme="dark"] .brand .logo-dark { display: block; }

.nav { display: flex; gap: 24px; height: 100%; }
.nav a {
  display: flex;
  align-items: center;
  height: 100%;
  font-family: var(--display);
  font-size: 16px;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  padding-top: 2px;
}
.nav a:hover { color: var(--blue-ink); }
.nav a[aria-current="page"] { border-bottom-color: var(--red); }

.theme { position: relative; margin-left: auto; }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid transparent; color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover, .icon-btn[aria-expanded="true"] { border-color: var(--rule); background: var(--mist); color: var(--blue-ink); }
.theme-menu { width: 200px; }
.menu.theme-menu button.menu-item { position: relative; padding-left: 38px; }
.menu.theme-menu button.menu-item[aria-checked="true"] { font-weight: 700; }
.menu.theme-menu button.menu-item[aria-checked="true"]::before { content: "✓"; position: absolute; left: 15px; font-weight: 700; color: var(--blue-ink); }
.account { position: relative; }
.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--rule);
  border-radius: 50%;
  font: 700 13px/1 var(--body);
  letter-spacing: .02em;
  background: var(--surface);
}
.avatar:hover, .avatar[aria-expanded="true"] { background: var(--blue); color: var(--on-blue); border-color: var(--blue); }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--rule);
  z-index: 30;
}
.menu-head { padding: 16px; border-bottom: 1px solid var(--hair); }
.menu-head strong { display: block; }
.menu-head span { display: block; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.menu-head .tag { margin-top: 10px; }
.menu nav { display: none; }
.menu a, .menu button.menu-item {
  display: block;
  width: 100%;
  padding: 11px 16px;
  text-align: left;
  color: var(--ink);
  text-decoration: none;
  font-size: 15px;
}
.menu a:hover, .menu button.menu-item:hover { background: var(--mist); color: var(--blue-ink); }

@media (max-width: 819px) {
  .top { gap: 12px; height: 56px; }
  .brand img { height: 36px; }
  .top > .nav { display: none; }
  .menu nav { display: block; border-bottom: 1px solid var(--hair); }
  .menu nav a { font-family: var(--display); }
}

/* ---------- Layout ---------- */
.page { width: 100%; max-width: 1480px; margin: 0 auto; padding: 24px var(--gutter) 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { color: var(--muted); margin-top: 6px; max-width: 60ch; }
.panel { background: var(--surface); border: 1px solid var(--rule); min-width: 0; }
.panel-pad { padding: 20px; }

/* ---------- Controls ---------- */
.label {
  display: block;
  margin-bottom: 6px;
  font: 700 12px/1.2 var(--body);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.field { display: flex; flex-direction: column; min-width: 0; }
.input, .select {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--rule);
  border-radius: 0;
  background: var(--surface);
  font-size: 15px;
  min-width: 0;
}
.select {
  appearance: none;
  padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 17px top 18px, right 12px top 18px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.input:focus-visible, .select:focus-visible { outline-offset: 0; }
.input[aria-invalid="true"] { border-color: var(--red); }
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  font: 700 13px/1.2 var(--body);
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover:not(:disabled), .btn:focus-visible { background: var(--blue); border-color: var(--blue); color: var(--on-blue); }
.btn:disabled { opacity: .45; }
.btn-solid { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.btn-danger:hover:not(:disabled) { background: var(--red); border-color: var(--red); }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 12px; }
.btn-wide { width: 100%; min-height: 48px; font-size: 14px; }
.link-btn { color: var(--blue-ink); text-decoration: underline; text-underline-offset: 3px; font-size: inherit; }
.link-btn:hover { text-decoration-thickness: 2px; }

/* Tabs and option rows share the brand's active state: a red underline. */
.tabs { display: flex; gap: 20px; flex-wrap: wrap; }
.tab {
  padding: 6px 0 5px;
  border-bottom: 2px solid transparent;
  font-size: 15px;
  color: var(--muted);
}
.tab:hover { color: var(--blue-ink); }
.tab[aria-pressed="true"], .tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--red); }
.tab .count { color: var(--subtle); font-size: 13px; margin-left: 4px; }

.stepper { display: flex; height: 40px; border: 1px solid var(--rule); background: var(--surface); }
.stepper button { width: 38px; font-size: 18px; line-height: 1; }
.stepper button:hover:not(:disabled) { background: var(--blue); color: var(--on-blue); }
.stepper button:disabled { opacity: .35; }
.stepper output { flex: 1; min-width: 44px; display: grid; place-items: center; font-size: 15px; border-left: 1px solid var(--hair); border-right: 1px solid var(--hair); }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border: 1px solid var(--blue-ink);
  color: var(--blue-ink);
  font: 700 11px/1.5 var(--body);
  letter-spacing: .05em;
  text-transform: uppercase;
  white-space: nowrap;
}
.tag.neutral { border-color: var(--subtle); color: var(--muted); }
.tag.alert { border-color: var(--red); color: var(--red); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

/* ---------- Messages ---------- */
.notice { padding: 14px 16px; border: 1px solid var(--rule); background: var(--surface); }
.notice strong { display: block; margin-bottom: 2px; }
.notice.alert { border-color: var(--red); border-left-width: 4px; }
.notice.alert strong { color: var(--red); }
.notice.ok { border-color: var(--blue-ink); border-left-width: 4px; }
.errors { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.errors li { display: flex; gap: 8px; color: var(--red); }
.errors li::before { content: "!"; flex: 0 0 18px; height: 18px; display: grid; place-items: center; border: 1px solid currentColor; border-radius: 50%; font: 700 11px/1 var(--body); margin-top: 1px; }
.errors li.warn { color: var(--muted); }
.errors li.warn::before { border-color: var(--subtle); color: var(--subtle); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  background: var(--ink);
  color: var(--surface);
  font-size: 15px;
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  position: sticky;
  top: 0;
  background: var(--faint);
  text-align: left;
  font: 700 12px/1.3 var(--body);
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--hair); vertical-align: top; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--mist) 55%, transparent); }
.table .num { text-align: right; }
.table s { color: var(--subtle); }

/* ---------- Dialog ---------- */
dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
}
dialog::backdrop { background: rgb(10 16 32 / .45); }
.dialog-body { padding: 22px 22px 18px; display: grid; gap: 10px; }
.dialog-body p { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--hair); flex-wrap: wrap; }

/* ---------- Sign-in gate ---------- */
.gate { display: grid; place-items: center; min-height: calc(100vh - 64px); padding: 32px var(--gutter); }
.gate-card { width: min(440px, 100%); }
.gate-card h1 { font-size: 30px; }
.gate-card > p { color: var(--muted); margin: 10px 0 22px; }
.gate-options { display: grid; gap: 10px; }
.gate-options .btn { justify-content: flex-start; min-height: 46px; gap: 12px; }
.gate-options svg { width: 18px; height: 18px; flex-shrink: 0; }
.gate-or { display: flex; align-items: center; gap: 12px; margin: 8px 0; color: var(--subtle); font-size: 13px; }
.gate-or::before, .gate-or::after { content: ""; flex: 1; border-top: 1px solid var(--hair); }
.gate-row { display: flex; gap: 8px; }
.gate-row .input { flex: 1; }
.gate-options .gate-row .btn { min-height: 40px; }
.gate-note { margin-top: 14px; font-size: 13px; color: var(--subtle); }
.theme + .account { margin-left: -18px; }
