/* Task API dashboard.
   Palette values come from the validated reference palette; the ordinal
   priority ramp (--p1..--p3) was validated per mode against each surface. */

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.14);
  /* Meter track: a dimmer step of the fill's own ramp, so state reads
     across the whole bar rather than fill-vs-nothing. */
  --track: #184f95;
  --p1: #86b6ef;
  --p2: #3987e5;
  --p3: #184f95;
}

:root[data-theme="light"] {
  color-scheme: light;
  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, 0.10);
  /* Meter track: a lighter step of the fill's own ramp. */
  --track: #cde2fb;
  --p1: #86b6ef;
  --p2: #2a78d6;
  --p3: #104281;
}

/* Status tokens are fixed and never themed. */
:root {
  --good: #0ca30c;
  --warn: #fab219;
  --crit: #d03b3b;
  --r: 10px;
  --gap: 14px;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

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

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 22px 20px 64px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: 18px;
}

.brand { display: flex; align-items: center; gap: 9px; }

.brand__dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
}

.brand__name { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }

.topbar__actions { display: flex; align-items: center; gap: 8px; }

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

.btn {
  font: inherit;
  font-weight: 500;
  padding: 7px 13px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.btn:hover { color: var(--ink); border-color: var(--baseline); }

.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn--primary:hover { filter: brightness(1.08); color: #fff; }

.btn--ghost { background: transparent; }

.btn--block { width: 100%; justify-content: center; }

.btn kbd {
  font: inherit;
  font-size: 11px;
  opacity: 0.7;
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 0 4px;
}

/* ---------- inputs ---------- */

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }

.field--inline { flex-direction: row; align-items: center; gap: 7px; margin: 0; }

.field__label { font-size: 12px; color: var(--muted); }

.field__label em { font-style: normal; opacity: 0.7; }

.input {
  font: inherit;
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--plane);
  color: var(--ink);
  width: 100%;
}

.input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.input::placeholder { color: var(--muted); }

.input--area { resize: vertical; min-height: 62px; }

.input--select { width: auto; cursor: pointer; padding-right: 8px; }

.input--search { padding-left: 12px; }

.searchwrap { flex: 1 1 220px; min-width: 180px; }
/* ---------- filter row (one row, scopes everything below) ---------- */

