/* Dataset-Agent – utilitarian two-pane tool UI.
   Tokens on :root; dark theme redefines tokens only. System fonts on purpose
   (no external font host: works offline in the container, no GDPR question). */

:root {
  --ground: #f4f6f8;
  --surface: #ffffff;
  --surface-sunk: #edf1f5;
  --ink: #141a21;
  --ink-muted: #56626e;
  --ink-faint: #8593a0;
  --border: #dce2e8;
  --border-strong: #bfc8d2;
  --accent: #1f5c8b;
  --accent-ink: #ffffff;
  --accent-soft: #e7eff6;
  --ok: #2c6549;
  --ok-soft: #e6f2ec;
  --warn: #9c4a16;
  --warn-soft: #faf0e7;
  --err: #a3312b;
  --err-soft: #fbeceb;

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 4px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0e1318;
    --surface: #161d25;
    --surface-sunk: #1c242d;
    --ink: #e3e9ef;
    --ink-muted: #98a5b2;
    --ink-faint: #6e7c8a;
    --border: #28323c;
    --border-strong: #3a4754;
    --accent: #6facd9;
    --accent-ink: #0e1318;
    --accent-soft: #172836;
    --ok: #6dbf97;
    --ok-soft: #14271e;
    --warn: #d8905b;
    --warn-soft: #2a1e14;
    --err: #e2837b;
    --err-soft: #2c1615;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code, pre { font-family: var(--mono); font-size: 0.86em; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* -- buttons ---------------------------------------------------------------- */

.btn-primary {
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: var(--radius);
  padding: 0.55rem 1.1rem; font-weight: 600; cursor: pointer;
}
.btn-primary:disabled { opacity: 0.5; cursor: progress; }

.btn-ghost {
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.35rem 0.75rem;
  color: var(--ink-muted); cursor: pointer; font-size: 0.87rem;
}
.btn-ghost:hover { border-color: var(--border-strong); color: var(--ink); }

/* -- top bar ---------------------------------------------------------------- */

.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.7rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 0.6rem; }
.brand-name { font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { color: var(--ink-faint); font-size: 0.85rem; }
.status { display: flex; gap: 0.4rem; flex-wrap: wrap; flex: 1; }
.actions { display: flex; gap: 0.4rem; }
.actions form { margin: 0; }

.chip {
  font-size: 0.8rem; color: var(--ink-muted);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.18rem 0.5rem; white-space: nowrap;
  max-width: 30rem; overflow: hidden; text-overflow: ellipsis;
}
.chip b { color: var(--ink); font-weight: 600; margin-right: 0.15rem; }
.chip .dim { color: var(--ink-faint); }
.chip-ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; font-weight: 600; }
.chip-warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; font-weight: 600; }

/* -- layout ----------------------------------------------------------------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  height: calc(100vh - 53px);
}

.chat { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }

.messages {
  flex: 1; overflow-y: auto;
  padding: 1.5rem 1.5rem 1rem;
  display: flex; flex-direction: column; gap: 1rem;
}

/* -- empty state ------------------------------------------------------------ */

.empty { max-width: 40rem; margin: 6vh auto 0; }
.empty h1 { font-size: 1.45rem; margin: 0 0 0.5rem; letter-spacing: -0.015em; text-wrap: balance; }
.empty p { color: var(--ink-muted); margin: 0 0 1.25rem; }
.examples { display: flex; flex-direction: column; gap: 0.5rem; }
.example {
  text-align: left; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.65rem 0.85rem; cursor: pointer; color: var(--ink);
}
.example:hover { border-color: var(--accent); }

/* -- messages --------------------------------------------------------------- */

.msg { max-width: 46rem; }
.msg-user {
  align-self: flex-end;
  background: var(--accent-soft); border-radius: var(--radius);
  padding: 0.6rem 0.9rem; white-space: pre-wrap;
}
.msg-agent { align-self: flex-start; }
.msg-agent .who {
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: 0.2rem;
}
.msg-agent .body > :first-child { margin-top: 0; }
.msg-agent .body > :last-child { margin-bottom: 0; }
.msg-agent .body p, .msg-agent .body ul, .msg-agent .body ol { margin: 0 0 0.6rem; }
.msg-agent .body ul, .msg-agent .body ol { padding-left: 1.2rem; }
.msg-agent .body h3, .msg-agent .body h4 { font-size: 1rem; margin: 0.9rem 0 0.3rem; }
.msg-agent .body code { background: var(--surface-sunk); padding: 0.05em 0.3em; border-radius: 3px; }
.msg-agent .body pre { background: var(--surface-sunk); padding: 0.7rem; border-radius: var(--radius); overflow-x: auto; }
.msg-agent .body pre code { background: none; padding: 0; }
.msg-stats { margin-top: 0.4rem; font-size: 0.78rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.msg-error { color: var(--err); background: var(--err-soft); border-radius: var(--radius); padding: 0.6rem 0.9rem; }

.working { display: flex; align-items: center; gap: 0.5rem; color: var(--ink-muted); font-size: 0.9rem; }

/* -- composer --------------------------------------------------------------- */

.composer {
  display: flex; gap: 0.6rem; align-items: flex-end;
  padding: 0.9rem 1.5rem 1.1rem;
  border-top: 1px solid var(--border); background: var(--surface);
}
.composer textarea {
  flex: 1; resize: none; min-height: 2.6rem; max-height: 12rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: 0.55rem 0.7rem; background: var(--ground);
}

/* -- trace ------------------------------------------------------------------ */

.trace { display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.trace-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 0.9rem 1.25rem 0.6rem; border-bottom: 1px solid var(--border);
}
.trace-head h2 {
  margin: 0; font-size: 0.78rem; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--ink-muted);
}
.trace-state { font-size: 0.8rem; color: var(--ink-faint); }
.trace-state.busy { color: var(--accent); font-weight: 600; }

