/* Spreadsheet page (spreadsheet.html). Uses the shared tokens from styles.css, so dark mode follows the rest of the site. */

.sheet-section { max-width: 1280px; }
.sheet-app[hidden] { display: none; }

/* ---- toolbar */
.sheet-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}
.sheet-group { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.sheet-group + .sheet-group { padding-left: 16px; border-left: 1px solid var(--border); }

.sheet-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .85rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.sheet-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.sheet-btn:focus-visible, .sheet-select:focus-visible, .sheet-color:focus-within { outline: none; box-shadow: var(--ring); border-color: var(--accent); }
.sheet-btn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.sheet-btn:disabled { opacity: .4; cursor: default; }
.sheet-btn:disabled:hover { border-color: var(--border-strong); background: var(--surface); }
.sheet-icon { width: 34px; padding: 0; }
.sheet-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sheet-color { gap: 6px; }
.sheet-color input { width: 22px; height: 22px; padding: 0; border: 0; border-radius: 4px; background: none; cursor: pointer; }
.sheet-select {
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .85rem;
}

/* ---- formula bar */
.sheet-formula-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 0;
}
.sheet-name-box, .sheet-formula {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .92rem;
}
.sheet-name-box { width: 96px; flex: none; text-align: center; font-weight: 600; }
.sheet-formula { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88rem; }
.sheet-name-box:focus, .sheet-formula:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.sheet-fx { color: var(--faint); font-style: italic; font-weight: 600; }
.sheet-message { min-height: 1.4em; margin: 0; padding: 4px 12px; border: 1px solid var(--border); border-top: 0; background: var(--surface); font-size: .85rem; color: var(--muted); }
.sheet-message.is-error { color: var(--text-bad); font-weight: 500; }
.sheet-message:empty { display: none; }

