:root {
  color-scheme: light dark;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #898781;
  --hairline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --danger: #d03b3b;
  --bar: #2a78d6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --ink-muted: #898781;
    --hairline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --bar: #3987e5;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  line-height: 1.5;
}

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface);
}

.brand { display: flex; align-items: center; gap: 0.6rem; }

.brand-mark {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: var(--accent);
}

.site-header h1 { font-size: 1.05rem; margin: 0; font-weight: 650; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  color: var(--ink-2);
}

.dept-badge {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.75rem;
  color: var(--ink-2);
}

/* Cards & layout */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
  margin-top: 1rem;
}

.card h2 { font-size: 0.95rem; margin: 0 0 0.75rem; font-weight: 650; }

.auth-card { max-width: 420px; margin: 3rem auto; }

.hint { color: var(--ink-2); font-size: 0.85rem; }

.banner {
  margin: 1rem 0 0;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.85rem;
}

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

/* Forms */
label { display: block; font-size: 0.8rem; color: var(--ink-2); margin-bottom: 0.25rem; }

input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  margin-bottom: 0.75rem;
}

input:focus, select:focus, textarea:focus, .btn:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; }
.btn:disabled { opacity: 0.55; cursor: default; }

.item-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
  align-items: end;
}

.item-form .field-wide, .item-form button { grid-column: 1 / -1; }
.item-form button { justify-self: start; }

@media (max-width: 560px) {
  .item-form { grid-template-columns: 1fr; }
}

/* Tabs (client-side state only — no routing) */
.tabs {
  display: flex;
  gap: 0.25rem;
  margin-top: 1.25rem;
  border-bottom: 1px solid var(--hairline);
}

.tab {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 0.9rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ink-2);
  cursor: pointer;
}

.tab.is-active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* Dashboard: KPI row of stat tiles */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.stat-label { font-size: 0.8rem; color: var(--ink-2); }
.stat-value { font-size: 1.75rem; font-weight: 600; color: var(--ink); }

/* Department bar list — single series, single hue, value at the tip */
.bar-list { display: flex; flex-direction: column; gap: 0.6rem; }

.bar-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
}

.bar-row .bar-name { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bar-track { display: flex; align-items: center; gap: 0.5rem; min-height: 16px; }

.bar-fill {
  height: 16px;
  background: var(--bar);
  border-radius: 0 4px 4px 0;
  min-width: 2px;
}

.bar-value { color: var(--ink); font-weight: 600; }

/* Action item list */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.list-header select { width: auto; margin: 0; }

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

.item-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--hairline);
}

.item-row:first-child { border-top: none; }

.item-title { font-weight: 600; }
.item-row.is-done .item-title { text-decoration: line-through; color: var(--ink-muted); }
.item-meta { font-size: 0.8rem; color: var(--ink-2); }
.item-meta .overdue { color: var(--danger); font-weight: 600; }

.item-actions { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.item-actions select { width: auto; margin: 0; font-size: 0.85rem; }

.btn-delete {
  font: inherit;
  background: none;
  border: none;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-delete:hover { color: var(--danger); }

/* Filters row */
.filters-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.25rem 0 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--hairline);
}

.filters-row select, .filters-row input { width: auto; margin: 0; }
.inline-label { margin: 0; font-size: 0.8rem; color: var(--ink-2); }

/* Countdown */
.countdown { margin: 1rem 0 0; font-size: 0.9rem; }

/* Badges */
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--ink-2);
}

.badge-blocked { color: var(--danger); border-color: var(--danger); }

/* Roadblock list */
.roadblock-list { list-style: none; margin: 0.25rem 0 0; padding: 0; }

.roadblock-list li {
  padding: 0.55rem 0;
  border-top: 1px solid var(--hairline);
  font-size: 0.9rem;
}

.roadblock-list li:first-child { border-top: none; }
.roadblock-list .rb-meta { display: block; font-size: 0.8rem; color: var(--ink-2); }
.roadblock-list .rb-overdue { color: var(--danger); font-weight: 600; }

/* Dependencies on item rows */
.dep-row { margin-top: 0.35rem; display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }

.dep-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
  font-size: 0.75rem;
  color: var(--ink-2);
}

.dep-chip.dep-active { border-color: var(--danger); color: var(--danger); }

.dep-chip button {
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0;
  line-height: 1;
}

.dep-add { display: inline-flex; align-items: center; gap: 0.3rem; }
.dep-add select { width: auto; max-width: 240px; margin: 0; font-size: 0.75rem; padding: 0.15rem 0.4rem; }
.dep-add .btn { padding: 0.15rem 0.6rem; font-size: 0.75rem; }

/* Charts */
.chart-scroll { overflow-x: auto; }
.chart-scroll svg { display: block; }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.78rem;
  color: var(--ink-2);
  margin-bottom: 0.5rem;
}

.chart-legend .key { display: inline-flex; align-items: center; gap: 0.35rem; }
.chart-legend .swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* Gantt (SVG classes; colors resolve per theme via CSS vars) */
.g-bar          { fill: var(--bar); }
.g-bar-done     { fill: var(--ink-muted); opacity: 0.45; }
.g-bar-overdue  { fill: var(--danger); }
.g-grid         { stroke: var(--hairline); stroke-width: 1; }
.g-label        { fill: var(--ink); font-size: 12px; }
.g-label-dept   { fill: var(--ink); font-size: 12px; font-weight: 650; }
.g-tick         { fill: var(--ink-muted); font-size: 11px; }
.g-today        { stroke: var(--ink-muted); stroke-width: 1; }
.g-festival     { stroke: #9085e9; stroke-width: 1.5; }
.g-marker-label { fill: var(--ink-2); font-size: 11px; }

/* AI review */
.ai-review { margin-top: 1.25rem; }
.ai-suggestions { list-style: none; margin: 0.5rem 0 0.75rem; padding: 0; }

.ai-suggestions li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0;
  border-top: 1px solid var(--hairline);
  font-size: 0.9rem;
}

.ai-suggestions li:first-child { border-top: none; }
.ai-suggestions input[type="checkbox"] { width: auto; margin: 0; }
.ai-suggestions .sug-title { flex: 1 1 240px; }
.ai-suggestions select, .ai-suggestions input[type="date"] { width: auto; margin: 0; font-size: 0.85rem; padding: 0.25rem 0.4rem; }
.ai-suggestions .sug-note { flex-basis: 100%; font-size: 0.78rem; color: var(--ink-2); }

/* AI assistant */
.ai-output {
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: var(--page);
  font-size: 0.9rem;
  white-space: pre-wrap;
  overflow-x: auto;
}
