/* AgencyForge Command Center
 *
 * One stylesheet, no build step, no framework. The design brief is narrow:
 * Chris opens this on a phone, decides something in under two minutes, and
 * closes it. So the decision buttons are the largest targets on any screen,
 * the type is big enough to read one-handed in sunlight, and nothing needs
 * horizontal scrolling except deliberately-scrollable tables.
 *
 * Light and dark both painted explicitly — the panel gets opened at 6am and
 * at 11pm, and a flashbang at either end is a real usability problem.
 */

:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efedea;
  --ink: #14181c;
  --ink-2: #565f68;
  --ink-3: #8b939b;
  --line: #ddd9d3;
  --accent: #1b3a57;
  --accent-ink: #ffffff;
  --ok: #2f7d4f;
  --warn: #a8620f;
  --danger: #a3282a;
  --auto: #5b3fa8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 28, .06), 0 2px 8px rgba(20, 24, 28, .04);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1c2024;
    --surface-2: #23282d;
    --ink: #e8e6e3;
    --ink-2: #a6adb4;
    --ink-3: #767e86;
    --line: #2f353b;
    --accent: #6ea8d8;
    --accent-ink: #0e1418;
    --ok: #63c08a;
    --warn: #e0a259;
    --danger: #e08183;
    --auto: #a48ce0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .2);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  -webkit-text-size-adjust: 100%;
}

/* ---------------------------------------------------------------- chrome -- */

.topbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 650;
  letter-spacing: -.01em;
  color: var(--ink);
  text-decoration: none;
}

.topbar .alerts {
  margin-left: auto;
  color: var(--danger);
  font-weight: 600;
  font-size: .9rem;
  text-decoration: none;
}

.topbar .alerts + .logout { margin-left: .75rem; }
.topbar .logout { margin-left: auto; }
.topbar .alerts ~ .logout { margin-left: 0; }

