:root {
  color-scheme: light;
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-muted: #f1f3f1;
  --ink: #17201b;
  --muted: #66716b;
  --line: #d8ded8;
  --green: #207a55;
  --red: #b6403a;
  --blue: #246ea3;
  --amber: #a76d16;
  --violet: #7562a7;
  --shadow: 0 18px 45px rgba(38, 45, 41, 0.1);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 32px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 244, 239, 0.94);
  backdrop-filter: blur(16px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  margin-top: 4px;
  font-size: clamp(1.6rem, 3vw, 2.45rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 1.05rem;
  letter-spacing: 0;
}

h2 .help-chip {
  transform: translateY(-1px);
}

.eyebrow {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header-actions,
.control-bar,
.panel-heading {
  display: flex;
  align-items: center;
}

.header-actions {
  gap: 10px;
}

.clock-stack {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.clock-card {
  min-width: 118px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.clock-card span,
.clock-card small {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.clock-card strong {
  display: block;
  margin: 2px 0;
  font-size: 1rem;
  line-height: 1.1;
}

.clock-card small {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0;
  text-transform: none;
}

.icon-button,
.primary-button,
.secondary-button,
.help-chip {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.icon-button {
  width: 42px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.2rem;
}

.primary-button {
  padding: 0 18px;
  border-color: #16221b;
  background: #16221b;
  color: #fff;
  font-weight: 700;
}

.secondary-button {
  min-height: 40px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
}

.help-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  min-width: 22px;
  height: 22px;
  min-height: 22px;
  margin-left: 5px;
  padding: 0;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  vertical-align: text-top;
}

.help-chip:hover,
.help-chip:focus-visible,
.secondary-button:hover,
.secondary-button:focus-visible,
.icon-button:hover,
.icon-button:focus-visible {
  border-color: #16221b;
  color: #16221b;
  outline: none;
}

.shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px 32px 44px;
}

.control-bar {
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.control-bar label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.control-bar select,
.control-bar input {
  min-width: 150px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 122px;
  padding: 18px;
  border-left: 5px solid var(--green);
}

.metric-card span,
.metric-card small {
  color: var(--muted);
}

.metric-card span {
  display: block;
  font-weight: 800;
}

.metric-card strong {
  display: block;
  margin: 12px 0 6px;
  font-size: 2.05rem;
  line-height: 1;
}

.accent-red {
  border-left-color: var(--red);
}

.accent-blue {
  border-left-color: var(--blue);
}

.accent-amber {
  border-left-color: var(--amber);
}

.accent-violet {
  border-left-color: var(--violet);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.82fr) minmax(560px, 1.18fr);
  gap: 18px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.regime-panel {
  min-height: 280px;
}

.decision-queue-panel {
  display: flex;
  flex-direction: column;
  grid-row: span 2;
  max-height: calc(100vh - 120px);
  overflow: hidden;
}

.decision-queue-panel .table-wrap {
  max-height: none;
  overflow: auto;
  overscroll-behavior: contain;
}

.event-panel,
.jobs-panel {
  min-height: 320px;
}

.tab-list {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.tab-button {
  flex: 1;
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.tab-button.active {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.tab-panel {
  min-height: 0;
  overflow: hidden;
}

.tab-panel.active {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

.tab-panel.active > .decision-list,
.tab-panel.active > .timeline,
.tab-panel.active > .table-wrap {
  flex: 1 1 auto;
  min-height: 0;
}

.panel-heading {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.status-pill,
.score-badge,
.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

.tag {
  width: max-content;
  max-width: 100%;
  align-self: start;
  justify-self: start;
}

.status-pill.ok,
.tag.ok {
  border-color: rgba(32, 122, 85, 0.28);
  background: rgba(32, 122, 85, 0.1);
  color: var(--green);
}

.status-pill.warn,
.status-pill.pending,
.tag.warn {
  border-color: rgba(167, 109, 22, 0.3);
  background: rgba(167, 109, 22, 0.12);
  color: var(--amber);
}

.status-pill.bad,
.tag.bad {
  border-color: rgba(182, 64, 58, 0.28);
  background: rgba(182, 64, 58, 0.1);
  color: var(--red);
}

.score-badge {
  min-width: 52px;
  background: #16221b;
  color: #fff;
}

.regime-summary {
  max-width: 760px;
  color: var(--muted);
  line-height: 1.6;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.answer-card {
  min-height: 112px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.answer-card strong {
  display: block;
  margin: 8px 0;
}

.answer-card pre {
  margin: 8px 0 0;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.84rem;
  line-height: 1.45;
  white-space: normal;
}

.answer-list {
  display: grid;
  gap: 6px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.answer-list li {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.answer-list b {
  color: var(--ink);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-align: left;
  text-transform: uppercase;
}

th,
td {
  padding: 12px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

td strong {
  display: block;
  overflow-wrap: anywhere;
}

td span {
  display: block;
}

.subtle {
  color: var(--muted);
  font-size: 0.78rem;
}

.score-meter {
  display: grid;
  gap: 6px;
}

.meter-track {
  width: 74px;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e0e3df;
}

.meter-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.timeline,
.job-list {
  display: grid;
  gap: 10px;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
  overscroll-behavior: contain;
}

.decision-list {
  display: grid;
  gap: 10px;
  max-height: 680px;
  overflow: auto;
  padding-right: 4px;
  overscroll-behavior: contain;
}

.decision-queue-panel .decision-list,
.decision-queue-panel .timeline {
  max-height: none;
}

.queue-timeline {
  max-height: none;
}

.event-item,
.decision-item,
.job-item {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.event-top,
.decision-top,
.job-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.decision-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.event-top > div,
.decision-top > div,
.job-top > div {
  min-width: 0;
}

.event-title,
.decision-title,
.job-title {
  font-weight: 800;
  overflow-wrap: anywhere;
}

.event-copy,
.decision-copy {
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.empty-state {
  padding: 28px 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.guide-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  justify-content: flex-end;
  background: rgba(22, 34, 27, 0.24);
}

.guide-panel.open {
  display: flex;
}

.guide-card {
  width: min(520px, 100%);
  height: 100%;
  overflow: auto;
  padding: 22px;
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: -18px 0 45px rgba(38, 45, 41, 0.16);
}

.guide-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.guide-intro {
  margin-bottom: 16px;
  color: var(--muted);
  line-height: 1.55;
}

.guide-content {
  display: grid;
  gap: 12px;
}

.guide-term {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.guide-term h3 {
  margin: 0 0 8px;
  font-size: 1rem;
  letter-spacing: 0;
}

.guide-term p {
  color: var(--muted);
  line-height: 1.5;
}

.guide-term p + p {
  margin-top: 8px;
}

.guide-action {
  color: var(--ink);
  font-weight: 800;
}

@media (max-width: 1060px) {
  .summary-grid,
  .workspace,
  .answer-grid {
    grid-template-columns: 1fr 1fr;
  }

  .decision-queue-panel,
  .regime-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .app-header {
    position: static;
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 18px;
  }

  .header-actions {
    width: 100%;
    flex-shrink: 0;
    flex-wrap: wrap;
  }

  .clock-stack {
    order: 3;
    width: 100%;
  }

  .clock-card {
    flex: 1;
    min-width: 0;
  }

  .shell {
    padding: 16px;
  }

  .summary-grid,
  .workspace,
  .answer-grid {
    grid-template-columns: 1fr;
  }

  .control-bar label,
  .control-bar select,
  .control-bar input,
  .primary-button {
    width: 100%;
  }

  .metric-card {
    min-height: 104px;
  }

  .guide-card {
    width: 100%;
    border-left: 0;
  }

  .decision-queue-panel .table-wrap,
  .timeline,
  .decision-list,
  .job-list {
    max-height: 520px;
  }

  .decision-queue-panel {
    max-height: none;
    overflow: visible;
  }

  .decision-queue-panel .decision-list,
  .decision-queue-panel .timeline,
  .decision-queue-panel .table-wrap {
    max-height: 560px;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tr[role="button"] {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-muted);
  }

  td {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 10px;
    padding: 0;
    border: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .meter-track {
    width: 100%;
    max-width: 180px;
  }
}
