*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

@font-face {
  font-family: 'Kyoto';
  src: url('fonts/Kyoto-Medium.woff2') format('woff2'),
       url('fonts/Kyoto-Medium.woff') format('woff');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Kyoto';
  src: url('fonts/Kyoto-MediumItalic.woff2') format('woff2'),
       url('fonts/Kyoto-MediumItalic.woff') format('woff');
  font-weight: 500;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'Geist';
  src: url('fonts/Geist-Light.woff2') format('woff2');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Geist';
  src: url('fonts/Geist-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Geist';
  src: url('fonts/Geist-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --dark-green:  #343f31;
  --light-green: #a7cc80;
  --pink:        #dbbcde;
  --blue:        #adcafa;
  --yellow:      #f3ed60;
  --brown:       #302508;
  --white:       #FFFFFF;
  --off-white:   #F4F2EF;
  --border:      rgba(52,63,49,0.12);
  --shadow-sm:   0 1px 4px rgba(52,63,49,0.08);
  --radius:      6px;
  --font:        'Geist', system-ui, -apple-system, sans-serif;
  --font-serif:  'Kyoto', Georgia, serif;
  --text-dark:   #343f31;
  --text-mid:    rgba(52,63,49,0.70);
  --text-muted:  rgba(52,63,49,0.45);
}

body {
  font-family: var(--font);
  background: var(--off-white);
  color: var(--text-dark);
  line-height: 1.55;
  font-size: 14px;
}

/* ─── HEADER ─────────────────────────── */
.header {
  background: var(--dark-green);
  border-bottom: 3px solid var(--yellow);
  padding: 0 48px;
  display: flex;
  align-items: center;
  min-height: 58px;
}
.header-logo {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: inherit;
}
.logo-img {
  height: 30px;
  width: auto;
  display: block;
}
.logo-divider {
  width: 1px;
  background: rgba(255,255,255,0.15);
  align-self: stretch;
  margin: 12px 0;
}
.logo-tagline {
  font-size: 11px;
  color: rgba(255,255,255,0.40);
  font-weight: 300;
  line-height: 1.45;
}
.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 18px;
}
.header-badge {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.65);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  padding: 4px 11px;
  border-radius: 20px;
  border: 0.5px solid rgba(255,255,255,0.12);
}
.header-meta {
  font-size: 11px;
  color: rgba(255,255,255,0.30);
  text-align: right;
  line-height: 1.45;
}

/* ─── HERO BAND ─────────────────────── */
.hero-band {
  background: var(--dark-green);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  padding: 22px 48px 0;
  display: flex;
  align-items: flex-end;
  min-height: 110px;
}
.hero-left {
  flex: 1;
  padding-bottom: 22px;
}
.hero-eyebrow {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--yellow);
  opacity: 0.9;
  margin-bottom: 8px;
}
.hero-title {
  font-family: var(--font-serif);
  font-size: 24px;
  color: white;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
  max-width: 800px;
}
.hero-sub {
  font-size: 12px;
  color: rgba(255,255,255,0.35);
  font-weight: 300;
}
.hero-stats {
  display: flex;
  align-items: stretch;
  border-left: 1px solid rgba(255,255,255,0.08);
}
.hero-stat {
  padding: 18px 24px 20px;
  border-right: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-width: 110px;
}
.hero-stat-eyebrow {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.30);
  margin-bottom: 5px;
}
.hero-stat-number {
  font-family: var(--font-serif);
  font-size: 34px;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--light-green);
}
.hero-stat-number.dim { color: rgba(255,255,255,0.55); }
.hero-stat-label {
  font-size: 11px;
  color: rgba(255,255,255,0.35);
  font-weight: 300;
  margin-top: 4px;
  line-height: 1.35;
}

/* ─── LAYOUT ──────────────────────────── */
.explorer-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: calc(100vh - 220px);
}

/* ─── SIDEBAR ─────────────────────────── */
.sidebar-shell {
  position: sticky;
  top: 0;
  max-height: 100vh;
  align-self: start;
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-right: 1px solid var(--border);
}
.explorer-sidebar {
  background: var(--white);
  padding: 16px 0;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}
/* Fade cue when the list scrolls past the visible area — hidden once scrolled to the end.
   A real element anchored to .sidebar-shell (not the scrolling pane), since position:sticky
   on generated content is unreliable in Safari. */
