/* CutList Optimizer — Responsive CSS */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* ── Theme: light, modern, blue-accent (matches reference UI) ────── */
  --bg-app:    #F2F4F7;
  --bg-card:   #FFFFFF;
  --bg-hdr:    #F4F6FA;     /* very light gray for section headers */
  --bg-tb:     #1E2D3D;     /* dark toolbar (kept) */
  --fg:        #1F2937;
  --fg-muted:  #6B7280;
  --fg-soft:   #9AA3B2;     /* uppercase column header text */
  --fg-accent: #4263EB;
  --fg-ok:     #2F8A57;
  --fg-danger: #B91C1C;
  --border:    #E5E7EB;     /* lighter, softer */
  --border-strong: #D1D5DB;
  --accent:    #4263EB;     /* royal blue — Add buttons / focus */
  --accent-hover: #3B53D6;
  --green:     #52A975;     /* Optimize green */
  --green-hover: #46966A;
  --row-num-bg: #E7ECFB;
  --row-num-fg: #4263EB;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-md: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --radius:    8px;
  --radius-sm: 6px;
  --safe-top:  env(safe-area-inset-top, 0px);
  --safe-bot:  env(safe-area-inset-bottom, 0px);
  --tb-h:      50px;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: system-ui,-apple-system,"Segoe UI",sans-serif;
  font-size: 14px;
  background: var(--bg-app);
  color: var(--fg);
  display: flex; flex-direction: column;
}

