/* ============================================================================
   Merit Field Unit (commercial)
   Tokens and control language from Aakhali Rajyam Field Unit scaffolding.
   No Aakhali wordmark. No glows. No web fonts. No microphone chrome.
   ========================================================================= */

:root {
  color-scheme: dark light;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: ui-monospace, "Roboto Mono", SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --fs-micro: .625rem;
  --fs-mini:  .75rem;
  --fs-sm:    .8125rem;
  --fs-body:  .9375rem;
  --fs-md:    1rem;
  --fs-lg:      clamp(1.0625rem, 0.982rem + 0.357vw, 1.25rem);
  --fs-xl:      clamp(1.25rem,   1.089rem + 0.714vw, 1.625rem);
  --fs-display: clamp(1.75rem,   1.321rem + 1.905vw, 2.75rem);

  --sp-1: 4px;  --sp-2: 6px;  --sp-3: 8px;  --sp-4: 10px;
  --sp-5: 12px; --sp-6: 14px; --sp-7: 16px; --sp-8: 20px;
  --sp-9: 24px; --sp-10: 32px;

  --r-xs: 2px; --r-sm: 3px; --r-md: 3px; --r-lg: 4px;

  --ease-out: cubic-bezier(.2, .7, .3, 1);
  --t-press: 60ms;
  --t-fast:  170ms;
  --t-base:  240ms;

  --topbar-h: 48px;
  --nav-h: 58px;
  --safe: env(safe-area-inset-bottom, 0px);
  --rail-w: 220px;
  --shell-max: 1160px;
  --shell-gutter: 40px;
}

:root {
  --bg: #131416;
  --surface-1: #191B1F;
  --surface-2: #1F2126;
  --surface-3: #26282E;
  --surface-4: #31343C;
  --line: #30333A;
  --line-soft: #282A30;
  --line-strong: #464A54;
  --text: #EAEAEC;
  --text-2: #AFB3BA;
  --text-3: #999DA6;
  --text-4: #6B6F78;
  --accent: #D9A441;
  --accent-press: #C08F2F;
  --accent-text: #E2B252;
  --accent-ink: #201806;
  --accent-edge: #8A6A24;
  --accent-ghost: #D9A4411F;
  --accent-edge-soft: #D9A44159;
  --focus: #E2B252;
  --ok: #63A87F;
  --ok-ghost: #63A87F1F;
  --warn: #C98F45;
  --warn-ghost: #C98F451F;
  --danger: #D97E6E;
  --danger-ghost: #D97E6E1F;
  --evidence: #CE8FA9;
  --chip: #EAEAEC12;
  --track: #2B2D33;
  --key-bg: linear-gradient(#2A2C33, #232529);
  --key-edge: #0C0D10;
  --input-bg: #17191D;
  --shadow-float: 0 16px 40px -12px #000000E6;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #E4E1DA;
    --surface-1: #EAE8E2;
    --surface-2: #F0EEE8;
    --surface-3: #F6F4EF;
    --surface-4: #E1DED6;
    --line: #C6C2B7;
    --line-soft: #D6D2C7;
    --line-strong: #A6A191;
    --text: #1C1A16;
    --text-2: #4E4A40;
    --text-3: #6B6558;
    --text-4: #948E80;
    --accent: #E8480C;
    --accent-press: #CE3E08;
    --accent-text: #BC3800;
    --accent-ink: #FFFFFF;
    --accent-edge: #A52F06;
    --accent-ghost: #E8480C17;
    --accent-edge-soft: #E8480C54;
    --focus: #BC3800;
    --ok: #1C6E45;
    --ok-ghost: #1C6E4514;
    --warn: #96570A;
    --warn-ghost: #96570A14;
    --danger: #AC3226;
    --danger-ghost: #AC322614;
    --evidence: #9C3A5E;
    --chip: #1C1A160D;
    --track: #D6D2C7;
    --key-bg: linear-gradient(#FBFAF6, #F0EEE8);
    --key-edge: #C9C4B7;
    --input-bg: #FBFAF6;
    --shadow-float: 0 14px 34px -14px #17151059;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #E4E1DA;
  --surface-1: #EAE8E2;
  --surface-2: #F0EEE8;
  --surface-3: #F6F4EF;
  --surface-4: #E1DED6;
  --line: #C6C2B7;
  --line-soft: #D6D2C7;
  --line-strong: #A6A191;
  --text: #1C1A16;
  --text-2: #4E4A40;
  --text-3: #6B6558;
  --text-4: #948E80;
  --accent: #E8480C;
  --accent-press: #CE3E08;
  --accent-text: #BC3800;
  --accent-ink: #FFFFFF;
  --accent-edge: #A52F06;
  --accent-ghost: #E8480C17;
  --accent-edge-soft: #E8480C54;
  --focus: #BC3800;
  --ok: #1C6E45;
  --ok-ghost: #1C6E4514;
  --warn: #96570A;
  --warn-ghost: #96570A14;
  --danger: #AC3226;
  --danger-ghost: #AC322614;
  --evidence: #9C3A5E;
  --chip: #1C1A160D;
  --track: #D6D2C7;
  --key-bg: linear-gradient(#FBFAF6, #F0EEE8);
  --key-edge: #C9C4B7;
  --input-bg: #FBFAF6;
  --shadow-float: 0 14px 34px -14px #17151059;
}

:root[data-theme="dark"] { color-scheme: dark; }

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

html {
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
  overflow-x: clip;
}

body {
  margin: 0;
  font: 400 var(--fs-body) / 1.5 var(--font-ui);
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--safe) + 16px);
  -webkit-tap-highlight-color: transparent;
  overflow-x: clip;
}

:root:not([data-theme="light"]) body { -webkit-font-smoothing: antialiased; }

h1, h2, h3, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, textarea, select, a { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}
#main:focus { outline: none; }

.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;
}

