/* Design tokens first; everything below uses them. Change the look here, not in components. */
:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --border: #deded8;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --radius: 8px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #1f1f1d;
    --text: #ececea;
    --muted: #a0a09a;
    --border: #34342f;
    --accent: #7c9cff;
    --accent-text: #0d0d0c;
    --danger: #ff8a80;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* The hidden attribute always wins. Without this, a class that sets display (.stack is flex)
   overrides the browser's own [hidden] rule, and "hidden" cards show (found on the phone, 2026-10-01). */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
}

/* Wide on a desktop: the dashboard fills the screen. Sign-in stays a narrow column. */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-3);
}

#login-view {
  max-width: 640px;
  margin: 0 auto;
}

/* The signed-in screen: cards flow into as many columns as fit (one on a phone). .wide spans them all. */
.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: var(--space-3);
  align-items: start;
}

.dashboard > * {
  margin: 0;
  min-width: 0;
}

.wide {
  grid-column: 1 / -1;
}

@media (max-width: 440px) {
  .dashboard {
    grid-template-columns: 1fr;
  }
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

h1 {
  font-size: 1.25rem;
  margin: 0;
}

h2 {
  font-size: 1rem;
  margin: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  color: var(--muted);
  font-size: 0.875rem;
}

input,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2);
}

.btn {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  background: var(--accent);
  color: var(--accent-text);
  align-self: flex-start;
}

.btn-quiet {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}

.list-item p {
  margin: var(--space-1) 0 0;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.empty {
  color: var(--muted);
  padding: var(--space-3) 0;
}

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

h3 {
  font-size: 0.875rem;
  margin: var(--space-2) 0 0;
  color: var(--muted);
  font-weight: 600;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

/* The run card's tabs: the board (the newest run), then the archive. They wrap on a narrow phone. */
.tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
}

.tab {
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-1) var(--space-2);
  background: transparent;
  color: var(--muted);
}

.tab[aria-selected='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.tabs-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: var(--space-2);
}

/* The run's real-vs-shadow table: scrolls sideways inside the card on a narrow phone, never the page. */
.table-wrap {
  overflow-x: auto;
}

.run-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.run-table th,
.run-table td {
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}

.run-table th:first-child,
.run-table td:first-child {
  text-align: left;
}

/* Three figures side by side on any screen; they wrap rather than squeeze on a narrow phone. */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: var(--space-2);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.stat-label {
  color: var(--muted);
  font-size: 0.75rem;
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* The ticket's fields: two columns where there's room, one on a narrow phone. */
.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-2);
}

.grow {
  flex: 1;
}

select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.headline {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
}

.small {
  font-size: 0.75rem;
}

/* Proposal tiles (phase 1, step 5): a grid of their own, each a column of text. */
.proposal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--space-3);
  list-style: none;
  margin: 0;
  padding: 0;
}

.proposal {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  min-width: 0;
}

.proposal p {
  margin: 0;
  overflow-wrap: anywhere;
}

.proposal:has(input:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* The whole header line ticks the box: a big target, not a 13px square. */
.pick {
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}

input[type='checkbox'] {
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  margin: 0;
  flex: none;
  accent-color: var(--accent);
  cursor: pointer;
}

.playbook-text {
  width: 100%;
  font: 0.875rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  margin: var(--space-2) 0;
}

.proposal textarea {
  width: 100%;
}

/* A whole-playbook edit spans the lesson grid; its diff scrolls within the card. */
.wide-proposal {
  grid-column: 1 / -1;
}

.diff {
  font: 0.8125rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 32rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2);
}

.diff-add {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.diff-del {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
}

.diff-gap {
  color: var(--muted);
  font-style: italic;
}

.prompt {
  white-space: pre-wrap;
  font: 0.875rem/1.5 var(--font);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  margin: var(--space-2) 0;
}

.badge {
  font-size: 0.75rem;
  border-radius: var(--radius);
  padding: 2px var(--space-2);
  align-self: flex-start;
}

.badge-ok {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
}

.badge-wait {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

.flash {
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
}