.sidebar-fade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 28px;
  background: linear-gradient(to bottom, rgba(244,242,239,0), var(--white) 85%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.sidebar-fade.has-more-below { opacity: 1; }
.sidebar-section { margin-bottom: 2px; }
.sidebar-group-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 18px 3px;
}
.sidebar-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  text-align: left;
  padding: 7px 18px;
  font-family: var(--font);
  background: none;
  border: none;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s, color 0.1s;
}
.sidebar-item-title {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-mid);
  line-height: 1.35;
}
.sidebar-item-sub {
  font-size: 10.5px;
  font-weight: 300;
  color: var(--text-muted);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sidebar-item:hover { background: rgba(167,204,128,0.18); }
.sidebar-item:hover .sidebar-item-title,
.sidebar-item:hover .sidebar-item-sub { color: var(--dark-green); }
.sidebar-item.active {
  background: var(--light-green);
  border-left-color: var(--yellow);
}
.sidebar-item.active .sidebar-item-title { color: var(--dark-green); font-weight: 600; }
.sidebar-item.active .sidebar-item-sub { color: rgba(52,63,49,0.65); }
#sidebar-search:focus {
  border-color: var(--light-green) !important;
  outline: none;
}

/* ─── CONTENT ─────────────────────────── */
.explorer-content {
  padding: 24px 36px 60px;
  background: var(--off-white);
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
}

/* ─── CONTROLS ────────────────────────── */
.explorer-controls-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.ctrl-group { display: flex; align-items: center; gap: 7px; }
.ctrl-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
}
.ctrl-select {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 400;
  color: var(--text-dark);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  cursor: pointer;
  outline: none;
  min-width: 200px;
}
.ctrl-select:focus { border-color: var(--light-green); }
.ctrl-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.ctrl-toggle-btn {
  padding: 6px 13px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  background: var(--white);
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.1s;
}
.ctrl-toggle-btn.active {
  background: var(--dark-green);
  color: var(--light-green);
}
.ctrl-reset-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 6px 12px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-mid);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.ctrl-reset-btn:hover { background: rgba(167,204,128,0.18); color: var(--dark-green); border-color: var(--light-green); }
.ctrl-reset-btn svg { flex-shrink: 0; }

/* Secondary control */
.secondary-ctrl-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  min-height: 22px;
}
.sec-label {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  opacity: 0.75;
}
.sec-select {
  font-family: var(--font);
  font-size: 12px;
  color: var(--text-muted);
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  cursor: pointer;
  outline: none;
  opacity: 0.75;
  transition: opacity 0.15s, border-color 0.15s;
}
.sec-select.enabled {
  opacity: 1;
  border-style: solid;
  border-color: var(--border);
  background: var(--white);
  color: var(--text-dark);
}
.sec-select:focus { border-color: var(--light-green); outline: none; }
.sec-hint {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  opacity: 0.6;
}
.sec-hint.hidden { display: none; }

