/* ===========================
   WATERMARK v2 — INSTITUTIONAL
   Modeled after USGS/EPA/WRI
   =========================== */

:root {
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;

  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-lg: 1.0625rem;
  --text-xl: 1.25rem;

  /* Institutional palette — USGS/EPA blue family */
  --blue-900: #0c2d48;
  --blue-800: #1a5276;
  --blue-700: #1f6f9f;
  --blue-600: #2980b9;
  --blue-100: #d6eaf8;
  --blue-50: #eaf2f8;

  --gray-900: #1a1a2e;
  --gray-800: #2d2d44;
  --gray-700: #4a4a5a;
  --gray-600: #5a6474;
  --gray-500: #7f8c8d;
  --gray-400: #aab0b5;
  --gray-300: #d5d8dc;
  --gray-200: #e8eaed;
  --gray-100: #f2f3f4;
  --gray-50: #f8f9fa;

  --red-700: #c0392b;
  --red-100: #fadbd8;
  --amber-700: #b7791f;
  --amber-100: #fef9e7;
  --green-700: #1e8449;
  --green-100: #d5f5e3;
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--gray-900);
  background: var(--gray-50);
  min-height: 100dvh;
}

a {
  color: var(--blue-700);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--blue-800);
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font: inherit;
}

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

/* ===========================
   HEADER — institutional bar
   =========================== */

.header {
  background: var(--blue-900);
  color: #fff;
  border-bottom: 3px solid var(--blue-600);
}

.header-bar {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.625rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: var(--text-lg);
  letter-spacing: -0.01em;
}

.header-brand svg circle,
.header-brand svg path {
  stroke: #fff;
  fill: none;
}

.header-brand svg path {
  fill: rgba(255,255,255,0.2);
  stroke: #fff;
}

.header-nav {
  display: flex;
  gap: 0.25rem;
}

.header-nav a {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 0.375rem 0.75rem;
  border-radius: 3px;
  transition: background 150ms, color 150ms;
}

.header-nav a:hover,
.header-nav a.nav-active {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

.header-desc {
  background: var(--blue-800);
  padding: 0.5rem 1.5rem;
  font-size: var(--text-sm);
  font-weight: 500;
  color: rgba(255,255,255,0.9);
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 768px) {
  .header-bar {
    flex-direction: column;
    align-items: flex-start;
    padding: 0.75rem 1rem;
  }
  .header-nav {
    flex-wrap: wrap;
    gap: 0.125rem;
  }
  .header-desc {
    padding: 0.5rem 1rem;
  }
}

/* ===========================
   MAIN TOOL LAYOUT
   =========================== */

.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1rem;
}

.tool-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 0;
  min-height: calc(100dvh - 120px);
}

@media (max-width: 1024px) {
  .tool-layout {
    grid-template-columns: 1fr;
  }
}

/* ===========================
   INPUT PANEL
   =========================== */

.input-panel {
  padding: 1.25rem 1.5rem 1.25rem 0.5rem;
  border-right: 1px solid var(--gray-300);
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: calc(100dvh - 90px);
}

@media (max-width: 1024px) {
  .input-panel {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--gray-300);
    padding: 1.25rem 0.5rem;
  }
}

.panel-heading {
  font-family: var(--font-body);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--blue-900);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--blue-600);
}

.field-group {
  border: none;
  margin-bottom: 1.25rem;
  padding: 0;
}

.field-legend {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--gray-700);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.5rem;
  display: block;
}

.field-row {
  margin-bottom: 0.375rem;
}

.field-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 0.25rem;
}

.field-number,
.field-select {
  width: 100%;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--gray-300);
  border-radius: 3px;
  font-size: var(--text-base);
  font-family: var(--font-body);
  background: #fff;
  color: var(--gray-900);
}

.field-number:focus,
.field-select:focus {
  outline: none;
  border-color: var(--blue-600);
  box-shadow: 0 0 0 2px rgba(41, 128, 185, 0.2);
}

.field-number {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.field-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.375rem;
}

.preset {
  padding: 0.25rem 0.5rem;
  font-size: var(--text-xs);
  font-weight: 500;
  border: 1px solid var(--gray-300);
  border-radius: 3px;
  background: #fff;
  color: var(--gray-700);
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: all 120ms;
}