.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

.micro {
  font: 600 var(--fs-micro) / 1.3 var(--font-num);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--text-3);
}

.page-title {
  font-size: var(--fs-display);
  font-weight: 650;
  line-height: 1.04;
  letter-spacing: -.028em;
  text-wrap: balance;
  margin: var(--sp-2) 0 var(--sp-7);
}

.faint { color: var(--text-3); }
.muted { color: var(--text-2); }

.topbar {
  position: sticky; top: 0; z-index: 40;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--surface-1);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
}
.topbar-mark { width: 22px; height: 22px; flex: 0 0 22px; color: var(--text); }
.topbar-word {
  flex: 1;
  font: 600 10px / 1 var(--font-num);
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--text);
}
.sysstrip { display: flex; align-items: center; gap: var(--sp-3); }

.iconbtn {
  width: 36px; height: 36px; display: grid; place-content: center;
  border-radius: var(--r-sm); color: var(--text-3);
  border: 1px solid transparent;
}
.iconbtn:active { background: var(--surface-4); color: var(--text); }
.iconbtn svg { width: 18px; height: 18px; }

.busy-line {
  position: absolute; left: 0; bottom: -1px; height: 2px; width: 100%;
  background: var(--accent); transform-origin: left; opacity: 0;
  pointer-events: none;
}
body[data-busy] .busy-line {
  opacity: 1;
  animation: indeterminate 1100ms linear infinite alternate;
}
@keyframes indeterminate {
  from { transform: translateX(0) scaleX(.15); }
  to   { transform: translateX(85%) scaleX(1); }
}

main {
  display: block;
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
  padding: var(--sp-7) var(--sp-7) 0;
  min-width: 0;
}

.view { animation: viewIn var(--t-base) var(--ease-out); }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

.kicker { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-2); }