/* ---- grid */
.sheet-viewport {
  --sheet-line: var(--border);
  position: relative;
  height: min(68vh, 620px);
  min-height: 280px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 0;
  font-size: .9rem;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-x pan-y;
}
.sheet-viewport:focus { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.sheet-inner { position: relative; }
.sheet-headrow { position: sticky; top: 0; z-index: 4; width: 100%; background: var(--bg-alt); }
.sheet-row { position: absolute; left: 0; display: flex; height: 28px; }

.sheet-corner, .sheet-colhead, .sheet-rowhead {
  flex: none;
  height: 28px;
  line-height: 27px;
  box-sizing: border-box;
  text-align: center;
  background: var(--bg-alt);
  color: var(--muted);
  font-size: .76rem;
  font-weight: 600;
  border-right: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
}
.sheet-corner { position: sticky; left: 0; z-index: 5; cursor: pointer; }
.sheet-rowhead { position: sticky; left: 0; z-index: 3; cursor: pointer; }
.sheet-colhead { position: relative; cursor: pointer; }
.sheet-colhead.is-selected, .sheet-rowhead.is-selected { background: color-mix(in srgb, var(--accent) 16%, var(--bg-alt)); color: var(--accent-ink); }
.sheet-resizer { position: absolute; top: 0; right: -4px; width: 9px; height: 100%; cursor: col-resize; z-index: 2; touch-action: none; }
.sheet-resizer:hover { background: color-mix(in srgb, var(--accent) 40%, transparent); }

.sheet-cell {
  flex: none;
  height: 28px;
  line-height: 27px;
  box-sizing: border-box;
  padding: 0 6px;
  overflow: hidden;
  white-space: nowrap;
  border-right: 1px solid var(--sheet-line);
  border-bottom: 1px solid var(--sheet-line);
  font-variant-numeric: tabular-nums;
  cursor: cell;
}
.sheet-cell.is-error { color: var(--text-bad); font-weight: 500; }

.sheet-sel, .sheet-active, .sheet-copy, .sheet-point { position: absolute; pointer-events: none; box-sizing: border-box; }
.sheet-sel { z-index: 1; background: color-mix(in srgb, var(--accent) 11%, transparent); border: 1px solid var(--accent); }
.sheet-active { z-index: 2; border: 2px solid var(--accent); }
.sheet-copy { z-index: 2; border: 2px dashed var(--accent); animation: sheet-march 1s linear infinite; }
.sheet-point { z-index: 2; border: 2px dashed var(--status-info); background: color-mix(in srgb, var(--status-info) 10%, transparent); }
@keyframes sheet-march { to { border-color: transparent; } }
@media (prefers-reduced-motion: reduce) { .sheet-copy { animation: none; } }

.sheet-editor {
  position: absolute;
  z-index: 6;
  height: 28px;
  box-sizing: border-box;
  padding: 0 5px;
  border: 2px solid var(--accent);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  user-select: text;
  -webkit-user-select: text;
}
.sheet-editor:focus { outline: none; }

/* ---- notes: a small red corner on a cell that has one */
.sheet-cell.has-note { position: relative; }
.sheet-cell.has-note::after { content: ''; position: absolute; top: 0; right: 0; width: 0; height: 0; border-top: 8px solid var(--status-bad, #c0392b); border-left: 8px solid transparent; pointer-events: none; }
.sheet-cell.has-spark { position: relative; padding: 0; }
.sheet-spark-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.sheet-textarea { width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-size: .9rem; resize: vertical; min-height: 64px; }
.sheet-textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }

/* ---- dropdown arrow and menu for cells with a list */
.sheet-dd-btn {
  position: absolute; z-index: 4; display: grid; place-items: center; width: 20px; padding: 0;
  box-sizing: border-box; border: 1px solid var(--border-strong); border-radius: 3px; background: var(--surface-2, var(--surface)); color: var(--text); cursor: pointer;
}
.sheet-dd-btn::before { content: ''; width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 5px solid currentColor; }
.sheet-dd-btn:hover { background: var(--accent-soft); }
.sheet-dd-btn:focus-visible { outline: none; box-shadow: var(--ring); border-color: var(--accent); }
.sheet-dd-menu {
  position: absolute; z-index: 7; margin: 2px 0 0; padding: 4px; list-style: none; box-sizing: border-box;
  max-height: 224px; overflow: auto; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: 0 8px 24px rgba(11, 18, 32, .18);
}
.sheet-dd-menu li { padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-dd-menu li:hover, .sheet-dd-menu li:focus { outline: none; background: var(--accent-soft); }
.sheet-dd-menu li[aria-selected="true"] { font-weight: 600; }
.sheet-dd-menu li[aria-selected="true"]::before { content: '✓ '; }

/* ---- sheets, stats */
.sheet-bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
}
.sheet-tabs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.sheet-tab {
  min-height: 32px;
  max-width: 180px;
  padding: 0 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-alt);
  color: var(--muted);
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}
.sheet-tab:hover { border-color: var(--accent); }
.sheet-tab[aria-selected="true"] { background: var(--surface); color: var(--text); border-color: var(--accent); font-weight: 600; box-shadow: var(--ring); }
.sheet-tab:focus-visible { outline: none; box-shadow: var(--ring); }
.sheet-tab-input { min-height: 32px; width: 140px; padding: 0 8px; border: 1px solid var(--accent); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-size: .85rem; }
.sheet-tab-input:focus { outline: none; box-shadow: var(--ring); }
.sheet-tab-add, .sheet-tab-del { width: 32px; padding: 0; text-align: center; background: var(--surface); color: var(--text); }
.sheet-grow { display: flex; gap: 6px; margin-left: auto; }
.sheet-stats { flex: 1 1 100%; min-height: 1.3em; font-size: .84rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.sheet-help { margin: 10px 2px 0; font-size: .82rem; color: var(--faint); }

/* ---- panels: find, filter */
.sheet-panel { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; background: var(--bg-alt); border: 1px solid var(--border); border-top: 0; }
.sheet-panel[hidden] { display: none; }
.sheet-panel input[type="text"] { min-height: 34px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-size: .9rem; min-width: 0; flex: 1 1 150px; }
#sheet-sharebar .sheet-field { flex: 1 1 340px; }
#sheet-sharebar input[type="text"] { text-overflow: ellipsis; }
.sheet-panel input[type="text"]:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.sheet-check { display: inline-flex; align-items: center; gap: 6px; font-size: .84rem; color: var(--muted); }
.sheet-panel-note { margin: 0; font-size: .84rem; color: var(--muted); }
.sheet-filter { flex-direction: column; align-items: stretch; }
.sheet-filter-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sheet-filter-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.sheet-rule-swatch { display: inline-block; min-width: 64px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: .88rem; text-align: center; }
.sheet-filter-list li .sheet-rule-swatch { min-width: 0; padding: 2px 8px; margin-right: 8px; }
.sheet-rule-item { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.sheet-rule-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.sheet-filter-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; font-size: .88rem; }
.sheet-panel-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- frozen panes, borders, fill handle */
.sheet-headcells { display: flex; height: 28px; width: 100%; }
.sheet-row.is-frozen-row { position: relative; left: auto; top: auto; }
.sheet-cell.is-fcol { position: sticky; z-index: 3; background-color: var(--surface); }
.sheet-colhead.is-fcol { position: sticky; z-index: 3; }
.sheet-cell.is-frow { background-color: var(--surface); }
.sheet-cell.fedge-x { border-right: 2px solid var(--chart-axis); }
.sheet-cell.fedge-y { border-bottom: 2px solid var(--chart-axis); }
.sheet-cell.f-sel { background-image: linear-gradient(color-mix(in srgb, var(--accent) 14%, transparent), color-mix(in srgb, var(--accent) 14%, transparent)); }
.sheet-cell.f-active { box-shadow: inset 0 0 0 2px var(--accent); }
.sheet-cell.is-wrap { white-space: normal; line-height: 19px; padding-top: 4px; padding-bottom: 4px; word-break: break-word; }
.sheet-fill-handle { position: absolute; z-index: 3; width: 9px; height: 9px; box-sizing: border-box; background: var(--accent); border: 1.5px solid var(--surface); cursor: crosshair; touch-action: none; }
.sheet-fill-handle[hidden] { display: none; }
.sheet-fillprev { position: absolute; z-index: 2; pointer-events: none; box-sizing: border-box; border: 2px dashed var(--accent); }
.sheet-fillprev[hidden] { display: none; }

/* ---- phones: the toolbar folds away behind a Tools button */
.sheet-tools-toggle { display: none; }
@media (max-width: 700px) {
  .sheet-tools-toggle { display: inline-flex; }
  .sheet-toolbar:not(.is-open) .sheet-group:not(.sheet-group-main) { display: none; }
  .sheet-toolbar .sheet-group-main { padding-left: 0; border-left: 0; }
}

/* ---- charts */
.sheet-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 480px), 1fr)); gap: 16px; margin-top: 16px; }
.sheet-charts[hidden] { display: none; }
.sheet-chart { display: flex; flex-direction: column; gap: 10px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); min-width: 0; }
.sheet-chart:focus { outline: none; box-shadow: var(--ring); }
.sheet-chart-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.sheet-chart-title { flex: 1 1 180px; min-width: 0; min-height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-weight: 600; }
.sheet-chart-title::placeholder { color: var(--faint); font-weight: 400; }
.sheet-chart-title:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.sheet-chart-body svg { display: block; width: 100%; height: auto; border-radius: 8px; }
.sheet-chart-notes { margin: 0; font-size: .82rem; color: var(--muted); }
.sheet-chart-notes:empty { display: none; }
.sheet-chart details { border-top: 1px solid var(--border); padding-top: 8px; }
.sheet-chart summary { cursor: pointer; font-size: .86rem; font-weight: 600; color: var(--muted); padding: 4px 0; }
.sheet-chart summary:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
.sheet-chart-settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px 14px; padding: 8px 0 4px; align-items: end; }
.sheet-chart-settings label { display: grid; gap: 4px; font-size: .8rem; color: var(--muted); }
.sheet-chart-settings input[type="text"], .sheet-chart-settings select { min-height: 34px; padding: 0 8px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-size: .88rem; }
.sheet-chart-settings .sheet-check { display: flex; align-items: center; gap: 8px; min-height: 34px; }
.sheet-chart-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.sheet-chart-data { max-height: 260px; overflow: auto; margin-top: 6px; border: 1px solid var(--border); border-radius: 8px; }
.sheet-chart-data table { width: 100%; border-collapse: collapse; font-size: .84rem; font-variant-numeric: tabular-nums; }
.sheet-chart-data th, .sheet-chart-data td { padding: 5px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.sheet-chart-data th:first-child, .sheet-chart-data td:first-child { text-align: left; }
.sheet-chart-data thead th { position: sticky; top: 0; background: var(--bg-alt); color: var(--muted); font-size: .74rem; }

/* ---- about */
.sheet-about { max-width: 920px; padding-bottom: 8px; }
.sheet-about h2 { font-size: 1.4rem; margin: 1.6em 0 .5em; }
.sheet-about h2:first-child { margin-top: 0; }
.sheet-about p { color: var(--text-2); line-height: 1.6; }
.sheet-notes { padding-left: 1.2em; color: var(--text-2); line-height: 1.6; display: grid; gap: 8px; }
.sheet-about code { padding: 1px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-alt); font-size: .85em; }
.sheet-table { width: 100%; border-collapse: collapse; margin: 10px 0 8px; font-size: .92rem; }
.sheet-table th, .sheet-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.sheet-table thead th { color: var(--muted); font-weight: 600; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; background: var(--bg-alt); }
.sheet-table tbody th { font-weight: 600; white-space: nowrap; width: 11em; }
.sheet-fn-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px 24px; }
.sheet-fn-group h3 { margin: 0 0 6px; font-size: .95rem; }
.sheet-fn-group p { margin: 0; line-height: 2; }
.sheet-fn-group code { display: inline-block; margin: 0 2px; }