.nav {
  display: flex;
  gap: .25rem;
  padding: .4rem .6rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.nav::-webkit-scrollbar { display: none; }

.nav-link {
  flex: 0 0 auto;
  padding: .45rem .7rem;
  border-radius: var(--radius);
  color: var(--ink-2);
  text-decoration: none;
  font-size: .92rem;
  white-space: nowrap;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.badge {
  display: inline-block;
  min-width: 1.3em;
  padding: 0 .35em;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  text-align: center;
}
.nav-link.active .badge { background: var(--accent-ink); color: var(--accent); }

main {
  max-width: 62rem;
  margin: 0 auto;
  padding: 1rem 1rem 4rem;
}

h1 { font-size: 1.5rem; margin: .5rem 0 .25rem; letter-spacing: -.015em; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; letter-spacing: -.01em; }

.lede { color: var(--ink-2); margin: 0 0 1rem; }
.lede.warn { color: var(--warn); font-weight: 600; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.err { color: var(--danger); }

.foot {
  max-width: 62rem;
  margin: 0 auto;
  padding: 1rem;
  color: var(--ink-3);
  font-size: .85rem;
  border-top: 1px solid var(--line);
}

.flash {
  max-width: 62rem;
  margin: .75rem auto 0;
  padding: .6rem .9rem;
  border-radius: var(--radius);
  border-left: 3px solid var(--ok);
  background: var(--surface);
}
.flash.error { border-left-color: var(--danger); }

/* ----------------------------------------------------------------- cards -- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  margin: .75rem 0;
  box-shadow: var(--shadow);
}

.card header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .5rem;
}
.card header strong { font-size: 1.02rem; }

.id { color: var(--ink-3); font: 600 .85rem var(--mono); }

.group h2 { display: flex; align-items: baseline; gap: .5rem; }
.count {
  font-size: .8rem;
  font-weight: 600;
  color: var(--ink-3);
  background: var(--surface-2);
  padding: .05rem .45rem;
  border-radius: 999px;
}

dl.meta {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem 1.25rem;
  margin: .5rem 0;
  font-size: .88rem;
}
dl.meta > div { display: flex; gap: .35rem; }
dl.meta dt { color: var(--ink-3); margin: 0; }
dl.meta dd { margin: 0; font-weight: 500; }
dl.meta.wide { flex-direction: column; gap: .3rem; }

.reviewer {
  margin: .5rem 0;
  padding: .5rem .7rem;
  background: var(--surface-2);
  border-radius: 6px;
  font-size: .9rem;
}

.preview, .doc, .diff {
  background: var(--surface-2);
  border-radius: 6px;
  padding: .7rem .8rem;
  font: .84rem/1.5 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 22rem;
  overflow: auto;
}
.doc { max-height: none; }
.diff { max-height: 30rem; }

.evidence { font-size: .85rem; margin: .5rem 0; }
.evidence code { word-break: break-all; }

.objective { margin: .25rem 0 .75rem; }
.rationale, .plan { margin: .5rem 0; padding-left: 1.2rem; font-size: .9rem; }
.rationale li, .plan li { margin: .3rem 0; }
.src { font-size: .82rem; }

details { margin: .5rem 0; }
summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 550;
  font-size: .92rem;
  padding: .2rem 0;
}

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

.actions {
  display: flex;
  gap: .5rem;
  align-items: center;
  margin-top: .75rem;
  flex-wrap: wrap;
}
.actions.wrap { gap: .5rem .75rem; }
form.inline { display: inline-flex; gap: .35rem; align-items: center; }

button, .btn {
  font: inherit;
  font-size: .95rem;
  font-weight: 600;
  padding: .55rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  /* 44px is the smallest reliable thumb target. */
  min-height: 44px;
}
button:hover { filter: brightness(.97); }
button:active { transform: translateY(1px); }

button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.secondary { background: var(--surface-2); }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.warn-btn { background: var(--auto); color: #fff; border-color: transparent; }
button.big { width: 100%; font-size: 1.05rem; padding: .8rem; }

button.link {
  background: none;
  border: none;
  color: var(--accent);
  padding: .35rem .4rem;
  min-height: 36px;
  text-decoration: underline;
  font-weight: 500;
}

input, select, textarea {
  font: inherit;
  font-size: .95rem;
  padding: .5rem .6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  min-height: 44px;
  max-width: 100%;
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.filters, .bulk, .killswitch { margin: .75rem 0; display: flex; gap: .5rem; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: .6rem; max-width: 26rem; }
.stack label { display: flex; flex-direction: column; gap: .2rem; font-size: .9rem; color: var(--ink-2); }
.stage-form { margin: .75rem 0; flex-wrap: wrap; }

.generate {
  margin-top: .6rem;
  padding-top: .6rem;
  border-top: 1px dashed var(--line);
  font-size: .88rem;
  color: var(--ink-3);
  display: flex;
  gap: .25rem;
  flex-wrap: wrap;
  align-items: center;
}

.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .75rem; }
.chip {
  padding: .3rem .7rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  text-decoration: none;
  font-size: .85rem;
}
.chip.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* ----------------------------------------------------------------- pills -- */

.pill {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
}
.pill.c-high, .pill.c-ok, .pill.c-executed, .pill.c-approved, .pill.c-adopted { background: var(--ok); color: #fff; }
.pill.c-medium, .pill.c-running, .pill.c-review, .pill.c-testing { background: var(--warn); color: #fff; }
.pill.c-low, .pill.c-failed, .pill.c-timeout, .pill.c-rejected, .pill.c-dropped { background: var(--danger); color: #fff; }
.pill.c-auto, .pill.c-scheduled { background: var(--auto); color: #fff; }
.pill.muted { background: transparent; border: 1px solid var(--line); }

.r-low { color: var(--ok); }
.r-medium { color: var(--warn); }
.r-high { color: var(--danger); font-weight: 600; }

/* ---------------------------------------------------------------- tables -- */

table.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: .89rem;
  margin: .5rem 0 1.5rem;
  /* Wide content scrolls inside its own container; the body never scrolls sideways. */
  display: block;
  overflow-x: auto;
  white-space: nowrap;
}
table.grid tr { border-bottom: 1px solid var(--line); }
table.grid th {
  text-align: left;
  color: var(--ink-3);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .4rem .6rem .4rem 0;
  font-weight: 600;
}
table.grid td { padding: .55rem .6rem .55rem 0; vertical-align: top; }
table.grid tr.off td { opacity: .5; }
.row-actions { white-space: nowrap; }

table.kpis { width: 100%; border-collapse: collapse; font-size: .87rem; margin: .5rem 0; }
table.kpis th { text-align: left; color: var(--ink-3); font-weight: 600; font-size: .78rem; }
table.kpis td, table.kpis th { padding: .3rem .5rem .3rem 0; border-bottom: 1px solid var(--line); }
.spark { font-family: var(--mono); letter-spacing: -.05em; color: var(--accent); }

code { font: .88em var(--mono); background: var(--surface-2); padding: .05em .35em; border-radius: 4px; }
code.small { font-size: .78rem; }

/* --------------------------------------------------------------- kanban --- */

.kanban {
  display: flex;
  gap: .75rem;
  overflow-x: auto;
  padding-bottom: 1rem;
  -webkit-overflow-scrolling: touch;
}
.kanban .column { flex: 0 0 15rem; }
.kanban .column h2 { font-size: .9rem; margin: 0 0 .5rem; }

.lead-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ink-3);
  border-radius: 8px;
  padding: .6rem .7rem;
  margin-bottom: .5rem;
  text-decoration: none;
  color: var(--ink);
  font-size: .87rem;
}
.lead-card.t-a { border-left-color: var(--danger); }
.lead-card.t-b { border-left-color: var(--warn); }
.lead-card.t-c { border-left-color: var(--ink-3); }
.lead-card strong { display: block; }
.lead-card span { display: block; font-size: .8rem; }
.lead-card .tier { float: right; font-weight: 700; color: var(--ink-3); }
.lead-card .next { margin-top: .35rem; color: var(--ink-2); }

.score { font-weight: 700; }
.score.s-hi { color: var(--ok); }
.score.s-mid { color: var(--warn); }
.score.s-lo { color: var(--ink-3); }

.reports { list-style: none; padding: 0; }
.reports li { padding: .5rem 0; border-bottom: 1px solid var(--line); }

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty p { margin: .25rem 0; }

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

.login-page { display: grid; place-items: center; min-height: 100vh; }
.login {
  max-width: 22rem;
  width: 100%;
  padding: 2rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 1rem;
}
.login h1 { text-align: center; margin-bottom: 1.25rem; }
.login form { display: flex; flex-direction: column; gap: .8rem; }
.login label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--ink-2); }
.login button { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.login .error {
  padding: .6rem .8rem;
  background: var(--surface-2);
  border-left: 3px solid var(--danger);
  border-radius: 6px;
  font-size: .9rem;
}
.login .warn { color: var(--warn); font-size: .85rem; }

/* ------------------------------------------------------------ small screens */

@media (max-width: 640px) {
  main { padding: .75rem .75rem 3rem; }
  h1 { font-size: 1.3rem; }
  .card { padding: .8rem; border-radius: 8px; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions form, .actions form.inline { width: 100%; }
  .actions button { width: 100%; }
  form.inline { flex-wrap: wrap; }
  form.inline input { flex: 1 1 8rem; }
  .kanban .column { flex: 0 0 85vw; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  button:active { transform: none; }
}
