:root {
  --bg: #0b1020;
  --surface: #151b30;
  --surface-2: #1d2540;
  --text: #e7ebf5;
  --muted: #8b93ad;
  --accent: #6366f1;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 16px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.screen { min-height: 100vh; display: flex; flex-direction: column; }
.muted { color: var(--muted); }
.error { color: var(--red); }
.brand { font-weight: 700; letter-spacing: .5px; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 12px var(--accent); }

/* Login */
.login { align-items: center; justify-content: center; padding: 24px; }
.login-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 28px 22px; width: 100%; max-width: 360px; text-align: center;
}
.login-card input, #token {
  width: 100%; padding: 14px; margin: 14px 0; border-radius: 12px;
  border: 1px solid var(--surface-2); background: var(--bg); color: var(--text);
  font-size: 16px;
}
.login-card button, #login-btn {
  width: 100%; padding: 14px; border: none; border-radius: 12px;
  background: var(--accent); color: white; font-size: 16px; font-weight: 600;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--surface);
  position: sticky; top: 0; z-index: 5;
  padding-top: max(14px, env(safe-area-inset-top));
}
.pill {
  font-size: 12px; padding: 5px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}
.pill.busy { color: var(--bg); background: var(--accent); }

/* Views */
#views { flex: 1; overflow-y: auto; padding: 16px; padding-bottom: 150px; }
.view { display: none; }
.view.active { display: block; }
h2 { font-size: 18px; margin: 4px 0 16px; }

/* Messages */
.messages { display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 85%; padding: 12px 14px; border-radius: 16px; line-height: 1.45;
  white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: white;
  border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface);
  border-bottom-left-radius: 4px; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 6px; }
.msg .sources { margin-top: 10px; border-top: 1px solid var(--surface-2);
  padding-top: 8px; }
.msg .source { font-size: 12px; margin: 4px 0; }
.msg .source a { color: #a5b4fc; text-decoration: none; }
.chip { display: inline-block; font-size: 10px; padding: 2px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); margin-left: 6px; }
.chip.green { color: var(--green); } .chip.amber { color: var(--amber); }
.chip.red { color: var(--red); } .chip.stale { color: var(--amber); }

/* Activity indicator */
.activity {
  align-self: flex-start; margin-top: 12px; padding: 10px 14px;
  background: var(--surface); border-radius: 16px; color: var(--muted);
  font-size: 14px; display: flex; align-items: center; gap: 10px;
}
.activity .spinner {
  width: 14px; height: 14px; border: 2px solid var(--surface-2);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Lists / cards */
.list { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--surface); border-radius: var(--radius); padding: 16px;
}
.card h3 { margin: 0 0 6px; font-size: 15px; }
.card .row { display: flex; justify-content: space-between; gap: 8px;
  font-size: 13px; color: var(--muted); }
.card .params { font-size: 12px; background: var(--bg); padding: 8px;
  border-radius: 8px; margin: 8px 0; overflow-x: auto; color: var(--muted); }

/* Approval risk banners */
.risk { font-weight: 700; text-transform: uppercase; font-size: 11px;
  padding: 3px 8px; border-radius: 6px; }
.risk.GREEN { background: rgba(34,197,94,.15); color: var(--green); }
.risk.AMBER { background: rgba(245,158,11,.15); color: var(--amber); }
.risk.RED { background: rgba(239,68,68,.15); color: var(--red); }
.approval-actions { display: flex; gap: 10px; margin-top: 12px; }
.approval-actions button { flex: 1; padding: 12px; border: none; border-radius: 10px;
  font-weight: 600; font-size: 15px; }
.btn-approve { background: var(--green); color: #052e12; }
.btn-reject { background: var(--surface-2); color: var(--text); }

/* Composer */
.composer {
  position: fixed; bottom: 56px; left: 0; right: 0; display: flex; gap: 8px;
  padding: 12px 16px; background: var(--surface);
  border-top: 1px solid var(--surface-2);
}
.composer input { flex: 1; padding: 12px 14px; border-radius: 999px;
  border: 1px solid var(--surface-2); background: var(--bg); color: var(--text);
  font-size: 16px; }
.composer button { padding: 12px 18px; border: none; border-radius: 999px;
  background: var(--accent); color: white; font-weight: 600; }

/* Tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex;
  background: var(--surface); border-top: 1px solid var(--surface-2);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab { flex: 1; padding: 14px 4px; background: none; border: none;
  color: var(--muted); font-size: 12px; position: relative; }
.tab.active { color: var(--text); }
.badge { position: absolute; top: 6px; right: 22%; background: var(--red);
  color: white; font-size: 10px; padding: 1px 6px; border-radius: 999px; }
.danger { background: var(--red); color: white; border: none; padding: 12px;
  border-radius: 10px; width: 100%; margin-top: 16px; font-weight: 600; }

/* When composer hidden on non-chat views */
body.no-composer .composer { display: none; }

/* Memory area */
.mem-search { width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--surface-2); background: var(--bg); color: var(--text);
  font-size: 16px; margin-bottom: 12px; }
.mem-card .mem-type { font-size: 10px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--accent); }
.mem-card .mem-meta { font-size: 12px; color: var(--muted); margin-top: 6px;
  display: flex; flex-wrap: wrap; gap: 6px; }
.mem-actions { display: flex; gap: 8px; margin-top: 10px; }
.mem-actions button { flex: 1; padding: 9px; border: none; border-radius: 8px;
  font-size: 13px; background: var(--surface-2); color: var(--text); }
.mem-actions .del { background: rgba(239,68,68,.15); color: var(--red); }
.status-tag { font-size: 10px; padding: 2px 7px; border-radius: 999px; }
.status-tag.superseded { background: rgba(245,158,11,.15); color: var(--amber); }
.status-tag.uncertain { background: rgba(245,158,11,.15); color: var(--amber); }
.status-tag.active { background: rgba(34,197,94,.12); color: var(--green); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; z-index: 20; }
.modal { background: var(--surface); width: 100%; border-radius: 20px 20px 0 0;
  padding: 20px; max-height: 80vh; overflow-y: auto; }
.modal h3 { margin-top: 0; }
.modal .prov { font-size: 13px; color: var(--muted); margin: 8px 0; }
.modal textarea { width: 100%; min-height: 70px; border-radius: 10px;
  border: 1px solid var(--surface-2); background: var(--bg); color: var(--text);
  padding: 10px; font-size: 15px; }
.modal .modal-actions { display: flex; gap: 8px; margin-top: 12px; }
.modal .modal-actions button { flex: 1; padding: 12px; border: none;
  border-radius: 10px; font-weight: 600; }

/* Ensure HTML hidden attribute always hides elements */
[hidden] { display: none !important; }