.preset:hover {
  border-color: var(--blue-600);
  color: var(--blue-800);
}

.preset.active {
  background: var(--blue-50);
  border-color: var(--blue-600);
  color: var(--blue-800);
}

.preset-note {
  font-size: 10px;
  background: var(--amber-100);
  color: var(--amber-700);
  padding: 0 4px;
  border-radius: 2px;
  font-weight: 600;
}

/* Location details table */
.loc-details {
  margin-top: 0.5rem;
}

.loc-table {
  font-size: var(--text-sm);
  border: 1px solid var(--gray-200);
}

.loc-table td {
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--gray-200);
}

.loc-key {
  color: var(--gray-600);
  font-weight: 500;
  width: 45%;
  background: var(--gray-100);
}

.loc-val {
  font-weight: 600;
  color: var(--gray-900);
  font-variant-numeric: tabular-nums;
}

.loc-cite {
  font-size: 11px;
  color: var(--gray-500);
  margin-top: 0.375rem;
  line-height: 1.5;
}

.loc-cite a {
  font-size: 11px;
}

.stress-high {
  color: var(--red-700);
  font-weight: 700;
}

.stress-medium {
  color: var(--amber-700);
  font-weight: 700;
}

.stress-low {
  color: var(--green-700);
  font-weight: 700;
}

/* Checkbox */
.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--gray-800);
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  margin-top: 0.2rem;
  accent-color: var(--blue-600);
  width: 16px;
  height: 16px;
}

/* Field notes — inline citations */
.field-note {
  font-size: 11px;
  color: var(--gray-500);
  line-height: 1.5;
  margin-top: 0.375rem;
}

.field-note a {
  font-size: 11px;
}

.last-updated {
  text-align: center;
  margin-top: 0.75rem;
  color: var(--gray-400);
}

/* Calculate button */
.calc-btn {
  width: 100%;
  padding: 0.625rem 1rem;
  background: var(--blue-800);
  color: #fff;
  font-size: var(--text-sm);
  font-weight: 600;
  border-radius: 3px;
  transition: background 150ms;
}

.calc-btn:hover {
  background: var(--blue-900);
}

/* ===========================
   RESULTS PANEL
   =========================== */

.results-panel {
  padding: 1.25rem 0.5rem 2rem 1.5rem;
  overflow-y: auto;
}

@media (max-width: 1024px) {
  .results-panel {
    padding: 1.25rem 0.5rem 2rem;
  }
}

.results-context {
  font-size: var(--text-sm);
  color: var(--gray-600);
  margin-bottom: 1.25rem;
  padding: 0.625rem 0.75rem;
  background: var(--blue-50);
  border-left: 3px solid var(--blue-600);
}

.results-context strong {
  color: var(--gray-900);
}

/* Results blocks */
.results-block {
  margin-bottom: 1.5rem;
}

.block-heading {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--blue-900);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.5rem;
  padding-bottom: 0.375rem;
  border-bottom: 1px solid var(--gray-300);
}

.block-note {
  font-size: var(--text-sm);
  color: var(--gray-600);
  margin-bottom: 0.75rem;
  line-height: 1.6;
}

.block-note a {
  font-size: var(--text-sm);
}

/* Results tables — the core display element */
.results-table {
  font-size: var(--text-sm);
  border: 1px solid var(--gray-300);
  margin-bottom: 0.5rem;
}

.results-table thead {
  background: var(--gray-100);
}

.results-table th {
  padding: 0.5rem 0.625rem;
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gray-600);
  border-bottom: 2px solid var(--gray-300);
}

.results-table td {
  padding: 0.5rem 0.625rem;
  border-bottom: 1px solid var(--gray-200);
  vertical-align: top;
}

.results-table .val {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--gray-900);
  white-space: nowrap;
}

.results-table .cite {
  font-size: 11px;
  color: var(--gray-500);
  line-height: 1.5;
}

.results-table .cite a {
  font-size: 11px;
}

.row-total {
  background: var(--blue-50);
}

.row-total td {
  border-bottom: 2px solid var(--blue-600);
}

