:root {
  color-scheme: dark;
  --bg: #16171a;
  --panel: #1e2024;
  --panel-2: #262930;
  --grid: #2c2f36;
  --head: #1f2126;
  --head-hl: #29313f;
  --text: #e4e6eb;
  --muted: #8b909a;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.16);
  --err: #ff6b6b;
  --row-head-w: 46px;
  --col-w: 100px;
  --row-h: 26px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- Sheet view ---------- */
.sheet-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--grid);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
}

.logo {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: linear-gradient(135deg, #4f8cff, #7b5cff);
  color: #fff;
  font-size: 13px;
}

.doc-title { display: flex; flex-shrink: 0; align-items: center; gap: 6px; min-width: 0; max-width: 300px; }
.doc-title .logo { flex-shrink: 0; }

.wb-name {
  max-width: 260px;
  height: 30px;
  padding: 0 8px;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: text;
}
.wb-name:hover { border-color: var(--grid); background: var(--panel-2); }

.wb-rename, .list-rename {
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.wb-rename { width: 220px; font-size: 15px; font-weight: 600; }

.tb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  min-width: 30px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
}
.tb:hover:not(:disabled) { background: var(--panel-2); }
.tb:disabled { opacity: 0.35; cursor: default; }
.tb.on { background: var(--accent-soft); border-color: rgba(79, 140, 255, 0.45); color: #cfe0ff; }
.tb b, .tb i, .tb u { font-size: 14px; }
.tb:focus-visible, .rb-big:focus-visible, .rb-tab:focus-visible, .rb-select:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.color-tb { position: relative; flex-direction: column; gap: 2px; padding: 0 7px; }
.color-tb .glyph { font-weight: 600; line-height: 1; }
.color-tb input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}
.color-tb:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; }
.swatch { width: 16px; height: 3px; border-radius: 2px; background: var(--text); }

.sep { width: 1px; height: 20px; margin: 0 6px; background: var(--grid); flex-shrink: 0; }

/* A small ▾ after a button label that opens a menu */
.caret { display: inline-block; width: 0; height: 0; margin-left: 4px; border: 3.5px solid transparent; border-top: 4px solid currentColor; border-bottom: 0; vertical-align: middle; opacity: 0.7; }

.quick { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.save-status { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* Opens Home > Plans (hidden in the Pro edition) */
.upgrade-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  flex-shrink: 0;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, #4f8cff, #7b5cff);
  color: #fff;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.upgrade-btn:hover { filter: brightness(1.1); }
.upgrade-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ---------- Ribbon ---------- */
.rb-tabs { display: flex; align-self: stretch; align-items: stretch; gap: 2px; min-width: 0; margin: -8px 0; overflow-x: auto; scrollbar-width: none; } /* scrolls sideways when the bar is narrow */
.rb-tabs::-webkit-scrollbar { display: none; }
.rb-tab {
  padding: 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
}
.rb-tab:hover { color: var(--text); background: var(--panel-2); }
.rb-tab.active { border-bottom-color: var(--accent); color: var(--text); font-weight: 600; }

.ribbon {
  background: var(--panel);
  border-bottom: 1px solid var(--grid);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}
.ribbon.collapsed { display: none; }
.rb-panel { display: flex; align-items: stretch; width: max-content; min-width: 100%; padding: 4px 6px 0; }

.rb-group {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 0 6px;
  border-right: 1px solid var(--grid);
}
.rb-group:last-child { border-right: 0; }
.rb-body { display: flex; align-items: center; gap: 2px; height: 58px; }
.rb-label { padding: 1px 0 4px; color: var(--muted); font-size: 11px; text-align: center; white-space: nowrap; }

.rb-rows { display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 2px; }
.rb-row { display: flex; align-items: center; gap: 2px; }
.rb-row .tb, .rb-stack .tb { height: 27px; min-width: 27px; padding: 0 6px; }
.rb-stack { display: flex; flex-direction: column; gap: 2px; }
.rb-stack .tb { justify-content: flex-start; }
.tb-label { font-size: 12.5px; }

/* Tall button: icon over label */
.rb-big {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 56px;
  min-width: 48px;
  padding: 2px 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}
.rb-big:hover { background: var(--panel-2); }
.rb-big.on { background: var(--accent-soft); border-color: rgba(79, 140, 255, 0.45); }
.rb-big svg { flex-shrink: 0; }
.rb-big:has(.two) { gap: 1px; padding-top: 0; padding-bottom: 0; }
.rb-big .two { line-height: 1.1; text-align: center; } /* a label on two lines */
.rb-row .tb > .lock-badge { position: static; margin-left: 2px; font-size: 9px; } /* small buttons: the lock after the label */

.rb-select {
  height: 27px;
  width: 116px;
  padding: 0 6px;
  border: 1px solid var(--grid);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

.sigma { font-size: 16px; font-weight: 600; line-height: 1; }

.rb-checks { flex-direction: column; align-items: flex-start; justify-content: center; gap: 1px; }
.rb-check { display: flex; align-items: center; gap: 6px; height: 19px; padding: 0 4px; border-radius: 4px; font-size: 12.5px; white-space: nowrap; cursor: pointer; }
.rb-check:hover { background: var(--panel-2); }
.rb-check input { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.rb-options { gap: 14px; padding: 0 4px; }
.rb-opt-col { display: flex; flex-direction: column; gap: 4px; }
.rb-opt-title { font-size: 12.5px; font-weight: 600; }

.zoom-level { min-width: 44px; color: var(--text); font-size: 12.5px; text-align: center; }

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed;
  z-index: 60;
  max-width: 260px;
  padding: 6px 9px;
  border: 1px solid var(--grid);
  border-radius: 6px;
  background: #2f333b;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  color: var(--text);
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
}
.tooltip b { font-weight: 600; }
.tooltip kbd { margin-left: 6px; color: var(--muted); font: inherit; }
.tooltip small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }

/* ---------- Formula bar ---------- */
.formula-row {
  display: flex;
  align-items: center;
  height: 38px;
  padding-right: 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--grid);
}

.name-box {
  width: 84px;
  flex-shrink: 0;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  color: var(--muted);
  border: 0;
  background: transparent;
  outline: none;
  font-family: inherit;
  font-size: inherit;
  line-height: 26px;
  padding: 0 4px;
}
.name-box:focus { color: var(--text); box-shadow: inset 0 0 0 2px var(--accent); }
.name-arrow {
  flex-shrink: 0;
  width: 18px;
  border: 0;
  border-right: 1px solid var(--grid);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.name-arrow:hover { background: var(--accent-soft); }
.name-arrow[hidden] { display: none; }

.fx { padding: 0 10px; color: var(--muted); font-style: italic; font-family: Georgia, serif; border: 0; background: transparent; font-size: inherit; cursor: pointer; }
.fx:hover { color: var(--accent); }

#formulaBar {
  flex: 1;
  min-width: 0;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--grid);
  border-radius: 6px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  font: 13px ui-monospace, "Cascadia Code", Consolas, monospace;
}
#formulaBar:focus { border-color: var(--accent); }
#formulaBar::placeholder { color: #5b606a; }

/* ---------- Grid ----------
   The grid is drawn with absolutely positioned boxes; app.js sets their sizes and positions and
   only creates the ones on screen. Header bars stick to the top and left while scrolling. */
.grid-wrap {
  position: relative;
  flex: 1;
  overflow: auto;
  outline: none;
  background: var(--bg);
}

.vg { position: relative; user-select: none; -webkit-user-select: none; }

.vg-colheads {
  position: sticky;
  top: 0;
  z-index: 8;
  height: var(--head-h, var(--row-h));
  background: var(--head);
}
.vg-corner {
  position: sticky;
  left: 0;
  z-index: 2;
  width: var(--head-w, var(--row-head-w));
  height: 100%;
  background: var(--head);
  border-right: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
  cursor: pointer;
}
.vg-corner::after { /* Excel's select-all triangle */
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  border: 5px solid transparent;
  border-right-color: #4a4f59;
  border-bottom-color: #4a4f59;
}
.vg-corner:hover::after { border-right-color: var(--muted); border-bottom-color: var(--muted); }

.vg-body { position: relative; }
.vg-rowheads {
  position: sticky;
  left: 0;
  z-index: 7;
  width: var(--head-w, var(--row-head-w));
  height: 100%;
  background: var(--head);
}

