:root {
  --bg: #f4efe7;
  --bg-deep: #ded5c7;
  --panel: rgba(255, 250, 244, 0.78);
  --panel-strong: rgba(255, 251, 247, 0.95);
  --ink: #18231f;
  --muted: #5c655e;
  --line: rgba(24, 35, 31, 0.12);
  --accent: #9d3d18;
  --accent-soft: rgba(157, 61, 24, 0.12);
  --alert: #c74b2a;
  --warn: #d78812;
  --safe: #2a6c5a;
  --shadow: 0 24px 60px rgba(52, 38, 20, 0.12);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --font-body: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(circle at top left, rgba(157, 61, 24, 0.2), transparent 34%),
    radial-gradient(circle at top right, rgba(42, 108, 90, 0.12), transparent 28%),
    linear-gradient(180deg, #fbf6ef 0%, var(--bg) 44%, var(--bg-deep) 100%);
}

.page-shell {
  width: min(1240px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.hero,
.panel,
.upload-card {
  backdrop-filter: blur(18px);
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: var(--shadow);
}

.hero {
  display: grid;
  grid-template-columns: 1.8fr 1fr;
  gap: 20px;
  padding: 28px;
  border-radius: 36px;
  margin-bottom: 20px;
}

.eyebrow,
.panel-kicker,
.hero-note-label {
  margin: 0 0 10px;
  color: var(--accent);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.72rem;
  font-weight: 700;
}

h1,
h2,
h3,
th {
  font-family: var(--font-display);
}

h1 {
  margin: 0;
  font-size: clamp(2.5rem, 5vw, 4.5rem);
  line-height: 0.96;
  letter-spacing: -0.04em;
}

.hero-copy,
.hero-note p,
.stack-item p,
td,
.upload-card p,
.upload-status {
  color: var(--muted);
  line-height: 1.6;
}

.hero-note {
  align-self: end;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: rgba(24, 35, 31, 0.92);
  color: #f7f0e6;
}

.hero-note p {
  color: rgba(247, 240, 230, 0.82);
  margin: 0;
}

.hero-note-label {
  color: #f4b46d;
}

.tab-panel {
  margin-bottom: 20px;
}

.tab-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.tab-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.tab-button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, color 180ms ease;
}

.tab-button.dataset {
  display: inline-flex;
  align-items: center;
}

.tab-remove {
  border: 0;
  background: rgba(24, 35, 31, 0.08);
  color: inherit;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font: inherit;
  line-height: 1;
}

.tab-remove:hover,
.tab-remove:focus-visible {
  background: rgba(199, 75, 42, 0.18);
  outline: none;
}

.tab-button:hover,
.tab-button:focus-visible {
  transform: translateY(-1px);
  outline: none;
  background: rgba(255, 255, 255, 0.9);
}

.tab-button.active {
  background: var(--ink);
  color: #f7f1e9;
}

.tab-button.upload {
  background: rgba(157, 61, 24, 0.12);
  color: var(--accent);
}

.upload-tab-panel {
  animation: rise 240ms ease;
}

.upload-card {
  border-radius: var(--radius-lg);
  padding: 22px;
}

.upload-dropzone {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 170px;
  border: 1.5px dashed rgba(157, 61, 24, 0.34);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(157, 61, 24, 0.08), rgba(157, 61, 24, 0.02));
  cursor: pointer;
  text-align: center;
  padding: 24px;
}

.upload-dropzone.is-dragging {
  background: linear-gradient(180deg, rgba(157, 61, 24, 0.16), rgba(157, 61, 24, 0.06));
  border-color: rgba(157, 61, 24, 0.58);
}

.upload-hint {
  display: inline-block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.92rem;
}

#csv-upload {
  width: 100%;
  margin-top: 16px;
}

.upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.action-button {
  border: 0;
  border-radius: 999px;
  padding: 10px 14px;
  cursor: pointer;
  font: inherit;
  transition: transform 160ms ease, background 160ms ease;
}

.action-button:hover,
.action-button:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

.action-button-muted {
  background: rgba(24, 35, 31, 0.08);
  color: var(--ink);
}