/* ─── CHART CARD ─────────────────────── */
.explorer-chart-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}
.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.explorer-chart-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.export-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  color: var(--dark-green);
  background: var(--light-green);
  border: 1px solid rgba(52,63,49,0.15);
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.1s;
}
.export-btn:hover { background: #93bb6a; }
.export-btn svg { flex-shrink: 0; }

.explorer-chart-wrap {
  position: relative;
  height: 300px;
  transition: height 0.2s ease;
}
.crosstab-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}
.ct-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-mid);
}
.ct-legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ─── TABLE CARD ─────────────────────── */
.explorer-table-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
}
.explorer-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.explorer-table th {
  background: var(--dark-green);
  color: var(--light-green);
  padding: 10px 14px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
}
.explorer-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--off-white);
  color: var(--text-dark);
}
.explorer-table tr:last-child td { border-bottom: none; }
.explorer-table tr:hover td { background: rgba(167,204,128,0.10); }
.explorer-table td.num {
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.explorer-table td.cat-label { font-weight: 600; }
.n-badge {
  display: inline-block;
  background: var(--light-green);
  color: var(--dark-green);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  margin-left: 8px;
}

/* ─── LOADING ─────────────────────────── */
.loading-spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--dark-green);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── TRELLIS ─────────────────────────── */
.trellis-warning {
  padding: 8px 14px;
  background: rgba(52,63,49,0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-mid);
  margin-bottom: 12px;
}
.trellis-grid { display: grid; gap: 14px; }
.trellis-cell {
  background: rgba(167,204,128,0.08);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px 10px;
  display: flex;
  flex-direction: column;
  height: 240px;
}
.trellis-cell-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--dark-green);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}
.trellis-cell canvas { display: block; width: 100%; height: 100%; }
.trellis-n-badge { font-size: 10px; color: var(--text-muted); margin-top: 4px; flex-shrink: 0; }
.trellis-n-badge.low { color: #a15c1c; }

/* ─── LOW-N WARNING ───────────────────── */
.n-warn {
  display: inline-block;
  font-size: 10px;
  color: #a15c1c;
  cursor: help;
}

/* ─── EXPORT DIALOG ───────────────────── */
.dialog-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(52,63,49,0.55);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.dialog-overlay.open { display: flex; animation: dialogFadeIn 0.18s ease; }
.dialog-overlay.open .dialog { animation: dialogPopIn 0.22s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes dialogFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes dialogPopIn {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.dialog {
  background: var(--white);
  border-radius: 12px;
  width: 420px;
  max-width: 92vw;
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(52,63,49,0.20);
}
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.dialog-title { font-size: 15px; font-weight: 600; color: var(--text-dark); }
.dialog-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 2px;
  display: flex; align-items: center;
}
.dialog-close:hover { color: var(--text-dark); }
.dialog-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.dialog-footer {
  display: flex; gap: 10px;
  padding: 18px 24px 22px;
  border-top: 1px solid var(--border);
}
.dialog-btn-sec {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font); font-size: 13px; font-weight: 600;
  color: var(--dark-green);
  background: var(--light-green);
  border: 1px solid rgba(52,63,49,0.15);
  border-radius: var(--radius);
  padding: 10px 0; cursor: pointer; transition: background 0.1s;
}
.dialog-btn-sec:hover { background: #93bb6a; }
.dialog-btn-primary {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px;
  font-family: var(--font); font-size: 13px; font-weight: 600;
  color: var(--light-green); background: var(--dark-green);
  border: none; border-radius: var(--radius);
  padding: 10px 0; cursor: pointer; transition: background 0.1s;
}
.dialog-btn-primary:hover { background: #2a3427; }

@media (max-width: 900px) {
  .header { padding-left: 20px; padding-right: 20px; }
  .hero-band { padding-left: 20px; padding-right: 20px; }
  .explorer-layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar-shell { position: relative; max-height: none; border-right: none; border-bottom: 1px solid var(--border); }
  .explorer-content { padding: 18px 20px 40px; }
  .hero-stats { display: none; }
}

@media (max-width: 700px) {
  .header { flex-wrap: wrap; min-height: auto; padding: 14px 16px; gap: 8px; }
  .logo-tagline { display: none; }
  .header-right { margin-left: 0; }
  .header-meta { display: none; }

  .hero-band { padding: 16px 16px 0; min-height: auto; flex-direction: column; align-items: flex-start; }
  .hero-left { padding-bottom: 16px; }
  .hero-title { font-size: 19px; }

  .explorer-content { padding: 14px 14px 32px; }
  .sidebar-shell { max-height: 220px; }

  .explorer-controls-row { gap: 8px; }
  .ctrl-group { flex: 1 1 100%; }
  .ctrl-select { min-width: 0; width: 100%; }
  .ctrl-toggle { width: 100%; }
  .ctrl-toggle-btn { flex: 1; }
  .ctrl-reset-btn { margin-left: 0; width: 100%; justify-content: center; }

  .secondary-ctrl-row { flex-wrap: wrap; }
  .sec-select { flex: 1 1 100%; width: 100%; }

  .explorer-chart-card { padding: 14px 12px; }
  .explorer-table { font-size: 12px; }
  .explorer-table th, .explorer-table td { padding: 8px 10px; }

  .trellis-grid { grid-template-columns: 1fr !important; }

  .dialog-footer { flex-direction: column; }
}

/* ─── PRINT ───────────────────────────── */
@media print {
  body { background: #fff; }

  /* Interactive chrome has no purpose on paper */
  .sidebar-shell, .explorer-controls-row, .secondary-ctrl-row,
  .export-btn, .ctrl-reset-btn, .dialog-overlay, .loading-spinner { display: none !important; }

  .explorer-layout { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .explorer-content { padding: 0; }

  .header, .hero-band {
    background: #fff !important;
    border-bottom: 1px solid #000;
    color: #000;
  }
  .header { border-bottom-width: 2px; }
  .logo-tagline, .header-badge, .header-meta, .hero-stats { display: none; }
  .hero-eyebrow { color: #555 !important; opacity: 1; }
  .hero-title { color: #000 !important; }
  .hero-sub { color: #333 !important; }

  .explorer-chart-card, .explorer-table-card {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
    margin-bottom: 16px;
  }
  .explorer-chart-wrap { height: 380px !important; }
  .explorer-table-card { overflow: visible; }

  .explorer-table th { background: #eee !important; color: #000 !important; }
  .explorer-table td[style*="background"] { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .trellis-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .trellis-cell { break-inside: avoid; background: #fff; }
}
