/* ─── Loading Overlay ───────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.loading-overlay.active {
  opacity: 1;
  pointer-events: all;
}
.loading-overlay .loading-content {
  text-align: center;
  color: var(--text);
}
.loading-overlay .loading-content p {
  margin-top: 14px;
  font-size: 1rem;
  color: var(--text-muted);
}
.spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--border-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Info Modal ────────────────────────────────────────────── */
.info-modal-backdrop {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.18s ease;
}
.info-modal {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  min-width: 300px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.2s ease;
  overflow: hidden;
}
.info-modal-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.info-modal-header span {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.info-modal-body {
  padding: 20px;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.55;
}
.info-modal-footer {
  padding: 12px 20px 16px;
  display: flex;
  justify-content: flex-end;
}
.info-modal-footer .btn-ok {
  padding: 7px 24px;
  background: var(--accent-dim);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
}
.info-modal-footer .btn-ok:hover {
  background: var(--accent);
}
.info-modal-footer .btn-ok.btn-ok--error {
  background: var(--danger);
}
.info-modal-footer .btn-ok.btn-ok--error:hover {
  background: #ff6b63;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

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

/* ─── Design Tokens ─────────────────────────────────────────── */
:root {
  --bg:          #0d1117;
  --surface:     #161b22;
  --surface-2:   #1c2128;
  --border:      #21262d;
  --border-soft: #30363d;
  --accent:      #58a6ff;
  --accent-dim:  #1f6feb;
  --accent-glow: rgba(88, 166, 255, 0.15);
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --text-faint:  #484f58;
  --danger:      #f85149;
  --success:     #3fb950;
  --warning:     #d29922;
  --radius:      6px;
  --radius-lg:   10px;
  --font-sans:   'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:   'JetBrains Mono', 'Fira Code', 'Consolas', 'Courier New', monospace;
  --transition:  0.15s ease;
}

body.light-mode {
  --bg:          #f6f8fa;
  --surface:     #ffffff;
  --surface-2:   #f0f2f4;
  --border:      #d0d7de;
  --border-soft: #c8cdd3;
  --accent:      #0969da;
  --accent-dim:  #0550ae;
  --accent-glow: rgba(9, 105, 218, 0.12);
  --text:        #1f2328;
  --text-muted:  #656d76;
  --text-faint:  #bbc0c6;
}

/* ─── Base ───────────────────────────────────────────────────── */
html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
  zoom: 1.25;
}

/* ─── Header ─────────────────────────────────────────────────── */
header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 18px 20px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

header .subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 3px;
  max-width: 580px;
  text-align: center;
  line-height: 1.4;
}

/* Logo / brand link */
header > a {
  position: absolute;
  top: 50%;
  left: 18px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  opacity: 0.85;
  transition: opacity var(--transition);
}
header > a:hover { opacity: 1; }
header > a img { height: 36px; }
header > a span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

/* Dark mode toggle */
.dark-mode-toggle {
  position: absolute;
  top: 50%;
  right: 18px;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

.dark-mode-toggle label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

/* Toggle switch */
.dark-mode-toggle input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 32px;
  height: 17px;
  background: var(--border-soft);
  border-radius: 9px;
  cursor: pointer;
  position: relative;
  transition: background var(--transition);
  flex-shrink: 0;
}
.dark-mode-toggle input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform var(--transition), background var(--transition);
}
.dark-mode-toggle input[type="checkbox"]:checked {
  background: var(--accent-dim);
}
.dark-mode-toggle input[type="checkbox"]:checked::after {
  transform: translateX(15px);
  background: #fff;
}

.version-info {
  font-size: 0.68rem;
  color: var(--text-faint);
  text-align: right;
  line-height: 1.4;
}

/* ─── Layout ─────────────────────────────────────────────────── */
.container {
  display: flex;
  flex-direction: row;
  max-width: 1200px;
  margin: 18px auto;
  gap: 16px;
  padding: 0 16px;
}

/* ─── Left Sidebar ───────────────────────────────────────────── */
.data-panel {
  flex: 0 0 272px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  height: calc(100vh - 120px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-soft) transparent;
}
.data-panel::-webkit-scrollbar { width: 4px; }
.data-panel::-webkit-scrollbar-thumb { background: var(--border-soft); border-radius: 2px; }

.data-panel h2 {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.data-panel > p {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-top: -6px;
}

/* ─── Textarea ───────────────────────────────────────────────── */
.data-panel textarea,
textarea#manualDataInput {
  width: 100%;
  padding: 9px 10px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  min-height: 140px;
}
.data-panel textarea:focus,
textarea#manualDataInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.data-panel textarea::placeholder,
textarea#manualDataInput::placeholder {
  color: var(--text-faint);
  font-style: italic;
}

/* ─── Inputs ─────────────────────────────────────────────────── */
input[type="number"],
input[type="text"],
select {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  outline: none;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
}
input[type="number"]:focus,
input[type="text"]:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238b949e'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
  cursor: pointer;
}
select option {
  background: var(--surface);
  color: var(--text);
}

/* ─── Labels ─────────────────────────────────────────────────── */
label {
  display: block;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}