.bottom-nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 45;
  height: calc(var(--nav-h) + var(--safe));
  padding-bottom: var(--safe);
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--surface-1);
  border-top: 1px solid var(--line);
}
.bottom-nav a {
  position: relative;
  min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px;
  color: var(--text-3);
  font: 600 8.5px / 1 var(--font-num);
  letter-spacing: .12em; text-transform: uppercase;
}
.bottom-nav svg {
  width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}
.bottom-nav a[aria-current="page"] { color: var(--accent-text); }
.bottom-nav a[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 0; width: 18px; height: 2px;
  background: var(--accent);
}

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 20px; padding-inline: var(--sp-3);
  border-radius: var(--r-xs);
  font: 600 9.5px / 1 var(--font-num);
  letter-spacing: .12em; text-transform: uppercase;
  background: var(--chip); color: var(--text-3);
}
.chip[data-tone="ready"], .chip[data-tone="done"], .chip[data-tone="ok"] { background: var(--ok-ghost); color: var(--ok); }
.chip[data-tone="warn"] { background: var(--warn-ghost); color: var(--warn); }
.chip[data-tone="error"] { background: var(--danger-ghost); color: var(--danger); }
.chip[data-tone="actionable"] { background: var(--accent-ghost); color: var(--accent-text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 44px; padding-inline: var(--sp-7);
  border-radius: var(--r-sm);
  font: 600 11px / 1 var(--font-num);
  letter-spacing: .12em; text-transform: uppercase;
  border: 1px solid var(--line-strong);
  background: var(--key-bg);
  box-shadow: 0 2px 0 var(--key-edge);
  color: var(--text);
}
.btn:active { transform: translateY(2px); box-shadow: 0 0 0 var(--key-edge); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent-edge);
  box-shadow: 0 2px 0 var(--accent-edge);
  color: var(--accent-ink);
}
.btn-primary:active { background: var(--accent-press); box-shadow: 0 0 0 var(--accent-edge); }
.btn-accent-ghost {
  background: var(--accent-ghost);
  border-color: var(--accent-edge-soft);
  color: var(--accent-text);
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .42; }
.btn-sm { min-height: 34px; padding-inline: var(--sp-5); font-size: 9.5px; box-shadow: 0 1.5px 0 var(--key-edge); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; }

body[data-route="login"] .bottom-nav { display: none; }
body[data-route="login"] { padding-bottom: 16px; }

.login-page {
  min-height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top, 0px) - 32px);
  display: grid;
  align-content: center;
  justify-items: center;
}
.login-card { width: 100%; max-width: 440px; }
.login-actions { display: grid; gap: var(--sp-3); }
.cv-preview {
  margin-top: var(--sp-6);
  padding: var(--sp-6);
  background: #F7F4EE;
  color: #1F2937;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  overflow: auto;
  max-height: 70dvh;
}
.cv-preview :is(h1,h2,h3,p,ul,li) { color: inherit; }
.file-drop {
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-sm);
  padding: var(--sp-6);
  background: var(--input-bg);
}
.btn-row { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-5); }

.form-card {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 15px;
  display: grid; gap: var(--sp-6);
  margin-top: var(--sp-5);
}
.field { display: grid; gap: var(--sp-2); }
.field > span {
  font: 600 var(--fs-micro) / 1.3 var(--font-num);
  letter-spacing: .16em; text-transform: uppercase; color: var(--text-3);
}

input, textarea {
  width: 100%; min-height: 44px;
  padding: var(--sp-4) var(--sp-5);
  font: 400 var(--fs-md) / 1.4 var(--font-ui);
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  caret-color: var(--accent);
}
textarea { min-height: 120px; max-height: 40dvh; resize: vertical; }
input:focus, textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-ghost);
}
input::placeholder, textarea::placeholder { color: var(--text-4); }

.offline-banner {
  background: var(--warn-ghost);
  color: var(--warn);
  font-size: var(--fs-sm);
  padding: var(--sp-3) var(--sp-7);
  border-bottom: 1px solid var(--line);
}

