/* ═══════════════════════════════════════════════════════════════════
   LAMINATE CALCULATOR v2 — Dark Theme
   Overrides Foundation 6 light defaults
   ═══════════════════════════════════════════════════════════════════ */

/* ── Google Fonts (JetBrains Mono) loaded in HTML ──────────────── */

:root {
  --bg-root:    #080808;
  --bg-card:    #0c0c0c;
  --bg-input:   #141414;
  --border:     #1e1e1e;
  --border-in:  #2a2a2a;
  --text:       #cccccc;
  --text-dim:   #777777;
  --text-head:  #999999;
  --accent:     #e8a735;
  --accent-dim: #b07a20;
  --green:      #22c55e;
  --amber:      #f59e0b;
  --red:        #ef4444;
  --blue:       #3b82f6;
  --radius:     8px;
  --mono:       'JetBrains Mono', monospace;
}

/* ── Reset / Base ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  background: var(--bg-root);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

/* Foundation overrides */
.grid-container { max-width: 100%; padding: 0 14px; }
.grid-x { --grid-padding: 14px; }

/* ── Typography ──────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 { color: var(--text); font-family: var(--mono); }
a { color: var(--accent); }

/* ── Header bar ──────────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid #1a1a1a;
  background: var(--bg-root);
  flex-wrap: wrap;
}
#header .brand {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
#header .brand-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.08em;
  line-height: 1.1;
}
#header .brand-sub {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.06em;
}
#board-name-input {
  flex: 1 1 200px;
  min-width: 120px;
  background: var(--bg-input);
  border: 1px solid var(--border-in);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 5px 10px;
  height: 32px;
  outline: none;
}
#board-name-input:focus { border-color: var(--accent); }
#board-name-input::placeholder { color: var(--text-dim); }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  height: 32px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  transition: opacity 0.15s, background 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-primary {
  background: var(--accent);
  color: #000;
}
.btn-secondary {
  background: #1a1a1a;
  color: var(--text);
  border: 1px solid var(--border-in);
}
.btn-secondary:hover { background: #242424; }
.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid transparent;
  padding: 4px 7px;
  height: 26px;
}
.btn-danger:hover { background: rgba(239,68,68,0.1); }
.btn-icon {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 4px 7px;
  height: 26px;
  font-size: 11px;
}
.btn-icon:hover { color: var(--accent); border-color: var(--accent); background: transparent; }
.btn-add {
  background: #111;
  color: var(--accent);
  border: 1px dashed #333;
  width: 100%;
  justify-content: center;
  height: 30px;
  font-size: 12px;
  border-radius: 4px;
  margin-top: 6px;
}
.btn-add:hover { background: #161616; border-color: var(--accent); }

/* ── Cards ───────────────────────────────────────────────────────── */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.panel-header:hover { background: #0f0f0f; }
.panel-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-head);
}
.panel-title.tension  { color: var(--blue); }
.panel-title.compress { color: var(--red); }
.panel-body { padding: 8px 10px; }

/* ── Layer Rows ──────────────────────────────────────────────────── */
.layer-list { display: flex; flex-direction: column; gap: 4px; }
.layer-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 4px;
  background: #101010;
  border: 1px solid #1a1a1a;
  border-radius: 4px;
}
.layer-row:hover { border-color: #2a2a2a; }
.layer-swatch {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid #333;
}
.layer-mat-select {
  flex: 1;
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-in);
  border-radius: 3px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 4px;
  height: 24px;
  outline: none;
}
.layer-mat-select:focus { border-color: var(--accent); }
.layer-t-input {
  width: 52px;
  flex-shrink: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-in);
  border-radius: 3px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 5px;
  height: 24px;
  outline: none;
  text-align: right;
}
.layer-t-input:focus { border-color: var(--accent); }
.layer-t-unit {
  font-size: 10px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.layer-move-btns {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.layer-move-btns .btn-icon {
  height: 11px;
  width: 18px;
  font-size: 8px;
  padding: 0 2px;
  line-height: 1;
}

/* ── Core section ────────────────────────────────────────────────── */
#core-section { }
.core-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
}
.core-selector label {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
  margin: 0;
}
.core-wood-select {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-in);
  border-radius: 3px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 5px;
  height: 26px;
  outline: none;
}
.core-wood-select:focus { border-color: var(--accent); }
.core-max-t {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}
.core-max-t span { color: var(--accent); font-weight: 700; }
.core-profile-toggle {
  font-size: 10px;
  color: var(--text-dim);
  cursor: pointer;
  text-decoration: underline;
  flex-shrink: 0;
}
.core-profile-toggle:hover { color: var(--text); }
.core-profile-body { padding: 8px 10px; }
.core-profile-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-in);
  border-radius: 3px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 10px;
  padding: 6px 8px;
  resize: vertical;
  min-height: 80px;
  outline: none;
  line-height: 1.4;
}
.core-profile-textarea:focus { border-color: var(--accent); }
.core-profile-hint { font-size: 10px; color: var(--text-dim); margin-top: 4px; }

