/* One stylesheet, dark, restrained. No framework. The dashboard's own
   rules live in dashboard.css under .db; the map's in map/map.css. */

:root {
  --bg: #0f1216;
  --panel: #161b21;
  --panel-2: #1d242c;
  --line: #262e37;
  --text: #d7dde3;
  --muted: #8a949e;
  --accent: #6aa1d8;
  --accent-dim: #3e6491;
  --ok: #62a87c;
  --bad: #c76f6f;
  --radius: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.3rem; font-weight: 600; margin: 0 0 1rem; }
h2 { font-size: 1rem; font-weight: 600; margin: 0 0 0.75rem; }
h2 .muted { font-weight: 400; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }
.error { color: var(--bad); }

/* --- frame ------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.6rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; letter-spacing: 0.04em; }

.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { color: var(--text); opacity: 0.85; }
.topbar nav a:hover { opacity: 1; text-decoration: none; color: var(--accent); }

/* At phone width the one-row bar overflowed to 411 px for an admin (three
   links and the account menu), so every page scrolled sideways: the bar
   wraps and the menu keeps the right edge. */
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; gap: 0.5rem 1rem; padding: 0.5rem 0.9rem; }
  .topbar nav { flex: 1 1 auto; gap: 0.75rem; }
  .menu { margin-left: auto; }
}

.who { color: var(--muted); font-size: 0.85rem; }

/* the account menu - a <details>, so it needs no script */
.menu { position: relative; }
.menu summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.85rem;
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover, .menu[open] summary { color: var(--text); border-color: var(--accent-dim); background: var(--panel-2); }
.caret {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
}
.menu[open] .caret { transform: rotate(180deg); }
.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 13rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  z-index: 10;
}
.menu-panel .who { display: block; padding: 0.3rem 0.5rem 0.55rem; border-bottom: 1px solid var(--line); margin-bottom: 0.3rem; }
.menu-panel a { color: var(--text); padding: 0.35rem 0.5rem; border-radius: 4px; }
.menu-panel a:hover { background: var(--panel); color: var(--accent); text-decoration: none; }
.menu-panel form { margin: 0.3rem 0 0; }
.menu-panel button { width: 100%; text-align: left; }

.page { padding: 1.25rem; max-width: 1200px; margin: 0 auto; }

/* --- forms and buttons -------------------------------------------------- */

label { display: block; margin-bottom: 0.75rem; color: var(--muted); font-size: 0.85rem; }

input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.45rem 0.6rem;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-dim);
}

button {
  padding: 0.45rem 0.9rem;
  background: var(--accent-dim);
  color: var(--text);
  border: none;
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
}

button:hover { background: var(--accent); color: #10141a; }
button:disabled { opacity: 0.5; cursor: default; }

button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 0.25rem 0.6rem;
  font-size: 0.85rem;
}

button.ghost:hover { color: var(--text); border-color: var(--accent-dim); }
button.ghost.danger:hover { color: var(--bad); border-color: var(--bad); }

form.inline { display: inline-block; margin: 0 0.25rem 0 0; }
form.inline select { display: inline-block; width: auto; margin: 0 0.25rem 0 0; }
form.stack { max-width: 24rem; }

/* --- auth cards --------------------------------------------------------- */