.trace-list { list-style: none; margin: 0; padding: 0.75rem 1.25rem 2rem; overflow-y: auto; flex: 1; }
.trace-list > li { position: relative; padding: 0.35rem 0 0.35rem 1.1rem; font-size: 0.87rem; }
.trace-list > li::before {
  content: ""; position: absolute; left: 0.2rem; top: 0.85rem;
  width: 6px; height: 6px; border-radius: 50%; background: var(--border-strong);
}
.trace-empty { color: var(--ink-faint); padding-left: 0 !important; }
.trace-empty::before { display: none; }

.trace-turn {
  margin-top: 0.9rem; padding-left: 0 !important;
  font-size: 0.75rem !important; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-faint); border-top: 1px solid var(--border); padding-top: 0.7rem !important;
}
.trace-turn:first-child { margin-top: 0; border-top: 0; padding-top: 0 !important; }
.trace-turn::before { display: none; }

.t-thinking { color: var(--ink-muted); }
.t-thinking.active::before { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.t-note { color: var(--ink-muted); font-style: italic; }

.t-tool::before { background: var(--accent); }
.t-tool.ok::before { background: var(--ok); }
.t-tool.err::before { background: var(--err); }
.t-tool .tool-line { display: flex; gap: 0.5rem; align-items: baseline; flex-wrap: wrap; }
.t-tool .tool-name { font-family: var(--mono); font-weight: 600; font-size: 0.84rem; }
.t-tool .tool-args { color: var(--ink-faint); font-family: var(--mono); font-size: 0.78rem; overflow-wrap: anywhere; }
.t-tool .tool-result { color: var(--ink-muted); margin-top: 0.1rem; }
.t-tool.err .tool-result { color: var(--err); }
.t-tool .tool-hint {
  margin-top: 0.25rem; padding: 0.3rem 0.5rem; border-radius: 3px;
  background: var(--warn-soft); color: var(--warn); font-size: 0.8rem;
}
.t-tool .pill {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.04em;
  padding: 0.05rem 0.4rem; border-radius: 3px; background: var(--accent-soft); color: var(--accent);
}
.t-tool.ok .pill { background: var(--ok-soft); color: var(--ok); }
.t-tool.err .pill { background: var(--err-soft); color: var(--err); }

.t-tool details { margin-top: 0.25rem; }
.t-tool summary { cursor: pointer; color: var(--ink-faint); font-size: 0.78rem; }
.t-tool pre {
  margin: 0.3rem 0 0; padding: 0.5rem 0.6rem; max-height: 18rem; overflow: auto;
  background: var(--surface-sunk); border-radius: var(--radius); font-size: 0.76rem;
}

.progress-steps { list-style: none; margin: 0.3rem 0 0; padding: 0 0 0 0.2rem; border-left: 2px solid var(--border); }
.progress-steps li { padding: 0.1rem 0 0.1rem 0.6rem; font-size: 0.8rem; color: var(--ink-muted); }

.t-done { color: var(--ink-faint); font-size: 0.8rem !important; font-variant-numeric: tabular-nums; }
.t-done::before { background: var(--ok) !important; }
.t-error { color: var(--err); }
.t-error::before { background: var(--err) !important; }

.spinner {
  width: 0.8rem; height: 0.8rem; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.3; } }

@media (prefers-reduced-motion: reduce) {
  .spinner, .t-thinking.active::before { animation: none; }
}

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

.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card {
  width: 100%; max-width: 22rem; display: flex; flex-direction: column; gap: 0.55rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.75rem;
}
.login-card h1 { margin: 0 0 0.6rem; font-size: 1.35rem; }
.login-card input {
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: 0.5rem 0.65rem; background: var(--ground);
}
.login-card label { font-size: 0.85rem; color: var(--ink-muted); }
.login-card button { margin-top: 0.5rem; }
.eyebrow {
  margin: 0; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--accent);
}
.form-error { margin: 0; color: var(--err); font-size: 0.87rem; }

/* -- narrow screens: stack chat and trace ---------------------------------- */

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 40vh; height: auto; min-height: calc(100vh - 53px); }
  .chat { border-right: 0; border-bottom: 1px solid var(--border); min-height: 60vh; }
  .topbar { padding: 0.6rem 1rem; }
  .messages, .composer { padding-left: 1rem; padding-right: 1rem; }
}