@media (max-width: 700px) {
  .sheet-group + .sheet-group { padding-left: 0; border-left: 0; }
  .sheet-viewport { height: 62vh; }
  .sheet-grow { margin-left: 0; }
}

.page-hero + .sheet-about { padding-top: 40px; }


/* ---- printing: only the sheet goes to paper */
.sheet-field { display: inline-flex; align-items: center; gap: 6px; font-size: .84rem; color: var(--muted); }
#sheet-print { display: none; color: #000; background: #fff; font: 12px/1.35 Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
.sheet-print-table { border-collapse: collapse; table-layout: fixed; max-width: none; }
.sheet-print-table td { padding: 2px 5px; overflow: hidden; white-space: nowrap; vertical-align: top; box-sizing: border-box; border: 0; }
.sheet-print-table td.is-wrap { white-space: normal; word-break: break-word; }
.sheet-print-table.has-grid td { border: 1px solid #d5d9e2; }
.sheet-print-chart { margin-top: 20px; break-inside: avoid; page-break-inside: avoid; }
.sheet-print-chart svg { display: block; width: 100%; max-width: 640px; height: auto; }
@media print {
  body.printing-sheet > *:not(#sheet-print) { display: none !important; }
  body.printing-sheet { background: #fff !important; color: #000 !important; margin: 0 !important; padding: 0 !important; }
  body.printing-sheet #sheet-print { display: block; }
  .sheet-print-table td, .sheet-print-chart svg { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet-print-table tr { break-inside: avoid; page-break-inside: avoid; }
}


/* ---- the "get a quote" callout */
.sheet-cta { max-width: 920px; margin-top: 32px; margin-bottom: 8px; padding: 24px 28px; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--border)); border-radius: var(--radius); }
.sheet-cta h2 { margin: 0 0 8px; font-size: 1.25rem; }
.sheet-cta p { margin: 0 0 14px; color: var(--text-2); line-height: 1.55; }
.sheet-cta p:last-child { margin-bottom: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.sheet-cta-note { font-size: .86rem; color: var(--muted); }

.sheet-tabbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