/* ── Metrics card ────────────────────────────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.metric-cell {
  padding: 10px 12px;
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
}
.metric-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.metric-value {
  font-size: 18px;
  font-weight: 800;
  font-family: var(--mono);
  line-height: 1.1;
}
.metric-value.green  { color: var(--green); }
.metric-value.amber  { color: var(--amber); }
.metric-value.red    { color: var(--red); }
.metric-value.accent { color: var(--accent); }
.metric-value.white  { color: #fff; }
.metric-unit {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}
.metric-sub {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
}
.metric-sub span {
  color: var(--text);
  font-weight: 700;
}

/* ── Balance Meter ───────────────────────────────────────────────── */
.balance-meter-cell { padding: 10px 12px; border-left: 1px solid var(--border); border-top: 1px solid var(--border); }
.balance-big-num {
  font-size: 28px;
  font-weight: 800;
  font-family: var(--mono);
  line-height: 1;
  margin-bottom: 6px;
}
.balance-bar-wrap {
  position: relative;
  height: 8px;
  background: #1a1a1a;
  border-radius: 4px;
  overflow: visible;
  margin-bottom: 4px;
}
.balance-bar-green {
  position: absolute;
  top: 0; bottom: 0;
  background: rgba(34,197,94,0.25);
  border-radius: 4px;
}
.balance-bar-fill {
  position: absolute;
  top: 1px;
  height: 6px;
  width: 4px;
  border-radius: 2px;
  transform: translateX(-50%);
  transition: left 0.3s;
}
.balance-label {
  font-size: 10px;
  margin-top: 4px;
}

/* ── Stacked metric (two values in one cell) ─────────────────────── */
.metric-stack { display: flex; flex-direction: column; gap: 6px; }
.metric-stack .metric-block { border-bottom: 1px solid #1a1a1a; padding-bottom: 6px; }
.metric-stack .metric-block:last-child { border-bottom: none; padding-bottom: 0; }
.metric-value-sm {
  font-size: 14px;
  font-weight: 800;
  font-family: var(--mono);
  line-height: 1.1;
}
.metric-value-sm.green  { color: var(--green); }
.metric-value-sm.amber  { color: var(--amber); }
.metric-value-sm.red    { color: var(--red); }
.metric-value-sm.accent { color: var(--accent); }
.metric-value-sm.white  { color: #fff; }

/* ── Explanation card ────────────────────────────────────────────── */
.explanation-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
}
.explanation-col {
  padding: 10px 12px;
  border-right: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.6;
}
.explanation-col:last-child { border-right: none; }
.explanation-col h5 {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 6px;
  margin-top: 0;
  letter-spacing: 0.04em;
}
.explanation-col p { margin: 0 0 6px; }

/* ── Flex Test card ──────────────────────────────────────────────── */
.flex-inputs {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.flex-input-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.flex-input-group label {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  margin: 0;
}
.flex-num-input {
  width: 80px;
  background: var(--bg-input);
  border: 1px solid var(--border-in);
  border-radius: 3px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  padding: 3px 7px;
  height: 26px;
  outline: none;
  text-align: right;
}
.flex-num-input:focus { border-color: var(--accent); }
.flex-unit { font-size: 10px; color: var(--text-dim); }
.flex-results {
  display: flex;
  gap: 0;
  flex-wrap: wrap;
}
.flex-result-item {
  padding: 8px 14px;
  border-right: 1px solid var(--border);
  min-width: 110px;
}
.flex-result-item:last-child { border-right: none; }
.flex-result-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin-bottom: 3px;
}
.flex-result-val {
  font-size: 14px;
  font-weight: 800;
  font-family: var(--mono);
  color: var(--accent);
}
.flex-result-unit { font-size: 10px; color: var(--text-dim); margin-top: 2px; }
.flex-measured {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.flex-measured label { font-size: 11px; color: var(--text-dim); margin: 0; }
.flex-back-calc {
  font-size: 12px;
  color: var(--text);
  margin-left: 10px;
}
.flex-back-calc .accent { color: var(--accent); font-weight: 700; }

/* ── Charts row ──────────────────────────────────────────────────── */
.charts-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}
.bottom-charts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}
.chart-panel { }
.chart-panel .panel-body { padding: 6px; }
svg.chart-svg { display: block; width: 100%; }
svg.xs-svg { display: block; width: 100%; }

