:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-muted: #edf1f2;
  --text: #172126;
  --muted: #607078;
  --line: #d9e0e3;
  --accent: #176b87;
  --accent-dark: #0f5067;
  --good: #237a43;
  --bad: #b83333;
  --warn: #9b6a10;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  background: var(--surface-muted);
  color: var(--text);
  border: 1px solid var(--line);
}

.secondary-button:hover {
  background: #dfe7ea;
}

.danger-button {
  width: 32px;
  min-height: 32px;
  padding: 0;
  background: #f3dede;
  color: var(--bad);
  border: 1px solid #e6b9b9;
}

.danger-button:hover {
  background: #e8c9c9;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.app-header,
.toolbar,
.settings-band,
.audit-layout {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
}

.app-header {
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.25rem);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 8px;
}

h3 {
  margin-bottom: 12px;
}

p {
  color: var(--muted);
  line-height: 1.45;
}

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

.summary-tile {
  min-height: 96px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.summary-tile span {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.summary-tile strong {
  font-size: 1.45rem;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 6px;
  margin-bottom: 18px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tab {
  flex: 1;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.settings-band,
.toolbar,
.audit-layout,
.table-wrap {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.settings-band,
.toolbar {
  margin-bottom: 18px;
}

.inline-form,
.button-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  background: #fff;
}

input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

textarea {
  resize: vertical;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.detail-row td {
  padding-top: 0;
  border-bottom: 1px solid var(--line);
}

.detail-row .subtle {
  margin-top: 0;
}

.number-cell {
  text-align: right;
  white-space: nowrap;
}

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

.group-row td {
  padding-top: 18px;
  background: #f8fafb;
  color: var(--accent-dark);
  font-weight: 700;
}

.positive {
  color: var(--good);
}

.negative {
  color: var(--bad);
}

.audit-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  margin-bottom: 18px;
}

.audit-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0 0;
}

.audit-stats div {
  padding: 14px;
  background: var(--surface-muted);
  border-radius: 8px;
}

.audit-stats dt {
  color: var(--muted);
  font-size: 0.86rem;
}

.audit-stats dd {
  margin: 8px 0 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.audit-notes-panel,
dialog form {
  display: grid;
  gap: 14px;
}

.audit-notes-panel {
  width: min(100%, 420px);
}

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

.forecast-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.forecast-list div {
  padding: 14px;
  background: var(--surface-muted);
  border-radius: 8px;
}

.forecast-list dt {
  color: var(--muted);
  font-size: 0.86rem;
}

.forecast-list dd {
  margin: 6px 0 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.occurrence-forecast {
  margin-top: 22px;
}

.forecast-chart {
  margin: 18px 0 8px;
  padding: 12px;
  background: #f8fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.forecast-chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-grid line {
  stroke: var(--line);
  stroke-width: 1;
}

.chart-grid text,
.chart-axis text {
  fill: var(--muted);
  font-size: 13px;
}

.chart-axis line {
  stroke: var(--line);
  stroke-width: 1;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-range {
  fill: rgba(23, 107, 135, 0.22);
  stroke: none;
}

.chart-range-line {
  fill: none;
  stroke: rgba(23, 107, 135, 0.42);
  stroke-width: 1.5;
  stroke-dasharray: 5 5;
}

.chart-points circle {
  fill: var(--surface);
  stroke: var(--accent);
  stroke-width: 2;
}

.month-heading {
  margin: 22px 0 10px;
}

.event-name {
  font-weight: 700;
}

.confirmed-row td {
  background: #f8fafb;
}

.checkpoint-row td {
  background: var(--surface-muted);
  font-weight: 700;
}

.range-cell .subtle {
  margin-top: 2px;
}

.table-input {
  width: 120px;
  min-height: 34px;
  margin-left: auto;
  text-align: right;
}

.subtle {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.history-text {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

dialog {
  width: min(420px, calc(100% - 32px));
  border: 0;
  border-radius: 8px;
  padding: 22px;
  box-shadow: 0 20px 70px rgba(23, 33, 38, 0.28);
}

dialog::backdrop {
  background: rgba(23, 33, 38, 0.45);
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 780px) {
  .app-header,
  .toolbar,
  .settings-band {
    display: grid;
  }

  .summary-grid,
  .two-column,
  .audit-layout,
  .forecast-grid {
    grid-template-columns: 1fr;
  }

  .audit-stats {
    grid-template-columns: 1fr;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab {
    min-width: 110px;
  }

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