:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --border: #e2dfd6;
  --text: #1d1c1a;
  --muted: #6b675e;
  --accent: #c8643f;
  --accent-text: #ffffff;
  --low: #2f7d4f;
  --low-bg: #e3f2e8;
  --med: #9a6a00;
  --med-bg: #fbf0d4;
  --high: #b3261e;
  --high-bg: #fbe3e0;
  --code-bg: #f1efe9;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --border: #2a2f39;
    --text: #ecebe7;
    --muted: #9a978f;
    --accent: #e0805c;
    --accent-text: #1a0f0a;
    --low: #6fcf97;
    --low-bg: #16301f;
    --med: #f2c14e;
    --med-bg: #33290f;
    --high: #ff8a80;
    --high-bg: #3a1714;
    --code-bg: #12151a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
code, pre { font-family: var(--mono); font-size: 13px; }

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 600; border-radius: 10px;
  padding: 11px 16px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; min-height: 44px;
  transition: transform .06s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn-ghost { background: transparent; }
.btn-approve { background: var(--low); border-color: var(--low); color: #fff; }
.btn-deny { background: var(--high); border-color: var(--high); color: #fff; }
.btn-danger-ghost { color: var(--high); }
/* The recommended answer is solid; the other one is just an outline. */
.btn-approve:not(.recommended) { background: transparent; color: var(--low); }
.btn-deny:not(.recommended) { background: transparent; color: var(--high); }
.btn.recommended::after { content: "★"; font-size: 11px; opacity: .85; }
@media (prefers-color-scheme: dark) {
  .btn-approve.recommended, .btn-deny.recommended { color: #0f1115; }
}

input {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; margin: 4px 0 12px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { font-size: 13px; color: var(--muted); font-weight: 600; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 32px 24px; box-shadow: var(--shadow); text-align: center;
}
.login-logo { width: 56px; height: 56px; }
.login-card h1 { font-size: 22px; margin: 14px 0 4px; }
.login-card p { margin: 0 0 22px; }
.setup { margin-top: 18px; text-align: left; }
.setup summary { cursor: pointer; color: var(--muted); font-size: 14px; text-align: center; padding: 6px; }
.setup[open] summary { margin-bottom: 12px; }
.error { color: var(--high); min-height: 1.2em; margin: 14px 0 0 !important; font-size: 14px; }

/* ---------- app shell ---------- */
.app { max-width: 760px; margin: 0 auto; padding-bottom: 40px; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 16px 10px; background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; margin-right: auto; }
.brand img { border-radius: 6px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  padding: 5px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-pill.on { color: var(--low); background: var(--low-bg); }
.status-pill.on .dot { background: var(--low); box-shadow: 0 0 0 3px color-mix(in srgb, var(--low) 30%, transparent); }
.status-pill.off { color: var(--high); background: var(--high-bg); }
.status-pill.off .dot { background: var(--high); }

.tabs {
  position: sticky; top: 56px; z-index: 4; display: flex; gap: 4px; padding: 4px 16px 10px;
  background: var(--bg); overflow-x: auto; scrollbar-width: none;
}
.tabs button {
  flex: 1 0 auto; appearance: none; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; font-size: 14px; padding: 9px 12px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); border: 1px solid var(--border); }
.badge {
  background: var(--accent); color: var(--accent-text); border-radius: 999px; font-size: 11px;
  min-width: 18px; height: 18px; padding: 0 5px; display: inline-grid; place-items: center;
}
.panel { padding: 4px 16px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 0 10px; }

/* ---------- approvals ---------- */
.approval {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
  animation: pop .25s ease;
}
@keyframes pop { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }
.approval-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.risk { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.risk.low { color: var(--low); background: var(--low-bg); }
.risk.medium { color: var(--med); background: var(--med-bg); }
.risk.high { color: var(--high); background: var(--high-bg); }
.tool-name { font-weight: 700; }
.countdown { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.approval h3 { font-size: 16px; margin: 0 0 8px; }
.approval .reason { font-size: 14px; color: var(--muted); margin: 10px 0 14px; }
.code {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto; margin: 0;
}
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions .btn-handoff { grid-column: 1 / -1; font-weight: 500; font-size: 14px; min-height: 38px; }
.rec-note { grid-column: 1 / -1; font-size: 12px; color: var(--muted); text-align: center; margin: -2px 0 0; }

.history { list-style: none; padding: 0; margin: 0; }
.history li {
  display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px;
}
.history .what { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.outcome { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.outcome.allow { color: var(--low); background: var(--low-bg); }
.outcome.deny { color: var(--high); background: var(--high-bg); }

.empty { text-align: center; padding: 34px 16px 10px; }
.empty p { margin: 4px 0; }
.empty-icon {
  width: 52px; height: 52px; border-radius: 50%; background: var(--low-bg); color: var(--low);
  display: grid; place-items: center; font-size: 24px; margin: 0 auto 10px; font-weight: 700;
}

/* ---------- activity ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 7px 12px; font: inherit; font-size: 13px; cursor: pointer; max-width: 240px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .st { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--muted); vertical-align: middle; }
.chip .st.working { background: var(--accent); }
.chip .st.waiting { background: var(--med); }

.timeline { list-style: none; margin: 8px 0 0; padding: 0; }
.ev { position: relative; padding: 0 0 14px 30px; }
.ev::before { content: ""; position: absolute; left: 10px; top: 24px; bottom: 0; width: 2px; background: var(--border); }
.ev:last-child::before { display: none; }
.ev-icon {
  position: absolute; left: 0; top: 2px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; background: var(--surface-2); color: var(--muted);
}
.ev-body { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 9px 12px; }
.ev-top { display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.ev-kind { font-weight: 700; }
.ev-time { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ev-summary { margin-top: 3px; font-size: 14px; word-break: break-word; }
.ev details summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 6px; }
.ev details .code { margin-top: 6px; font-size: 12px; }
.ev.prompt .ev-body { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.ev.prompt .ev-time { color: inherit; opacity: .8; }
.ev.prompt .ev-icon { background: var(--accent); color: var(--accent-text); }
.ev.reply .ev-icon { background: var(--low-bg); color: var(--low); }
.ev.ask .ev-icon { background: var(--med-bg); color: var(--med); }
.ev.fail .ev-icon, .ev.denied .ev-icon { background: var(--high-bg); color: var(--high); }

/* ---------- server ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 620px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.tile .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.tile .v { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--muted); }
.meter { height: 6px; border-radius: 99px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--low); border-radius: inherit; }
.meter i.warn { background: var(--med); }
.meter i.bad { background: var(--high); }
.rows { list-style: none; padding: 0; margin: 0 0 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.rows li { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.rows li:last-child { border-bottom: 0; }
.rows .name { flex: 1; font-weight: 600; }
.log { background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto; font-size: 12px; margin: 0; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  font-weight: 600; box-shadow: 0 6px 24px rgba(0,0,0,.2); z-index: 20; max-width: calc(100% - 32px);
}