/* ── SVG chart text ──────────────────────────────────────────────── */
.chart-axis-label {
  fill: #555;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
}
.chart-grid-line { stroke: #1a1a1a; stroke-width: 1; }
.chart-ref-line { stroke: #555; stroke-width: 1; stroke-dasharray: 3,3; }
.chart-band { fill: rgba(34,197,94,0.07); }
.chart-area-fill { opacity: 0.15; }
.chart-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── Cross section SVG ───────────────────────────────────────────── */
.xs-na-line  { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 4,2; }
.xs-ctr-line { stroke: #444; stroke-width: 1; stroke-dasharray: 2,3; }
.xs-label    { fill: #888; font-family: 'JetBrains Mono', monospace; font-size: 9px; }

/* ── Boards Drawer (overlay) ─────────────────────────────────────── */
#boards-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
}
#boards-overlay.open { display: flex; }
#boards-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
}
#boards-drawer {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 340px;
  background: #0e0e0e;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1;
}
#boards-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
#boards-drawer-header h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
#boards-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.board-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 6px;
  background: #111;
  gap: 8px;
}
.board-item:hover { border-color: #333; }
.board-item-info { flex: 1; min-width: 0; }
.board-item-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.board-item-meta {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}
.board-item-btns { display: flex; gap: 5px; flex-shrink: 0; }
#boards-count-badge {
  background: var(--accent);
  color: #000;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
}

/* ── Inputs global ───────────────────────────────────────────────── */
input, select, textarea {
  color-scheme: dark;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

/* ── Scrollbars ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #0a0a0a; }
::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a3a; }

/* ── Responsive tweaks ───────────────────────────────────────────── */
@media (max-width: 640px) {
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .bottom-charts { grid-template-columns: 1fr; }
  .explanation-grid { grid-template-columns: 1fr; }
  .charts-row { grid-template-columns: 1fr; }
}

/* ── Utility ─────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-dim { color: var(--text-dim); }
.text-accent { color: var(--accent); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.mt-4 { margin-top: 4px; }
.mb-0 { margin-bottom: 0; }
.w-full { width: 100%; }

/* Foundation override: remove default light backgrounds */
.button { font-family: var(--mono); }
fieldset { border: 1px solid var(--border); }
label { color: var(--text-dim); }

/* ── Compare panel (left column) ─────────────────────────────────── */
.compare-panel-title {
  color: #888;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
  font-family: var(--mono);
}
.compare-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 4px;
  border-radius: 3px;
  border: 1px solid transparent;
  margin-bottom: 2px;
  font-family: var(--mono);
}
.compare-row-active { background: #1a150022; }
.compare-row-name {
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.compare-row-tag {
  font-size: 9px;
  flex-shrink: 0;
  color: var(--text-dim);
}
.compare-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
.btn-tiny {
  font-family: var(--mono);
  font-size: 9px;
  padding: 2px 7px;
  background: none;
  border: 1px solid #333;
  border-radius: 3px;
  cursor: pointer;
  color: #666;
  flex-shrink: 0;
}
.btn-tiny:hover { opacity: 0.8; }

/* ── Metrics active-board indicator ─────────────────────────────── */
.metrics-active-board {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
}

/* ── Chart legend ────────────────────────────────────────────────── */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  padding: 6px 4px 4px;
  font-family: var(--mono);
  font-size: 11px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.legend-line {
  display: inline-block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
}
.legend-line-dashed {
  background: none;
  border-top: 2px dashed;
  height: 0;
}

/* ── Boards list: current board highlight + compare dot ─────────── */
.board-item-current { background: #0f0f00 !important; border-color: #e8a73530 !important; }

/* ── Left column layout ──────────────────────────────────────────── */
#left-col { padding-right: 8px; }
#right-col { padding-left: 0; }

/* Foundation grid cell gutters */
.grid-x > .cell { padding: 0 4px; }
.grid-x > .cell:first-child { padding-left: 0; }
.grid-x > .cell:last-child { padding-right: 0; }

/* Main layout spacing */
#main-content { padding: 8px 14px 40px; }
