/* Scatterize — Quarto/R-docs aesthetic */

/* ─── Fonts ─────────────────────────────────────────────────────────────── */

@font-face {
  font-family: "League Spartan";
  src: url("../fonts/LeagueSpartan-VF.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-display: swap;
}

/* ─── Reset & Base ─────────────────────────────────────────────────────── */

/* Ensure [hidden] is respected even when author styles set display. */
[hidden] { display: none !important; }

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

:root {
  --font-sans: "League Spartan", sans-serif;
  --color-bg:         #ffffff;
  --color-surface:    #f8f9fa;
  --color-border:     #dee2e6;
  --color-border-mid: #ced4da;
  --color-text:       #212529;
  --color-text-muted: #6c757d;
  --color-accent:     #2780e3;
  --color-accent-dk:  #1a6bbf;

  /* Plot colors */
  --color-point:      #4e79a7;
  --color-regline:    #b5541a;
  --color-censored:   #aaaaaa;

  --header-height: 52px;
  --footer-height: 32px;
  --controls-width: 190px;
  --stats-width: 230px;
  --panel-pad: 14px;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-bg);
  overflow: hidden;
}

/* ─── Header ────────────────────────────────────────────────────────────── */

.site-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  flex-shrink: 0;
}

.site-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
  color: var(--color-text);
}

.site-title-link {
  color: inherit;
  text-decoration: none;
}
.site-title-link:hover { text-decoration: underline; }

.url-bar {
  display: flex;
  flex: 1;
  gap: 8px;
  min-width: 0;
}

.url-input {
  flex: 1;
  min-width: 0;
  padding: 5px 10px;
  font-size: 13px;
  font-family: var(--font-sans);
  border: 1px solid var(--color-border-mid);
  border-radius: 4px;
  background: var(--color-bg);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s;
}

.url-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(39, 128, 227, 0.15);
}

/* ─── Buttons ───────────────────────────────────────────────────────────── */

.btn {
  padding: 5px 14px;
  font-size: 13px;
  font-family: var(--font-sans);
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}
.btn-primary:hover { background: var(--color-accent-dk); border-color: var(--color-accent-dk); }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border-mid);
}
.btn-secondary:hover { background: var(--color-border); }
.btn-secondary:disabled,
.btn-secondary:disabled:hover {
  opacity: 0.45;
  cursor: not-allowed;
  background: var(--color-surface);
  border-color: var(--color-border-mid);
}

/* ─── App Grid ──────────────────────────────────────────────────────────── */

.app-grid {
  display: grid;
  grid-template-columns: var(--controls-width) 1fr var(--stats-width);
  grid-template-rows: 1fr;
  height: calc(100dvh - var(--header-height) - var(--footer-height));
  overflow: hidden;
}

/* ─── Panels ────────────────────────────────────────────────────────────── */

.panel {
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
  overflow-y: auto;
  padding: var(--panel-pad);
}

.panel-stats {
  border-right: none;
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

/* ─── Controls ──────────────────────────────────────────────────────────── */

.control-group {
  margin-bottom: 14px;
}

.control-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 5px;
}

.form-select {
  width: 100%;
  padding: 4px 8px;
  font-size: 13px;
  font-family: var(--font-sans);
  border: 1px solid var(--color-border-mid);
  border-radius: 4px;
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
  outline: none;
}

.form-select:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(39, 128, 227, 0.15);
}

.form-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: normal;
  text-transform: none;
  letter-spacing: normal;
  color: var(--color-text);
  cursor: pointer;
}

.checkbox-list input[type="checkbox"] {
  cursor: pointer;
  margin: 0;
}

.control-note {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--color-text-muted);
  font-style: italic;
}

/* ─── Plot Container ────────────────────────────────────────────────────── */

.plot-container {
  position: relative;
  background: var(--color-bg);
  overflow: hidden;
}

.scatter-layer {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.overlay-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  will-change: transform;
}

/* ─── Loading State ─────────────────────────────────────────────────────── */

.loading-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--color-text-muted);
}

.loading-state.hidden {
  display: none;
}

/* ─── Empty State ───────────────────────────────────────────────────────── */

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-state-inner {
  max-width: 30em;
}

.empty-state h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin: 0 0 8px;
  text-align: center;
  margin-bottom: 2em;
}

.empty-state p {
  font-size: 14px;
  color: var(--color-text-muted);
  margin: 4px 0;
}

.empty-state.hidden {
  display: none;
}

/* ─── Stats Panel ───────────────────────────────────────────────────────── */

.stats-section {
  padding: var(--panel-pad);
}

.stats-section h3, .diag-plots h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 8px;
}

.stats-section--model {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--color-border);
}

.stats-section--desc {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  border-bottom: 1px solid var(--color-border);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-family: var(--font-sans);
}

.stats-table td {
  padding: 2px 0;
  vertical-align: top;
}