/* Indirect block highlight */
.indirect-block {
  background: var(--amber-100);
  border: 1px solid #e8d5a0;
  border-radius: 3px;
  padding: 1rem;
}

.indirect-block .block-heading {
  border-bottom-color: #c9a94e;
  color: var(--amber-700);
}

.indirect-block .results-table {
  border-color: #d4b96a;
}

.indirect-block .results-table thead {
  background: #f5ecd1;
}

.indirect-block .results-table th {
  border-bottom-color: #c9a94e;
  color: var(--amber-700);
}

.indirect-block .results-table td {
  border-bottom-color: #e8d5a0;
}

.indirect-block .row-total {
  background: #f0e2b8;
}

.indirect-block .row-total td {
  border-bottom-color: var(--amber-700);
}

/* Comparison bar */
.comparison-bar {
  display: flex;
  height: 28px;
  border-radius: 3px;
  overflow: hidden;
  margin: 0.75rem 0;
  font-size: 11px;
  font-weight: 600;
}

.comp-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  min-width: 60px;
  transition: width 500ms ease;
}

.comp-direct {
  background: var(--blue-700);
}

.comp-indirect {
  background: var(--amber-700);
}

/* Supply bar */
.supply-chart {
  margin-bottom: 0.5rem;
}

.supply-bar-bg {
  width: 100%;
  height: 20px;
  background: var(--gray-200);
  border: 1px solid var(--gray-300);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}

.supply-bar-fill {
  height: 100%;
  background: var(--blue-700);
  transition: width 500ms ease;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 4px;
  min-width: 36px;
}

.supply-label {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
}

.supply-scale {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--gray-500);
  margin-top: 0.25rem;
}

.supply-threshold {
  color: var(--red-700);
  font-weight: 500;
}

/* Actions */
.results-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.875rem;
  font-size: var(--text-sm);
  font-weight: 500;
  border: 1px solid var(--gray-300);
  border-radius: 3px;
  background: #fff;
  color: var(--gray-700);
  transition: all 120ms;
}

.action-btn:hover {
  border-color: var(--blue-600);
  color: var(--blue-800);
  background: var(--blue-50);
}

/* Limitations */
.limitations {
  background: var(--gray-100);
  border: 1px solid var(--gray-300);
  border-radius: 3px;
  padding: 1rem;
}

.limitations .block-heading {
  color: var(--gray-600);
}

.limitations-list {
  list-style: none;
  padding: 0;
}

.limitations-list li {
  font-size: var(--text-sm);
  color: var(--gray-600);
  line-height: 1.6;
  padding: 0.375rem 0;
  padding-left: 1rem;
  position: relative;
  border-bottom: 1px solid var(--gray-200);
}

.limitations-list li:last-child {
  border-bottom: none;
}

.limitations-list li::before {
  content: '▸';
  position: absolute;
  left: 0;
  color: var(--gray-400);
}

/* ===========================
   FOOTER
   =========================== */

.footer {
  background: var(--gray-100);
  border-top: 1px solid var(--gray-300);
  padding: 1.25rem 1.5rem;
  margin-top: 2rem;
}

.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 2rem;
}

.footer-left,
.footer-right {
  font-size: 11px;
  color: var(--gray-500);
  line-height: 1.6;
}

.footer-left p:first-child,
.footer-right p:first-child {
  margin-bottom: 0.25rem;
}

.footer a {
  font-size: 11px;
  color: var(--gray-600);
}

@media (max-width: 768px) {
  .footer-inner {
    flex-direction: column;
    gap: 0.75rem;
  }
}

/* ===========================
   PRINT STYLES
   =========================== */

@media print {
  .header,
  .input-panel,
  .results-actions,
  .footer {
    display: none;
  }

  .tool-layout {
    display: block;
  }

  .results-panel {
    padding: 0;
  }

  .results-block {
    break-inside: avoid;
  }

  body {
    font-size: 11pt;
    color: #000;
    background: #fff;
  }

  .results-table {
    font-size: 10pt;
  }

  a {
    color: #000;
    text-decoration: none;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 8pt;
    color: #666;
  }

  .indirect-block {
    border: 2px solid #999;
    background: #f9f6ef;
  }
}
