/* Sheet grid — SheetGrid editor (.sg-*), same design language as slide-canvas */

#sheet-grid-root {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: var(--bg-primary, #fff);
}

/* ── Toolbar ── */
.sg-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary, #fff);
  flex-wrap: wrap;
}
.sg-tb {
  min-width: 30px;
  height: 28px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sg-tb:hover { background: var(--bg-secondary, #f5f5f5); }
.sg-tb.sg-on {
  background: var(--bg-secondary, #eef2f7);
  border-color: var(--border);
  color: var(--accent-blue, #079d9d);
}
.sg-tb-txt { font-size: 12px; white-space: nowrap; }
.sg-tb-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.sg-tb-flex { flex: 1; }
.sg-tb-select {
  height: 28px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 6px);
  background: var(--bg-primary, #fff);
  color: var(--text-primary);
  font-size: 12px;
  max-width: 110px;
}
.sg-tb-A {
  border-bottom: 3px solid var(--accent-blue, #079d9d);
  line-height: 1.1;
  font-weight: 600;
}
.sg-tb-fill {
  width: 14px;
  height: 14px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: linear-gradient(135deg, #FEF3C7 50%, #DBEAFE 50%);
}
.sg-formula-hint {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  cursor: help;
}

/* Color palette popup */
.sg-palette {
  position: fixed;
  z-index: 1000;
  display: grid;
  grid-template-columns: repeat(3, 24px);
  gap: 6px;
  padding: 8px;
  background: var(--bg-primary, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
}
.sg-swatch {
  width: 24px;
  height: 24px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
}
.sg-swatch:hover { transform: scale(1.12); }
.sg-swatch-none {
  background: var(--bg-primary, #fff);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1;
}

/* ── fx bar ── */
.sg-fxbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary, #fff);
}
.sg-namebox {
  width: 84px;
  height: 26px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 6px);
  font-size: 12px;
  font-family: Consolas, monospace;
  text-align: center;
  color: var(--text-primary);
  background: var(--bg-primary, #fff);
}
.sg-fx-label { color: var(--text-secondary); font-size: 13px; font-style: italic; }
.sg-fx {
  flex: 1;
  height: 26px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 6px);
  font-size: 13px;
  font-family: Consolas, monospace;
  color: var(--text-primary);
  background: var(--bg-primary, #fff);
}
.sg-fx:focus, .sg-namebox:focus {
  outline: none;
  border-color: var(--accent-blue, #079d9d);
}

/* ── Grid ── */
.sg-scroller {
  flex: 1;
  min-height: 0;
  overflow: auto;
  outline: none;
  background: var(--bg-secondary, #fafafa);
}
.sg-table {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  background: var(--bg-primary, #fff);
}
.sg-table th, .sg-table td {
  border-right: 1px solid var(--border, #e5e7eb);
  border-bottom: 1px solid var(--border, #e5e7eb);
  box-sizing: border-box;
}
.sg-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 28px;
  background: var(--bg-secondary, #f5f6f8);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  user-select: none;
  cursor: default;
}
.sg-corner {
  position: sticky;
  left: 0;
  z-index: 4 !important;
}
.sg-rowhead {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--bg-secondary, #f5f6f8);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  text-align: center;
  user-select: none;
}
.sg-colhead { position: relative; }
/* Splitter = two half-zones per boundary (right edge of one th + left edge of
   the next, same data-col). Kept INSIDE the th: sticky th's are separate
   stacking contexts, so anything overflowing gets covered by the next th —
   the original single 7px overflowing span is why dragging "didn't work". */
.sg-col-resize {
  position: absolute;
  right: 0;
  top: 0;
  /* 10px per half → ~20px grab zone per boundary (Sheets-like; the old 6px
     made grabs slip into column-select — Thầy 2026-07-13). */
  width: 10px;
  height: 100%;
  cursor: col-resize;
  z-index: 5;
  touch-action: none;   /* pointermove is ours, never a scroll gesture */
}
.sg-col-resize-l { right: auto; left: 0; }
.sg-col-resize:hover {
  box-shadow: inset -7px 0 0 -5px var(--accent-blue, #079d9d);
}
.sg-col-resize-l:hover {
  box-shadow: inset 7px 0 0 -5px var(--accent-blue, #079d9d);
}

/* While dragging a splitter: lock the resize cursor everywhere (no flicker
   when the pointer leaves the 10px handle) and kill text selection. */
body.sg-resizing-col, body.sg-resizing-col * { cursor: col-resize !important; user-select: none !important; }
body.sg-resizing-row, body.sg-resizing-row * { cursor: row-resize !important; user-select: none !important; }

/* Full-height/width guide line following the pointer (Excel feedback) */
#sg-resize-guide { position: fixed; z-index: 90; pointer-events: none; background: var(--accent-blue, #079d9d); opacity: 0.55; }
#sg-resize-guide.sg-guide-v { width: 2px; margin-left: -1px; }
#sg-resize-guide.sg-guide-h { height: 2px; margin-top: -1px; }
.sg-cell {
  height: 26px;
  padding: 2px 6px;
  /* Calibri-first: exported .xlsx cells ARE Calibri 11 — the grid shows the
     same face (falls back to the app sans off-Windows). fmt.font overrides
     inline per cell. */
  font-family: Calibri, var(--font-sans, 'Inter'), sans-serif;
  /* 14px ≈ 10.5pt — giữa Google Sheets (10pt) và Excel (11pt); cells with
     an explicit fmt.size override inline at pt × 4/3. */
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: cell;
  position: relative;
  background: var(--bg-primary, #fff);
}
.sg-spacer td { border: none; padding: 0; background: var(--bg-secondary, #fafafa); }

.sg-b { font-weight: 700; }
.sg-i { font-style: italic; }
.sg-s { text-decoration: line-through; }
.sg-u { text-decoration: underline; }
.sg-s.sg-u { text-decoration: line-through underline; }
.sg-a-left { text-align: left; }
.sg-a-center { text-align: center; }
.sg-a-right { text-align: right; }
.sg-va-center { vertical-align: middle; }
.sg-va-bottom { vertical-align: bottom; }
.sg-wrap { white-space: normal; word-break: break-word; }
.sg-fnv { color: var(--text-secondary); font-style: italic; }
.sg-err { color: #E03E3E; font-weight: 600; }
.sg-merged { vertical-align: top; }

/* Row resize handle (bottom edge of the row header) */
.sg-rowhead { position: sticky; }
/* Same two-half-zone scheme as .sg-col-resize (sticky rowheads would cover
   an overflowing span the same way). */
.sg-row-resize {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 8px;   /* wider grab zone, same rationale as .sg-col-resize */
  cursor: row-resize;
  z-index: 5;
  touch-action: none;
}
.sg-row-resize-t { bottom: auto; top: 0; }
.sg-row-resize:hover {
  box-shadow: inset 0 -7px 0 -5px var(--accent-blue, #079d9d);
}
.sg-row-resize-t:hover {
  box-shadow: inset 0 7px 0 -5px var(--accent-blue, #079d9d);
}

/* Toolbar extras */
.sg-tb.sg-dis { opacity: 0.35; pointer-events: none; }
.sg-size-val {
  min-width: 22px;
  text-align: center;
  font-size: 12px;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 6px);
  padding: 3px 4px;
}
.sg-menu {
  display: flex;
  flex-direction: column;
  grid-template-columns: none;
  min-width: 150px;
  padding: 4px;
}
.sg-menu-item {
  border: none;
  background: transparent;
  text-align: left;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text-primary);
  border-radius: var(--radius-sm, 6px);
  cursor: pointer;
}
.sg-menu-item:hover { background: var(--bg-secondary, #f5f6f8); }
/* Glyph pick lists (borders…) — icon + label in one row */
.sg-menu-item--icon { display: flex; align-items: center; gap: 9px; }
.sg-menu-item--icon svg { flex-shrink: 0; }
/* Armed parameter (border line weight) — Excel-style check tint */
.sg-menu-item.sg-checked { color: var(--accent-blue, #079d9d); font-weight: 600; }

.sg-fchip {
  position: absolute;
  top: 1px;
  right: 2px;
  font-size: 9px;
  font-style: italic;
  color: var(--accent-blue, #079d9d);
  opacity: 0.85;
  pointer-events: auto;
  cursor: help;
}

/* Point mode: the cell whose ref was just inserted into the formula */
.sg-cell.sg-point-src {
  outline: 2px dashed var(--accent-blue, #079d9d);
  outline-offset: -2px;
}

/* Selection */
.sg-cell.sg-insel { background-color: rgba(7, 157, 157, 0.08); }
.sg-cell.sg-active {
  outline: 2px solid var(--accent-blue, #079d9d);
  outline-offset: -2px;
}
.sg-cell.sg-editing { padding: 0; overflow: visible; }
.sg-editor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 2px solid var(--accent-blue, #079d9d);
  padding: 1px 4px;
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
  outline: none;
  background: var(--bg-primary, #fff);
  color: var(--text-primary);
  z-index: 6;
}

/* Remote-change flash (same rhythm as canvas .sc-flash) */
@keyframes sg-flash-kf {
  0% { background-color: rgba(7, 157, 157, 0.35); }
  100% { background-color: transparent; }
}
.sg-cell.sg-flash { animation: sg-flash-kf 2s ease-out; }

/* Empty state + mobile note */
.sg-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  padding: 28px 36px;
  background: var(--bg-primary, #fff);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md, 12px);
  z-index: 7;
}
#sheet-grid-root { position: relative; }
.sg-empty-title { font-size: 14px; color: var(--text-secondary); }
.sg-mobile-note {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-secondary, #f5f6f8);
  border-bottom: 1px solid var(--border);
}

/* Selected row/col headers (selection state, distinct from the .sg-hl hover) */
th.sg-colhead.sg-head-sel, th.sg-rowhead.sg-head-sel {
  background: rgba(7, 157, 157, 0.14);
  color: var(--accent-blue, #079d9d);
  font-weight: 600;
}

/* Fill handle — small square at the bottom-right of a cell-mode selection */
.sg-fill-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 8px;
  height: 8px;
  background: var(--accent-blue, #079d9d);
  border: 1px solid var(--bg-primary, #fff);
  box-sizing: border-box;
  cursor: crosshair;
  z-index: 6;
}
/* Fill target preview while dragging the handle */
.sg-cell.sg-fill-preview {
  outline: 1px dashed var(--accent-blue, #079d9d);
  outline-offset: -1px;
  background-color: rgba(7, 157, 157, 0.08);
}

/* Context-menu separator + disabled item */
.sg-menu-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--border);
}
.sg-menu-item.sg-dis { opacity: 0.4; pointer-events: none; }

/* Hidden column: 0-width <col> collapses the cells; strip borders/padding so
   the column truly disappears (the left neighbor's border marks the gap). */
.sg-col-hidden { border-left: 0; border-right: 0; padding: 0; overflow: hidden; }

/* ── W2 (P6.D/E): CF / validation / link / comment / filter / find / dialogs ── */

/* Monochrome inline-SVG toolbar icon (filter funnel); inherits currentColor. */
.sg-ic { vertical-align: -2px; }
.sg-tb-zoom { max-width: 78px; }

/* Conditional-formatting data bar: sits above the cell background, below text
   (which we wrap in .sg-ctext) so both stay legible. Clipped by the cell. */
.sg-databar {
  position: absolute;
  left: 1px; top: 1px; bottom: 1px;
  min-width: 1px;
  z-index: 0;
  opacity: 0.9;
  border-radius: 2px;
  pointer-events: none;
}
.sg-ctext { position: relative; z-index: 1; }

/* Comment marker: small red triangle in the top-right corner (hover = title). */
.sg-cell.sg-note::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 0; height: 0;
  border-top: 6px solid #E03E3E;
  border-left: 6px solid transparent;
  pointer-events: none;
}

/* Hyperlink cell (fmt.link). CF/fmt inline colour still overrides this. */
.sg-cell.sg-link { color: var(--accent-blue, #079d9d); text-decoration: underline; cursor: pointer; }

/* Data-validation reject flash (MVP warns, does not block the write). */
@keyframes sg-invalid-kf {
  0%, 100% { box-shadow: inset 0 0 0 2px #E03E3E; }
  50% { box-shadow: none; }
}
.sg-cell.sg-invalid { animation: sg-invalid-kf 0.45s ease-in-out 2; }

/* List-validation dropdown arrow (active cell). Fill handle (z6) stays on top. */
.sg-dd-btn {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-blue, #079d9d);
  color: #fff;
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  z-index: 5;
}
.sg-dd-btn:hover { filter: brightness(1.08); }

/* AutoFilter funnel button on the range's header row — opens the sort/filter panel. */
.sg-filter-icon {
  position: absolute;
  right: 2px; top: 50%;
  transform: translateY(-50%);
  padding: 0 2px;
  font-size: 9px;
  line-height: 1.3;
  color: var(--text-secondary);
  background: var(--bg-secondary, #eef2f7);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
}
.sg-filter-icon:hover {
  color: var(--text-primary, #111);
  border-color: var(--text-secondary, #6b7280);
}
.sg-filter-icon.sg-filter-on {
  color: #fff;
  background: var(--primary, #079d9d);
  border-color: var(--primary, #079d9d);
}

/* Sort + filter-by-values panel (opens from the ▾ funnel) */
.sg-filter-pop {
  position: fixed;
  z-index: 1000;
  width: 232px;
  display: flex;
  flex-direction: column;
  padding: 6px;
  background: var(--bg-primary, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  font-size: 13px;
}
.sg-filter-sort {
  display: block;
  width: 100%;
  padding: 6px 8px;
  border: none;
  background: none;
  text-align: left;
  font-size: 13px;
  color: var(--text-primary, #111);
  border-radius: 4px;
  cursor: pointer;
}
.sg-filter-sort:hover { background: var(--bg-secondary, #f5f6f8); }
.sg-filter-search {
  margin: 6px 2px 4px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12.5px;
}
.sg-filter-links {
  display: flex;
  gap: 10px;
  padding: 0 4px 4px;
}
.sg-filter-links button {
  border: none;
  background: none;
  padding: 2px 0;
  font-size: 12px;
  color: var(--primary, #079d9d);
  cursor: pointer;
}
.sg-filter-links button:hover { text-decoration: underline; }
.sg-filter-list {
  max-height: 210px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding: 4px 2px;
}
.sg-filter-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.sg-filter-item:hover { background: var(--bg-secondary, #f5f6f8); }
.sg-filter-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sg-filter-note {
  padding: 4px 6px;
  font-size: 11.5px;
  color: var(--text-secondary);
}
.sg-filter-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 6px 2px 2px;
  border-top: 1px solid var(--border);
}
.sg-filter-foot .btn { padding: 4px 14px; font-size: 12.5px; }
.sg-filter-foot .btn[disabled] { opacity: 0.5; pointer-events: none; }

/* Find panel — floating so the grid stays usable while searching. */
.sg-find {
  position: fixed;
  z-index: 1050;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: var(--bg-primary, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
}
.sg-find-input {
  width: 160px;
  height: 26px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 6px);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-primary, #fff);
}
.sg-find-input:focus { outline: none; border-color: var(--accent-blue, #079d9d); }
.sg-find-count { min-width: 40px; text-align: center; font-size: 11px; color: var(--text-secondary); }
.sg-find-nav {
  width: 24px;
  height: 24px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
}
.sg-find-nav:hover { background: var(--bg-secondary, #f5f6f8); }

/* Mini modal shell for link / comment / CF / validation dialogs. */
.sg-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.28);
}
.sg-dialog {
  width: 340px;
  max-width: calc(100vw - 32px);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-primary, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 12px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}
.sg-dialog-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.sg-dialog-body { display: flex; flex-direction: column; gap: 8px; }
.sg-dialog-body label { font-size: 12px; color: var(--text-secondary); }
.sg-dialog-body input, .sg-dialog-body textarea, .sg-dialog-body select {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 6px);
  font-size: 13px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-primary, #fff);
}
.sg-dialog-body input:focus, .sg-dialog-body textarea:focus { outline: none; border-color: var(--accent-blue, #079d9d); }
.sg-dialog-body textarea { min-height: 96px; resize: vertical; }
.sg-dialog-foot { display: flex; justify-content: flex-end; gap: 8px; }

/* ── Sheet chrome ── */

#sheet-tabbar {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 2px;
  padding: 4px 8px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary, #f5f6f8);
}
.sg-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}
.sg-tab {
  max-width: 160px;
  padding: 5px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm, 6px) var(--radius-sm, 6px) 0 0;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}
.sg-tab:hover { background: var(--bg-hover, #ececec); }
.sg-tab-active {
  background: var(--bg-primary, #fff);
  border-color: var(--border);
  border-bottom-color: var(--bg-primary, #fff);
  color: var(--accent-blue, #079d9d);
  font-weight: 600;
}
.sg-tab-rename-input {
  width: 120px;
  height: 22px;
  padding: 0 4px;
  border: 1px solid var(--accent-blue, #079d9d);
  border-radius: var(--radius-sm, 4px);
  outline: none;
  font-size: 12px;
  background: var(--bg-primary, #fff);
  color: var(--text-primary);
}
.sg-tab-add {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin-left: 2px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.sg-tab-add:hover { background: var(--bg-hover, #ececec); color: var(--accent-blue, #079d9d); }
.sg-statusbar {
  display: none;
  flex-shrink: 0;
  margin-left: 12px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Excel-style zoom, bottom-right of the tab bar (− ──●── + 100%) */
.sg-zoomctl {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 12px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}
.sg-zoom-btn {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.sg-zoom-btn:hover { background: var(--bg-hover, #ececec); color: var(--text-primary); }
.sg-zoom-slider {
  width: 90px;
  height: 3px;
  accent-color: var(--accent-blue, #079d9d);
  cursor: pointer;
}
.sg-zoom-pct {
  min-width: 42px;
  border: 0;
  background: transparent;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  text-align: right;
  cursor: pointer;
}
.sg-zoom-pct:hover { color: var(--accent-blue, #079d9d); }
@media (max-width: 900px) { .sg-zoomctl { display: none; } }
@media (max-width: 760px) {
  /* !important: SheetChrome sets inline display:flex on render() — the
     stylesheet must win to stay hidden on mobile regardless of JS state. */
  #sheet-tabbar { display: none !important; }
}

/* Header highlight driven by the 'sheet-selection' contract event
   (P6.B mục 5) — background tint stronger than the .sg-insel selection
   tint above, text in the accent color per plan. */
th.sg-colhead.sg-hl, th.sg-rowhead.sg-hl {
  background: rgba(7, 157, 157, 0.18);
  color: var(--accent-blue, #079d9d);
}

/* Row hover tint. box-shadow (not background) so it layers on top of any
   inline fmt.fill the cell already has instead of overwriting it. */
.sg-table tbody tr:hover td.sg-cell {
  box-shadow: inset 0 0 0 9999px rgba(7, 157, 157, 0.05);
}

/* ── Sheet charts ── */

/* Positioning context for the absolute #sg-chart-layer overlay (P6.D
   contract: chart x/y are content-relative px, so the layer must anchor to
   the scroller's own content box, not the viewport). z-index sits below the
   sticky row/col headers (2-4) so a chart scrolls UNDER them like Excel's
   frozen panes, but above plain cells (auto/0). */
.sg-scroller { position: relative; }
.sg-chart-layer {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  pointer-events: none;
}
.sg-chart {
  position: absolute;
  box-sizing: border-box;
  background: var(--bg-primary, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 6px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  pointer-events: auto;
  cursor: move;
}
.sg-chart-sel {
  border-color: var(--accent-blue, #079d9d);
  box-shadow: 0 0 0 2px rgba(7, 157, 157, 0.3), 0 2px 10px rgba(0, 0, 0, 0.1);
}
.sg-chart-body { width: 100%; height: 100%; }
.sg-chart-body svg { display: block; width: 100%; height: 100%; }
.sg-chart-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(17, 17, 17, 0.55);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  display: none;
}
.sg-chart-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, var(--accent-blue, #079d9d) 50%);
  display: none;
}
.sg-chart-sel .sg-chart-del, .sg-chart-sel .sg-chart-resize { display: block; }

/* Insert-chart dialog — own card styling (not .sg-palette: that class is
   shaped for the 3-col colour-swatch grid, not a labelled form). */
.sg-chart-dialog {
  position: fixed;
  z-index: 1000;
  width: 320px;
  padding: 14px;
  background: var(--bg-primary, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
}
.sg-chart-dialog-title {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}
.sg-chart-dialog-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}
.sg-chart-dialog-row input, .sg-chart-dialog-row select {
  flex: 1;
  max-width: 190px;
  height: 26px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 6px);
  font-size: 12px;
  color: var(--text-primary);
  background: var(--bg-primary, #fff);
}
.sg-chart-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 4px;
}

/* ── Ribbon (P7.B) ── */
/* Desktop with the Office ribbon active: the ribbon replaces the legacy
   toolbar, so hide #sg-toolbar. Mobile (<900px) never gets the ribbon and
   keeps the toolbar untouched. */
@media (min-width: 900px) {
  .sg-has-ribbon .sg-toolbar { display: none; }
}
/* Format painter armed → signal that the next click stamps the copied fmt. */
.sg-scroller.sg-painter,
.sg-scroller.sg-painter td.sg-cell { cursor: copy; }