.stats-table td:first-child {
  color: var(--color-text-muted);
  padding-right: 10px;
  white-space: nowrap;
  font-family: var(--font-sans);
  font-size: 13px;
}

.stats-table td:last-child {
  text-align: right;
}

.stats-divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 8px 0;
}

.stats-nuisance-header {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-sans);
  padding-bottom: 4px;
}

/* ─── Diagnostic Plots ──────────────────────────────────────────────────── */

.diag-plots {
  flex: 0 0 auto;
  padding: var(--panel-pad);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}

.diag-plots.hidden {
  display: none;
}

.diag-svg-container {
  position: relative;
}

.diag-svg {
  display: block;
  width: 100%;
}

/* ─── Help Modal ────────────────────────────────────────────────────────── */

#help-modal {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 20px 24px;
  min-width: 280px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.15);
  font-family: var(--font-sans);
  color: var(--color-text);
}

#help-modal::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.help-modal-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin: 0 0 12px;
}

.help-table {
  border-collapse: collapse;
  font-size: 13px;
  width: 100%;
}

.help-table td {
  padding: 3px 0;
  vertical-align: middle;
}

.help-table td:first-child {
  padding-right: 16px;
  white-space: nowrap;
}

.help-modal-dismiss {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--color-text-muted);
}

kbd {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: 11px;
  padding: 1px 5px;
  border: 1px solid var(--color-border-mid);
  border-radius: 3px;
  background: var(--color-surface);
  line-height: 1.4;
}

/* ─── Share Button ──────────────────────────────────────────────────────── */

.share-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  font-size: 12px;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border-mid);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  z-index: 10;
}
.share-btn:hover {
  background: var(--color-surface);
  border-color: var(--color-border);
}

/* ─── Share Modal ───────────────────────────────────────────────────────── */

#share-modal {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0;
  min-width: 360px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.15);
  font-family: var(--font-sans);
  color: var(--color-text);
}

#share-modal::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.share-section {
  padding: 14px 18px;

  & + .share-section {
    border-top: 1px solid var(--color-border);
  }

  & h3 {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin: 0 0 10px;
  }
}

.share-download-row {
  display: flex;
  gap: 8px;
  align-items: center;

  & + .share-download-row {
    margin-top: 6px;
  }
}

.share-filename-input {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  font-size: 12px;
  font-family: var(--font-sans);
  border: 1px solid var(--color-border-mid);
  border-radius: 4px;
  background: var(--color-bg);
  color: var(--color-text);
  outline: none;

  &:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px rgba(39, 128, 227, 0.15);
  }

  &:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    background: var(--color-surface);
  }
}

.share-url-note {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--color-text-muted);
  font-style: italic;
}

/* ─── Footer ────────────────────────────────────────────────────────────── */

.site-footer {
  height: var(--footer-height);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

.footer-link {
  font-size: 13px;
  font-family: var(--font-sans);
  color: var(--color-text-muted);
  text-decoration: none;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}
.footer-link:hover { color: var(--color-text); text-decoration: underline; }

.footer-sep {
  color: var(--color-border-mid);
  font-size: 13px;
  user-select: none;
}

/* ─── Error Banner ──────────────────────────────────────────────────────── */

.error-banner {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #c0392b;
  color: #fff;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 600px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
  z-index: 100;
}

.error-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  opacity: 0.8;
}
.error-close:hover { opacity: 1; }

/* ─── Drop Overlay ──────────────────────────────────────────────────────── */

.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(39, 128, 227, 0.06);
  border: 3px dashed var(--color-accent);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 200;
}

.drop-overlay.visible {
  opacity: 1;
}

.drop-overlay-inner {
  background: var(--color-bg);
  border: 2px solid var(--color-accent);
  border-radius: 8px;
  padding: 20px 36px;
  text-align: center;
  box-shadow: 0 2px 16px rgba(39, 128, 227, 0.15);
}

.drop-message {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-accent);
  margin: 0;
}

/* ─── Mobile layout ─────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  html, body {
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .app-grid {
    display: flex;
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  /* Show plot first, then controls, then stats */
  .plot-container { order: 1; }
  .panel-controls  { order: 2; }
  .panel-stats     { order: 3; }

  .plot-container {
    height: 72vw;
    min-height: 260px;
    flex-shrink: 0;
  }

  /* Panels expand to content rather than clipping */
  .panel {
    overflow-y: visible;
    border-right: none;
    border-top: 1px solid var(--color-border);
  }

  .panel-stats {
    display: block;
    overflow: visible;
    border-left: none;
    border-top: 1px solid var(--color-border);
    padding: var(--panel-pad);
  }

  .stats-section {
    padding: 0;
    border-bottom: none;
  }
  

  .stats-section--desc {
    overflow-y: visible;
    min-height: 0;
    padding-top: var(--panel-pad);
  }

}

