/* Mobile first. Every rule here is the phone layout; the one media query at
   the bottom widens things for a desktop browser. Touch targets are 44px
   minimum. */

:root {
  --bg: #0f1115;
  --panel: #171a21;
  --line: #262b35;
  --ink: #e6e9ef;
  --muted: #8b93a3;
  --accent: #6ea8fe;
  --good: #5fb87a;
  --danger: #e0684f;
  --radius: 12px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --line: #e2e5ea;
    --ink: #171a21;
    --muted: #616a7a;
    --accent: #2f6fd0;
    --good: #3d8b58;
  }
}

* { box-sizing: border-box; }

/* The UA rule for [hidden] is `display: none`, which any class selector that
   sets display beats on specificity. Make hidden mean hidden. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea, select { font: inherit; color: inherit; }
/* 16px is the threshold below which iOS Safari zooms the page on focus, which
   then leaves the layout scrolled sideways. Never shrink an input's font. */
input, textarea, select { font-size: 16px; }

.muted { color: var(--muted); }
.error { color: var(--danger); }

input, textarea, select {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  width: 100%;
  min-height: 44px;
}
textarea { resize: vertical; }

button {
  background: var(--accent);
  color: #0b0d12;
  border: 0;
  border-radius: var(--radius);
  padding: 11px 16px;
  min-height: 44px;
  font-weight: 600;
  cursor: pointer;
}
button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 500;
}
button.danger { color: var(--danger); }

/* ------------------------------------------------------------------ login */

.login {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 24px;
}
.login-box {
  display: grid;
  gap: 12px;
  width: min(360px, 100%);
}
.login-box h1 { margin: 0 0 8px; font-size: 28px; letter-spacing: 0.04em; }

/* ------------------------------------------------------------------ shell */

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.tab {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#tab-chat { padding-bottom: 0; }

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}
.bar h2 { margin: 0; font-size: 18px; }
.bar input[type="search"] { max-width: 55%; }

.tabs {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border-radius: 0;
  font-weight: 500;
  position: relative;
}
.tabs button.on { color: var(--accent); }
.badge {
  position: absolute;
  top: 6px;
  right: 50%;
  transform: translateX(18px);
  background: var(--accent);
  color: #0b0d12;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
}

/* ------------------------------------------------------------------- chat */

.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 8px;
}
.msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #0b0d12;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
}
.msg.error { border-color: var(--danger); color: var(--danger); }

/* The tool trace. Shown as it happens and kept afterwards, because "what did
   it do while I was asleep" is the whole question an assistant has to answer
   for itself. */
.steps {
  align-self: flex-start;
  max-width: 88%;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.steps .step::before { content: "› "; }
.steps .step.bad { color: var(--danger); }

.say {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom) / 2);
  background: var(--bg);
  position: sticky;
  bottom: 0;
}
.say textarea { max-height: 40vh; }
.say button { width: 48px; padding: 0; font-size: 20px; }

/* ------------------------------------------------------------------ lists */

.list { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card.unread { border-color: var(--accent); }
.card h3 { margin: 0; font-size: 16px; }
.card .meta { font-size: 13px; color: var(--muted); }
.card .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.card label { font-size: 13px; color: var(--muted); }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1 1 auto; }
.row > button, .row > .check { flex: 0 0 auto; }
.check { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.check input { width: auto; min-height: 0; }

.out {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  font-size: 13px;
  white-space: pre-wrap;
  overflow-x: auto;
  margin: 0;
}
.pill {
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  color: var(--muted);
}

@media (min-width: 760px) {
  .app { max-width: 780px; margin: 0 auto; width: 100%; }
  .tab { padding: 16px 16px 6px; }
}