.auth-card {
  max-width: 22rem;
  margin: 4rem auto;
  padding: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* --- the operations page's cards ----------------------------------------- */

.cards { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1.25rem; }

.card {
  flex: 1 1 10rem;
  padding: 0.9rem 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.card-value { display: block; font-size: 1.45rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.card-label { display: block; color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }

/* the navigation loading bar - the only hint on a slow page load */
body.nav-loading::before {
  content: "";
  position: fixed;
  top: 0;
  left: -30%;
  height: 2px;
  width: 30%;
  background: var(--accent);
  z-index: 100;
  animation: loadbar 1.2s ease-in-out infinite;
}
@keyframes loadbar { to { left: 100%; } }
@media (prefers-reduced-motion: reduce) {
  body.nav-loading::before { animation: none; left: 0; width: 100%; opacity: 0.5; }
}

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.panel {
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
}
.panel.wide { grid-column: 1 / -1; }

@media (max-width: 800px) {
  .grid { grid-template-columns: 1fr; }
}

/* --- tables ------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }

table.list th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
  border-bottom: 1px solid var(--line);
}

table.list td { padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line); }
table.list tr:last-child td { border-bottom: none; }
table.list th.num { text-align: right; }
tr.inactive td { opacity: 0.5; }

td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.error-cell { color: var(--bad); font-size: 0.8rem; max-width: 24rem; }
td.prompt-cell {
  max-width: 18rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

/* --- badges -------------------------------------------------------------- */

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
}
.badge.ok { color: var(--ok); border-color: var(--ok); background: transparent; }
.badge.bad { color: var(--bad); border-color: var(--bad); background: transparent; }

/* --- chat ---------------------------------------------------------------- */

.chat-shell { max-width: none; height: calc(100vh - 3.2rem); padding: 0; }

.chat { display: flex; height: 100%; }

.chat-side {
  width: 17rem;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 1rem;
  overflow-y: auto;
}

.new-session { margin-bottom: 1rem; }
.new-session button { width: 100%; }

.session-list { list-style: none; margin: 0; padding: 0; }
.session-list li { border-radius: var(--radius); margin-bottom: 0.25rem; }
.session-list li.current { background: var(--panel-2); }
.session-list a { display: block; padding: 0.5rem 0.6rem; color: var(--text); }
.session-list a:hover { text-decoration: none; background: var(--panel-2); border-radius: var(--radius); }
.s-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}
.s-meta { display: block; color: var(--muted); font-size: 0.75rem; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-head {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
  min-height: 2.1rem;
}

.messages { flex: 1; overflow-y: auto; padding: 1rem; }

.msg {
  max-width: 46rem;
  margin: 0 auto 0.75rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.msg.user { background: var(--accent-dim); color: #eef3f8; }
.msg.assistant { background: var(--panel); border: 1px solid var(--line); }
.msg.tool { color: var(--muted); font-size: 0.8rem; padding: 0.1rem 0.8rem; }
.msg.error { color: var(--bad); border: 1px solid var(--bad); }

.composer {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.composer textarea { flex: 1; resize: none; margin: 0; }
.composer button { align-self: flex-end; }

.hint { margin: 4rem auto; color: var(--muted); }

/* one failing dashboard card shows a banner, never a 500 */
.banner-error {
  background: #4a1d1d;
  border: 1px solid #7a2e2e;
  color: #f0caca;
  padding: 0.6rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}

/* collapsed tool and reasoning lines - click to expand */
.evt { margin: 0.15rem 0 0.15rem 0.5rem; font-size: 12px; color: #8a8f98; }
.evt summary { cursor: pointer; list-style-position: inside; }
.evt summary:hover { color: #b8bdc6; }
.evt pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #16181d;
  border: 1px solid #262a31;
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
  margin: 0.3rem 0 0.3rem 1rem;
  font-size: 12px;
  color: #aeb4bd;
}
.evt.thinking summary { font-style: italic; }

/* the turn-in-flight indicator */
.working { margin: 0.3rem 0 0.3rem 0.5rem; font-size: 12px; color: #8a8f98; }
.working::after { content: " ..."; }
.working { animation: working-pulse 1.4s ease-in-out infinite; }
@keyframes working-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* the grouped activity block and its steps */
.evt.activity .steps { margin: 0.3rem 0 0.3rem 1rem; }
.step { margin: 0.35rem 0; }
.step-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6d727b;
  margin-bottom: 0.15rem;
}

/* markdown inside assistant bubbles */
.msg.assistant table { border-collapse: collapse; margin: 0.5rem 0; display: block; overflow-x: auto; }
.msg.assistant th, .msg.assistant td {
  border: 1px solid #2b2f36;
  padding: 0.3rem 0.6rem;
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
}
.msg.assistant th { background: #1c1f24; }
.msg.assistant code {
  background: #16181d;
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
  font-size: 12.5px;
}
.msg.assistant pre { background: #16181d; border-radius: 6px; padding: 0.5rem 0.7rem; overflow-x: auto; }
.msg.assistant pre code { background: none; padding: 0; }
.msg.assistant p { margin: 0.4rem 0; }
.msg.assistant ul, .msg.assistant ol { margin: 0.4rem 0 0.4rem 1.2rem; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3 { font-size: 15px; margin: 0.6rem 0 0.3rem; }