.action-button-danger {
  background: rgba(199, 75, 42, 0.14);
  color: var(--alert);
}

#dashboard {
  animation: rise 320ms ease;
}

.summary-grid,
.insight-grid,
.chart-grid,
.table-grid {
  display: grid;
  gap: 18px;
  margin-bottom: 18px;
}

.summary-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.insight-grid,
.table-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chart-grid {
  grid-template-columns: 1.3fr 1fr;
}

.summary-card,
.panel {
  border-radius: var(--radius-lg);
  padding: 20px;
}

.summary-card {
  background: var(--panel-strong);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: var(--shadow);
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.summary-value {
  font-family: var(--font-display);
  font-size: clamp(1.85rem, 2vw, 2.6rem);
  line-height: 1;
  letter-spacing: -0.04em;
}

.summary-detail {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.94rem;
}

.panel-heading {
  margin-bottom: 14px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 1.7rem;
  letter-spacing: -0.03em;
}

.stack-list {
  display: grid;
  gap: 12px;
}

.stack-item {
  padding: 16px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.45);
  border: 1px solid rgba(24, 35, 31, 0.06);
}

.stack-item h3 {
  margin: 0 0 8px;
  font-size: 1.12rem;
}

.stack-item p {
  margin: 0;
}

.stack-item.signal-high {
  border-left: 4px solid var(--alert);
}

.stack-item.signal-warn {
  border-left: 4px solid var(--warn);
}

.stack-item.signal-safe {
  border-left: 4px solid var(--safe);
}

.chart-frame {
  min-height: 340px;
}

.timeline-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.9rem;
  font-weight: 600;
}

.legend-chip.day {
  background: rgba(224, 159, 44, 0.16);
  color: #9b6500;
}

.legend-chip.night {
  background: rgba(42, 108, 90, 0.14);
  color: #225546;
}

.timeline-detail {
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.65);
  color: var(--muted);
  line-height: 1.5;
}

.timeline-detail strong {
  color: var(--ink);
}

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

.axis-label,
.chart-note,
.threshold-label {
  fill: var(--muted);
  font-family: var(--font-body);
  font-size: 12px;
}

.timeline-line {
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.timeline-line.day {
  stroke: #b14f1f;
}

.timeline-line.night {
  stroke: #2f6e62;
}

.day-night-band.day {
  fill: rgba(224, 159, 44, 0.08);
}

.day-night-band.night {
  fill: rgba(42, 108, 90, 0.07);
}

.timeline-point {
  cursor: pointer;
  stroke: rgba(255, 251, 247, 0.9);
  stroke-width: 1.2;
  opacity: 0.48;
  transition: opacity 140ms ease, r 140ms ease, stroke-width 140ms ease;
}

.timeline-point.day {
  fill: #b14f1f;
}

.timeline-point.night {
  fill: #2f6e62;
}

.timeline-point:hover,
.timeline-point:focus-visible,
.timeline-point.selected {
  opacity: 1;
  stroke-width: 2.4;
  outline: none;
}

.threshold-line {
  fill: none;
  stroke-width: 1.2;
  stroke-dasharray: 5 5;
}

.grid-line {
  stroke: rgba(24, 35, 31, 0.08);
  stroke-width: 1;
}

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

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

th,
td {
  text-align: left;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

th {
  font-size: 1rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.84rem;
  font-weight: 600;
}

.pill.alert {
  background: rgba(199, 75, 42, 0.12);
  color: var(--alert);
}

.pill.warn {
  background: rgba(215, 136, 18, 0.12);
  color: #936000;
}

.pill.safe {
  background: rgba(42, 108, 90, 0.12);
  color: var(--safe);
}

.empty-state {
  padding: 18px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.45);
  color: var(--muted);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .hero,
  .insight-grid,
  .chart-grid,
  .table-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .page-shell {
    width: min(100vw - 20px, 1240px);
    padding-top: 14px;
  }

  .hero {
    padding: 22px;
  }

  .timeline-meta {
    flex-direction: column;
  }
}
