/* ── CSS Variables & Reset ────────────────────────────────────────── */
:root {
  --navy: #2c3e50;
  --teal: #1abc9c;
  --gold: #f1c40f;
  --coral: #e74c3c;
  --bg: #1a2634;
  --surface: #243447;
  --surface2: #2e4057;
  --text: #ecf0f1;
  --text-muted: #95a5a6;
  --radius: 8px;
}

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

html, body {
  height: 100%;
  font-family: 'Montserrat', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── Layout ───────────────────────────────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
}

.left-panel {
  width: 480px;
  min-width: 280px;
  max-width: 70vw;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow-y: auto;
}

.resize-handle {
  width: 6px;
  cursor: col-resize;
  background: var(--teal);
  flex-shrink: 0;
  position: relative;
  transition: background 0.15s;
}

.resize-handle::after {
  content: '⋮';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--navy);
  font-size: 14px;
  font-weight: 700;
  pointer-events: none;
  opacity: 0.5;
  transition: opacity 0.15s;
}

.resize-handle:hover,
.resize-handle.dragging {
  background: var(--gold);
}

.resize-handle:hover::after,
.resize-handle.dragging::after {
  opacity: 1;
}

.right-panel {
  flex: 1;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
  overflow: hidden;
}

.panel-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--surface2);
}

.panel-section h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--teal);
  margin-bottom: 8px;
}

/* ── Buttons ──────────────────────────────────────────────────────── */
button {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

button:hover { opacity: 0.85; }

.btn-teal { background: var(--teal); color: #fff; }
.btn-surface { background: var(--surface2); color: var(--text); }
.btn-coral { background: var(--coral); color: #fff; }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-active { outline: 2px solid var(--gold); outline-offset: 1px; }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

/* ── Formula Bar ──────────────────────────────────────────────────── */
.formula-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--bg);
  font-size: 14px;
}

.formula-bar.active { display: flex; }

.formula-bar label {
  font-weight: 600;
  color: var(--gold);
  white-space: nowrap;
}

.formula-bar input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--text-muted);
  border-radius: 4px;
  color: var(--text);
  padding: 4px 8px;
  font-family: 'Montserrat', monospace;
  font-size: 14px;
}

.formula-bar .formula-error {
  color: var(--coral);
  font-size: 13px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Data Table ───────────────────────────────────────────────────── */
.table-wrap {
  overflow: auto;
  flex: 1;
  min-height: 200px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}

th, td {
  border: 1px solid var(--surface2);
  padding: 0;
  text-align: center;
  height: 34px;
  min-width: 90px;
}

th {
  background: var(--navy);
  position: sticky;
  top: 0;
  z-index: 2;
}

/* Row number column */
th:first-child, td:first-child {
  width: 36px;
  min-width: 36px;
  max-width: 36px;
  background: var(--navy);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  position: sticky;
  left: 0;
  z-index: 1;
}

th:first-child { z-index: 3; }

.col-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 4px;
}

.col-header-name {
  background: none;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  width: 100%;
  padding: 2px;
  border-radius: 3px;
}

.col-header-name:focus {
  background: var(--surface2);
  outline: 1px solid var(--teal);
}

.col-type-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 3px;
  cursor: pointer;
  user-select: none;
}

.col-type-badge.data { background: var(--teal); color: #fff; }
.col-type-badge.formula { background: var(--gold); color: var(--navy); }
.col-type-badge.error { background: var(--coral); color: #fff; }

.col-header-warn {
  color: var(--coral);
  font-size: 15px;
  line-height: 1;
}

/* Linked-to selector for error columns */
.col-linked {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 2px;
}

.col-linked select {
  font-family: inherit;
  font-size: 11px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--text-muted);
  border-radius: 3px;
  padding: 0 2px;
  max-width: 70px;
}

.col-delete {
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  position: absolute;
  top: 2px;
  right: 4px;
  line-height: 1;
}

.col-delete:hover { color: var(--coral); }

.err-type-btn {
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  border: 1px solid var(--text-muted);
  background: var(--surface2);
  color: var(--text-muted);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.err-type-btn.active {
  background: var(--gold);
  color: var(--navy);
  border-color: var(--gold);
}

th .th-inner {
  position: relative;
}

/* Cell input */
td input {
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  text-align: center;
  font-family: inherit;
  font-size: 14px;
  padding: 0 4px;
  outline: none;
}

td input:focus {
  background: var(--surface2);
  outline: 2px solid var(--teal);
  outline-offset: -2px;
}

td.formula-cell input {
  color: var(--gold);
}

td.error-val input {
  color: var(--coral);
}

td.formula-cell {
  background: rgba(241, 196, 15, 0.05);
}

/* ── Axis Selectors ───────────────────────────────────────────────── */
.axis-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.axis-grid label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
  margin-bottom: 2px;
}

.axis-grid select, .axis-grid input[type="text"] {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 5px 8px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--surface2);
  border-radius: 4px;
}

.range-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 6px;
  margin-top: 6px;
}

.range-row label { font-size: 12px; color: var(--text-muted); }
.range-row input[type="number"] {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 4px 6px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--surface2);
  border-radius: 4px;
}

.range-row input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 14px;
}

.check-row input[type="checkbox"] {
  accent-color: var(--teal);
}

/* ── LOBF Info Panel ──────────────────────────────────────────────── */
.lobf-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.7;
  display: none;
}

.lobf-panel.active { display: block; }

.lobf-panel .line-label {
  font-weight: 700;
  margin-bottom: 2px;
}

.lobf-panel .eq { color: var(--teal); font-weight: 600; }
.lobf-panel .worst-eq { font-weight: 600; }
.lobf-panel .uncertainty { color: var(--gold); font-weight: 600; }

/* ── Graph Toolbar ────────────────────────────────────────────────── */
.graph-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface2);
  flex-shrink: 0;
}

.graph-toolbar .spacer { flex: 1; }

.copied-toast {
  font-size: 13px;
  color: var(--teal);
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s;
}

.copied-toast.show { opacity: 1; }

/* ── Canvas ───────────────────────────────────────────────────────── */
.canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--teal);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.12s;
  z-index: 10;
}

.tooltip.show { opacity: 1; }

/* ── Type Picker Dropdown ─────────────────────────────────────────── */
.type-picker {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--teal);
  border-radius: var(--radius);
  padding: 4px 0;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  min-width: 110px;
}

.type-picker div {
  padding: 6px 14px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}

.type-picker div:hover { background: var(--surface2); }
.type-picker .tp-data { color: var(--teal); }
.type-picker .tp-formula { color: var(--gold); }
.type-picker .tp-error { color: var(--coral); }

/* ── Scrollbar ────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