label strong {
  color: var(--text);
  font-weight: 600;
}

/* ─── Buttons ────────────────────────────────────────────────── */
.btn,
.btn-file,
.btn-select,
button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: background var(--transition), border-color var(--transition),
              color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  user-select: none;
  text-decoration: none;
}
.btn:hover,
.btn-file:hover,
.btn-select:hover {
  background: var(--border);
  border-color: var(--border-soft);
}
.btn:active,
.btn-file:active,
.btn-select:active {
  background: var(--border-soft);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.2);
}
.btn:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-glow);
  border-color: var(--accent);
}

/* Primary */
.primary-btn,
.data-panel > button {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: #fff;
}
.primary-btn:hover,
.data-panel > button:hover {
  background: #388bfd;
  border-color: #388bfd;
}

/* ─── Baseline Controls ──────────────────────────────────────── */
.baseline-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.baseline-controls button {
  width: 100%;
  text-align: center;
}

.baseline-controls label {
  margin-top: 4px;
}

.baseline-controls > div[style] {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ─── Help Tooltip ───────────────────────────────────────────── */
.help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border-soft);
  border-radius: 50%;
  cursor: pointer;
  position: relative;
  transition: border-color var(--transition), color var(--transition);
  vertical-align: middle;
  margin-right: 4px;
}
.help:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.help::after {
  content: attr(data-help);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  white-space: pre-wrap;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-soft);
  padding: 8px 10px;
  border-radius: var(--radius);
  width: 210px;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
  z-index: 200;
  pointer-events: none;
}
.help:hover::after {
  opacity: 1;
  visibility: visible;
}

/* ─── Main Content ───────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* ─── Chart Wrapper & Containers ────────────────────────────── */
#chartWrapper {
  position: relative;
  width: 818px;
  height: 500px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  flex-shrink: 0;
}

#chartContainer,
#chartContainerLambert {
  width: 818px;
  height: 500px;
  background: transparent;
}

#chartContainerLambert {
  position: absolute;
  top: 0;
  left: 0;
  display: none;
}

/* D3 axis text */
#chartContainer .axis text,
#chartContainerLambert .axis text {
  fill: var(--text-muted);
  font-size: 11px;
  font-family: var(--font-sans);
}
#chartContainer .axis line,
#chartContainer .axis path,
#chartContainerLambert .axis line,
#chartContainerLambert .axis path {
  stroke: var(--border-soft);
}

/* ─── Zoom Controls ──────────────────────────────────────────── */
#zoomControls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 3px;
  z-index: 10;
}

#zoomControls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 1rem;
  font-weight: 600;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition);
  font-family: var(--font-sans);
  padding: 0;
}
#zoomControls button:hover {
  background: var(--border);
}
#zoomControls button img {
  width: 15px;
  height: 15px;
  opacity: 0.7;
  filter: invert(1);
}
body.light-mode #zoomControls button img {
  filter: none;
}

/* ─── Points Table Section ───────────────────────────────────── */
.points-table-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  width: 818px;
  flex-shrink: 0;
}

.points-table-section h3 {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* Action buttons row */
.points-table-section > section > button,
.points-table-section button {
  margin-right: 6px;
  margin-bottom: 6px;
}

/* ─── Table ──────────────────────────────────────────────────── */
.table-container {
  margin-bottom: 14px;
}
.table-container h4 {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.points-list {
  width: 100%;
  max-height: 260px;
  overflow-y: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  scrollbar-width: thin;
  scrollbar-color: var(--border-soft) transparent;
}
.points-list::-webkit-scrollbar { width: 4px; }
.points-list::-webkit-scrollbar-thumb { background: var(--border-soft); border-radius: 2px; }

.points-list table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  font-family: var(--font-mono);
}
.points-list th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 1;
}
.points-list td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  color: var(--text);
}
.points-list tr:last-child td { border-bottom: none; }
.points-list tr:nth-child(even) td { background: var(--surface-2); }
.points-list tr:hover td { background: var(--accent-glow); }

/* ─── Interpolation Options ──────────────────────────────────── */
.interpolation-options {
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.interpolation-options label {
  font-size: 0.8rem;
  margin: 0;
}
.interpolation-options input[type="number"] {
  width: 76px;
}
.interpolation-options input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ─── Section dividers inside sidebar ───────────────────────── */
.baseline-controls > br {
  display: block;
  content: '';
  margin: 0;
}

/* ─── Scrollbar global ───────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-soft); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ─── Light mode overrides (remaining) ──────────────────────── */
body.light-mode .dark-mode-toggle input[type="checkbox"]:not(:checked)::after {
  background: #aaa;
}
body.light-mode select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23656d76'/%3E%3C/svg%3E");
}

/* ─── Responsive touch: larger tap targets on mobile ─────────── */
@media (max-width: 900px) {
  .container {
    flex-direction: column;
  }
  .data-panel {
    flex: none;
    height: auto;
    max-height: 340px;
  }
  #chartWrapper,
  #chartContainer {
    width: 100%;
    height: auto;
    aspect-ratio: 16/10;
  }
}