/* ── Pages ─────────────────────────────────────────────────────────── */
.page { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

/* ── Toolbar ────────────────────────────────────────────────────────── */
.toolbar {
  background: var(--bg-tb);
  padding: 8px 14px;
  padding-top: calc(8px + var(--safe-top));
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0; position: relative; z-index: 100;
}
.toolbar-brand { color:#fff; font-size:15px; font-weight:700; white-space:nowrap; flex-shrink:0; }
.brand-short   { display:none; }
.brand-full    { display:inline; }

.toolbar-actions { display:flex; align-items:center; gap:8px; flex-wrap:wrap; margin-left:auto; }
.toolbar-actions label { color:#90A4AE; font-size:12px; display:flex; align-items:center; gap:4px; }

.tb-input  { background:#2D3F52; border:1px solid #3D5166; color:#fff; padding:4px 8px; border-radius:4px; font-size:13px; width:110px; }
.tb-num    { width:50px; }
.tb-select { background:#2D3F52; border:1px solid #3D5166; color:#fff; padding:4px 6px; border-radius:4px; font-size:13px; }

/* Mobile toolbar */
.toolbar-mobile { display:flex; align-items:center; gap:6px; margin-left:auto; }
.desktop-only   { display:flex; }
.mobile-only    { display:none; }

/* Toolbar results page */
.toolbar-results { gap:10px; }
.btn-back { background:rgba(255,255,255,.15); border:none; color:#fff; padding:6px 12px; border-radius:5px; font-size:14px; cursor:pointer; }

/* ── Options bar ────────────────────────────────────────────────────── */
.options-bar { background:var(--bg-card); border-bottom:1px solid var(--border); padding:6px 16px; display:flex; align-items:center; gap:6px; flex-wrap:wrap; flex-shrink:0; }
.opt-label   { color:var(--fg-muted); font-size:12px; font-weight:600; }
.opt-divider { width:1px; height:18px; background:var(--border); margin:0 8px; }
.radio-lbl   { display:flex; align-items:center; gap:4px; font-size:13px; cursor:pointer; }

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn { border:none; border-radius:6px; cursor:pointer; font-size:13px; font-weight:600; padding:6px 12px; white-space:nowrap; transition:filter .15s, background .15s; -webkit-tap-highlight-color:transparent; }
.btn:hover  { filter:brightness(1.05); }
.btn:active { filter:brightness(.92); }
.btn:disabled { opacity:.45; cursor:default; filter:none; }

.btn-optimize  { background:var(--green); color:#fff; }
.btn-optimize:hover { background:var(--green-hover); filter:none; }
.btn-pdf       { background:var(--accent); color:#fff; }
.btn-pdf:hover { background:var(--accent-hover); filter:none; }
.btn-tool      { background:#37474F; color:#fff; }
.btn-recent    { background:#37474F; color:#fff; }

/* + Add Panel / + Add Sheet — solid blue pill (matches reference) */
.btn-add       { background:var(--accent); color:#fff; font-size:13px; padding:7px 14px; border-radius:6px; font-weight:600; box-shadow:var(--shadow-sm); }
.btn-add:hover { background:var(--accent-hover); filter:none; }

.btn-eq        { background:var(--accent); color:#fff; padding:8px 16px; font-size:15px; }
.btn-unit-tag  { background:#E8F5E9; color:#1B6E3A; border:1px solid #A5D6A7; font-size:13px; padding:5px 12px; }
.btn-link      { background:none; border:none; color:var(--fg-danger); cursor:pointer; font-size:12px; }

/* Mobile icon buttons — outlined pills + blue accent for PDF */
.btn-optimize-sm,
.btn-pdf-sm,
.btn-tool-sm {
  background:#fff;
  color:#475569;
  border:1px solid var(--border-strong);
  border-radius:8px;
  padding:8px 11px;
  min-width:40px;
  min-height:38px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  box-shadow:var(--shadow-sm);
  transition:background .15s, border-color .15s;
}
.btn-optimize-sm:hover,
.btn-pdf-sm:hover,
.btn-tool-sm:hover { background:#F8FAFC; filter:none; }
.btn-optimize-sm:active,
.btn-pdf-sm:active,
.btn-tool-sm:active { background:#F1F5F9; filter:none; }

/* PDF button gets the blue accent treatment */
.btn-pdf-sm {
  background:var(--accent);
  color:#fff;
  border-color:var(--accent);
}
.btn-pdf-sm:hover  { background:var(--accent-hover); border-color:var(--accent-hover); }
.btn-pdf-sm:active { background:var(--accent-hover); border-color:var(--accent-hover); }
.btn-pdf-sm:disabled { background:#fff; color:#9AA3B2; border-color:var(--border-strong); }

/* Optimize on mobile keeps a green pill so the primary action stays visible */
.btn-optimize-sm {
  background:var(--green);
  color:#fff;
  border-color:var(--green);
}
.btn-optimize-sm:hover  { background:var(--green-hover); border-color:var(--green-hover); }
.btn-optimize-sm:active { background:var(--green-hover); border-color:var(--green-hover); }

/* Inline icons inside toolbar buttons */
.btn-icon { width:18px; height:18px; display:inline-block; vertical-align:middle; flex-shrink:0; }
.btn-icon-sm { width:20px; height:20px; }
.btn-icon-inline { width:16px; height:16px; display:inline-block; vertical-align:-2px; flex-shrink:0; margin-right:4px; }

/* ── Main two-pane layout ───────────────────────────────────────────── */
.main-layout { display:flex; gap:8px; padding:8px; flex:1; overflow:hidden; min-height:0; }

/* ── Input pane ─────────────────────────────────────────────────────── */
.input-pane { width:700px; min-width:380px; max-width:1200px; flex-shrink:0; display:flex; flex-direction:column; gap:0; overflow-y:auto; }

.section-card   { background:var(--bg-card); border:1px solid var(--border); border-radius:var(--radius); overflow:hidden; box-shadow:var(--shadow-md); }
.section-header { 
  background:#fff; 
  padding:14px 16px; 
  display:flex; 
  align-items:center; 
  justify-content:space-between; 
  font-weight:600; 
  font-size:14px; 
  color:#2D3F52; 
  border-bottom:1px solid #E7ECFB; 
}
.section-header small { 
  font-weight:400; 
  color:#8E99AE; 
  font-size:12px;
}

/* Column headers — uppercase soft gray */
.col-headers { 
  background:#fff; 
  border-bottom:1px solid #E7ECFB; 
  display:flex; 
  align-items:center; 
  padding:10px 6px; 
  font-size:11px; 
  font-weight:600; 
  color:#7A8FA6; 
  text-transform:uppercase; 
  letter-spacing:.05em;
  gap:3px;
}
.ch { text-align:center; }
.ch-num   { width:32px;  flex-shrink:0; text-align:center; }
.ch-dim   { width:80px;  flex-shrink:0; }
.ch-unit  { width:58px;  flex-shrink:0; }
.ch-x     { width:20px;  flex-shrink:0; }
.ch-qty   { width:44px;  flex-shrink:0; }
.ch-lbl   { flex:1; min-width:70px; text-align:left; padding-left:4px; }
.ch-grain { width:82px;  flex-shrink:0; }
.ch-del   { width:34px;  flex-shrink:0; }

.rows-container { overflow-y:visible; padding:6px 0; }

/* ── Desktop input row ──────────────────────────────────────────────── */
.input-row { 
  display:flex; 
  align-items:center; 
  padding:8px 6px; 
  border-bottom:1px solid #F4F6FA; 
  gap:3px; 
  transition:background .15s ease;
}
.input-row:hover { background:#FAFBFC; }
.input-row:last-child { border-bottom:none; }

/* Mobile row collapse/expand */
.mobile-row-summary { display:flex; align-items:center; flex:1; padding:8px 6px; cursor:pointer; user-select:none; font-size:13px; color:var(--fg); }
.mobile-row-summary:active { background:#F0FFF4; border-radius:4px; }
.mobile-row-expanded { display:none; flex-direction:column; width:100%; gap:6px; padding:8px 0; }

/* Row number — light grey circle */
.row-num   {
  width:36px;
  display:flex; 
  align-items:center; 
  justify-content:center;
  flex-shrink:0;
  font-size:12px; 
  font-weight:500;
  font-family:inherit;
  color:#6B7280;
}
.row-num span {
  display:inline-flex; 
  align-items:center; 
  justify-content:center;
  width:24px; 
  height:24px;
  background:#F3F4F6;
  border:1px solid #E5E7EB;
  border-radius:50%;
  font-weight:500;
  color:#6B7280;
}

.row-entry { 
  border:1px solid #DDE4ED; 
  border-radius:5px; 
  padding:8px 10px; 
  font-size:14px; 
  font-weight:500;
  font-family:inherit;
  background:#fff; 
  color:#111827; 
  outline:none; 
  transition:border-color .15s, box-shadow .15s, background .15s; 
}
.row-entry::placeholder { color:#9CA3AF; font-weight:400; }
.row-entry:focus { 
  border-color:#4F46E5; 
  box-shadow:0 0 0 3px rgba(79,70,229,.1); 
  background:#fff;
}
.entry-dim   { width:80px; flex-shrink:0; }
.entry-qty   { width:44px; flex-shrink:0; }
.entry-label { flex:1; min-width:70px; }
.row-x       { width:20px; text-align:center; color:var(--fg-muted); flex-shrink:0; font-family:inherit; }
.row-select  { 
  border:1px solid #DDE4ED; 
  border-radius:5px; 
  padding:8px 8px; 
  font-size:14px; 
  font-weight:500;
  font-family:inherit;
  background:#fff; 
  color:#111827; 
  width:60px; 
  flex-shrink:0; 
  transition:border-color .15s, background .15s;
  cursor:pointer;
}
.row-select:focus { 
  border-color:#4F46E5; 
  outline:none; 
  background:#fff;
}
.row-grain   { width:120px; flex-shrink:0; }
.row-del     { width:34px; text-align:center; flex-shrink:0; background:none; border:none; color:#9AA3B2; cursor:pointer; font-size:16px; border-radius:5px; padding:4px; -webkit-tap-highlight-color:transparent; transition:background .15s, color .15s, border .15s; }
.row-del:hover { background:#FF4444; color:#fff; border:1px solid #CC0000; }

/* ── Fraction quick-select ──────────────────────────────────────────── */
.frac-presets { display:none; } /* hidden on desktop by default */

/* ── Status bar ─────────────────────────────────────────────────────── */
.status-bar { display:none; margin-top:8px; background:#fff; border:1px solid var(--border); border-radius:var(--radius); padding:8px 12px; font-size:12px; color:var(--fg-muted); flex-shrink:0; box-shadow:var(--shadow-sm); }

/* ── Bottom Optimize bar (mobile reference shows full-width green) ── */
.btn-optimize-wide {
  width:auto;
  max-width:240px;
  background:var(--green);
  color:#fff;
  border:none;
  border-radius:var(--radius);
  padding:10px 20px;
  font-size:14px;
  font-weight:700;
  cursor:pointer;
  box-shadow:var(--shadow-md);
  transition:background .15s;
  display:flex;
  justify-content:center;
  align-items:center;
}
.btn-optimize-wide:hover { background:var(--green-hover); }
.btn-optimize-wide:disabled { opacity:.5; cursor:default; }

/* ── Results pane ───────────────────────────────────────────────────── */
.results-pane { flex:1; overflow-y:auto; background:var(--bg-card); border:1px solid var(--border); border-radius:var(--radius); display:flex; flex-direction:column; min-width:300px; box-shadow:var(--shadow-md); }
.placeholder-msg { display:flex; flex-direction:column; align-items:center; justify-content:center; padding:60px 20px; color:var(--fg-muted); gap:12px; text-align:center; }
.placeholder-icon { font-size:40px; opacity:.3; }

/* ── Stats ──────────────────────────────────────────────────────────── */
.stats-row { display:flex; gap:6px; flex-wrap:wrap; padding:10px; background:var(--bg-app); border-bottom:1px solid var(--border); flex-shrink:0; }
.stat-card  { background:#fff; border:1px solid var(--border); border-radius:6px; padding:6px 12px; text-align:center; min-width:70px; flex:1; box-shadow:var(--shadow-sm); }
.stat-label { font-size:10px; color:var(--fg-muted); text-transform:uppercase; letter-spacing:.04em; font-weight:600; }
.stat-value { font-size:17px; font-weight:700; }
.stat-good  { color:var(--fg-ok); }
.stat-warn  { color:#92400E; }
.stat-bad   { color:var(--fg-danger); }
.stat-blue  { color:var(--fg-accent); }

/* ── Sheet tabs ─────────────────────────────────────────────────────── */
.sheet-tabs { display:flex; gap:2px; padding:8px 8px 0; border-bottom:1px solid var(--border); overflow-x:auto; flex-shrink:0; -webkit-overflow-scrolling:touch; }
.sheet-tab  { padding:7px 14px; border-radius:6px 6px 0 0; border:1px solid var(--border); border-bottom:none; cursor:pointer; font-size:12px; background:var(--bg-hdr); color:var(--fg-muted); white-space:nowrap; flex-shrink:0; font-weight:600; }
.sheet-tab.active { background:var(--accent); color:#fff; border-color:var(--accent); }

/* ── Sheet panel ────────────────────────────────────────────────────── */
.sheet-panel { display:none; padding:10px; flex:1; flex-direction:column; gap:10px; }
.sheet-panel.active { display:flex; }
.diagram-wrap { background:#F8FAFC; border:1px solid var(--border); border-radius:6px; overflow:auto; -webkit-overflow-scrolling:touch; display:flex; justify-content:center; padding:8px; }
.diagram-wrap svg { max-width:100%; height:auto; }
.cut-table-wrap { overflow-x:auto; -webkit-overflow-scrolling:touch; }
.cut-table  { width:100%; border-collapse:collapse; font-size:12px; }
.cut-table th { background:var(--bg-hdr); padding:6px 8px; text-align:center; font-size:11px; border:1px solid var(--border); color:var(--fg-muted); text-transform:uppercase; letter-spacing:.04em; font-weight:700; }
.cut-table td { padding:5px 8px; text-align:center; border:1px solid #F0F4F8; }
.cut-table tr:nth-child(even) td { background:#F8FAFC; }
.unplaced-warn { background:#FEF2F2; border:1px solid #FECACA; border-radius:6px; padding:10px 12px; color:var(--fg-danger); font-weight:600; font-size:13px; }

/* ── Pane resizer ───────────────────────────────────────────────────── */
.pane-resizer { width:6px; flex-shrink:0; cursor:col-resize; background:var(--border); border-radius:3px; transition:background .15s; align-self:stretch; margin:0 2px; }
.pane-resizer:hover, .pane-resizer.dragging { background:var(--accent); }

/* ── Results page (mobile full-screen) ──────────────────────────────── */
.results-page-body { flex:1; overflow-y:auto; -webkit-overflow-scrolling:touch; padding:8px; display:flex; flex-direction:column; gap:10px; }

/* ── Modals ─────────────────────────────────────────────────────────── */
.modal-overlay { position:fixed; inset:0; background:rgba(0,0,0,.5); z-index:200; display:flex; align-items:center; justify-content:center; padding:12px; overflow-y:auto; }
.modal-box  { background:#fff; border-radius:12px; box-shadow:0 10px 40px rgba(0,0,0,.2); width:460px; max-width:100%; max-height:90vh; overflow-y:auto; display:flex; flex-direction:column; }
.modal-wide { width:520px; }
.modal-header { background:var(--bg-hdr); border-bottom:1px solid var(--border); padding:14px 16px; display:flex; align-items:center; justify-content:space-between; font-weight:700; font-size:15px; border-radius:12px 12px 0 0; position:sticky; top:0; z-index:1; }
.modal-close { background:none; border:none; cursor:pointer; font-size:18px; color:var(--fg-muted); padding:4px 8px; border-radius:5px; min-width:36px; min-height:36px; display:flex; align-items:center; justify-content:center; }
.modal-close:hover { background:#FEE2E2; color:var(--fg-danger); }
.modal-body { padding:14px 16px; }

/* ── Settings modal ─────────────────────────────────────────────────── */
.settings-modal-body { padding:12px 14px; overflow-y:auto; max-height:calc(90vh - 60px); }
.settings-grid  { display:flex; gap:8px; flex-wrap:wrap; margin-bottom:10px; }
.settings-lbl   { display:flex; flex-direction:column; gap:2px; font-size:11px; font-weight:700; color:var(--fg-muted); text-transform:uppercase; letter-spacing:.04em; }
.settings-sheet-row { display:flex; gap:6px; align-items:flex-end; margin-bottom:10px; flex-wrap:wrap; }
.settings-lbl-inline { display:flex; align-items:center; gap:4px; font-size:11px; font-weight:700; color:var(--fg-muted); text-transform:uppercase; letter-spacing:.04em; }
.settings-input { border:1px solid var(--border-strong); border-radius:6px; padding:8px 10px; font-size:14px; width:140px; transition:border-color .15s, box-shadow .15s; }
.settings-input:focus { border-color:var(--accent); box-shadow:0 0 0 3px rgba(66,99,235,.1); outline:none; }
.settings-num   { width:80px; }
.settings-select { border:1px solid var(--border-strong); border-radius:6px; padding:8px; font-size:13px; min-height:36px; background:#fff; }
.settings-radios { display:flex; gap:12px; flex-wrap:wrap; }
.sr-group { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.sr-label { color:var(--fg-muted); font-size:11px; font-weight:700; white-space:nowrap; text-transform:uppercase; letter-spacing:.04em; }
.sr-group label { color:var(--fg); font-size:14px; display:flex; align-items:center; gap:5px; cursor:pointer; }

/* ── Converter ──────────────────────────────────────────────────────── */
.conv-input-row { display:flex; gap:10px; align-items:flex-end; flex-wrap:wrap; margin-bottom:8px; }
.conv-input-row label { display:flex; flex-direction:column; gap:4px; font-size:12px; }
.conv-input  { border:1px solid var(--border-strong); border-radius:6px; padding:9px 10px; font-size:15px; width:180px; }
.conv-input:focus { border-color:var(--accent); box-shadow:0 0 0 3px rgba(66,99,235,.12); outline:none; }
.conv-select { border:1px solid var(--border-strong); border-radius:6px; padding:8px; font-size:14px; background:#fff; min-height:36px; }
.conv-hint   { font-size:11px; color:var(--fg-muted); margin-bottom:10px; }
.conv-table  { width:100%; border-collapse:collapse; font-size:13px; }
.conv-table th { background:var(--bg-hdr); padding:7px 10px; text-align:left; border-bottom:2px solid var(--border); font-size:11px; text-transform:uppercase; letter-spacing:.04em; color:var(--fg-muted); }
.conv-table td { padding:9px 10px; border-bottom:1px solid #F4F6FA; }
.conv-table td:nth-child(2), .conv-table td:nth-child(3) { text-align:right; font-weight:600; }
.conv-table td:nth-child(2) { color:var(--fg-accent); }
.highlight-row td { background:#F0F5FF; }
.frac-cell { color:#1B6E3A !important; font-size:15px !important; }

/* ── Calculator ─────────────────────────────────────────────────────── */
.calc-body    { padding:0; }
.calc-display { background:#1E2D3D; padding:12px 16px 8px; }
.calc-expr    { color:#90CAF9; font-size:12px; text-align:right; min-height:18px; word-break:break-all; }
.calc-result  { color:#fff; font-size:24px; font-weight:700; text-align:right; }
.calc-frac    { display:none; }
.calc-allunits { background:#162230; padding:8px 14px; border-bottom:1px solid #2D3F52; overflow:hidden; }
.au-grid  { display:grid; grid-template-columns:36px 1fr 90px; gap:3px 6px; align-items:center; }
.au-unit  { color:#607D8B; font-size:11px; }
.au-dec   { color:#90CAF9; font-weight:600; text-align:right; font-size:12px; }
.au-frac  { color:#A5D6A7; text-align:right; font-size:11px; min-width:70px; }
.au-hl.au-dec  { color:#A5D6A7; }
.au-hl.au-unit { color:#81C784; }
.calc-opts  { display:flex; gap:14px; align-items:center; padding:8px 14px; background:var(--bg-app); border-bottom:1px solid var(--border); font-size:13px; }
.calc-opts label { display:flex; align-items:center; gap:6px; }
.calc-type-row  { display:flex; gap:8px; align-items:center; padding:8px 12px; background:var(--bg-app); border-bottom:1px solid var(--border); }
.calc-kb-input  { flex:1; border:1px solid var(--border-strong); border-radius:6px; padding:9px 10px; font-size:14px; min-height:40px; }
.calc-kb-hidden { position:absolute; opacity:0; width:0; height:0; pointer-events:none; }
.calc-unit-row  { display:grid; grid-template-columns:repeat(7,1fr); gap:5px; padding:8px 10px; background:var(--bg-app); border-bottom:1px solid var(--border); }
.kp-unit     { background:#E8F5E9; color:#1B6E3A; border:1px solid #A5D6A7; border-radius:6px; font-size:13px; font-weight:600; padding:10px 4px; cursor:pointer; min-height:46px; text-align:center; -webkit-tap-highlight-color:transparent; }
.kp-unit:active { filter:brightness(.85); }
.kp-unit-sp  { font-size:11px; }
.keypad      { display:grid; grid-template-columns:repeat(5,1fr); gap:5px; padding:10px 12px; background:var(--bg-app); }
.keypad-6    { grid-template-columns:repeat(6,1fr); }
.kp-btn      { background:#EEF2F7; border:none; border-radius:6px; padding:12px 0; font-size:20px; font-weight:500; cursor:pointer; transition:background .1s; -webkit-tap-highlight-color:transparent; min-height:48px; }
.kp-btn:active { filter:brightness(.85); }
.kp-op   { background:#DBE5FF; color:var(--accent); }
.kp-clr  { background:#FEE2E2; color:var(--fg-danger); font-weight:600; }
.kp-spc  { background:#F0F4FF; color:var(--fg-muted); border:1px dashed var(--border-strong); font-size:16px; }
.kp-eq   { background:var(--accent); color:#fff; min-height:52px; }
.calc-hist-header { display:flex; justify-content:space-between; align-items:center; padding:6px 12px; background:var(--bg-hdr); border-top:1px solid var(--border); font-size:11px; font-weight:700; color:var(--fg-muted); }
.calc-history { min-height:50px; max-height:100px; overflow-y:auto; padding:6px 12px; background:#fff; font-family:"Menlo","Consolas",monospace; font-size:11px; color:var(--fg-muted); }

/* ── Recent projects ────────────────────────────────────────────────── */
.recent-list  { max-height:400px; overflow-y:auto; }
.recent-item  { padding:14px 16px; border-bottom:1px solid var(--border); cursor:pointer; transition:background .1s; }
.recent-item:hover { background:#F0F5FF; }
.recent-item:last-child { border-bottom:none; }
.recent-name  { font-weight:700; font-size:14px; color:var(--fg); margin-bottom:3px; }
.recent-meta  { font-size:11px; color:var(--fg-muted); }
.recent-empty { padding:24px 16px; text-align:center; color:var(--fg-muted); font-size:13px; }

/* ── Fraction presets ───────────────────────────────────────────────── */
.frac-presets    { display:flex; flex-wrap:wrap; gap:4px; padding:6px; background:#F8FAFC; border-top:1px solid var(--border); }
.frac-preset-btn { background:#fff; border:1px solid var(--border-strong); border-radius:5px; padding:4px 8px; font-size:11px; cursor:pointer; color:var(--fg); -webkit-tap-highlight-color:transparent; flex:0 0 auto; }
.frac-preset-btn:active { background:#DBE5FF; }

/* ── Spinner ────────────────────────────────────────────────────────── */
.spinner { display:inline-block; width:16px; height:16px; border:2px solid rgba(255,255,255,.5); border-top-color:#fff; border-radius:50%; animation:spin .7s linear infinite; vertical-align:middle; margin-right:6px; }
@keyframes spin { to { transform:rotate(360deg); } }


/* ═══════════════════════════════════════════════════════════════════
   MOBILE  ≤ 768px
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .desktop-only { display:none !important; }
  .mobile-only  { display:flex; }
  .brand-full   { display:none; }
  .brand-short  { display:inline; }

  /* Full-height fixed layout — page-level bounce is blocked */
  html, body { height:100%; overflow:hidden; }
  /* Page fills body and distributes height to children */
  .page {
    height:100%;
    overflow:hidden;
    display:flex;
    flex-direction:column;
  }

  /* Toolbar tighter */
  .toolbar { padding:8px 10px; padding-top:calc(8px + var(--safe-top)); }

  /* Main layout fills remaining space below toolbar + options bar */
  .main-layout {
    flex-direction:column;
    padding:0;
    gap:0;
    flex:1;          /* fill remaining vertical space */
    min-height:0;    /* allow flex child to shrink below content size */
    overflow:hidden;
  }

  /* Input pane — flex:1 means it fills space between toolbar and status bar */
  .input-pane {
    width:100%; min-width:0; max-width:100%;
    flex:1;
    min-height:0;                   /* critical for flex+overflow to work */
    overflow-y:scroll;              /* always-on scrollbar track */
    -webkit-overflow-scrolling:touch;
    padding:10px;
    padding-bottom:16px;            /* breathing room at bottom of list */
    scrollbar-width:thin;
    scrollbar-color:var(--border-strong) transparent;
  }
  .input-pane::-webkit-scrollbar { width:4px; }
  .input-pane::-webkit-scrollbar-track { background:transparent; }
  .input-pane::-webkit-scrollbar-thumb { background:var(--border-strong); border-radius:2px; }

  /* Hide results pane on mobile — results go to own page */
  .results-pane { display:none !important; }
  .pane-resizer { display:none !important; }

  .rows-container { max-height:none; overflow:visible; }
  .section-card { overflow:visible; }

  /* Status bar — sits BELOW the scroll area, never overlaps content */
  .status-bar {
    flex-shrink:0;
    margin:0;
    padding:10px 14px;
    padding-bottom:calc(10px + var(--safe-bot));
    background:var(--bg-hdr);
    border-top:1px solid var(--border);
    border-left:none; border-right:none; border-bottom:none;
    border-radius:0;
    box-shadow:none;
    font-size:12px;
    color:var(--fg-muted);
  }

  /* ── Mobile card rows ────────────────────────────────────────── */
  .input-row {
    display:flex;
    flex-direction:column;
    padding:34px 12px 12px;
    border:1px solid var(--border);
    border-radius:8px;
    margin:8px 0;
    background:#fff;
    box-shadow:var(--shadow-sm);
    position:relative;
    overflow:visible;
  }
  .input-row:last-child { border-bottom:1px solid var(--border); }
  
  .mobile-row-summary { display:flex; padding:0; cursor:pointer; }
  .mobile-row-expanded { display:grid; grid-template-columns:1fr 1fr; gap:8px; }

  .row-num {
    position:absolute; top:8px; left:10px;
    width:auto;
    font-size:11px; font-weight:700;
    color:var(--row-num-fg);
    background:var(--row-num-bg);
    border-radius:11px;
    padding:2px 9px;
  }
  .row-num span { background:transparent; width:auto; height:auto; }
  .row-del { position:absolute; top:6px; right:8px; width:24px; height:24px; font-size:13px; display:flex; align-items:center; justify-content:center; background:#FEE2E2; border-radius:4px; color:var(--fg-danger); }

  .row-entry   { padding:11px; font-size:16px; border-radius:6px; width:100%; }
  .entry-dim   { width:100%; }
  .entry-qty   { width:100%; }
  .entry-label { width:100%; }
  .row-select  { width:100%; padding:11px 8px; font-size:15px; min-height:44px; }
  .row-grain   { width:100%; }

  .dim-group { display:flex; gap:5px; align-items:center; grid-column:span 2; }
  .dim-group .row-entry  { flex:2; }
  .dim-group .row-select { flex:1; min-width:0; }
  .dim-group .row-x { width:auto; padding:0 2px; font-size:16px; flex-shrink:0; }

  .qty-lbl-group { display:flex; gap:6px; align-items:center; grid-column:span 2; }
  .qty-lbl-group .entry-qty   { flex:0 0 60px; }
  .qty-lbl-group .entry-label { flex:1; }

  .grain-group { grid-column:span 2; }

  /* ── Fraction presets visible on mobile ─────────────────────── */
  .frac-presets { display:flex; flex-wrap:nowrap; gap:3px; grid-column:span 2; overflow-x:auto; -webkit-overflow-scrolling:touch; padding:8px; background:rgba(82, 169, 117, 0.15); border-radius:6px; }
  .frac-preset-btn { flex:0 0 auto; padding:6px 8px; font-size:11px; min-height:36px; width:auto; }

  /* ── Results page ────────────────────────────────────────────── */
  .results-page-body { padding:6px; }

  /* Sheet tabs: reduce font and padding for mobile efficiency text */
  .sheet-tab { padding:5px 10px; font-size:11px; }

  /* Diagram wrap: allow both scroll AND pinch-zoom */
  .diagram-wrap {
    padding:4px;
    overflow:auto;
    -webkit-overflow-scrolling:touch;
    cursor:grab;
  }
  /* The SVG itself gets touch-action:pan-x pan-y pinch-zoom
     so iOS Safari allows two-finger zoom inside this container */
  .diagram-wrap svg {
    touch-action:pan-x pan-y pinch-zoom;
    transform-origin:top left;
  }

  /* ── Modals: bottom sheet ───────────────────────────────────── */
  .modal-overlay { align-items:flex-end; padding:0; }
  .modal-box, .modal-wide { width:100%; max-width:100%; max-height:92vh; border-radius:14px 14px 0 0; margin-top:auto; }
  .modal-header { border-radius:14px 14px 0 0; }

  /* Converter */
  .conv-input { width:100%; font-size:16px; }
  .conv-input-row { flex-direction:column; }
  .conv-input-row label { width:100%; }
  .conv-table td { font-size:14px; padding:10px; }
  .frac-cell { font-size:16px !important; }

  /* Calculator */
  .calc-result { font-size:32px; }
  .calc-frac   { font-size:13px; }
  .calc-expr   { font-size:11px; }
  .calc-opts   { padding:6px 10px; font-size:12px; }
  .calc-type-row { display:none !important; }
  .keypad-6    { grid-template-columns:repeat(6,1fr); }
  .kp-btn,
  .kp-btn.kp-op,
  .kp-btn.kp-clr,
  .kp-btn.kp-spc,
  .kp-btn.kp-frac  { min-height:54px; font-size:22px !important; border-radius:8px; }
  .kp-eq           { min-height:60px; font-size:24px !important; }
  .keypad      { gap:5px; padding:8px; }
  .kp-unit     { min-height:46px; font-size:13px; padding:10px 2px; }
  .calc-unit-row { gap:4px; padding:6px 8px; }
  .calc-history { max-height:60px; font-size:10px; }
  /* Calculator: true full-screen on mobile */
  #modal-calc.modal-overlay {
    align-items:stretch;
    padding:0;
  }
  #modal-calc .modal-box {
    height:100%;
    max-height:100%;
    border-radius:0;
    display:flex;
    flex-direction:column;
    padding-bottom:var(--safe-bot);
  }
  #modal-calc .modal-header { border-radius:0; }
  #modal-calc .calc-body { flex:1; overflow-y:auto; display:flex; flex-direction:column; }

  /* Settings modal */
  .settings-grid { flex-direction:column; }
  .settings-input, .settings-select { width:100%; font-size:16px; }

  /* Stats */
  .stat-card  { min-width:0; padding:5px 6px; }
  .stat-value { font-size:15px; }

  /* Section header on mobile gets the "+ Add" button styled to match reference */
  .section-header { padding:14px 16px; }
  .btn-add { padding:8px 14px; font-size:13px; min-height:36px; }
}

@media (max-width:360px) {
  .kp-btn, .kp-btn.kp-op, .kp-btn.kp-clr, .kp-btn.kp-spc, .kp-btn.kp-frac { min-height:48px; font-size:19px !important; }
  .calc-result { font-size:22px; }
  .btn-tool-sm, .btn-pdf-sm, .btn-optimize-sm { padding:7px 9px; min-width:36px; min-height:36px; }
  .toolbar-mobile { gap:5px; }
}

/* ── Calculator fraction quick-select ──────────────────────────────── */
.calc-frac-row {
  display:flex;
  flex-wrap:nowrap;
  flex-direction:row;
  gap:5px;
  padding:6px 8px;
  background:var(--bg-app);
  border-bottom:1px solid var(--border);
  overflow-x:auto;
  -webkit-overflow-scrolling:touch;
  /* Show scrollbar on iOS */
  scrollbar-width:thin;
  scrollbar-color:#A5D6A7 transparent;
}
.calc-frac-row::-webkit-scrollbar { height:4px; }
.calc-frac-row::-webkit-scrollbar-track { background:transparent; }
.calc-frac-row::-webkit-scrollbar-thumb { background:#A5D6A7; border-radius:2px; }
.kp-frac-btn {
  background:#E8F5E9;
  color:#1B6E3A;
  border:1px solid #A5D6A7;
  border-radius:6px;
  font-size:13px;
  font-weight:600;
  padding:10px 8px;
  cursor:pointer;
  min-height:46px;
  min-width:52px;
  flex-shrink:0;
  text-align:center;
  white-space:nowrap;
  -webkit-tap-highlight-color:transparent;
}
.kp-frac-btn:active { filter:brightness(.85); }
/* Fraction / button highlight */
.kp-frac { background:#E8F5E9 !important; color:#1B6E3A !important; border:1px solid #A5D6A7 !important; }


/* ── Active field highlight ──────────────────────────────────────────── */
/* Mobile: JS sets background directly; desktop uses CSS :focus */
@media (min-width: 769px) {
  .row-entry:focus { background: #F8FAFF !important; border-color: var(--accent) !important; box-shadow:0 0 0 3px rgba(66,99,235,.15) !important; }
}

/* ── Mobile unit toggle pills ────────────────────────────────────────── */
.unit-toggle {
  display:none;   /* hidden on desktop — select is used instead */
}
@media (max-width:768px) {
  .unit-toggle {
    display:flex;
    flex-direction:column;
    gap:3px;
    flex-shrink:0;
  }
  /* Two pills per row in a 2x2 grid */
  .unit-toggle {
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:3px;
    flex-shrink:0;
    width:76px;
  }
  .unit-pill {
    background:#fff;
    border:1px solid var(--border-strong);
    border-radius:6px;
    font-size:13px;
    font-weight:600;
    color:var(--fg-muted);
    padding:6px 0;
    text-align:center;
    cursor:pointer;
    -webkit-tap-highlight-color:transparent;
    line-height:1;
    /* Don't steal focus */
    -webkit-touch-callout:none;
  }
  .unit-pill-active {
    background:var(--accent);
    color:#fff;
    border-color:var(--accent);
  }
  .unit-pill:active { filter:brightness(.92); }
  /* Hide the hidden input visually but keep it in DOM */
  .unit-toggle input[type=hidden] { display:none; }
  /* dim-group with toggle: give more flex space to inputs */
  .dim-group .unit-toggle { flex-shrink:0; }
}

/* ── Insert-back button ──────────────────────────────────────────────── */
.insert-row {
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 0 4px;
  border-top:1px solid var(--border);
  margin-top:10px;
}
.insert-row-inline {
  padding:0;
  margin:0;
  border:none;
}
.insert-hint {
  font-size:12px;
  color:var(--fg-muted);
  flex:1;
}
.btn-insert {
  background:var(--green);
  color:#fff;
  padding:8px 18px;
  font-size:13px;
  font-weight:600;
  border-radius:6px;
  white-space:nowrap;
}
.btn-insert:hover { background:var(--green-hover); filter:none; }
@media (max-width:768px) {
  .insert-row { padding:8px 0 4px; }
  .btn-insert  { padding:10px 20px; font-size:15px; min-height:44px; }
}

/* ── Compact insert button for calculator header ─────────────────────── */
.btn-insert-sm {
  padding:5px 10px !important;
  font-size:16px !important;
  min-height:32px !important;
  line-height:1;
}