.notice {
  padding: var(--sp-4) var(--sp-5);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: var(--fs-sm);
  color: var(--text-2);
}
.notice[data-tone="warn"] { border-color: var(--warn); color: var(--warn); }
.notice[data-tone="ok"] { border-color: var(--ok); color: var(--ok); }
.stack-gap { margin-top: var(--sp-7); }

.question-card, .app-row {
  padding: 13px 0;
  border-bottom: 1px solid var(--line-soft);
}
.question-title { font-size: 14px; font-weight: 550; }
.question-meta { margin-top: var(--sp-2); }

.evidence-row {
  display: grid; grid-template-columns: 1fr auto; gap: var(--sp-5);
  position: relative;
  padding: 13px 0 13px var(--sp-4);
  border-bottom: 1px solid var(--line-soft);
}
.evidence-row[data-verified="0"]::before {
  content: ""; position: absolute; inset-block: 13px; inset-inline-start: 0;
  width: 3px; background: var(--warn);
}
.evidence-title { font-size: 14px; font-weight: 550; }
.evidence-statement { font-size: var(--fs-sm); line-height: 1.45; color: var(--text-2); margin-top: var(--sp-2); }
.evidence-meta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: var(--sp-3); }
.evidence-actions { display: grid; gap: var(--sp-3); justify-items: end; align-content: start; }
.verified-mark { display: grid; justify-items: center; gap: var(--sp-2); color: var(--ok); }
.verified-mark .micro { color: var(--ok); }
.verified-mark svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.result-count {
  font: 600 var(--fs-micro) / 1.3 var(--font-num);
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--text-3);
  margin: var(--sp-8) 0 var(--sp-3);
}

.chat-thread {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  margin: var(--sp-6) 0;
}
.chat-msg { display: flex; flex-direction: column; max-width: 92%; }
.chat-msg[data-role="user"] { align-self: flex-end; align-items: flex-end; }
.chat-msg[data-role="assistant"] { align-self: flex-start; align-items: flex-start; }
.chat-bubble {
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--r-sm);
  font-size: var(--fs-body);
  line-height: 1.5;
  white-space: pre-wrap;
}
.chat-msg[data-role="user"] .chat-bubble {
  background: var(--accent-ghost);
  border: 1px solid var(--accent-edge-soft);
  border-bottom-right-radius: 0;
}
.chat-msg[data-role="assistant"] .chat-bubble {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 0;
}

.fact-card {
  margin-top: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  max-width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--evidence);
  border-radius: var(--r-sm);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.fact-card[data-state="verified"] { border-left-color: var(--ok); }
.fact-card[data-state="dismissed"] { opacity: .55; border-left-color: var(--line-strong); }
.fact-title { font-size: var(--fs-sm); font-weight: 600; }
.fact-statement { margin: 0; font-size: var(--fs-body); line-height: 1.5; }
.fact-lint { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

.chat-composer {
  position: sticky;
  bottom: calc(var(--nav-h) + var(--safe) + var(--sp-3));
  background: var(--surface-1);
  border: 1px solid var(--line-strong);
  z-index: 5;
}
.chat-composer-row { display: flex; gap: var(--sp-3); align-items: center; }
.chat-composer-row .chat-send { flex: 1; }

.app-row {
  display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-4);
}
.app-row-main { display: grid; gap: 4px; min-width: 0; }
.queue-title { font-weight: 550; }
.job-meta { font-size: var(--fs-sm); color: var(--text-3); }

