:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-alt: #f8f7f4;
  --border: #e3e5ea;
  --text: #1c2128;
  --text-muted: #5c6370;
  --accent: #5b5bd6;
  --accent-contrast: #ffffff;
  --ok: #1c8a5a;
  --warn: #b87a12;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(20, 20, 43, 0.06), 0 8px 24px rgba(20, 20, 43, 0.06);
  --radius: 14px;
  --status-backlog: #64748b;
  --status-mission: #b87a12;
  --status-in_progress: #2563a8;
  --status-proposed: #5b5bd6;
  --status-accepted: #0d8a7a;
  --status-integrated: #1c8a5a;
  --status-rejected: #c0356b;
  --status-failed: #6b7280;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #15171c;
    --surface: #1c1f26;
    --surface-alt: #20232b;
    --border: #2b2f38;
    --text: #e7e9ee;
    --text-muted: #9aa1ad;
    --accent: #8a8af0;
    --accent-contrast: #15171c;
    --ok: #3ecb8a;
    --warn: #e0a941;
    --danger: #f06a63;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
    --status-backlog: #94a3b8;
    --status-mission: #e0a941;
    --status-in_progress: #5b9bd8;
    --status-proposed: #8a8af0;
    --status-accepted: #3ecbb3;
    --status-integrated: #3ecb8a;
    --status-rejected: #f06a9a;
    --status-failed: #9aa1ad;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: inherit;
}

header.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}

.brand .icon {
  color: var(--accent);
}

nav.main-nav {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  flex-wrap: wrap;
}

nav.main-nav a {
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

nav.main-nav a:hover {
  color: var(--text);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
  overflow-x: hidden;
}

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

h2 {
  font-size: 1.05rem;
  margin: 0 0 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

section {
  margin-bottom: 2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  min-width: 0;
  overflow-wrap: anywhere;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 1rem;
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
}

.empty-state .icon {
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.decision-card header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  min-width: 0;
}

.decision-card h3, .mission-card h3 {
  font-size: 1rem;
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.fact-lines {
  margin: 0.5rem 0;
  padding-left: 0;
  list-style: none;
}

.fact-lines li {
  padding: 0.15rem 0;
  color: var(--text);
}

.source-line {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.confidence-meter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.6rem 0;
}

.confidence-meter .track {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.confidence-meter .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.confidence-meter .value {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 2.5rem;
  text-align: right;
}

.actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.85rem;
  flex-wrap: wrap;
}

.actions form.inline, .actions > button {
  flex: 1 1 auto;
}

.actions button {
  width: 100%;
}

.mission-card .instructions {
  white-space: pre-wrap;
  background: var(--surface-alt);
  border-radius: 10px;
  padding: 0.75rem;
  margin: 0.5rem 0;
  overflow-wrap: anywhere;
}

.hint {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.kpis {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  flex: 1 1 140px;
  max-width: 100%;
}

.kpi .icon {
  color: var(--kpi-color, var(--accent));
  flex-shrink: 0;
}

.kpi .kpi-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

.kpi .value {
  font-size: 1.4rem;
  font-weight: 700;
  display: block;
  line-height: 1.1;
}

.kpi .label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.kpi.status-backlog { --kpi-color: var(--status-backlog); }
.kpi.status-mission { --kpi-color: var(--status-mission); }
.kpi.status-in_progress { --kpi-color: var(--status-in_progress); }
.kpi.status-proposed { --kpi-color: var(--status-proposed); }
.kpi.status-accepted { --kpi-color: var(--status-accepted); }
.kpi.status-integrated { --kpi-color: var(--status-integrated); }
.kpi.status-rejected { --kpi-color: var(--status-rejected); }
.kpi.status-failed { --kpi-color: var(--status-failed); }

.progress-row {
  margin-bottom: 0.85rem;
}

.progress-row .meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
}

.progress-row .meta .muted {
  color: var(--text-muted);
}

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

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

.table-scroll {
  overflow-x: auto;
}

th, td {
  text-align: left;
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

td.nowrap {
  white-space: nowrap;
}

.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 0.4rem;
}

.status-dot.ok { background: var(--ok); }
.status-dot.error { background: var(--danger); }
.status-dot.unknown { background: var(--text-muted); }

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

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-alt);
  color: var(--badge-color, var(--text-muted));
  border: 1px solid var(--border);
  white-space: nowrap;
}

.status-badge.status-backlog { --badge-color: var(--status-backlog); }
.status-badge.status-mission { --badge-color: var(--status-mission); }
.status-badge.status-in_progress { --badge-color: var(--status-in_progress); }
.status-badge.status-proposed { --badge-color: var(--status-proposed); }
.status-badge.status-accepted { --badge-color: var(--status-accepted); }
.status-badge.status-integrated { --badge-color: var(--status-integrated); }
.status-badge.status-rejected { --badge-color: var(--status-rejected); }
.status-badge.status-failed { --badge-color: var(--status-failed); }

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.1rem;
}

.filter-chips a {
  text-decoration: none;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--surface);
}

.filter-chips a.active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.task-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  min-width: 0;
}

.task-row:last-child {
  border-bottom: none;
}

.task-row .icon {
  color: var(--accent);
  flex-shrink: 0;
}

.task-row .main {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.task-row .label {
  font-weight: 600;
}

.task-row .meta {
  color: var(--text-muted);
  font-size: 0.82rem;
}

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

.timeline li {
  display: flex;
  gap: 0.75rem;
  padding-bottom: 1.1rem;
  position: relative;
}

.timeline li:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 24px;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.timeline .dot-wrap {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--dot-color, var(--accent));
}

.dot-wrap.status-backlog { --dot-color: var(--status-backlog); }
.dot-wrap.status-mission { --dot-color: var(--status-mission); }
.dot-wrap.status-in_progress { --dot-color: var(--status-in_progress); }
.dot-wrap.status-proposed { --dot-color: var(--status-proposed); }
.dot-wrap.status-accepted { --dot-color: var(--status-accepted); }
.dot-wrap.status-integrated { --dot-color: var(--status-integrated); }
.dot-wrap.status-rejected { --dot-color: var(--status-rejected); }
.dot-wrap.status-failed { --dot-color: var(--status-failed); }

.timeline-main {
  min-width: 0;
  overflow-wrap: anywhere;
}

.timeline .meta {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.transcription {
  white-space: pre-wrap;
  font-family: Georgia, "Iowan Old Style", serif;
  background: var(--surface-alt);
  padding: 0.85rem;
  border-radius: 10px;
}

form.inline {
  display: inline;
}

button, input[type=submit] {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

button.reject {
  background: var(--danger);
}

input[type=text], input[type=password] {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.85rem;
  background: var(--surface);
  color: var(--text);
}

.login-page {
  min-height: calc(100vh - 56px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  max-width: 340px;
  width: 100%;
  text-align: center;
}

.login-card .icon {
  color: var(--accent);
}

.footer-version {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 2rem 0 1rem;
}

@media (max-width: 600px) {
  .kpis {
    gap: 0.5rem;
  }

  .kpi {
    flex-basis: calc(50% - 0.25rem);
  }

  .table-scroll table {
    min-width: 520px;
  }

  .actions {
    flex-direction: column;
  }

  .actions form.inline, .actions > button {
    width: 100%;
  }
}
