/* ══════════════════════════════════════════════════════════════════════
   Jarvis — decision dashboard
   Arc-reactor cyan on graphite, with a light theme that keeps the contrast.
   ══════════════════════════════════════════════════════════════════════ */

:root {
  --bg:        #070b10;
  --bg-2:      #0c131c;
  --panel:     rgba(14, 22, 32, 0.82);
  --panel-solid: #0e1620;
  --line:      rgba(94, 234, 212, 0.14);
  --line-soft: rgba(148, 163, 184, 0.14);

  --text:      #dbe7f0;
  --text-dim:  #8497a8;
  --text-mute: #5b6b7a;

  --cyan:      #5eead4;
  --cyan-deep: #14b8a6;
  --amber:     #fbbf24;
  --red:       #fb7185;
  --green:     #4ade80;
  --violet:    #a78bfa;

  --radius:    14px;
  --radius-sm: 9px;
  --glow:      0 0 0 1px rgba(94, 234, 212, 0.22), 0 0 22px -6px rgba(94, 234, 212, 0.45);
  --shadow:    0 18px 48px -22px rgba(0, 0, 0, 0.9);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, monospace;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

html[data-theme="light"] {
  --bg:        #eef2f6;
  --bg-2:      #e3e9f0;
  --panel:     rgba(255, 255, 255, 0.9);
  --panel-solid: #ffffff;
  --line:      rgba(13, 148, 136, 0.26);
  --line-soft: rgba(15, 23, 42, 0.12);
  --text:      #0f1b25;
  --text-dim:  #44586a;
  --text-mute: #6b7c8d;
  --cyan:      #0d9488;
  --cyan-deep: #0f766e;
  --amber:     #b45309;
  --red:       #be123c;
  --green:     #15803d;
  --violet:    #6d28d9;
  --shadow:    0 16px 40px -24px rgba(15, 23, 42, 0.5);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(1100px 620px at 78% -8%, rgba(94, 234, 212, 0.1), transparent 62%),
    radial-gradient(760px 520px at 8% 104%, rgba(167, 139, 250, 0.08), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

[hidden] { display: none !important; }

::selection { background: rgba(94, 234, 212, 0.28); }

/* ── Scrollbars ─────────────────────────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 99px;
}
*::-webkit-scrollbar-track { background: transparent; }

/* ══ Gate ═════════════════════════════════════════════════════════════ */
.gate {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 24px;
  background: radial-gradient(700px 460px at 50% 26%, rgba(94, 234, 212, 0.12), transparent 70%), var(--bg);
}

.gate__card {
  position: relative;
  width: min(400px, 100%);
  padding: 40px 32px 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  text-align: center;
  animation: rise 0.5s var(--ease) both;
}

.gate__arc {
  width: 82px; height: 82px; margin: 0 auto 20px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, var(--cyan), #38bdf8, var(--violet), var(--cyan));
  -webkit-mask: radial-gradient(circle, transparent 56%, #000 57%);
  mask: radial-gradient(circle, transparent 56%, #000 57%);
  animation: spin 7s linear infinite;
}

.gate__title {
  margin: 0 0 6px;
  font-family: var(--mono);
  font-size: 27px;
  font-weight: 600;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  color: var(--cyan);
  text-shadow: 0 0 26px rgba(94, 234, 212, 0.5);
}

.gate__sub { margin: 0 0 26px; color: var(--text-dim); font-size: 13.5px; }

.gate__error {
  margin: 12px 0 0; padding: 9px 12px;
  background: rgba(251, 113, 133, 0.1);
  border: 1px solid rgba(251, 113, 133, 0.32);
  border-radius: var(--radius-sm);
  color: var(--red); font-size: 13px; text-align: left;
}

.field { display: block; text-align: left; margin-bottom: 16px; }
.field__label {
  display: block; margin-bottom: 7px;
  font-family: var(--mono); font-size: 10.5px;
  letter-spacing: 0.15em; text-transform: uppercase; color: var(--text-mute);
}
.field input {
  width: 100%; padding: 12px 14px;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  color: var(--text); font-family: var(--mono); font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
html[data-theme="light"] .field input { background: rgba(15, 23, 42, 0.04); }
.field input:focus {
  outline: none; border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.14);
}

/* ══ Buttons ══════════════════════════════════════════════════════════ */
.btn {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono); font-size: 12px;
  font-weight: 500; letter-spacing: 0.13em; text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.12s, box-shadow 0.2s;
}
.btn:hover:not(:disabled) { border-color: var(--cyan); color: var(--cyan); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.btn--sm { padding: 6px 12px; font-size: 10.5px; }

.btn--primary {
  width: 100%; padding: 13px 20px;
  background: linear-gradient(135deg, var(--cyan-deep), #0e7490);
  border-color: transparent; color: #04121a; font-weight: 600;
}
.btn--primary:hover:not(:disabled) {
  color: #04121a; box-shadow: var(--glow);
}
.btn__glow {
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.32), transparent);
  transform: translateX(-100%);
  animation: sweep 3.4s var(--ease) infinite;
}

.btn--ghost { border-color: var(--line-soft); color: var(--text-dim); }
.btn--send {
  width: 44px; height: 44px; flex: none; padding: 0;
  background: linear-gradient(135deg, var(--cyan-deep), #0e7490);
  border-color: transparent; color: #04121a;
}
.btn--send:hover:not(:disabled) { color: #04121a; box-shadow: var(--glow); }
.btn--warn { border-color: rgba(251, 191, 36, 0.4); color: var(--amber); }
.btn--warn:hover:not(:disabled) { background: rgba(251, 191, 36, 0.12); color: var(--amber); }

/* ══ Shell ════════════════════════════════════════════════════════════ */
.shell {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  width: 100%; max-width: 1440px; margin: 0 auto;
  padding: 0 22px 22px;
  animation: rise 0.45s var(--ease) both;
}

/* ── Topbar ─────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 18px 4px 16px;
}
.topbar__brand { display: flex; align-items: center; gap: 11px; }
.topbar__name {
  font-family: var(--mono); font-size: 16px; font-weight: 600;
  letter-spacing: 0.3em; color: var(--cyan);
}
.topbar__ver {
  font-family: var(--mono); font-size: 10.5px;
  letter-spacing: 0.1em; color: var(--text-mute);
  padding: 2px 7px; border: 1px solid var(--line-soft); border-radius: 5px;
}

.topbar__dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--text-mute); flex: none;
}
.topbar__dot[data-state="ok"]    { background: var(--cyan); box-shadow: 0 0 10px var(--cyan); animation: pulse 2.4s ease-in-out infinite; }
.topbar__dot[data-state="warn"]  { background: var(--amber); box-shadow: 0 0 10px var(--amber); }
.topbar__dot[data-state="error"] { background: var(--red);   box-shadow: 0 0 10px var(--red); animation: pulse 1s ease-in-out infinite; }

.topbar__meta { display: flex; align-items: center; gap: 8px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--line-soft); border-radius: 6px;
  font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.11em; color: var(--text-mute);
  white-space: nowrap;
}
.chip b { color: var(--text-dim); font-weight: 600; }
.chip[data-on="true"]  { border-color: rgba(94, 234, 212, 0.34); }
.chip[data-on="true"] b { color: var(--cyan); }
.chip[data-on="false"] b { color: var(--text-mute); }

.chip--btn { cursor: pointer; transition: border-color 0.2s, color 0.2s; }
.chip--btn:hover { border-color: var(--cyan); color: var(--cyan); }

/* ── Grid ───────────────────────────────────────────────────────────── */
.grid {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 358px;
  gap: 18px;
}

.panel {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
  flex: none;
}
.panel__title {
  margin: 0;
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  letter-spacing: 0.2em; text-transform: uppercase; color: var(--text-dim);
}

/* ── Log ────────────────────────────────────────────────────────────── */
.log {
  flex: 1; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 22px 18px;
  display: flex; flex-direction: column; gap: 20px;
  scroll-behavior: smooth;
}

.turn { display: flex; flex-direction: column; gap: 7px; animation: rise 0.3s var(--ease) both; }
.turn--user { align-items: flex-end; }

.bubble {
  max-width: min(76ch, 88%);
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  overflow-wrap: anywhere;
}
.bubble--jarvis {
  background: rgba(94, 234, 212, 0.055);
  border: 1px solid var(--line);
  border-bottom-left-radius: 3px;
  align-self: flex-start;
}
.bubble--user {
  background: linear-gradient(135deg, rgba(94, 234, 212, 0.15), rgba(56, 189, 248, 0.1));
  border: 1px solid rgba(94, 234, 212, 0.26);
  border-bottom-right-radius: 3px;
  align-self: flex-end;
}
.bubble__text { margin: 0; }
.bubble__text > :first-child { margin-top: 0; }
.bubble__text > :last-child { margin-bottom: 0; }
.bubble__text code {
  padding: 1px 5px; border-radius: 4px;
  background: rgba(94, 234, 212, 0.12);
  font-family: var(--mono); font-size: 0.88em; color: var(--cyan);
}
.bubble__text pre {
  margin: 10px 0; padding: 12px; overflow-x: auto;
  background: rgba(0, 0, 0, 0.45); border: 1px solid var(--line-soft);
  border-radius: 7px;
}
html[data-theme="light"] .bubble__text pre { background: rgba(15, 23, 42, 0.05); }
.bubble__text pre code { padding: 0; background: none; color: var(--text); }
.bubble__text ul, .bubble__text ol { margin: 8px 0; padding-left: 20px; }

.turn__hint {
  margin: 2px 0 0; align-self: flex-start;
  font-size: 12px; color: var(--text-mute);
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
}

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--cyan); opacity: 0.35;
  animation: blink 1.3s ease-in-out infinite;
}
.typing i:nth-child(2) { animation-delay: 0.18s; }
.typing i:nth-child(3) { animation-delay: 0.36s; }

.caret::after {
  content: "▍"; margin-left: 2px;
  color: var(--cyan); animation: blink 1s steps(2) infinite;
}

/* ── Composer ───────────────────────────────────────────────────────── */
.composer {
  flex: none;
  padding: 14px 16px 16px;
  border-top: 1px solid var(--line-soft);
  background: rgba(0, 0, 0, 0.16);
}
html[data-theme="light"] .composer { background: rgba(15, 23, 42, 0.025); }

.composer__row { display: flex; gap: 10px; align-items: flex-end; }

.composer textarea {
  flex: 1;
  max-height: 172px; min-height: 44px;
  padding: 11px 14px;
  background: rgba(0, 0, 0, 0.34);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  color: var(--text); font-family: var(--sans); font-size: 14.5px;
  line-height: 1.5; resize: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
html[data-theme="light"] .composer textarea { background: rgba(255, 255, 255, 0.75); }
.composer textarea:focus {
  outline: none; border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.13);
}
.composer textarea::placeholder { color: var(--text-mute); }

.composer__confirm {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 11px; padding: 9px 13px;
  background: rgba(251, 191, 36, 0.09);
  border: 1px solid rgba(251, 191, 36, 0.3);
  border-radius: var(--radius-sm);
  font-size: 13px; color: var(--amber);
}

/* ── Decision panel ─────────────────────────────────────────────────── */
.panel--decision { overflow-y: auto; }

.route-badge {
  padding: 5px 11px;
  border: 1px solid var(--line-soft); border-radius: 6px;
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  letter-spacing: 0.15em; color: var(--text-mute);
  white-space: nowrap;
}
.route-badge[data-route="direct"]   { border-color: rgba(74, 222, 128, 0.42); color: var(--green); }
.route-badge[data-route="confirm"]  { border-color: rgba(251, 191, 36, 0.46); color: var(--amber); }
.route-badge[data-route="clarify"]  { border-color: rgba(167, 139, 250, 0.46); color: var(--violet); }
.route-badge[data-route="escalate"] { border-color: rgba(251, 113, 133, 0.5);  color: var(--red); }

.decision { padding: 16px 18px; display: flex; flex-direction: column; gap: 15px; }
.decision__idle { margin: 0; font-size: 13px; color: var(--text-mute); line-height: 1.65; }

.signal { display: flex; flex-direction: column; gap: 5px; }
.signal__top {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}
.signal__label {
  font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-mute);
}
.signal__conf {
  font-family: var(--mono); font-size: 10.5px; color: var(--cyan);
}
.signal__value { font-size: 14px; color: var(--text); }
.signal__value[data-kind="choice"] { text-transform: capitalize; font-weight: 500; }
.signal__unit {
  font-family: var(--mono); font-size: 10px; color: var(--text-mute); margin-left: 6px;
}

.bars { display: flex; flex-direction: column; gap: 4px; margin-top: 2px; }
.bar { display: grid; grid-template-columns: 1fr 38px; gap: 8px; align-items: center; }
.bar__name {
  font-size: 11.5px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar--top .bar__name { color: var(--text); font-weight: 500; }
.bar__track {
  grid-column: 1; height: 5px; border-radius: 99px;
  background: rgba(148, 163, 184, 0.14); overflow: hidden;
}
.bar__fill {
  height: 100%; border-radius: 99px; background: var(--line-soft);
  transition: width 0.55s var(--ease);
}
.bar--top .bar__fill { background: linear-gradient(90deg, var(--cyan-deep), var(--cyan)); }
.bar__pct {
  grid-column: 2; grid-row: 1;
  font-family: var(--mono); font-size: 10.5px;
  color: var(--text-mute); text-align: right;
}
.bar--top .bar__pct { color: var(--cyan); }

.rationale { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.rationale li {
  position: relative;
  padding-left: 16px;
  font-size: 12.5px; color: var(--text-dim); line-height: 1.6;
}
.rationale li::before {
  content: ""; position: absolute; left: 3px; top: 8px;
  width: 4px; height: 4px; border-radius: 50%; background: var(--cyan-deep);
}

.rationale--alert li::before { background: var(--red); }

.badge-row { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  padding: 4px 9px; border-radius: 5px;
  border: 1px solid var(--line-soft);
  font-family: var(--mono); font-size: 9.5px;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-mute);
}
.badge--warn { border-color: rgba(251, 191, 36, 0.38); color: var(--amber); }
.badge--bad  { border-color: rgba(251, 113, 133, 0.4); color: var(--red); }

/* ── Meter ──────────────────────────────────────────────────────────── */
.meter-wrap { flex: none; padding: 4px 18px 16px; }
.meter { display: grid; grid-template-columns: 1fr auto; gap: 7px 10px; align-items: center; }
.meter__label {
  font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-mute);
}
.meter__value { font-family: var(--mono); font-size: 12px; color: var(--cyan); }
.meter__track {
  grid-column: 1 / -1; position: relative;
  height: 7px; border-radius: 99px;
  background: rgba(148, 163, 184, 0.14); overflow: hidden;
}
.meter__fill {
  height: 100%; width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--violet), var(--cyan-deep), var(--cyan));
  transition: width 0.7s var(--ease);
}
.meter__floor {
  position: absolute; top: -3px; bottom: -3px; width: 2px;
  background: var(--amber); opacity: 0.85;
  transition: left 0.4s var(--ease);
}

/* ── Thresholds ─────────────────────────────────────────────────────── */
.threshold { flex: none; border-top: 1px solid var(--line-soft); }
.threshold summary {
  padding: 13px 18px;
  font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.15em; text-transform: uppercase; color: var(--text-mute);
  cursor: pointer; list-style: none; user-select: none;
}
.threshold summary::-webkit-details-marker { display: none; }
.threshold summary::before { content: "▸ "; color: var(--cyan-deep); }
.threshold[open] summary::before { content: "▾ "; }
.threshold summary:hover { color: var(--text-dim); }

.threshold dl {
  margin: 0; padding: 0 18px 16px;
  display: grid; grid-template-columns: 1fr auto; gap: 6px 12px;
}
.threshold dt {
  font-family: var(--mono); font-size: 10.5px; color: var(--text-mute);
}
.threshold dd {
  margin: 0; font-family: var(--mono); font-size: 10.5px;
  color: var(--text-dim); text-align: right;
}

/* ── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 26px;
  transform: translateX(-50%);
  z-index: 60;
  padding: 11px 18px;
  background: var(--panel-solid);
  border: 1px solid rgba(251, 113, 133, 0.42);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  color: var(--red); font-size: 13px;
  animation: rise 0.25s var(--ease) both;
  max-width: min(520px, calc(100vw - 40px));
}
.toast[data-tone="info"] { border-color: var(--line); color: var(--text-dim); }

/* ══ Responsive ═══════════════════════════════════════════════════════ */
@media (max-width: 1080px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .panel--decision { max-height: 46vh; }
  .bubble { max-width: 92%; }
}

@media (max-width: 620px) {
  .shell { padding: 0 12px 12px; }
  .topbar { padding: 14px 2px 12px; }
  .topbar__name { font-size: 14px; letter-spacing: 0.22em; }
  .topbar__meta { width: 100%; justify-content: space-between; }
  .log { padding: 16px 13px; gap: 16px; }
  .panel__head { padding: 12px 14px; }
  .bubble { max-width: 100%; font-size: 14px; }
  .chip[data-verbose] { display: none; }
}

/* ══ Motion ═══════════════════════════════════════════════════════════ */
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes sweep {
  0%, 62%  { transform: translateX(-100%); }
  100%     { transform: translateX(100%); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.42; }
}
@keyframes blink {
  0%, 100% { opacity: 0.25; }
  50%      { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}