:root {
  --bg: #08080b;
  --bg-2: #0e0e13;
  --panel: #131319;
  --panel-2: #1a1a22;
  --line: #26262f;
  --line-hot: #3a2a08;
  --txt: #e7e7ee;
  --txt-dim: #9a9aa8;
  --txt-faint: #62626f;
  /* Brand accent: gold/amber */
  --gold: #ffc40e;
  --gold-deep: #c8910a;
  --gold-glow: rgba(255,196,14,0.55);
  --on-gold: #15120a;
  /* Danger / semantic red (refused, against, delete) */
  --red: #ff3b30;
  --red-deep: #c8101d;
  --red-glow: rgba(255,59,48,0.5);
  --line-danger: #3a0d12;
  --chrome-1: #f4f5f7;
  --chrome-2: #9aa0aa;
  --good: #35c759;
  --warn: #ffb02e;
  --radius: 12px;
  --tap: 48px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, #1a1402 0%, var(--bg) 55%) fixed;
  color: var(--txt);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---- top bar ---- */
#topbar {
  display: flex; align-items: center; gap: 10px;
  height: 60px; padding: 0 10px;
  padding-top: env(safe-area-inset-top);
  background: linear-gradient(180deg, #0c0c11, #08080b);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 #000, 0 8px 24px rgba(0,0,0,0.5);
  position: relative; z-index: 30;
}
#topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-glow) 50%, transparent);
}
.wordmark { height: 24px; object-fit: contain; }
.spacer { flex: 1; }
.case-select {
  background: var(--panel); color: var(--txt); border: 1px solid var(--line);
  border-radius: 9px; height: var(--tap); padding: 0 10px; max-width: 50vw; font-size: 15px; font-weight: 600;
}
.icon-btn {
  min-width: var(--tap); height: var(--tap); border-radius: 9px;
  background: var(--panel); color: var(--txt); border: 1px solid var(--line);
  font-size: 22px; line-height: 1; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--panel-2); }
#navToggle { display: none; min-width: 52px; height: 52px; font-size: 26px; }

/* ---- layout ---- */
#body { flex: 1; display: flex; min-height: 0; }
#sidebar {
  width: 230px; flex-shrink: 0; overflow-y: auto;
  background: var(--bg-2); border-right: 1px solid var(--line);
  padding: 10px 8px calc(20px + env(safe-area-inset-bottom));
}
.nav-section {
  font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--txt-faint); padding: 14px 12px 6px;
}
.nav-item {
  display: flex; padding: 13px 14px; margin: 3px 0; border-radius: 10px;
  color: var(--txt-dim); text-decoration: none; cursor: pointer; font-size: 15px;
  min-height: var(--tap); align-items: center; gap: 10px;
}
.nav-item:hover { background: var(--panel); color: var(--txt); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(255,196,14,0.16), rgba(255,196,14,0.02));
  color: #fff; box-shadow: inset 2px 0 0 var(--gold);
}
#main { flex: 1; overflow-y: auto; padding: 18px 20px calc(40px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }

/* ---- headings ---- */
.page-head { display: flex; align-items: center; gap: 12px; margin: 2px 0 16px; flex-wrap: wrap; }
.page-head h1 {
  margin: 0; font-size: 22px; letter-spacing: .02em; font-weight: 800;
  background: linear-gradient(180deg, var(--chrome-1), var(--chrome-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.page-head .sub { color: var(--txt-faint); font-size: 13px; }
.page-head .spacer { flex: 1; }
.laser { height: 1px; background: linear-gradient(90deg, transparent, var(--gold-glow), transparent); margin: 4px 0 18px; }

/* ---- buttons ---- */
.btn {
  height: var(--tap); padding: 0 16px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--txt);
  font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
  border-color: var(--gold-deep); color: var(--on-gold); box-shadow: 0 4px 16px rgba(255,196,14,0.28);
}
.btn.ghost { background: transparent; }
.btn.sm { height: 34px; padding: 0 11px; font-size: 13px; }
.btn.danger { color: var(--red); border-color: var(--line-danger); }

/* ---- cards / panels ---- */
.grid { display: grid; gap: 14px; }
.cards { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px;
}
.case-card.active { border-color: var(--gold-deep); box-shadow: 0 0 0 1px var(--gold-deep), 0 8px 24px rgba(255,196,14,0.1); }
.case-stats { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 12px; color: var(--txt-dim); font-size: 13px; }
.case-stats b { color: var(--txt); font-weight: 800; }

.stat { padding: 16px; }
.stat .n { font-size: 30px; font-weight: 800; background: linear-gradient(180deg, var(--chrome-1), var(--chrome-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat .l { color: var(--txt-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; margin-top: 4px; }

/* ---- list rows ---- */
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 11px; margin-bottom: 8px;
}
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .meta { color: var(--txt-dim); font-size: 12.5px; margin-top: 2px; }
.row .meta b { color: var(--txt); font-weight: 600; }
.row-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ---- chips / states ---- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px;
  border-radius: 999px; font-size: 12px; font-weight: 700; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--txt-dim); white-space: nowrap;
}
.chip.marked { color: var(--txt-dim); }
.chip.offered { color: var(--warn); border-color: #4a3a10; background: #1d180a; }
.chip.admitted { color: var(--good); border-color: #143a20; background: #0c1d12; }
.chip.refused { color: var(--red); border-color: var(--line-danger); background: #1d0b0e; }
.chip.limited { color: #6fd0ff; border-color: #103040; background: #0a1820; }
.chip.open { color: var(--txt-dim); }
.chip.supported { color: var(--warn); border-color: #4a3a10; background: #1d180a; }
.chip.proved { color: var(--good); border-color: #143a20; background: #0c1d12; }
.chip.cite { color: #7fd6ff; border-color: #123040; background: #0a1620; font-family: ui-monospace, Menlo, monospace; cursor: pointer; }
.chip.flag { color: var(--red); border-color: var(--line-danger); background: #1d0b0e; }

/* ---- segmented control for exhibit state ---- */
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.seg button {
  height: 32px; padding: 0 10px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--txt-dim); font-size: 12px; font-weight: 700; cursor: pointer;
}
.seg button.on { color: var(--on-gold); background: linear-gradient(180deg, var(--gold), var(--gold-deep)); border-color: var(--gold-deep); }

/* ---- toolbar / filters ---- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filter { display: inline-flex; gap: 4px; }
.filter button {
  height: 36px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--txt-dim); font-size: 13px; cursor: pointer;
}
.filter button.on { color: #fff; border-color: var(--gold-deep); background: rgba(255,196,14,0.14); }
.search { flex: 1; min-width: 140px; height: 40px; }

/* ---- forms ---- */
input, select, textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); color: var(--txt);
  border-radius: 9px; padding: 11px 12px; font-size: 15px; font-family: inherit;
}
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold-deep); box-shadow: 0 0 0 3px rgba(255,196,14,0.16); }
label { display: block; font-size: 12px; color: var(--txt-dim); margin: 12px 0 5px; text-transform: uppercase; letter-spacing: .06em; }
.form-grid { display: grid; gap: 0 14px; grid-template-columns: 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }
.field-mono { font-family: ui-monospace, Menlo, monospace; }

/* ---- modal ---- */
#modal-root:empty { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center; z-index: 100;
}
.modal {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-top: 2px solid var(--gold);
  border-radius: 16px 16px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  animation: slideup .18s ease;
}
@keyframes slideup { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 720px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 16px; border-top: 2px solid var(--gold); }
}
.modal h2 { margin: 2px 0 6px; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; margin-top: 18px; }
.modal-actions .spacer { flex: 1; }

/* ---- toast ---- */
#toast-root { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 200; pointer-events: none; }
.toast {
  background: #15151c; border: 1px solid var(--line); border-left: 3px solid var(--gold);
  color: var(--txt); padding: 11px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6); max-width: 90vw; animation: slideup .15s ease;
}
.toast.ok { border-left-color: var(--good); }
.toast.err { border-left-color: var(--red); }

/* ---- AI output ---- */
.ai-section { margin-bottom: 18px; }
.ai-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--txt-dim); margin: 0 0 8px; }
.ai-item { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; margin-bottom: 8px; }
.ai-item .pt { font-weight: 600; }
.ai-item .q { color: var(--txt-dim); font-size: 13px; font-style: italic; margin: 5px 0; border-left: 2px solid var(--line-hot); padding-left: 9px; }
.ai-item .foot { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }

.empty { color: var(--txt-faint); text-align: center; padding: 40px 16px; }
.loading { color: var(--txt-faint); padding: 30px; text-align: center; }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.tally { display: inline-flex; gap: 14px; align-items: center; }
.tally .for { color: var(--good); font-weight: 800; }
.tally .against { color: var(--red); font-weight: 800; }

.fav { display: inline-flex; gap: 3px; }
.fav button { width: 30px; height: 30px; border-radius: 7px; border: 1px solid var(--line); background: var(--bg-2); color: var(--txt-dim); font-weight: 800; cursor: pointer; }
.fav button.on.pos { color: var(--good); border-color: #143a20; }
.fav button.on.neg { color: var(--red); border-color: var(--line-danger); }

/* ---- temperature (juror + court vibe) ---- */
:root {
  --t-cold: #3b82f6; --t-cool: #22c0c8; --t-neutral: #8a8a96; --t-warm: #ffb02e; --t-hot: #ff5a36;
}
.heat { display: inline-flex; gap: 4px; }
.heat button {
  flex: 1; min-width: 30px; height: 34px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-2); cursor: pointer; font-size: 11px; font-weight: 800; color: var(--txt-faint);
  transition: transform .08s;
}
.heat button:active { transform: scale(0.95); }
.heat button[data-t="-2"].on { background: var(--t-cold); border-color: var(--t-cold); color: #fff; }
.heat button[data-t="-1"].on { background: var(--t-cool); border-color: var(--t-cool); color: #06222a; }
.heat button[data-t="0"].on  { background: var(--t-neutral); border-color: var(--t-neutral); color: #0a0a0a; }
.heat button[data-t="1"].on  { background: var(--t-warm); border-color: var(--t-warm); color: #2a1c00; }
.heat button[data-t="2"].on  { background: var(--t-hot); border-color: var(--t-hot); color: #fff; }
.temp-chip { display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 11.5px; font-weight: 800; border: 1px solid; }
.t--2 { color: var(--t-cold); border-color: var(--t-cold); background: rgba(59,130,246,0.12); }
.t--1 { color: var(--t-cool); border-color: var(--t-cool); background: rgba(34,192,200,0.12); }
.t-0  { color: #c8c8d2; border-color: var(--t-neutral); background: rgba(138,138,150,0.14); }
.t-1  { color: var(--t-warm); border-color: var(--t-warm); background: rgba(255,176,46,0.12); }
.t-2  { color: var(--t-hot); border-color: var(--t-hot); background: rgba(255,90,54,0.14); }

.eng { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.eng button { height: 30px; padding: 0 9px; border-radius: 7px; border: 1px solid var(--line); background: var(--bg-2); color: var(--txt-dim); font-size: 12px; cursor: pointer; }
.eng button.on { border-color: var(--gold-deep); background: rgba(255,196,14,0.12); color: #fff; }
.eng button.on[data-e="asleep"] { border-color: var(--t-cold); background: rgba(59,130,246,0.16); color: #cfe0ff; }

/* court-temperature thermometer */
.thermo { height: 14px; border-radius: 999px; background: linear-gradient(90deg, var(--t-cold), var(--t-cool), var(--t-neutral), var(--t-warm), var(--t-hot)); position: relative; margin: 10px 0 6px; }
.thermo .pin { position: absolute; top: -5px; width: 8px; height: 24px; border-radius: 4px; background: #fff; box-shadow: 0 0 0 2px #000, 0 2px 8px rgba(0,0,0,0.6); transform: translateX(-50%); }

/* ---- mobile ---- */
@media (max-width: 760px) {
  #navToggle { display: inline-flex; }
  #sidebar {
    position: fixed; top: 60px; bottom: 0; left: 0; z-index: 25;
    transform: translateX(-100%); transition: transform .2s ease; width: 264px;
    box-shadow: 12px 0 40px rgba(0,0,0,0.6);
  }
  #sidebar.open { transform: none; }
  .form-grid { grid-template-columns: 1fr; }
  #main { padding: 14px 12px calc(40px + env(safe-area-inset-bottom)); }
}
/* ---- login overlay ---- */
.login-overlay {
  position: fixed; inset: 0; z-index: 300; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(900px 500px at 50% -10%, #1a1402 0%, var(--bg) 60%); padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top));
}
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-top: 2px solid var(--gold); border-radius: 16px; padding: 22px 20px calc(22px + env(safe-area-inset-bottom)); box-shadow: 0 30px 70px rgba(0,0,0,0.7); }
.login-logo { width: 100%; max-height: 40px; object-fit: contain; margin: 4px 0 18px; }
.login-tabs { display: flex; gap: 6px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 4px; margin-bottom: 16px; }
.login-tabs .lt { flex: 1; height: 38px; border: 0; border-radius: 7px; background: transparent; color: var(--txt-dim); font-weight: 700; font-size: 13px; cursor: pointer; }
.login-tabs .lt.on { background: linear-gradient(180deg, var(--gold), var(--gold-deep)); color: var(--on-gold); }
.login-form label { margin-top: 12px; }
.login-err { color: var(--red); font-size: 13px; min-height: 16px; margin-top: 10px; }
.login-foot { text-align: center; color: var(--txt-faint); font-size: 12px; margin-top: 16px; letter-spacing: .03em; }
.code-box { font-family: ui-monospace, Menlo, monospace; font-size: 22px; font-weight: 800; letter-spacing: .08em; text-align: center; padding: 16px; border-radius: 12px; background: var(--bg-2); border: 1px dashed var(--gold-deep); color: var(--gold); }

/* ---- co-pilot ---- */
#copilotFab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 90;
  width: 60px; height: 60px; border-radius: 50%; padding: 0; cursor: pointer;
  border: 2px solid var(--gold); background: #000; overflow: hidden;
  box-shadow: 0 6px 24px rgba(255,196,14,0.35), 0 4px 16px rgba(0,0,0,0.6);
}
#copilotFab img { width: 100%; height: 100%; object-fit: cover; display: block; }
#copilotFab:active { transform: scale(0.96); }
#copilot {
  position: fixed; z-index: 95; display: flex; flex-direction: column;
  right: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
  width: 400px; max-width: calc(100vw - 24px); height: 540px; max-height: calc(100dvh - 90px);
  background: var(--panel); border: 1px solid var(--line); border-top: 2px solid var(--gold);
  border-radius: 16px; box-shadow: 0 24px 60px rgba(0,0,0,0.7); overflow: hidden;
  animation: slideup .18s ease;
}
#copilot.hidden { display: none; }
.copilot-head { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.copilot-title { font-weight: 800; background: linear-gradient(180deg, var(--chrome-1), var(--chrome-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.copilot-sub { grid-column: 1; font-size: 11.5px; color: var(--txt-faint); }
.copilot-head .icon-btn { grid-row: 1 / span 2; height: 36px; min-width: 36px; }
.copilot-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }
.cp-msg { max-width: 86%; padding: 10px 12px; border-radius: 12px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.cp-msg.user { align-self: flex-end; background: linear-gradient(180deg, var(--gold), var(--gold-deep)); color: var(--on-gold); border-bottom-right-radius: 4px; font-weight: 600; }
.cp-msg.bot { align-self: flex-start; background: var(--bg-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.cp-msg.bot.thinking { color: var(--txt-faint); }
.cp-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.cp-hint { color: var(--txt-faint); font-size: 12.5px; text-align: center; padding: 10px; }
.copilot-input { display: flex; gap: 8px; align-items: flex-end; padding: 10px; border-top: 1px solid var(--line); }
.copilot-input textarea { flex: 1; min-height: 44px; max-height: 120px; resize: none; padding: 11px 12px; }
.copilot-input .icon-btn { height: 44px; }
#copilotMic.rec { border-color: var(--red-deep); color: var(--red); background: #1d0b0e; }
@media (max-width: 760px) {
  #copilot { right: 0; left: 0; bottom: 0; width: 100%; max-width: 100%; height: 78dvh; border-radius: 16px 16px 0 0; }
}

.scrim { position: fixed; inset: 60px 0 0 0; background: rgba(0,0,0,0.5); z-index: 20; display: none; }
.scrim.show { display: block; }
@media (min-width: 761px) { .scrim { display: none !important; } }
