:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-2: #f0f3f7;
  --text: #16202c;
  --muted: #64748b;
  --line: #dde3ea;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --panel: #16213a;
    --panel-2: #1c2842;
    --text: #e6edf6;
    --muted: #94a3b8;
    --line: #2b3a55;
    --accent: #60a5fa;
    --accent-ink: #0b1220;
    --ok: #86efac;
    --ok-bg: #14532d;
    --warn: #fcd34d;
    --warn-bg: #78350f;
    --bad: #fca5a5;
    --bad-bg: #7f1d1d;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 6px; font-weight: 650; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
p { margin: 0 0 10px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.error { color: var(--bad); }
button { font: inherit; border: 0; border-radius: 8px; padding: 8px 14px; background: var(--accent); color: var(--accent-ink); cursor: pointer; }
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
label { display: block; margin-bottom: 10px; }
label input, label select { display: block; width: 100%; margin-top: 4px; }
.row { display: flex; gap: 8px; align-items: center; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.tag { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; background: var(--warn-bg); color: var(--warn); border-radius: 999px; padding: 2px 8px; vertical-align: middle; margin-left: 6px; }

/* login */
.screen { min-height: 100%; }
#login { display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); }
.login-card button { width: 100%; margin-top: 6px; }

/* app frame */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 2; }
.brand { font-weight: 700; font-size: 16px; }
.topbar-right { display: flex; gap: 12px; align-items: center; }
.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr) 380px; gap: 14px; padding: 14px; height: calc(100vh - 53px); }
.sidebar, .main, .chat { min-height: 0; overflow: auto; }
.sidebar { display: flex; flex-direction: column; gap: 12px; }
.side-block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.side-title { display: flex; justify-content: space-between; align-items: center; font-weight: 650; margin-bottom: 8px; gap: 8px; }
.side-title input[type=date] { padding: 4px 6px; font-size: 12px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 8px; border-radius: 8px; cursor: pointer; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li:hover { background: var(--panel-2); }
.list li.active { background: var(--panel-2); outline: 1px solid var(--accent); }
.list .l1 { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.list .l2 { font-size: 12px; color: var(--muted); }
.list .l3 { font-size: 12px; margin-top: 2px; }
#search-form input { flex: 1; }

/* profile */
.empty { display: grid; place-items: center; text-align: center; height: 100%; padding: 30px; }
.profile-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.section-title { font-weight: 650; margin-bottom: 8px; }
.score-grid { display: grid; grid-template-columns: 120px repeat(6, 1fr); gap: 6px 10px; align-items: center; font-size: 13px; }
.score-grid .h { color: var(--muted); font-size: 12px; text-align: center; }
.score-grid .eye { font-weight: 650; }
.pill { display: inline-block; min-width: 46px; text-align: center; padding: 2px 8px; border-radius: 999px; font-weight: 650; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.mid { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.na { background: var(--panel-2); color: var(--muted); }
.warnings { margin-top: 8px; font-size: 12px; color: var(--muted); }
.warnings div::before { content: "⚠ "; }
.flags { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 12px; }
.flag { border-radius: 999px; padding: 2px 10px; background: var(--warn-bg); color: var(--warn); }
.flag.note { background: var(--panel-2); color: var(--muted); }
table.params { width: 100%; border-collapse: collapse; font-size: 13px; }
table.params th, table.params td { padding: 5px 6px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.params th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.params td.name, table.params th.name { text-align: left; white-space: normal; }
table.params td.unit { color: var(--muted); font-size: 12px; text-align: left; }
table.params td.na { color: var(--muted); }
table.params td.derived { font-style: italic; }
details summary { cursor: pointer; font-weight: 600; }
#uncatalogued, #provenance { margin-top: 8px; white-space: pre-wrap; }

/* GRI model suggestion */
.sug-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sug-eye { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--panel-2); }
.sug-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.sug-head .eye { font-weight: 700; }
.sug-bar { display: grid; grid-template-columns: 90px 1fr 42px; gap: 8px; align-items: center; font-size: 12px; margin: 3px 0; }
.sug-track { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.sug-fill { display: block; height: 100%; background: var(--accent); }
.sug-fill.non { background: var(--bad); }
.sug-v { text-align: right; color: var(--muted); }
.sug-flags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; font-size: 12px; }
#sug-notes { margin-top: 10px; }
@media (max-width: 900px) { .sug-grid { grid-template-columns: 1fr; } }

/* chat */
.chat { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 650; }
.chat-empty { padding: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px 0; }
.chips button { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); padding: 5px 10px; font-size: 12px; border-radius: 999px; }
.messages { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 100%; padding: 8px 12px; border-radius: 10px; white-space: normal; font-size: 13px; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); white-space: pre-wrap; }
.msg.assistant { align-self: stretch; background: var(--panel-2); }
.msg.assistant p { margin: 0 0 8px; }
.msg.assistant p:last-child { margin: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 4px 0 8px 18px; padding: 0; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3 { font-size: 13px; margin: 8px 0 4px; }
.msg.error { background: var(--bad-bg); color: var(--bad); }
.msg .meta { display: block; margin-top: 6px; font-size: 11px; color: var(--muted); }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.chat-form textarea { flex: 1; resize: vertical; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr); height: auto; }
  .chat { grid-column: 1 / -1; height: 60vh; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
}