.vg-head {
  position: absolute;
  overflow: hidden;
  background: var(--head);
  border-right: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
}
.vg-colhead { top: var(--gut-c, 0px); height: calc(100% - var(--gut-c, 0px)); line-height: calc(var(--row-h) - 1px); cursor: s-resize; }
.vg-rowhead { left: var(--gut-r, 0px); right: 0; display: flex; align-items: center; justify-content: center; cursor: e-resize; }
.vg-head.hl { background: var(--head-hl); color: #cfe0ff; }
/* A hidden column or row sits just before this header */
.vg-colhead.after-hidden { box-shadow: inset 2px 0 0 #6b7280; }
.vg-rowhead.after-hidden { box-shadow: inset 0 2px 0 #6b7280; }
.vg-colhead.hl { box-shadow: inset 0 -2px 0 var(--accent); }
.vg-rowhead.hl { box-shadow: inset -2px 0 0 var(--accent); }

/* Drag handles on the right edge of column headers and the bottom edge of row numbers */
.col-resizer, .row-resizer { position: absolute; z-index: 1; }
.col-resizer { top: 0; right: 0; bottom: 0; width: 6px; cursor: col-resize; }
.row-resizer { left: 0; right: 0; bottom: 0; height: 5px; cursor: row-resize; }
.col-resizer:hover, .row-resizer:hover { background: var(--accent); }
body.resizing-col, body.resizing-col * { cursor: col-resize !important; }
body.resizing-row, body.resizing-row * { cursor: row-resize !important; }
body.no-resize .col-resizer, body.no-resize .row-resizer { display: none; }

.vg-cells { position: absolute; top: 0; font-size: calc(13px * var(--zoom, 1)); cursor: cell; }

/* A cell is a box holding one line of text (or several when wrapped), centered vertically
   unless it's aligned to the top or bottom. */
.cell {
  position: absolute;
  display: flex;
  align-items: center;
  overflow: hidden;
  padding: 0 calc(6px * var(--zoom, 1));
  border-right: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
}
.cell-bd { position: absolute; inset: 0; pointer-events: none; background-repeat: no-repeat; } /* dashed, dotted, dash-dot and double borders (borderStyles) */
.cell > span { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; line-height: 1.3; }
.cell.wrap > span { max-height: 100%; white-space: pre-wrap; overflow-wrap: anywhere; text-overflow: clip; line-height: 1.25; }
.cell.va-top { align-items: flex-start; padding-top: 2px; }
.cell.va-bottom { align-items: flex-end; padding-bottom: 2px; }
.cell.num { text-align: right; }
.cell.err { color: var(--err); }
.cell.locked-note { color: var(--muted); font-style: italic; } /* "🔒 COUNTIF needs Pro" */
.vg.no-grid .cell { border-color: transparent; }

.sel-rect {
  position: absolute;
  z-index: 1;
  background: var(--accent-soft);
  border: 1px solid rgba(79, 140, 255, 0.55);
  pointer-events: none;
}
.active-rect {
  position: absolute;
  z-index: 2;
  border: 2px solid var(--accent);
  pointer-events: none;
}
/* The fill handle at the selection's corner (grey on plans without it), and the dashed outline
   of the cells it will fill while it's dragged. */
.fill-handle {
  position: absolute;
  z-index: 3;
  width: 7px;
  height: 7px;
  margin: -4px 0 0 -4px;
  border: 1px solid var(--bg);
  background: var(--accent);
  cursor: crosshair;
}
.fill-handle.locked { background: var(--muted); }
.fill-rect { position: absolute; z-index: 2; border: 1px dashed var(--text); pointer-events: none; }

.cell-editor {
  position: absolute;
  z-index: 3;
  padding: 0 calc(4px * var(--zoom, 1));
  border: 2px solid var(--accent);
  outline: none;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  resize: none;
  overflow: hidden;
  white-space: pre; /* Alt+Enter lines (cellShortcuts) */
  display: block;
}

/* ---------- Sheet tabs ---------- */
.sheetbar {
  display: flex;
  align-items: stretch;
  gap: 6px;
  height: 34px;
  padding: 0 8px;
  background: var(--panel);
  border-top: 1px solid var(--grid);
}

.add-sheet { align-self: center; height: 26px; min-width: 26px; padding: 0; font-size: 18px; line-height: 1; color: var(--muted); }

.sheet-tabs {
  display: flex;
  align-items: stretch;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.sheet-tabs::-webkit-scrollbar { display: none; }

.sheet-tab {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  max-width: 220px;
  margin-top: -1px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-top: none;
  border-radius: 0 0 8px 8px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.sheet-tab:hover { background: var(--panel-2); color: var(--text); }
.sheet-tab.active {
  background: var(--bg);
  border-color: var(--grid);
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--accent);
}
.tab-name { overflow: hidden; text-overflow: ellipsis; }

.tab-close {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-right: -8px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  visibility: hidden;
}
.sheet-tab:hover .tab-close, .sheet-tab.active .tab-close { visibility: visible; }
.tab-close:hover { background: var(--grid); color: var(--err); }

.tab-rename {
  width: 130px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  outline: none;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}
.tab-rename.invalid { border-color: var(--err); }

/* ---------- Status bar ---------- */
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 28px;
  padding: 0 14px;
  background: var(--panel);
  border-top: 1px solid var(--grid);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.statusbar .hint { overflow: hidden; text-overflow: ellipsis; }
#stats { color: var(--text); }
#stats span { margin-left: 14px; }
#stats em { font-style: normal; color: var(--muted); }

/* ---------- Home ---------- */
.home { display: flex; flex: 1; min-height: 0; }

.home-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 200px;
  flex-shrink: 0;
  padding: 14px 10px;
  background: var(--panel);
  border-right: 1px solid var(--grid);
}
.home-nav .brand { padding: 2px 8px 16px; }
.nav-spacer { flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: #cfe0ff; font-weight: 600; }
.nav-install { color: var(--accent); }
/* Shown when a newer version has been published (see "Update notice" in app.js). */
.nav-update { height: auto; min-height: 40px; padding: 9px 12px; background: var(--accent); color: #fff; font-weight: 600; line-height: 1.25; }
.nav-update:hover { background: #3d7af0; color: #fff; }
.nav-update svg { flex-shrink: 0; }
.nav-update:focus-visible, .update-bar:focus-visible { outline: 2px solid #fff; outline-offset: -4px; }
.update-bar { display: none; } /* the phone version of the button */

.home-main { flex: 1; min-width: 0; overflow-y: auto; padding: 28px 40px 40px; }
.pane { max-width: 1040px; margin: 0 auto; }
.pane h1 { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }

.home-head { display: flex; align-items: center; justify-content: space-between; gap: 16px 20px; flex-wrap: wrap; }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(360px, 100%);
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  cursor: text;
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; color: var(--text); font: inherit; font-size: 14px; }
.search input::placeholder { color: var(--muted); }

.section-title { margin: 28px 0 12px; font-size: 14px; font-weight: 600; color: var(--muted); }

.new-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 20px; margin-top: 24px; }

.new-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.new-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.new-desc { margin-top: -4px; color: var(--muted); font-size: 12px; }
.new-cat { color: #a9c4ff; font-size: 11.5px; font-weight: 600; }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Home: template gallery */
.tpl-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 20px; margin: 28px 0 12px; }
.tpl-head .section-title { margin: 0; }
.tpl-search { width: min(280px, 100%); height: 36px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip {
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--grid);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { border-color: var(--accent); background: #1f2a3f; color: #cfe0ff; font-weight: 600; }
.chip:focus-visible, .tpl-more:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 18px 16px; }
.tpl-grid .new-name { white-space: normal; }
.tpl-grid .new-desc { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.tpl-empty { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.tpl-more {
  margin-top: 16px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.tpl-more:hover { border-color: var(--accent); }

.thumb {
  position: relative;
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr;
  grid-auto-rows: 1fr;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--bg);
  transition: border-color 0.12s, transform 0.12s;
}
.new-card:hover .thumb, .new-card:focus-visible .thumb { border-color: var(--accent); transform: translateY(-2px); }
.new-card:focus-visible { outline: none; }
.new-card:focus-visible .thumb { box-shadow: 0 0 0 1px var(--accent); }
.thumb i { display: flex; align-items: center; padding: 0 5px; border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid); }
.thumb b { height: 3px; border-radius: 2px; background: #5b606a; }
.thumb b.strong { height: 4px; }
.thumb.blank i { opacity: 0.6; }
.thumb .plus {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 40px;
  font-weight: 300;
}

.list-tabs { display: flex; align-items: center; gap: 22px; margin-top: 32px; border-bottom: 1px solid var(--grid); }
.list-tablist { display: flex; align-items: center; gap: 22px; }
.list-tab {
  padding: 10px 2px;
  margin-bottom: -1px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.list-tab:hover { color: var(--text); }
.list-tab.active { border-bottom-color: var(--accent); color: var(--text); font-weight: 600; }
.home-status { margin-left: auto; color: var(--muted); font-size: 12px; }

.file-head { display: flex; justify-content: space-between; padding: 10px 54px 6px 50px; color: var(--muted); font-size: 12px; }
.file-head span:last-child { width: 170px; }

.file-row { display: flex; align-items: center; border-radius: 8px; }
.file-row:hover, .file-row:focus-within { background: var(--panel); }
.file-open {
  display: grid;
  grid-template-columns: 28px minmax(0, auto) 1fr 170px;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.file-open:focus-visible, .file-more:focus-visible, .nav-item:focus-visible, .list-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.file-icon { display: grid; place-items: center; color: #7ee787; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-star { grid-column: 3; color: #e3b341; font-size: 13px; }
.file-date { grid-column: 4; color: var(--muted); font-size: 13px; white-space: nowrap; }
.file-more {
  width: 36px;
  height: 36px;
  margin-right: 6px;
  flex-shrink: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.file-more:hover { background: var(--panel-2); color: var(--text); }
.list-rename { flex: 1; min-width: 0; margin: 0 8px 0 50px; font-size: 14px; }

.empty { margin: 0; padding: 36px 12px; color: var(--muted); text-align: center; font-size: 14px; }

/* Workbook menu (⋯ / right-click) */
.ctx-menu {
  position: fixed;
  z-index: 50;
  min-width: 200px;
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--grid);
  border-radius: 10px;
  background: var(--panel-2);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.menu-item {
  display: block;
  width: 100%;
  height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover, .menu-item:focus { background: var(--accent-soft); outline: none; }
.menu-item.danger { color: var(--err); }
.ctx-menu.has-checks .menu-item { position: relative; padding-left: 30px; }
.menu-item.checked::before { content: "✓"; position: absolute; left: 11px; color: var(--accent); }
.menu-sep { height: 1px; margin: 5px 4px; background: var(--grid); }

/* Options */
.opt-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 640px;
  margin-top: 20px;
  padding: 16px 18px;
  border: 1px solid var(--grid);
  border-radius: 10px;
  background: var(--panel);
  font-size: 14px;
}
.opt-card p { margin: 0; }
.opt-card small { display: block; color: var(--muted); font-size: 12px; }
.opt-row { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.opt-row input { flex-shrink: 0; width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent); }
.opt-row small { margin-top: 2px; }

/* Home: Pro banner (opens Plans) */
.pro-promo {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  margin-top: 28px;
  padding: 14px 18px;
  border: 1px solid rgba(123, 92, 255, 0.35);
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(79, 140, 255, 0.12), rgba(123, 92, 255, 0.12));
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s;
}
.pro-promo:hover { border-color: #7b5cff; }
.pro-promo:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pro-promo-icon { display: grid; place-items: center; width: 36px; height: 36px; flex-shrink: 0; border-radius: 9px; background: linear-gradient(135deg, #4f8cff, #7b5cff); color: #fff; }
.pro-promo-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.pro-promo-text b { font-size: 14px; font-weight: 600; }
.pro-promo-text span { color: var(--muted); font-size: 13px; }
.pro-promo-link { flex-shrink: 0; color: #a9c4ff; font-size: 13px; font-weight: 600; white-space: nowrap; }

/* Plans */
.plans-sub { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.plans-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin-top: 36px; align-items: stretch; }
.plan-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 24px;
  border: 1px solid var(--grid);
  border-radius: 14px;
  background: var(--panel);
}
.plan-pro {
  border-color: transparent;
  background: linear-gradient(var(--panel), var(--panel)) padding-box, linear-gradient(135deg, #4f8cff, #7b5cff) border-box;
  box-shadow: 0 14px 40px rgba(79, 140, 255, 0.12);
}
.plan-max {
  border-color: transparent;
  background: linear-gradient(var(--panel), var(--panel)) padding-box, linear-gradient(135deg, #7b5cff, #e86fb0) border-box;
  box-shadow: 0 14px 40px rgba(123, 92, 255, 0.14);
}
.plan-popular { position: absolute; top: -13px; left: 24px; padding: 3px 12px; border-radius: 999px; background: linear-gradient(135deg, #3b6fe0, #6a4bf0); color: #fff; font-size: 12px; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
.plan-summary { flex: 1; margin: 0; font-size: 13.5px; line-height: 1.45; }
.plan-summary b { display: block; margin-bottom: 2px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.02em; }
.plan-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 26px; }
.plan-name { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 18px; font-weight: 600; }
.plan-pro .plan-name { background: linear-gradient(135deg, #7fb0ff, #a28bff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.plan-label { padding: 2px 8px; border: 1px solid var(--grid); border-radius: 999px; color: var(--muted); font-size: 11.5px; font-weight: 500; }
.plan-badge { padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: #cfe0ff; font-size: 12px; font-weight: 600; white-space: nowrap; }
.plan-price { display: flex; align-items: baseline; gap: 6px; }
.plan-price b { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.plan-price span { color: var(--muted); font-size: 14px; }
.plan-note { margin: -6px 0 0; color: var(--muted); font-size: 13.5px; }
.plan-btn {
  height: 42px;
  border: 1px solid var(--grid);
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.plan-btn:disabled { color: var(--muted); cursor: default; }
.plan-btn.primary { border: 0; background: linear-gradient(135deg, #3b6fe0, #6a4bf0); color: #fff; }
.plan-btn.primary:hover { filter: brightness(1.1); }
.plan-btn.soon { background: var(--accent-soft); color: #cfe0ff; filter: none; }
.plan-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.plan-status { margin: -6px 0 0; color: #a9c4ff; font-size: 12.5px; }
.plan-status:empty { display: none; }
.plan-billing { display: flex; flex-direction: column; gap: 2px; margin: -4px 0 0; color: var(--muted); font-size: 12px; }
.plan-intro { margin: 4px 0 0; padding-top: 16px; border-top: 1px solid var(--grid); color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.02em; }
.plan-list { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; list-style: none; }
.plan-list li { display: flex; align-items: flex-start; gap: 10px; font-size: 13.5px; }
.plan-list svg { flex-shrink: 0; margin-top: 1px; color: var(--accent); }
.plan-pro .plan-list svg { color: #9b85ff; }
.plan-max .plan-name { background: linear-gradient(135deg, #a28bff, #f39ac6); -webkit-background-clip: text; background-clip: text; color: transparent; }
.plan-max .plan-list svg { color: #e58cc0; }
.plan-max .plan-btn.primary { background: linear-gradient(135deg, #6a4bf0, #b8438a); }
.plan-list li.soon { color: var(--muted); }
.plan-list li.soon svg { opacity: 0.5; }
.soon-tag { flex-shrink: 0; margin-left: auto; padding: 1px 7px; border: 1px solid var(--grid); border-radius: 999px; color: var(--muted); font-size: 11px; font-style: normal; }
/* Plans: comparison table */
.compare { margin-top: 40px; }
.compare-title { margin: 0 0 12px; font-size: 18px; font-weight: 600; }
.compare-table { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; font-size: 13.5px; }
.compare-table th, .compare-table td { padding: 10px 8px; border-bottom: 1px solid var(--grid); }
.compare-table thead th { position: sticky; top: -28px; z-index: 1; padding: 12px 8px; background: var(--bg); font-size: 14px; font-weight: 600; text-align: center; }
.compare-table thead th:first-child { width: auto; }
.compare-plan { width: 96px; }
.compare-label { font-weight: 400; text-align: left; }
.compare-table td { text-align: center; }
.compare-table .current { background: #1b2436; }
.compare-group th { padding: 24px 8px 8px; border-bottom: 1px solid var(--grid); color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.05em; text-align: left; text-transform: uppercase; }
.compare-yes { color: var(--accent); }
.compare-yes svg { display: block; margin: 0 auto; }
.compare-no { color: var(--muted); }
.compare-soon { display: inline-block; padding: 1px 7px; border: 1px solid var(--grid); border-radius: 999px; color: var(--muted); font-size: 11px; }
.plans-foot { margin: 20px 0 0; color: var(--muted); font-size: 12px; }

/* ---------- Locked features (not in the user's plan; see "Plans" in app.js) ---------- */
[data-locked] { position: relative; color: var(--muted) !important; }
[data-locked] .thumb { opacity: 0.55; }
.lock-badge { position: absolute; top: 0; right: 0; font-size: 9px; line-height: 1; pointer-events: none; }
select + .lock-badge { position: relative; top: -9px; margin-left: -12px; }
.menu-item .lock-badge, .ctx-menu .menu-item .lock-badge { position: static; float: right; margin-left: 10px; font-size: 11px; line-height: 34px; }
.new-card .lock-badge { top: 8px; right: 8px; font-size: 14px; }
.list-tab .lock-badge { top: 4px; right: -12px; }
.tooltip .tip-lock { color: #c6b8ff; }

/* Upgrade popup */
.dlg-body.upsell { align-items: center; gap: 8px; padding: 6px 22px 10px; text-align: center; }
.upsell-badge { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 14px; background: linear-gradient(135deg, #4f8cff, #7b5cff); font-size: 24px; box-shadow: 0 10px 28px rgba(79, 140, 255, 0.3); }
.upsell-badge.plan-max { background: linear-gradient(135deg, #7b5cff, #e86fb0); }
.upsell-title { margin: 6px 0 0; font-size: 17px; font-weight: 600; line-height: 1.35; }
.upsell-benefit { align-self: stretch; margin-top: 4px; padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); }
.upsell-benefit-label { display: block; color: #a9c4ff; font-size: 11.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.upsell-benefit p { margin: 3px 0 0; font-size: 14.5px; line-height: 1.4; }
.upsell-soon { align-self: center; margin: 0; padding: 2px 10px; border: 1px solid var(--grid); border-radius: 999px; color: var(--muted); font-size: 12px; }
.menu-item .soon-tag { float: right; margin: 8px 0 0 10px; line-height: 1.4; }
.upsell-price { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.upsell-price b { color: var(--text); font-size: 20px; }
.upsell .plan-intro { align-self: stretch; margin-top: 8px; text-align: left; }
.upsell .plan-list { align-self: stretch; text-align: left; }
.upsell + .dlg-msg { color: #a9c4ff; text-align: center; }

/* Welcome tour (a dialog) */
.dlg-btn[hidden] { display: none; }
.dlg-body.tour { align-items: center; gap: 8px; padding: 6px 22px 10px; text-align: center; }
.tour-icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 14px; background: linear-gradient(135deg, #3b6fe0, #6a4bf0); color: #fff; }
.tour-step { margin: 6px 0 0; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.04em; }
.tour-title { margin: 0; font-size: 18px; font-weight: 600; }
.tour-text { margin: 0; color: #c9ccd3; font-size: 14px; line-height: 1.5; }

/* Hint that a feature needs a paid plan (doesn't take focus) */
.lock-hint {
  position: fixed;
  left: 50%;
  bottom: 44px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 24px);
  padding: 8px 8px 8px 14px;
  border: 1px solid rgba(123, 92, 255, 0.45);
  border-radius: 10px;
  background: var(--panel-2);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  font-size: 13px;
  transform: translateX(-50%);
}
.lock-hint-more { flex-shrink: 0; height: 28px; padding: 0 12px; border: 0; border-radius: 7px; background: linear-gradient(135deg, #4f8cff, #7b5cff); color: #fff; font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.lock-hint-x { flex-shrink: 0; width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 17px; cursor: pointer; }
.lock-hint-x:hover { background: var(--panel); color: var(--text); }

/* Test mode: the badge and plan switcher in the corner (config.js TEST_MODE, and localhost) */
.test-plans {
  position: fixed;
  right: 12px;
  bottom: 40px;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px dashed #e3b341;
  border-radius: 9px;
  background: var(--panel-2);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  font-size: 12px;
}
.test-plans-label { padding: 0 6px; color: #e3b341; font-weight: 600; }
.test-plans button { height: 24px; padding: 0 9px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font: inherit; cursor: pointer; }
.test-plans button:hover { color: var(--text); }
.test-plans button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }
@media print { .test-plans, .lock-hint { display: none !important; } }

/* ---------- Storage meter (Home sidebar, Home on phones, Options) ---------- */
.storage-meter { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.storage-line { display: flex; justify-content: space-between; gap: 8px; }
.storage-line b { color: var(--text); font-weight: 600; }
.storage-bar { display: flex; height: 6px; overflow: hidden; border-radius: 3px; background: var(--panel-2); }
.storage-bar i { height: 100%; transition: width 0.3s; }
.storage-bar .own { background: var(--accent); }
.storage-bar.full .own { background: var(--err); }
.storage-meter small { display: block; font-size: 12px; line-height: 1.35; }
.nav-storage { margin: 10px 8px 2px; padding-top: 12px; border-top: 1px solid var(--grid); }
.home-storage { display: none; }
.opt-storage { max-width: 420px; margin: 4px 0 2px; font-size: 13px; }
.opt-storage .storage-bar { height: 8px; border-radius: 4px; }

/* ---------- Opening animation (skipped with reduced motion) ---------- */
.splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg);
  pointer-events: none; /* never blocks a click */
  animation: splash-out 0.2s ease-in 0.65s forwards;
}
.splash .logo {
  width: 76px;
  height: 76px;
  border-radius: 20px;
  font-size: 42px;
  box-shadow: 0 12px 36px rgba(79, 140, 255, 0.35);
  animation: splash-logo 0.45s cubic-bezier(0.2, 0.8, 0.25, 1.15) both;
}
.splash-name { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; animation: splash-name 0.35s ease-out 0.2s both; }
@keyframes splash-logo { from { opacity: 0; transform: scale(0.55) rotate(-10deg); } to { opacity: 1; transform: none; } }
@keyframes splash-name { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes splash-out { to { opacity: 0; visibility: hidden; } }
@media (prefers-reduced-motion: reduce) { .splash { display: none; } }
@media print { .splash { display: none; } }

/* ---------- Narrow screens ---------- */
@media (max-width: 960px) {
}

/* Sheet view on narrower screens: the seven ribbon tabs get their own line under the title. */
@media (max-width: 1279px) {
  .topbar { flex-wrap: wrap; row-gap: 0; }
  .rb-tabs { order: 3; flex: 1 0 100%; height: 34px; margin: 0 0 -8px; }
}

@media (max-width: 700px) {
  .home { flex-direction: column; }
  .nav-update { display: none; }
  .nav-storage { display: none; }
  .home-storage { display: flex; margin-top: 28px; }
  .update-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 44px;
    padding: 10px 16px;
    border: 0;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
  }
  .home-nav {
    flex-direction: row;
    align-items: center;
    width: auto;
    padding: 8px 10px;
    gap: 2px;
    border-right: 0;
    border-bottom: 1px solid var(--grid);
    overflow-x: auto; /* never wider than the screen; scrolls sideways if the items don't fit */
    scrollbar-width: none;
  }
  .home-nav .brand { padding: 0 6px 0 0; font-size: 0; gap: 0; } /* logo only */
  .nav-item { flex-shrink: 0; height: 36px; padding: 0 8px; gap: 5px; font-size: 13px; }
  .nav-item[data-pane="options"], .nav-install, .nav-plans { padding: 0 9px; }
  .nav-item[data-pane="options"] span, .nav-install span, .nav-plans span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  /* Phones: just the plan name, outlined in the test colour instead of the TEST tag. */
  .home-main { padding: 20px 16px 32px; }
  .pane h1 { font-size: 22px; }
  .search { width: 100%; }
  .pro-promo { gap: 12px; margin-top: 22px; padding: 12px 14px; }
  .pro-promo-link { font-size: 0; }
  .pro-promo-link span { font-size: 16px; }
  .plans-grid { grid-template-columns: minmax(0, 1fr); gap: 22px; margin-top: 32px; }
  .tpl-head { margin-top: 22px; }
  .tpl-search { width: 100%; }
  .chip { min-height: 40px; }
  .tpl-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px 12px; }
  .compare { margin-top: 32px; }
  .compare-table { font-size: 12.5px; }
  .compare-table thead th { top: -20px; }
  .compare-table th, .compare-table td { padding: 9px 4px; }
  .compare-plan { width: 56px; }
  .compare-soon { padding: 1px 5px; font-size: 10.5px; }
  .plan-card { padding: 20px 18px; }
  .section-title { margin-top: 22px; }
  .file-head { display: none; }
  .file-open { grid-template-columns: 28px minmax(0, auto) 1fr; grid-template-rows: auto auto; height: 58px; row-gap: 1px; }
  .file-icon { grid-row: 1 / 3; }
  .file-date { grid-column: 2 / 4; grid-row: 2; font-size: 12px; }
  .list-rename { margin-left: 12px; }

  /* Sheet view: title and status on the first line; ribbon tabs and quick buttons on the
     second; the ribbon below scrolls sideways */
  .topbar { flex-wrap: wrap; gap: 4px 8px; padding: 6px 8px 0; }
  .doc-title { flex: 1 1 calc(100% - 180px); min-width: 0; } /* leaves no room for the tabs on this line */
  .wb-name { max-width: none; min-width: 0; }
  .wb-rename { flex: 1; width: auto; min-width: 0; }
  .save-status { order: 2; }
  .upgrade-btn { order: 2; width: 28px; padding: 0; justify-content: center; }
  .upgrade-btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .rb-tabs { order: 3; flex: 1 1 200px; height: 34px; min-width: 0; margin: 0; overflow-x: auto; scrollbar-width: none; } /* beside the quick buttons; swipe for more tabs */
  .rb-tabs::-webkit-scrollbar { display: none; }
  .rb-tab { padding: 0 9px; }
  .quick { order: 4; margin-left: auto; }
  .quick .tb-label, .quick .sep { display: none; }
  .quick .tb { padding: 0 7px; }
  .ribbon { scrollbar-width: none; }
  .ribbon::-webkit-scrollbar { display: none; }
  .rb-panel { padding-left: 2px; }
  .rb-group { padding: 0 5px; }
  .statusbar .hint { display: none; }
  .statusbar { justify-content: flex-end; }
}

/* ---------- Printing (Page Layout > Print) ----------
   app.js lays the sheet out into numbered pages: in .print-area just before printing, and in the
   print preview. */
.print-area { display: none; }
@media print {
  body.print-sheet { display: block; height: auto; overflow: visible; background: #fff; color: #000; }
  body.print-sheet > :not(.print-area) { display: none !important; }
  body.print-sheet .print-area { display: block; }
}
.print-page { position: relative; overflow: hidden; background: #fff; color: #000; break-after: page; }
.print-page:last-child { break-after: auto; }
.print-page table {
  border-collapse: collapse;
  table-layout: fixed;
  color: #000;
  font: 10pt/1.25 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.print-page td, .print-page th {
  overflow: hidden;
  padding: 0 4px;
  border: 1px solid transparent;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.print-page.gridlines td { border-color: #bfbfbf; }
.print-page th { background: #f0f0f0; border-color: #bfbfbf; color: #444; font-weight: 400; text-align: center; }
.print-page .num { text-align: right; }
.print-page .err { color: #c00; }
.print-page .locked-note { color: #666; font-style: italic; }
.print-page .empty-sheet { margin: 0; color: #666; font: 10pt system-ui, sans-serif; }
.print-hf { position: absolute; left: 0; right: 0; display: flex; justify-content: space-between; gap: 12px; color: #444; font: 9pt system-ui, sans-serif; }
.print-header { top: 4px; }
.print-footer { bottom: 4px; }
.print-hf span { flex: 1; min-width: 0; overflow: hidden; white-space: pre; text-overflow: ellipsis; }
.hf-l { text-align: left; }
.hf-c { text-align: center; }
.hf-r { text-align: right; }
.print-objs { position: absolute; overflow: hidden; transform-origin: 0 0; }
.print-obj { position: absolute; }
.print-obj .obj-body { position: absolute; inset: 0; }
.print-page { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

/* Print preview */
.preview { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; background: #0f1012; }
.pv-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--grid); }
.pv-title { font-size: 15px; }
.pv-field { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.pv-field select { height: 28px; padding: 0 6px; border: 1px solid var(--grid); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; font-size: 13px; }
.pv-count { color: var(--muted); font-size: 13px; }
.pv-spacer { flex: 1; }
.pv-hint { margin: 0; padding: 6px 16px; color: var(--muted); font-size: 12px; }
.pv-pages { flex: 1; overflow: auto; padding: 8px 24px 32px; }
.pv-sheet { margin: 16px auto; background: #fff; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6); }

/* ---------- Ribbon extras: split buttons, font boxes ---------- */
.split { display: inline-flex; align-items: stretch; border-radius: 6px; }
.split:hover { box-shadow: inset 0 0 0 1px var(--grid); }
.split > .tb:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split .split-arrow { min-width: 16px !important; padding: 0 3px !important; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.split-arrow .caret { margin: 0; }
.split-big { flex-direction: column; }
.split-big .rb-big { height: 44px; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.split-big .split-arrow {
  height: 14px;
  border: 0;
  border-radius: 0 0 6px 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.split-big .split-arrow:hover:not(:disabled) { background: var(--panel-2); }
.split-arrow:disabled { opacity: 0.35; cursor: default; }
.font-select { width: 110px; }
.size-select { width: 54px; }
.glyph-a { font-size: 14px; font-weight: 600; line-height: 1; }
.glyph-a.small { font-size: 12px; }
.glyph-a small { margin-left: 1px; font-size: 7px; vertical-align: top; }
.cur-sym { min-width: 10px; font-size: 14px; font-weight: 600; }
.comma { font-size: 16px; line-height: 0.6; }
.ctx-menu .menu-item kbd { float: right; margin-left: 18px; color: var(--muted); font: inherit; font-size: 12px; }
.menu-item:disabled { opacity: 0.4; cursor: default; }
.menu-item:disabled:hover { background: transparent; }

body.painting .vg-cells, body.painting .vg-cells * { cursor: copy; }

/* Narrower screens drop some button labels (the icons and tooltips stay), like Excel. */
@media (max-width: 1439px) { .lbl-1 { display: none; } }
@media (max-width: 1365px) { .lbl-2 { display: none; } .font-select { width: 96px; } }

/* ---------- Filter arrows and their dropdown ---------- */
.filter-btn {
  position: absolute;
  top: 50%;
  right: 2px;
  width: 18px;
  height: 18px;
  margin-top: -9px;
  padding: 0;
  border: 1px solid #4a4f59;
  border-radius: 3px;
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
}
.filter-btn::after { content: ""; position: absolute; left: 4px; top: 6px; border: 4px solid transparent; border-top: 5px solid currentColor; border-bottom: 0; }
.filter-btn:hover { color: var(--text); border-color: var(--muted); }
.filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
/* Data validation: the drop-down button just right of the active cell, and its alert's text */
.dv-btn {
  position: absolute;
  z-index: 3;
  width: 18px;
  padding: 0;
  border: 1px solid var(--grid);
  border-radius: 0 3px 3px 0;
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
}
.dv-btn::after { content: ""; position: absolute; left: 4px; top: calc(50% - 2px); border: 4px solid transparent; border-top: 5px solid currentColor; border-bottom: 0; }
.dv-btn:hover { color: var(--text); border-color: var(--muted); }
.dv-text { margin: 0; max-width: 360px; font-size: 13.5px; line-height: 1.45; white-space: pre-wrap; }
/* Conditional formatting > Manage Rules */
.cf-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.cf-row { display: grid; grid-template-columns: minmax(130px, 1fr) auto 100px 28px 28px 28px; align-items: center; gap: 6px; font-size: 13px; }
.cf-sample { padding: 2px 8px; border: 1px solid var(--grid); border-radius: 4px; font-size: 12px; }
.cf-row input { min-width: 0; }
.cf-del { width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 17px; cursor: pointer; }
.cf-del:hover { background: var(--panel); color: var(--err); }

/* Charts: a card floating over the cells (see "Charts" in app.js) */
.chart {
  position: absolute;
  z-index: 4;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  cursor: move;
  user-select: none;
}
.chart > svg { display: block; width: 100%; height: 100%; }
.chart.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.chart text { fill: var(--text); font-family: inherit; }
.chart .ct-title { font-size: 15px; font-weight: 600; }
.chart .ct-axis, .chart .ct-axtitle, .chart .ct-note { fill: var(--muted); }
.chart .ct-axis, .chart .ct-label { font-size: 11px; }
.chart .ct-axtitle, .chart .ct-legend { font-size: 12px; }
.chart .ct-note { font-size: 13px; }
.chart .ct-pielabel { font-size: 11px; font-weight: 600; fill: #fff; paint-order: stroke; stroke: rgba(0, 0, 0, 0.55); stroke-width: 3px; }
.chart .ct-grid { stroke: var(--grid); }
.chart .ct-zero { stroke: var(--muted); }
.chart .ct-slice { stroke: var(--panel); stroke-width: 1.5; }
.chart-handle { display: none; position: absolute; right: -7px; bottom: -7px; width: 12px; height: 12px; border: 2px solid var(--bg); border-radius: 3px; background: var(--accent); cursor: nwse-resize; }
.chart-tools { display: none; position: absolute; top: 0; left: 100%; flex-direction: column; gap: 4px; margin-left: 8px; }
.chart-tools button { display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid var(--grid); border-radius: 7px; background: var(--panel-2); color: var(--text); cursor: pointer; }
.chart-tools button:hover { border-color: var(--accent); }
.chart.selected .chart-handle { display: block; }
.chart.selected .chart-tools { display: flex; }
.chart.locked { cursor: pointer; }
.chart.locked > svg { opacity: 0.35; }
.chart-lock { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text); font-size: 13px; font-weight: 600; }
@media print { .chart { display: none; } }

/* Notes (red corner) and comments (purple; grey when resolved), and links */
.cell.has-note::before, .cell.has-cmt::before, .cell.cmt-done::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  border-style: solid;
  border-width: 0 7px 7px 0;
  border-color: transparent #e5534b transparent transparent;
  pointer-events: none;
}
.cell.has-cmt::before { border-right-color: #a371f7; }
.cell.cmt-done::before { border-right-color: #6e7681; }
.cell.has-link { color: #6ea8ff; cursor: pointer; }
.cell.has-link > span { text-decoration: underline; }
.note-card {
  position: fixed;
  z-index: 60;
  max-width: 280px;
  padding: 8px 10px;
  border: 1px solid #c9a227;
  border-radius: 6px;
  background: #fff8c5;
  color: #1f2328;
  font-size: 12.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
.note-card.is-cmt { border-color: var(--grid); background: var(--panel-2); color: var(--text); }
.note-text { margin: 0 0 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.cmt-when { display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; }
.cmt-done-tag { color: var(--muted); font-size: 11px; font-style: italic; }
.dlg-textarea { width: 100%; min-width: 320px; padding: 8px; border: 1px solid var(--grid); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; font-size: 13px; resize: vertical; }
.dlg-textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.cmt-list { display: flex; flex-direction: column; gap: 8px; max-height: 40vh; overflow-y: auto; }
.cmt-msg { padding: 8px 10px; border-radius: 8px; background: var(--panel-2); }
.cmt-text { margin: 0 0 2px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }

.popover {
  position: fixed;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 250px;
  padding: 8px;
  border: 1px solid var(--grid);
  border-radius: 10px;
  background: var(--panel-2);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.pop-sort { display: flex; flex-direction: column; padding-bottom: 6px; border-bottom: 1px solid var(--grid); }
.pop-search, .dlg input[type="text"], .dlg input[type="url"], .dlg select {
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--grid);
  border-radius: 6px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.pop-search:focus, .dlg input[type="text"]:focus, .dlg input[type="url"]:focus, .dlg select:focus { border-color: var(--accent); }
.pop-list { display: flex; flex-direction: column; max-height: 220px; overflow-y: auto; padding: 4px; border: 1px solid var(--grid); border-radius: 6px; background: var(--bg); }
.pop-list .dlg-check { padding: 3px 4px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pop-list .dlg-check:hover { background: var(--panel-2); }
.pop-all { font-weight: 600; }
.pop-foot { display: flex; justify-content: flex-end; gap: 6px; }

/* ---------- Dialogs (Sort, Find and Replace, Go To, Series, sizes) ---------- */
.dlg {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--grid);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  color: var(--text);
  font: inherit;
}
.dlg::backdrop { background: rgba(0, 0, 0, 0.45); }
.dlg.modeless { position: fixed; inset: 110px 16px auto auto; margin: 0; z-index: 40; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 4px 16px; font-size: 15px; }
.dlg-x { width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; }
.dlg-x:hover { background: var(--panel-2); color: var(--text); }
.dlg-body { display: flex; flex-direction: column; gap: 10px; padding: 8px 16px; }
.dlg-field { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.dlg-field input, .dlg-field select { color: var(--text); font-size: 13px; }
.dlg-check { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.dlg-check input { margin: 0 4px 0 0; accent-color: var(--accent); }
.dlg-note { margin: 0; color: var(--muted); font-size: 12px; }
.dlg-msg { min-height: 18px; margin: 0; padding: 0 16px; color: #e3b341; font-size: 12px; }
.dlg-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 8px 16px 14px; }
.dlg-btn {
  height: 30px;
  padding: 0 14px;
  border: 1px solid var(--grid);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.dlg-btn:hover:not(:disabled) { border-color: var(--muted); }
.dlg-btn:disabled { opacity: 0.4; cursor: default; }
.dlg-btn.primary { border-color: #3566d6; background: #3566d6; color: #fff; }
.dlg-btn.primary:hover { border-color: #2d5fcb; background: #2d5fcb; }
.dlg-btn:focus-visible, .dlg-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sort-levels { display: flex; flex-direction: column; gap: 8px; }
.sort-level { display: grid; grid-template-columns: 60px 1fr 1fr; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.sort-level select { min-width: 0; color: var(--text); }
.sort-level.pro { grid-template-columns: 52px minmax(0, 1.1fr) 92px minmax(0, 1.4fr) 24px; }
.sort-detail { display: flex; gap: 6px; min-width: 0; }
.sort-detail select { flex: 1; width: 0; }
.cf-cond { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cf-cond select, .cf-cond input { flex: 1 1 110px; min-width: 0; }
.cf-cond .fc-label { flex: 0 0 auto; }
.mi-dot.none { border: 1px dashed var(--muted); }
.mi-preview:has(.mi-dot) { width: 26px; }

/* Measures wrapped text for AutoFit row height. */
.measure-box { position: absolute; top: -9999px; left: -9999px; visibility: hidden; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.25; }

/* ---------- Frozen panes (View > Freeze Panes) ----------
   Sticky layers sized and placed by app.js (applySizes); they take no room in the page flow. */
.frz { position: sticky; overflow: hidden; margin-left: var(--head-w, 46px); }
.frz-cells { background: var(--bg); }
.frz-cells .cell { background-color: var(--bg); }
.frz-rows { top: var(--head-h, 26px); z-index: 4; box-shadow: 0 1px 0 #7b818c; }
.frz-cols { left: var(--head-w, 46px); z-index: 3; box-shadow: 1px 0 0 #7b818c; }
.frz-corner { top: var(--head-h, 26px); left: var(--head-w, 46px); z-index: 5; box-shadow: 1px 1px 0 #7b818c; }
.frz-colheads { left: var(--head-w, 46px); z-index: 1; background: var(--head); box-shadow: 1px 0 0 #7b818c; }
.frz-rowheads { top: var(--head-h, 26px); z-index: 1; margin-left: 0; background: var(--head); box-shadow: 0 1px 0 #7b818c; }

/* ---------- Split panes and Page Break Preview (View tab, viewExtras) ---------- */
.sheet-view { position: relative; }
.frz-in { position: absolute; left: 0; top: 0; width: 100%; height: 100%; will-change: transform; }
.split-bars { position: absolute; inset: 0; z-index: 12; pointer-events: none; }
.split-bar { position: absolute; z-index: 2; pointer-events: auto; background: transparent; touch-action: none; }
.split-bar::before { content: ""; position: absolute; background: var(--accent); opacity: .85; }
.split-bar-h { height: 8px; cursor: row-resize; }
.split-bar-h::before { left: 0; right: 0; top: 3px; height: 2px; }
.split-bar-v { width: 8px; cursor: col-resize; }
.split-bar-v::before { top: 0; bottom: 0; left: 3px; width: 2px; }
.split-bar:hover::before, .split-bar:focus-visible::before { opacity: 1; box-shadow: 0 0 0 2px var(--accent-soft); }
.split-bar:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.split-nudge-group { position: absolute; display: inline-flex; gap: 2px; }
.split-bar-h .split-nudge-group { right: 6px; top: -9px; }
.split-bar-v .split-nudge-group { bottom: 6px; left: -9px; flex-direction: column; }
.split-nudge { width: 22px; height: 18px; padding: 0; border: 1px solid var(--grid); border-radius: 4px; background: var(--head); color: var(--text); font-size: 9px; line-height: 1; cursor: pointer; pointer-events: auto; }
.split-nudge:hover { background: var(--head-hl); }
.split-grab { position: absolute; background: var(--muted); opacity: .7; border-radius: 2px; pointer-events: auto; touch-action: none; }
.split-grab:hover { background: var(--accent); opacity: 1; }
.split-grab-h { width: 22px; height: 6px; cursor: row-resize; }
.split-grab-v { width: 6px; height: 22px; cursor: col-resize; }
.pb-layer { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.pb-layer > div { position: absolute; }
.pb-shade { background: rgba(120, 125, 135, .32); }
.pb-area { border: 2px solid #3b82f6; box-sizing: border-box; }
.pb-page { display: flex; align-items: center; justify-content: center; color: rgba(150, 160, 175, .55); font-weight: 700; letter-spacing: .02em; overflow: hidden; }
.pb-line { pointer-events: auto; z-index: 3; touch-action: none; }
.pb-line::before { content: ""; position: absolute; border: 0 dashed #3b82f6; }
.pb-h { height: 8px; cursor: row-resize; }
.pb-h::before { left: 0; right: 0; top: 3px; border-top-width: 2px; }
.pb-v { width: 8px; cursor: col-resize; }
.pb-v::before { top: 0; bottom: 0; left: 3px; border-left-width: 2px; }
.pb-line.manual::before { border-style: solid; }
.pb-line:hover::before, .pb-line.dragging::before { border-color: #93c5fd; }
.pb-line.discard::before { border-color: #e5534b; opacity: .6; }

/* Dynamic arrays: the outline of the spill the active cell is in, and its formula greyed in the formula bar */
.spill-rect { position: absolute; z-index: 1; border: 1px solid #4f8cff; box-shadow: inset 0 0 0 1px rgba(79, 140, 255, .35); pointer-events: none; }
#formulaBar.spill-ghost { color: var(--muted); }

/* Page Layout > Print Area: a dashed outline around it */
.print-area-rect { position: absolute; z-index: 1; border: 1px dashed #9aa0aa; pointer-events: none; }

/* ---------- Zoom sliders (View tab and status bar) ---------- */
.zoom-slider { width: 110px; accent-color: var(--accent); cursor: pointer; }
.status-right { display: flex; align-items: center; gap: 14px; min-width: 0; }
.sb-zoom { display: flex; align-items: center; gap: 4px; }
.sb-zoom .zoom-slider { width: 100px; }
.sb-btn { min-width: 22px; height: 22px; padding: 0 4px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font: inherit; cursor: pointer; }
.sb-btn:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.sb-btn:disabled { opacity: 0.4; cursor: default; }
.sb-level { min-width: 42px; }
.dlg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 700px) { .sb-zoom .zoom-slider { width: 70px; } }


/* Format Cells (see "Format Cells" in app.js) */
.dlg.wide { width: min(560px, calc(100vw - 32px)); }
.dlg-body.fc { gap: 8px; padding-top: 4px; }
.fc-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--grid); }
.fc-tab { padding: 7px 14px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; }
.fc-tab:hover { color: var(--text); }
.fc-tab[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--text); font-weight: 600; }
.fc-panels { min-height: 340px; }
.fc-pane { display: flex; flex-direction: column; gap: 10px; padding-top: 8px; }
.fc-label { color: var(--muted); font-size: 12px; }
.fc-number { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 14px; padding-top: 8px; }
.fc-cats, .fc-right, .fc-opts { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.fc-list, .fc-codes { width: 100%; padding: 4px; border: 1px solid var(--grid); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; font-size: 13px; }
.fc-list { height: 290px; }
.fc-codes { height: 120px; }
.fc-sample { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border: 1px solid var(--grid); border-radius: 6px; color: var(--muted); font-size: 12px; }
.fc-sample b { min-height: 20px; color: var(--text); font-size: 15px; font-weight: 600; }
.fc-code-err { min-height: 0; padding: 0; }
.fc-preview { display: grid; place-items: center; height: 70px; overflow: hidden; border: 1px solid var(--grid); border-radius: 6px; background: var(--bg); }
.fc-colorrow { display: flex; align-items: center; gap: 12px; }
.fc-colorrow input[type=color] { width: 46px; height: 28px; padding: 0; border: 1px solid var(--grid); border-radius: 4px; background: var(--bg); }
.fc-rot { display: flex; align-items: center; gap: 10px; }
.fc-rot input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.fc-rot input[type=number] { width: 70px; }
.fc-unit { color: var(--muted); font-size: 12px; }
.fc-orient { display: flex; flex-direction: column; gap: 6px; }
.fc-rot-box { display: grid; place-items: center; height: 84px; overflow: hidden; border: 1px solid var(--grid); border-radius: 6px; background: var(--bg); }
.fc-rot-sample { display: inline-block; font-size: 15px; transition: transform 0.1s; }
.fc-presets { display: flex; gap: 8px; }
.fc-swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.fc-swatch { width: 28px; height: 28px; border: 1px solid var(--grid); border-radius: 6px; cursor: pointer; }
.fc-swatch:hover { outline: 2px solid var(--accent); }
.fc-fill-sample { height: 64px; border: 1px solid var(--grid); border-radius: 6px; }

/* Rotated text and shrink to fit */
.cell.rot > span { flex: 0 0 auto; margin: auto; overflow: visible; text-overflow: clip; transform: rotate(var(--rot, 0deg)); }
.cell.shrink > span { overflow: visible; text-overflow: clip; }

/* Conditional formatting visuals: a data bar behind the text, an icon at the left */
.cf-bar { position: absolute; top: 3px; bottom: 3px; z-index: 0; margin-left: 1px; border-radius: 1px; pointer-events: none; }
.cell.has-bar > span { position: relative; z-index: 1; }
.cf-icon { position: absolute; left: calc(3px * var(--zoom, 1)); top: 50%; width: calc(14px * var(--zoom, 1)); height: calc(14px * var(--zoom, 1)); transform: translateY(-50%); pointer-events: none; }
/* What-If: Goal Seek's result and the scenario list */
.gs-head { margin: 0 0 8px; font-weight: 600; }
.gs-list { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0 0 8px; }
.gs-list dt { color: var(--muted, #8b919c); }
.gs-list dd { margin: 0; font-variant-numeric: tabular-nums; }
.dlg select.sc-list { height: 150px; padding: 4px; }
.sc-values { display: grid; gap: 6px; max-height: 50vh; overflow: auto; }
/* Sparkline colours side by side */
.dlg-colors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
/* The Mark choices of the sparkline dialog */
.dlg-checks { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; }
/* Sparklines: a tiny chart in the cell (an svg the size of the cell) */
.spark { position: absolute; inset: 0; pointer-events: none; display: block; }
.spark svg, .spark-p { display: block; width: 100%; height: 100%; overflow: visible; }
.spark-p { position: absolute; left: 0; top: 0; pointer-events: none; }
.mi-preview { display: inline-flex; align-items: center; gap: 2px; width: 70px; margin-right: 12px; vertical-align: middle; }
.mi-bar { display: block; width: 100%; height: 14px; border-radius: 2px; }
.mi-icon { display: block; width: 14px; height: 14px; }
.cf-sample-bar { display: inline-block; width: 70px; padding: 2px; }
.cf-sample-bar i { display: block; height: 12px; border-radius: 2px; }
.cf-sample-scale { display: inline-block; width: 70px; height: 20px; padding: 0; }
.cf-sample-icons { display: inline-flex; gap: 2px; padding: 2px 4px; }
.cf-sample-icons i { display: block; width: 14px; height: 14px; }
.cf-icon-p { display: inline-block; width: 1em; height: 1em; margin-right: 4px; vertical-align: -0.15em; }
.dlg input[type="number"] { height: 30px; padding: 0 8px; border: 1px solid var(--grid); border-radius: 6px; outline: none; background: var(--bg); color: var(--text); font: inherit; }
.dlg input[type="number"]:focus { border-color: var(--accent); }
.dlg select.fc-list { height: 290px; padding: 4px; }
.dlg select.fc-codes { height: 120px; padding: 4px; }


/* Sheet tab extras: a colour strip, a mark where a dragged tab will go */
.sheet-tab.has-color { box-shadow: inset 0 -3px 0 var(--tab-color); }
.sheet-tabs.dragging { cursor: grabbing; }
.sheet-tab.drop-before { box-shadow: inset 3px 0 0 var(--accent); }
.sheet-tab.drop-before.has-color { box-shadow: inset 3px 0 0 var(--accent), inset 0 -3px 0 var(--tab-color); }
.sheet-tabs.drop-end { box-shadow: inset -3px 0 0 var(--accent); }
.mi-dot { display: block; width: 14px; height: 14px; border-radius: 50%; }

/* Text to Columns */
.ttc-section { display: flex; flex-direction: column; gap: 8px; }
.ttc-delims { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
.dlg .ttc-other { width: 52px; height: 24px; margin-left: 4px; }
.ttc-preview { display: flex; flex-direction: column; gap: 4px; max-height: 190px; overflow: auto; }
.ttc-preview table { border-collapse: collapse; font-size: 12.5px; }
.ttc-preview td { padding: 3px 8px; border: 1px solid var(--grid); white-space: pre; }

/* Format as Table and Cell Styles */
.ts-groups { display: flex; flex-direction: column; gap: 6px; max-height: 46vh; overflow-y: auto; padding-right: 4px; }
.ts-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.ts-btn { padding: 4px; border: 2px solid transparent; border-radius: 6px; background: var(--bg); cursor: pointer; }
.ts-btn:hover { border-color: var(--grid); }
.ts-btn[aria-pressed="true"] { border-color: var(--accent); }
.ts-thumb { display: flex; flex-direction: column; gap: 1px; height: 38px; }
.ts-thumb i { display: block; flex: 1; }
.cs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; }
.cs-btn { min-height: 30px; padding: 4px 8px; border: 1px solid var(--grid); border-radius: 4px; background: var(--bg); color: var(--text); font: inherit; font-size: 12.5px; text-align: left; cursor: pointer; }
.cs-btn:hover { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Insert Function, formula suggestions and argument hints */
.dlg.wide { width: min(560px, calc(100vw - 32px)); }
.fn-list, .nm-list { display: flex; flex-direction: column; height: 190px; overflow-y: auto; padding: 4px; border: 1px solid var(--grid); border-radius: 6px; background: var(--bg); outline: none; }
.fn-list:focus-visible, .nm-list:focus-visible { border-color: var(--accent); }
.fn-row, .nm-row { display: flex; align-items: baseline; gap: 10px; padding: 4px 8px; border-radius: 4px; cursor: pointer; }
.fn-row:hover, .nm-row:hover { background: var(--panel-2); }
.fn-row.picked, .nm-row.picked { background: var(--accent-soft); }
.fn-row small { margin-left: auto; color: var(--muted); font-size: 11.5px; }
.fn-row .lock-badge { position: static; flex-shrink: 0; font-size: 11px; }
.nm-row b { min-width: 110px; }
.nm-row span { flex: 1; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.fn-none { padding: 14px 8px; color: var(--muted); font-size: 13px; }
.fn-info { min-height: 62px; padding: 8px 10px; border-radius: 6px; background: var(--panel-2); font-size: 13px; }
.fn-info b { overflow-wrap: anywhere; }
.fn-info p { margin: 4px 0 0; color: var(--muted); }
.fn-lock { display: block; margin-top: 4px; color: var(--accent); }

.fn-suggest, .fn-hint { position: fixed; z-index: 80; border: 1px solid var(--grid); border-radius: 8px; background: var(--panel-2); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); font-size: 12.5px; }
.fn-suggest { display: flex; flex-direction: column; width: 330px; max-width: calc(100vw - 12px); padding: 4px; }
.fn-sug { display: flex; align-items: baseline; gap: 6px; padding: 3px 6px; border-radius: 4px; cursor: pointer; white-space: nowrap; }
.fn-sug.picked { background: var(--accent-soft); }
.fn-sug i { width: 14px; flex-shrink: 0; color: var(--accent); font-style: italic; text-align: center; }
.fn-sug small { flex: 1; min-width: 0; overflow: hidden; color: var(--muted); text-overflow: ellipsis; }
.fn-sug-foot { padding: 3px 6px 1px; color: var(--muted); font-size: 11px; }
.fn-hint { padding: 5px 9px; max-width: min(560px, calc(100vw - 12px)); color: var(--muted); pointer-events: none; overflow-wrap: anywhere; }
.fn-hint b { color: var(--text); }

/* Pictures, shapes and text boxes */
.obj { position: absolute; z-index: 5; pointer-events: none; user-select: none; }
.obj-body { position: absolute; inset: 0; }
.obj-body > svg, .obj-body > img { display: block; width: 100%; height: 100%; overflow: visible; }
.obj-body > img { object-fit: fill; -webkit-user-drag: none; }
.obj-body > img, .obj-body > svg > * { pointer-events: auto; cursor: move; }
.obj-text { position: absolute; inset: 0; display: flex; flex-direction: column; overflow: hidden; line-height: 1.25; white-space: pre-wrap; overflow-wrap: anywhere; font-family: inherit; cursor: move; pointer-events: auto; }
.obj-line .obj-text, .obj-arrow .obj-text { display: none; }
.obj.selected { outline: 1.5px dashed var(--accent); outline-offset: 2px; }
.obj-h, .obj-rot { display: none; position: absolute; pointer-events: auto; }
.obj.selected .obj-h, .obj.selected .obj-rot { display: block; }
.obj-h { width: 10px; height: 10px; border: 2px solid var(--bg); border-radius: 3px; background: var(--accent); }
.obj-h-nw { left: -7px; top: -7px; cursor: nwse-resize; }
.obj-h-ne { right: -7px; top: -7px; cursor: nesw-resize; }
.obj-h-sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.obj-h-se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.obj-rot { left: 50%; top: -26px; width: 12px; height: 12px; margin-left: -6px; border: 2px solid var(--bg); border-radius: 50%; background: var(--accent); cursor: grab; }
.obj-rot::after { content: ""; position: absolute; left: 3px; top: 8px; width: 1px; height: 12px; background: var(--accent); }

/* Page Setup and Scale to Fit */
.dlg .page-setup { max-height: min(70vh, 640px); overflow-y: auto; }
.dlg-sub { margin-top: 6px; font-size: 13px; }
.hf-codes { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.hf-codes .dlg-btn { height: 26px; padding: 0 8px; font-size: 12px; }
.rb-opt-col.rb-scale { gap: 2px; justify-content: center; }
.rb-opt-line { display: flex; align-items: center; justify-content: space-between; gap: 6px; height: 18px; font-size: 12.5px; white-space: nowrap; }
.rb-opt-line .rb-select { width: 92px; height: 18px; padding: 0 4px; font-size: 12px; border-radius: 4px; }
.rb-opt-line .pct { display: flex; align-items: center; gap: 3px; }
.rb-num { width: 54px; height: 18px; padding: 0 4px; border: 1px solid var(--grid); border-radius: 4px; background: var(--bg); color: var(--text); font: inherit; font-size: 12.5px; }

/* Two-line option columns (Sheet Options) fit the ribbon's height */
.rb-options .rb-opt-col { gap: 1px; justify-content: center; }
.rb-options .rb-opt-title { line-height: 15px; }
.rb-options .rb-check { height: 17px; }

/* Formula auditing: trace arrows, the green error corner, Evaluate Formula */
.audit-svg { position: absolute; left: 0; top: 0; z-index: 6; pointer-events: none; }
.audit-svg svg { display: block; overflow: visible; }
.cell.chk::after { content: ""; position: absolute; top: 0; left: 0; border-style: solid; border-width: 7px 7px 0 0; border-color: #2da44e transparent transparent transparent; pointer-events: none; }
.audit-what { margin: 0; font-weight: 600; }
.eval-box { padding: 8px 10px; border: 1px solid var(--grid); border-radius: 6px; background: var(--bg); font: 13px/1.5 ui-monospace, Consolas, monospace; overflow-wrap: anywhere; white-space: pre-wrap; }
.eval-next { text-decoration: underline; text-decoration-thickness: 2px; color: var(--accent); }
.eval-done { color: #4ade80; font-weight: 600; }

/* Outline: lines, +/- buttons and level numbers by the headers */
.ol-el { position: absolute; }
.ol-holder { z-index: 3; pointer-events: none; background: var(--head); }
.ol-line { width: 1px; background: #8b909a; }
.ol-hline { height: 1px; width: auto; }
.ol-btn { box-sizing: border-box; width: 12px; height: 12px; padding: 0; border: 1px solid #8b909a; border-radius: 2px; background: var(--panel); color: var(--text); font: 600 11px/10px system-ui, sans-serif; text-align: center; cursor: pointer; pointer-events: auto; }
.ol-btn:hover { border-color: var(--accent); color: var(--accent); }
.ol-lvl { width: 14px; height: 14px; line-height: 12px; font-size: 10px; background: var(--panel-2); z-index: 4; }
.sub-cols { display: flex; flex-direction: column; gap: 2px; max-height: 150px; overflow-y: auto; padding: 6px; border: 1px solid var(--grid); border-radius: 6px; background: var(--bg); }

/* PivotTable field list */
.pv-pane { position: fixed; right: 14px; top: 150px; z-index: 45; display: flex; flex-direction: column; gap: 8px; width: 300px; max-height: calc(100vh - 210px); overflow-y: auto; padding: 10px 12px 12px; border: 1px solid var(--grid); border-radius: 10px; background: var(--panel); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5); }
.pv-head { display: flex; align-items: center; justify-content: space-between; }
.pv-fields { display: flex; flex-direction: column; max-height: 170px; overflow-y: auto; padding: 4px; border: 1px solid var(--grid); border-radius: 6px; background: var(--bg); }
.pv-fields .dlg-check { padding: 2px 4px; border-radius: 4px; cursor: grab; }
.pv-fields .dlg-check:hover { background: var(--panel-2); }
.pv-areas { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pv-area { display: flex; flex-direction: column; gap: 3px; min-height: 64px; padding: 5px; border: 1px dashed var(--grid); border-radius: 6px; background: var(--bg); }
.pv-area.over { border-color: var(--accent); background: var(--accent-soft); }
.pv-area-title { color: var(--muted); font-size: 11.5px; font-weight: 600; }
.pv-chip { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 2px 4px 2px 7px; border: 1px solid var(--grid); border-radius: 5px; background: var(--panel-2); font-size: 12px; cursor: grab; }
.pv-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-chip-menu { flex-shrink: 0; width: 20px; height: 20px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; }
.pv-chip-menu:hover { background: var(--accent-soft); color: var(--text); }
.pv-foot { display: flex; flex-direction: column; gap: 5px; }
@media (max-width: 700px) { .pv-pane { left: 8px; right: 8px; top: auto; bottom: 40px; width: auto; max-height: 55vh; } }
@media print { .pv-pane { display: none; } }

/* Version history (modules/versions.js) */
.vh-pane { position: fixed; right: 14px; top: 150px; z-index: 45; display: flex; flex-direction: column; gap: 8px; width: 330px; max-height: calc(100vh - 210px); overflow-y: auto; padding: 10px 12px 12px; border: 1px solid var(--grid); border-radius: 10px; background: var(--panel); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5); }
.vh-pane[hidden] { display: none; }
.vh-head { display: flex; align-items: center; justify-content: space-between; }
.vh-title { margin: 0; font-size: 14px; font-weight: 600; }
.vh-pane .dlg-note { margin: 0; }
.vh-save { align-self: flex-start; }
.vh-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.vh-item { padding: 8px 10px; border: 1px solid var(--grid); border-radius: 8px; background: var(--bg); }
.vh-item.saved { border-color: rgba(79, 140, 255, 0.45); }
.vh-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; }
.vh-when { font-weight: 600; }
.vh-size { flex-shrink: 0; color: var(--muted); }
.vh-name { margin-top: 2px; color: #c9ccd3; font-size: 12.5px; overflow-wrap: anywhere; }
.vh-tag { margin-right: 6px; padding: 0 6px; border-radius: 999px; background: var(--accent-soft); color: #cfe0ff; font-size: 11px; font-weight: 600; }
.vh-acts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.vh-act { min-height: 28px; padding: 0 9px; border: 1px solid var(--grid); border-radius: 6px; background: var(--panel-2); color: var(--text); font: inherit; font-size: 12px; cursor: pointer; }
.vh-act:hover { border-color: var(--accent); }
.vh-act.danger:hover { border-color: var(--err); color: #ffb3b3; }
.vh-act:focus-visible, .preview-bar-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.vh-empty, .vh-usage { margin: 0; color: var(--muted); font-size: 12px; }
/* A version opened as a read-only preview */
.preview-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 8px 14px; border-bottom: 1px solid #6b5a1e; background: #2b2410; color: #ffe7a3; font-size: 13px; }
.preview-bar[hidden] { display: none; }
.preview-bar-text { flex: 1 1 220px; }
.preview-bar-btn { min-height: 32px; padding: 0 12px; border: 1px solid #8a7426; border-radius: 7px; background: transparent; color: #ffe7a3; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.preview-bar-btn.primary { border-color: #ffe7a3; background: #ffe7a3; color: #2b2410; }
@media (max-width: 700px) {
  .vh-pane { left: 8px; right: 8px; top: auto; bottom: 40px; width: auto; max-height: 60vh; }
  .vh-act { min-height: 36px; }
}
@media print { .vh-pane, .preview-bar { display: none; } }

/* ---------- Polish (part 40, Pro) ---------- */
/* Checkboxes in cells: a box in the middle of the cell, ticked when TRUE */
.cell.has-cb { justify-content: center; }
.cell.has-cb > span { display: none; }
.cell-cb { display: block; flex: none; width: calc(14px * var(--zoom, 1)); height: calc(14px * var(--zoom, 1)); border: 1.5px solid var(--muted); border-radius: 3px; background: var(--bg); cursor: pointer; }
.cell-cb.on { border-color: var(--accent); background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m3.5 8.4 3 3 6-6.8' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 100% no-repeat; }
/* Symbols */
.sym-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 4px; max-height: 46vh; overflow: auto; }
.sym-btn { height: 38px; border: 1px solid var(--grid); border-radius: 6px; background: var(--panel-2); color: var(--text); font-size: 18px; cursor: pointer; }
.sym-btn:hover { border-color: var(--accent); }
.sym-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Command search */
.cmd-body { min-width: min(460px, 82vw); }
.cmd-list { max-height: 50vh; margin: 0; padding: 0; overflow: auto; list-style: none; }
.cmd-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.cmd-item.active, .cmd-item:hover { background: var(--accent-soft); }
.cmd-item.active { box-shadow: inset 2px 0 0 var(--accent); }
.cmd-where { color: var(--muted); font-size: 12px; text-align: right; }
.cmd-desc { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
.cmd-none { padding: 10px; color: var(--muted); }
/* Spelling */
.spell-list { display: grid; gap: 8px; max-height: 50vh; overflow: auto; padding-right: 4px; }
.spell-text { width: 100%; padding: 6px 8px; border: 1px solid var(--grid); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; resize: vertical; }
.spell-text:focus { border-color: var(--accent); outline: none; }
/* Find options */
.find-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
/* Options > Theme */
.opt-theme { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.opt-choice { display: inline-flex; align-items: center; gap: 8px; min-height: 32px; cursor: pointer; }
.opt-choice input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

/* ---------- Light theme (lightTheme) ---------- */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #f6f7f9;
  --panel-2: #eef0f4;
  --grid: #dadde3;
  --head: #f1f3f5;
  --head-hl: #dbe6fb;
  --text: #1f2328;
  --muted: #5b616b;
  --accent: #2563d9;
  --accent-soft: rgba(37, 99, 217, 0.12);
  --err: #c4262e;
}
/* Colours made for the dark look, made darker here so they read on white */
:root[data-theme="light"] .tb.on, :root[data-theme="light"] .vg-head.hl, :root[data-theme="light"] .nav-item.active,
:root[data-theme="light"] .chip[aria-pressed="true"], :root[data-theme="light"] .plan-badge, :root[data-theme="light"] .plan-btn.soon,
:root[data-theme="light"] .vh-tag { color: #1a4fb4; }
:root[data-theme="light"] .chip[aria-pressed="true"] { background: #e3ecfd; }
:root[data-theme="light"] .new-cat, :root[data-theme="light"] .pro-promo-link, :root[data-theme="light"] .plan-status,
:root[data-theme="light"] .upsell-benefit-label, :root[data-theme="light"] .upsell + .dlg-msg { color: #2754b8; }
:root[data-theme="light"] .tour-text, :root[data-theme="light"] .vh-name { color: #3b4048; }
:root[data-theme="light"] .tooltip .tip-lock { color: #5a3fc0; }
:root[data-theme="light"] .tooltip, :root[data-theme="light"] .ctx-menu, :root[data-theme="light"] .dlg { box-shadow: 0 8px 26px rgba(20, 30, 50, 0.18); }
:root[data-theme="light"] .tooltip { background: #ffffff; }
:root[data-theme="light"] .dlg::backdrop { background: rgba(20, 30, 50, 0.3); }
:root[data-theme="light"] .dlg-msg { color: #8a5300; }
:root[data-theme="light"] #formulaBar::placeholder { color: #8a909a; }
:root[data-theme="light"] .vg-corner::after { border-right-color: #a9aeb7; border-bottom-color: #a9aeb7; }
:root[data-theme="light"] .cell.has-link { color: #1a5fd0; }
:root[data-theme="light"] .compare-table .current { background: #eef3fd; }
:root[data-theme="light"] .file-icon { color: #1a7f37; }
:root[data-theme="light"] .fav-star, :root[data-theme="light"] .test-plans-label { color: #9a6700; }
:root[data-theme="light"] .test-plans { border-color: #bf8700; }
:root[data-theme="light"] .thumb b { background: #b9bec7; }
:root[data-theme="light"] .frz-rows, :root[data-theme="light"] .frz-rowheads { box-shadow: 0 1px 0 #9aa0aa; }
:root[data-theme="light"] .frz-cols, :root[data-theme="light"] .frz-colheads { box-shadow: 1px 0 0 #9aa0aa; }
:root[data-theme="light"] .frz-corner { box-shadow: 1px 1px 0 #9aa0aa; }
:root[data-theme="light"] .ol-line { background: #8a909a; }
:root[data-theme="light"] .ol-btn { border-color: #8a909a; }
:root[data-theme="light"] .eval-done { color: #1a7f37; }
:root[data-theme="light"] .vh-act.danger:hover { color: #b3261e; }
:root[data-theme="light"] .tip, :root[data-theme="light"] .lock-hint { box-shadow: 0 8px 24px rgba(20, 30, 50, 0.18); }
/* Phones: the command search button would push the top bar onto another line (Ctrl+/ is for keyboards anyway) */
@media (max-width: 520px) { #btnCommands { display: none; } }

/* ---------- Opening files: Home > Open, drag and drop, progress ---------- */
.dlg.open-dlg { width: min(460px, calc(100vw - 32px)); }
.open-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 12px;
  border: 1.5px dashed var(--grid);
  border-radius: 10px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.open-drop svg { color: var(--accent); }
.open-drop b { color: var(--text); font-size: 14px; font-weight: 600; }
.open-link { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.open-link input { color: var(--text); font-size: 13px; }
.open-note { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.open-error { margin: 0; line-height: 1.5; }
body.file-drag::after {
  content: 'Drop the file to open it';
  position: fixed;
  inset: 10px;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  pointer-events: none;
}
.open-progress {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid var(--grid);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  color: var(--text);
  font-size: 13px;
  transform: translateX(-50%);
}
.open-progress[hidden] { display: none; }
.open-progress-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.open-progress-bar { position: relative; display: block; height: 6px; overflow: hidden; border-radius: 3px; background: var(--panel-2); }
.open-progress-bar span { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 3px; background: var(--accent); transition: width 0.15s; }
/* (a transform, so it keeps moving while the page is busy reading the file) */
.open-progress.busy .open-progress-bar span { width: 35%; animation: open-busy 1.1s ease-in-out infinite; will-change: transform; }
@keyframes open-busy { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
@media (prefers-reduced-motion: reduce) { .open-progress.busy .open-progress-bar span { width: 100%; animation: none; opacity: 0.5; } }

/* ---------- Install card (centered, over a dimmed background) ---------- */
.install-overlay { position: fixed; inset: 0; z-index: 120; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, 0); transition: background 0.2s ease; }
.install-overlay.open { background: rgba(0, 0, 0, 0.5); }
.install-overlay.closing { background: rgba(0, 0, 0, 0); }
.install-card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(340px, 100%); padding: 26px 24px 20px; border: 1px solid var(--grid); border-radius: 16px; background: var(--panel); box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55); color: var(--text); text-align: center; opacity: 0; transform: scale(0.88); transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
.install-overlay.open .install-card { opacity: 1; transform: none; }
.install-overlay.closing .install-card { opacity: 0; transform: scale(0.94); transition: opacity 0.18s ease, transform 0.18s ease; }
.install-icon { width: 64px; height: 64px; border-radius: 14px; }
.install-visual { position: absolute; top: 26px; left: 50%; width: 64px; height: 64px; margin-left: -32px; display: none; align-items: center; justify-content: center; border-radius: 14px; background: var(--panel); }
.install-card[data-state="working"] .install-visual, .install-card[data-state="done"] .install-visual { display: flex; }
.install-ring { width: 44px; height: 44px; border: 4px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: install-spin 0.8s linear infinite; }
.install-tick { display: none; color: #3fb950; }
.install-card[data-state="done"] .install-ring { display: none; }
.install-card[data-state="done"] .install-tick { display: block; }
.install-tick circle { stroke-dasharray: 182; stroke-dashoffset: 182; animation: install-draw 0.45s ease-out forwards; }
.install-tick path { stroke-dasharray: 50; stroke-dashoffset: 50; animation: install-draw 0.35s 0.3s ease-out forwards; }
.install-title { margin: 6px 0 0; font-size: 18px; font-weight: 600; }
.install-text { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.install-card[data-state="done"] .install-title { color: #3fb950; }
.install-bar { display: none; position: relative; width: 100%; height: 5px; overflow: hidden; margin-top: 6px; border-radius: 3px; background: var(--panel-2); }
.install-bar span { position: absolute; inset: 0 auto 0 0; width: 35%; border-radius: 3px; background: var(--accent); animation: install-slide 1.1s ease-in-out infinite; }
.install-card[data-state="working"] .install-bar { display: block; }
.install-actions { display: flex; justify-content: center; gap: 8px; margin-top: 12px; }
.install-actions .dlg-btn { min-width: 96px; height: 34px; }
@keyframes install-spin { to { transform: rotate(360deg); } }
@keyframes install-draw { to { stroke-dashoffset: 0; } }
@keyframes install-slide { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
@media (prefers-reduced-motion: reduce) {
  .install-overlay, .install-card, .install-overlay.closing .install-card { transition: none; }
  .install-card { transform: none; }
  .install-ring, .install-bar span { animation: none; }
  .install-bar span { width: 100%; opacity: 0.5; }
  .install-tick circle, .install-tick path { animation: none; stroke-dashoffset: 0; }
}

/* ---------- Batch 1: easy features ---------- */
/* Full screen (View > Full Screen, fullScreen): the ribbon and bars go; Esc or the button comes back */
body.focus-mode .topbar, body.focus-mode .ribbon, body.focus-mode .formula-row, body.focus-mode .sheetbar, body.focus-mode .statusbar { display: none; }
.focus-exit { position: fixed; top: 10px; right: 26px; z-index: 60; height: 30px; padding: 0 12px; border: 1px solid var(--grid); border-radius: 15px; background: var(--panel); color: var(--text); font: inherit; font-size: 12.5px; opacity: 0.8; cursor: pointer; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35); }
.focus-exit:hover, .focus-exit:focus-visible { opacity: 1; border-color: var(--accent); }
.focus-exit[hidden] { display: none; }

/* A picture behind the cells (Page Layout > Background, sheetBackground); frozen cells show it too unless they have a fill */
.has-bg .frz-cells .cell { background-color: transparent; }
#btnDeleteBackground:disabled { opacity: 0.45; cursor: default; }

/* The Info button by the workbook name, and its dialog (workbookInfo) */
.doc-title #btnInfo { flex-shrink: 0; width: 28px; height: 28px; padding: 0; justify-content: center; }
.info-stats { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 12px 0 0; padding: 10px 12px; border: 1px solid var(--grid); border-radius: 8px; background: var(--bg); font-size: 12.5px; }
.info-stats dt { color: var(--muted); }
.info-stats dd { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Custom Views (customViews) */
.cv-list { height: 170px; }
.dlg select.cv-list { height: 170px; }
.cv-add { display: flex; gap: 8px; }
.cv-add input { flex: 1; min-width: 0; }

/* Recommended Charts (recommendedCharts): cards with a small chart each */
.rec-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 8px; }
.rec-card { display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 8px; border: 1px solid var(--grid); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.rec-card:hover { border-color: var(--muted); }
.rec-card.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.rec-card b { font-size: 13px; }
.rec-card span { color: var(--muted); font-size: 12px; line-height: 1.35; }
.rec-chart { position: relative; z-index: auto; height: 124px; border: 0; background: transparent; box-shadow: none; cursor: pointer; pointer-events: none; }

/* Coloured range highlights while typing a formula (rangeHighlights): outlines on the sheet, coloured text under see-through text */
.ref-hl { position: absolute; z-index: 2; box-sizing: border-box; border: 2px solid; border-radius: 2px; pointer-events: none; }
.cell-editor.fx-on { color: transparent; background: transparent; caret-color: var(--text); }
.fx-mirror { position: absolute; z-index: 3; box-sizing: content-box; padding: 0 calc(4px * var(--zoom, 1)); border: 2px solid var(--accent); background: var(--panel-2); color: var(--text); font: inherit; white-space: pre; overflow: hidden; pointer-events: none; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45); }
.formula-row { position: relative; }
#formulaBar.fx-on { color: transparent; background: transparent; caret-color: var(--text); position: relative; z-index: 1; }
.fx-mirror-bar { position: absolute; z-index: 0; box-sizing: border-box; overflow: hidden; white-space: pre; pointer-events: none; background: var(--bg); border: 1px solid transparent; color: var(--text); }
.fx-mirror-bar[hidden] { display: none; }

/* Drag to move cells (dragMove) */
.vg.move-cursor .vg-cells, .vg.move-cursor .cell, .vg.moving .vg-cells, .vg.moving .cell { cursor: move; }
.vg.copy-mode .vg-cells, .vg.copy-mode .cell { cursor: copy; }
.move-rect { position: absolute; z-index: 3; box-sizing: border-box; border: 2px dashed var(--accent); background: var(--accent-soft); pointer-events: none; }
.move-rect[hidden] { display: none; }

/* Go To Special (goToSpecial): the cells found */
.special-hit { position: absolute; z-index: 2; box-sizing: border-box; border: 2px solid #ff9f43; background: rgba(255, 159, 67, 0.14); pointer-events: none; }
.gts-kind { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; }
.gts-kind small { flex-basis: 100%; margin-left: 22px; color: var(--muted); font-size: 11.5px; }
.gts-types { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; margin: 6px 0 0 22px; }

/* Page Layout > Themes (themes): a row of the theme's colours in the menu */
.mi-swatch { display: inline-block; width: 11px; height: 11px; margin-right: 2px; border-radius: 2px; }

/* Format Cells > Fill: fill effects */
.fc-fx { display: grid; gap: 8px; margin: 6px 0; }
.fc-fx input[type="color"] { width: 48px; height: 28px; padding: 0; }

/* ---------- Page Layout view (pageLayoutView) ---------- */
.pl-view { flex: 1 1 auto; min-height: 0; overflow: auto; background: var(--panel-2, #1e2025); padding: 12px; outline: none; }
.pl-view[hidden] { display: none; }
.pl-pages { display: flex; flex-direction: column; align-items: flex-start; gap: 22px; width: max-content; margin: 0 auto; }
.pl-row { display: flex; align-items: flex-start; gap: 0; }
.pl-col { display: flex; flex-direction: column; }
.pl-label { color: var(--muted); font-size: 11px; padding: 0 0 2px 2px; }
.pl-paper { position: relative; box-sizing: border-box; flex: none; background: #fff; color: #000; box-shadow: 0 2px 14px rgba(0, 0, 0, 0.5); }
.pl-page { box-sizing: border-box; background: #fff; }
.pl-page td { cursor: cell; }
.pl-page td.pl-sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.pl-hf { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 4px; padding: 0 10px; box-sizing: border-box; z-index: 2; }
.pl-h { top: 0; }
.pl-f { bottom: 0; }
.pl-hf-part { flex: 1 1 0; min-width: 0; height: 22px; border: 1px dashed transparent; border-radius: 4px; background: transparent; color: #444; font: 9pt system-ui, sans-serif; cursor: text; overflow: hidden; white-space: pre; text-overflow: ellipsis; padding: 0 4px; }
.pl-hf-l { text-align: left; }
.pl-hf-c { text-align: center; }
.pl-hf-r { text-align: right; }
.pl-hf-part { border-color: rgba(0, 0, 0, 0.14); }
.pl-hf-part.empty { color: transparent; }
.pl-hf-part.empty.pl-hf-c { color: rgba(0, 0, 0, 0.38); }
.pl-page:not(.gridlines) td { border: 1px solid #e3e5e9; }
.pl-hf-part:hover, .pl-hf-part:focus-visible { border-color: #4f8cff; background: rgba(79, 140, 255, 0.08); }
.pl-hf-part.empty:hover, .pl-hf-part.empty:focus-visible { color: #6b7280; }
.pl-hf-input { flex: 1 1 0; min-width: 0; height: 24px; box-sizing: border-box; border: 1px solid #4f8cff; border-radius: 4px; padding: 0 6px; background: #fff; color: #000; font: 9pt system-ui, sans-serif; }
.pl-ruler { position: relative; flex: none; background: #d9dce2; color: #555; font: 9px system-ui, sans-serif; overflow: hidden; }
.pl-ruler-h { height: 16px; margin-bottom: 2px; background-image: repeating-linear-gradient(90deg, #8a8f99 0 1px, transparent 1px 37.8px); background-size: 37.8px 6px; background-repeat: repeat-x; background-position: 0 bottom; }
.pl-ruler-v { width: 16px; margin: 0 2px 0 0; align-self: flex-start; background-image: repeating-linear-gradient(180deg, #8a8f99 0 1px, transparent 1px 37.8px); background-size: 6px 37.8px; background-repeat: repeat-y; background-position: right 0; margin-top: 18px; }
.pl-ruler span { position: absolute; }
.pl-ruler-h span { top: 1px; transform: translateX(-50%); }
.pl-ruler-v span { left: 1px; transform: translateY(-50%); writing-mode: vertical-rl; }
.pl-cell-input { position: absolute; z-index: 5; box-sizing: border-box; border: 2px solid var(--accent); background: #fff; color: #000; font: 13px system-ui, sans-serif; padding: 0 4px; }
.pl-empty { color: var(--muted); }
.pl-view .print-objs { pointer-events: none; }
#btnPageLayoutView.on { background: var(--panel-2); }

/* ---------- Check Accessibility (accessibility) ---------- */
.a11y-dlg { width: min(420px, calc(100vw - 24px)); }
.a11y-list { display: flex; flex-direction: column; gap: 12px; max-height: 50vh; overflow: auto; padding-right: 4px; }
.a11y-group { display: flex; flex-direction: column; gap: 4px; }
.a11y-kind { margin: 0; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.a11y-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; padding: 7px 10px; border: 1px solid var(--grid); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.a11y-item span { color: var(--muted); font-size: 12px; }
.a11y-item:hover, .a11y-item:focus-visible { border-color: var(--accent); outline: none; }
@media (max-width: 640px) { .dlg.modeless.a11y-dlg { inset: auto 8px 8px 8px; width: auto; } .a11y-list { max-height: 34vh; } }

/* ---------- Account: sign in, the account menu (account.js) ---------- */
.acct-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 10px; flex-shrink: 0; border: 1px solid var(--grid); border-radius: 14px; background: transparent; color: var(--text); font: inherit; font-size: 12.5px; white-space: nowrap; cursor: pointer; }
.acct-btn:hover { background: var(--panel-2); }
.acct-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.acct-btn.signed-in { width: 28px; padding: 0; border-color: transparent; }
.home-acct { height: 34px; border-radius: 17px; padding: 0 14px; font-size: 13px; }
.home-acct.signed-in { width: 34px; }
.acct-avatar { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%; background: linear-gradient(135deg, #4f8cff, #7b5cff); color: #fff; font-size: 12.5px; font-weight: 700; }
.home-acct .acct-avatar { width: 32px; height: 32px; font-size: 14px; }
.acct-avatar.big { width: 38px; height: 38px; flex: none; font-size: 16px; }
.acct-menu { position: fixed; z-index: 60; width: min(290px, calc(100vw - 16px)); padding: 12px; border: 1px solid var(--grid); border-radius: 12px; background: var(--panel); box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5); color: var(--text); font-size: 13px; }
.acct-head { display: flex; align-items: center; gap: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--grid); }
.acct-who { display: flex; flex-direction: column; min-width: 0; }
.acct-who span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-plan { margin: 10px 0 2px; }
.acct-note { margin: 0 0 8px; color: var(--muted); font-size: 12px; }
.acct-item { display: block; width: 100%; padding: 8px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.acct-item:hover, .acct-item:focus-visible { background: var(--panel-2); outline: none; }
.acct-dlg { width: min(400px, calc(100vw - 24px)); }
.acct-dlg .dlg-body { padding-bottom: 16px; }
.acct-google { display: flex; justify-content: center; min-height: 44px; }
.acct-or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.acct-or::before, .acct-or::after { content: ''; flex: 1; border-top: 1px solid var(--grid); }
.acct-email { display: flex; flex-wrap: wrap; gap: 8px; }
.acct-email input { flex: 1 1 160px; min-width: 0; height: 34px; padding: 0 10px; border: 1px solid var(--grid); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; }
.acct-email input:focus { border-color: var(--accent); outline: none; }
.acct-email .dlg-btn { height: 34px; }
.acct-toast { position: fixed; left: 50%; bottom: 44px; z-index: 70; max-width: calc(100vw - 32px); padding: 9px 14px; border-radius: 8px; background: #2b2f38; color: #fff; font-size: 13px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; }
.acct-toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 700px) {
  .acct-btn:not(.home-acct) { order: 2; width: 28px; padding: 0; }
  .acct-btn:not(.home-acct) .acct-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}
@media print { .acct-toast, .acct-menu { display: none !important; } }
.home-head .search { margin-left: auto; } /* the search box and the account button together at the right */
.site-links { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 28px 0 8px; padding-top: 14px; border-top: 1px solid var(--grid); font-size: 12.5px; }
.site-links a { color: var(--muted); text-decoration: none; }
.site-links a:hover { color: var(--text); text-decoration: underline; }
.site-links a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.acct-test { margin: 0 0 6px; padding: 6px 8px; border: 1px dashed #e3b341; border-radius: 6px; color: #e3b341; font-size: 12px; }
:root[data-theme="light"] .acct-test { color: #9a6700; border-color: #bf8700; }
@media (max-width: 700px) {
  .test-plans { right: 8px; bottom: 44px; padding: 2px; }
  .test-plans-label { padding: 0 5px; }
  .test-plans button { padding: 0 8px; }
}