.filters {
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.segmented--full { display: flex; }

.segmented--full .seg { flex: 1; justify-content: center; }

.seg {
  font: inherit;
  font-size: 13px;
  padding: 5px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  transition: background 120ms ease, color 120ms ease;
}

.seg:hover { color: var(--ink); }

.seg.is-active { background: var(--accent-soft); color: var(--ink); }

.seg:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- dashboard ---------- */

.dash {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
  margin-bottom: 22px;
}

.tile { display: flex; flex-direction: column; gap: 4px; }

.tile__label {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

/* Proportional figures: tabular-nums makes big numbers look loose. */
.tile__value {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.tile__foot {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* A colored dot beside text carries identity; the text keeps its ink token. */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot--good { background: var(--good); }
.dot--warn { background: var(--warn); }

/* ---------- completion meter ---------- */

/* Row 1 is the three tiles; row 2 is meter + chart filling the width. */
.meter { display: flex; flex-direction: column; gap: 9px; }

.chart { grid-column: span 2; }

.meter__head { display: flex; align-items: baseline; justify-content: space-between; }

.meter__pct { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }

.meter__track {
  height: 8px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}

.meter__fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 320ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

.meter__fill.is-full { background: var(--good); }
/* ---------- priority breakdown (ordinal ramp, horizontal bars) ---------- */

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

.bars { display: flex; flex-direction: column; gap: 9px; }

.bar {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 9px;
}

.bar__name { font-size: 12px; color: var(--muted); }

.bar__track { height: 8px; background: var(--grid); border-radius: 2px; }

/* 4px rounded data-end, square at the baseline. */
.bar__fill {
  height: 100%;
  border-radius: 0 4px 4px 0;
  min-width: 2px;
  transition: width 320ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

.bar--p1 .bar__fill { background: var(--p1); }
.bar--p2 .bar__fill { background: var(--p2); }
.bar--p3 .bar__fill { background: var(--p3); }

.bar__val { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* Table view twin, so no value is reachable only by hovering. */
.tableview { font-size: 12px; color: var(--muted); }

.tableview summary { cursor: pointer; padding-top: 4px; }

.dtable { width: 100%; border-collapse: collapse; margin-top: 8px; }

.dtable th, .dtable td {
  text-align: left;
  padding: 4px 0;
  border-bottom: 1px solid var(--grid);
  font-weight: 400;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.dtable th { color: var(--muted); }

/* ---------- task list ---------- */

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

/* Refetch holds the previous render at reduced opacity - no skeleton flash. */
.list[aria-busy="true"] { opacity: 0.55; transition: opacity 120ms ease; }

.task {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--baseline);
  border-radius: var(--r);
  padding: 13px 14px;
  animation: rise 200ms ease both;
}

.task--p1 { border-left-color: var(--p1); }
.task--p2 { border-left-color: var(--p2); }
.task--p3 { border-left-color: var(--p3); }

.task:hover { border-color: var(--baseline); }

.task.is-done .task__title { color: var(--muted); text-decoration: line-through; }

@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .task { animation: none; }
  .meter__fill, .bar__fill { transition: none; }
}

.check {
  appearance: none;
  width: 18px; height: 18px;
  margin: 2px 0 0;
  border: 1.5px solid var(--baseline);
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  position: relative;
  flex: none;
}

.check:checked { background: var(--good); border-color: var(--good); }

.check:checked::after {
  content: "";
  position: absolute;
  left: 5px; top: 1px;
  width: 5px; height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.check:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.task__body { min-width: 0; }

.task__title { font-weight: 500; word-wrap: break-word; }

.task__desc { color: var(--ink-2); font-size: 13px; margin-top: 3px; word-wrap: break-word; }

.task__meta { color: var(--muted); font-size: 12px; margin-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; }

.task__actions { display: flex; gap: 4px; opacity: 0; transition: opacity 120ms ease; }

.task:hover .task__actions,
.task:focus-within .task__actions { opacity: 1; }

.iconbtn {
  font: inherit;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.iconbtn:hover { color: var(--ink); border-color: var(--baseline); }

.iconbtn--danger:hover { color: var(--crit); border-color: var(--crit); }

.iconbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.pill {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.empty { text-align: center; padding: 54px 20px; color: var(--muted); }

.empty__title { color: var(--ink); font-weight: 500; margin-bottom: 4px; }

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- gate & modal ---------- */

/* The hidden attribute must beat these display values. Without this the
   overlays stay in the layout at inset:0 and silently eat every click. */
[hidden] { display: none !important; }

.gate, .modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  padding: 20px;
  z-index: 20;
}

.gate__card, .modal__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 400px;
  animation: pop 160ms ease both;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

.gate__title, .modal__title { margin: 0 0 6px; font-size: 17px; font-weight: 600; }

.gate__hint { margin: 0 0 16px; color: var(--muted); font-size: 13px; }

.gate__hint code {
  background: var(--plane);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

.gate__error, .modal__error {
  color: var(--crit);
  font-size: 13px;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 30;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  animation: slide 180ms ease both;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast--good { border-left-color: var(--good); }
.toast--bad { border-left-color: var(--crit); }

@keyframes slide {
  from { opacity: 0; transform: translateX(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------- assistant drawer ---------- */

.chat {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -18px 0 40px rgba(0, 0, 0, 0.22);
  z-index: 25;
  animation: drawer 180ms cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

@keyframes drawer {
  from { transform: translateX(14px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .chat { animation: none; }
}

.chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  flex: none;
}

.chat__title { display: flex; align-items: center; gap: 8px; font-weight: 600; }

.chat__headbtns { display: flex; gap: 6px; }

/* Live dot: identity beside text, per the same rule the stat tiles follow. */
.dot--live { background: var(--good); }

.chat__log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg { max-width: 88%; padding: 9px 12px; border-radius: 12px; word-wrap: break-word; }

.msg--user {
  align-self: flex-end;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-bottom-right-radius: 4px;
}

.msg--bot {
  align-self: flex-start;
  background: var(--plane);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg--err { align-self: flex-start; border-left: 3px solid var(--crit); color: var(--ink-2); }

.msg p { margin: 0 0 7px; }
.msg p:last-child { margin-bottom: 0; }

/* Reasoning summary: present but visibly secondary, collapsed by default. */
.think {
  align-self: flex-start;
  max-width: 88%;
  font-size: 12px;
  color: var(--muted);
  border-left: 2px solid var(--grid);
  padding-left: 9px;
}

.think summary { cursor: pointer; }
.think__body { margin-top: 5px; white-space: pre-wrap; }

/* Tool activity: one chip per call, so the work is visible not implied. */
.act {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--ink-2);
  background: var(--plane);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 11px;
}

.act__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.act.is-running .act__dot { animation: pulse 900ms ease-in-out infinite; }
.act.is-done .act__dot { background: var(--good); }
.act.is-error .act__dot { background: var(--crit); }

@keyframes pulse { 50% { opacity: 0.25; } }

@media (prefers-reduced-motion: reduce) {
  .act.is-running .act__dot { animation: none; }
}

.chat__empty { color: var(--muted); font-size: 13px; }

.chat__empty p { margin: 0 0 10px; }

.suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.suggest button {
  font: inherit;
  font-size: 12px;
  text-align: left;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}

.suggest button:hover { color: var(--ink); border-color: var(--baseline); }
.suggest button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.chat__composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.chat__input {
  resize: none;
  max-height: 140px;
  min-height: 38px;
  line-height: 1.45;
  padding: 9px 11px;
}

.chat[data-busy="true"] .chat__input { opacity: 0.6; }

/* On a narrow screen the drawer takes the whole viewport. */
@media (max-width: 560px) {
  .chat { width: 100vw; border-left: 0; }
}

@media (max-width: 720px) {
  .dash { grid-template-columns: repeat(2, 1fr); }
  .chart { grid-column: span 2; }
}

@media (max-width: 460px) {
  .dash { grid-template-columns: 1fr; }
  .chart, .meter { grid-column: span 1; }
}