.editor-dialog {
  width: min(520px, calc(100vw - 24px));
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface-1);
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow-float);
}
.editor-dialog::backdrop { background: #101116D9; }
.editor-form { padding: var(--sp-7); display: grid; gap: var(--sp-6); }
.editor-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-4); }
.editor-title { font-size: var(--fs-lg); font-weight: 650; }
.editor-copy { font-size: var(--fs-sm); color: var(--text-3); }
.editor-fields { display: grid; gap: var(--sp-5); }
.editor-actions { display: flex; justify-content: flex-end; gap: var(--sp-3); }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe) + var(--sp-5));
  transform: translateX(-50%) translateY(12px);
  max-width: min(420px, calc(100vw - 32px));
  padding: var(--sp-4) var(--sp-6);
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  opacity: 0;
  pointer-events: none;
  z-index: 60;
}
#toast.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 721px) {
  body { padding-bottom: 32px; }

  .topbar-inner {
    width: 100%;
    padding-inline: var(--shell-gutter);
  }

  .shell {
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  .shell > main {
    width: 100%;
    max-width: 800px;
    margin-inline: auto;
    padding: var(--sp-8) var(--shell-gutter) 0;
  }

  .bottom-nav {
    order: -1;
    position: sticky;
    top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    inset: auto;
    height: 48px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: stretch;
    gap: 4px;
    background: var(--surface-1);
    border-top: 0;
    border-bottom: 1px solid var(--line);
  }

  .bottom-nav a {
    flex: 0 1 auto;
    flex-direction: row;
    min-width: 88px;
    min-height: 48px;
    padding: 0 var(--sp-5);
    gap: var(--sp-3);
    font-size: 10px;
    letter-spacing: .14em;
  }

  .bottom-nav a[aria-current="page"]::before {
    top: auto;
    bottom: 0;
    width: 18px;
    height: 2px;
  }

  body[data-route="login"] { padding-bottom: 32px; }

  body[data-route="login"] .topbar-inner {
    max-width: 440px;
    margin-inline: auto;
    padding-inline: 0;
  }

  body[data-route="login"] .shell {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  body[data-route="login"] .shell > main {
    max-width: 440px;
    width: 100%;
    margin-inline: auto;
    padding-inline: 0;
  }

  .chat-composer { bottom: var(--sp-5); }
  #toast { bottom: var(--sp-8); }
}

@media (min-width: 1080px) {
  .topbar-inner {
    max-width: var(--shell-max);
    margin-inline: auto;
  }

  body[data-route="login"] .topbar-inner {
    max-width: 440px;
  }

  .shell {
    display: grid;
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
    grid-template-areas: "nav main";
    column-gap: var(--shell-gutter);
    max-width: var(--shell-max);
    margin-inline: auto;
    padding: var(--sp-9) var(--shell-gutter) var(--sp-10);
    align-items: start;
  }

  .shell > main {
    grid-area: main;
    max-width: 800px;
    margin-inline: 0;
    padding: 0;
  }

  .bottom-nav {
    grid-area: nav;
    order: 0;
    position: sticky;
    top: calc(var(--topbar-h) + var(--sp-9));
    height: auto;
    min-height: calc(100dvh - var(--topbar-h) - 64px);
    padding: 0 var(--sp-5) var(--sp-7) 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 4px;
    background: transparent;
    border-bottom: 0;
    border-right: 1px solid var(--line);
  }

  .bottom-nav::before {
    content: "";
    display: block;
    width: 24px;
    height: 2px;
    margin: 0 12px var(--sp-6);
    background: var(--accent);
  }

  .bottom-nav a {
    flex: 0 0 auto;
    justify-content: flex-start;
    min-width: 0;
    min-height: 42px;
    padding: 0 var(--sp-4);
    border: 1px solid transparent;
    border-radius: var(--r-sm);
  }

  .bottom-nav svg {
    width: 18px;
    height: 18px;
  }

  .bottom-nav a[aria-current="page"] {
    background: var(--surface-2);
    border-color: var(--line);
    box-shadow: inset 2.5px 0 0 var(--accent);
  }

  .bottom-nav a[aria-current="page"]::before { display: none; }

  body[data-route="login"] .shell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    grid-template-columns: none;
    grid-template-areas: none;
    column-gap: 0;
    padding-top: var(--sp-9);
  }

  body[data-route="login"] .shell > main {
    grid-area: auto;
    max-width: 440px;
    width: 100%;
    margin-inline: auto;
  }
}

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