:root {
  /* Colors */
  --color-white: #fff;
  --color-black: #000;
  --color-cream-50: #fcfcf9;
  --color-cream-100: #fffdfd;
  --color-gray-200: #f5f5f5;
  --color-gray-300: #a7a9a9;
  --color-gray-400: #777c7c;
  --color-slate-500: #626c71;
  --color-brown-600: #5e5240;
  --color-charcoal-700: #1f2121;
  --color-charcoal-800: #262828;
  --color-slate-900: #13343b;
  --color-teal-300: #32b8c6;
  --color-teal-400: #2da6b2;
  --color-teal-500: #21808d;
  --color-teal-600: #1d7480;
  --color-teal-700: #1a6873;
  --color-red-400: #ff5459;
  --color-red-500: #c0152f;
  --color-orange-400: #e68161;
  --color-orange-500: #a84b2f;
  --repo-status-offline: #2c2c2c;
  --repo-status-user: #34d399;
  --repo-status-org: #ef4444;

  /* Semantic tokens */
  --color-background: var(--color-cream-50);
  --color-surface: var(--color-cream-100);
  --color-surface-alt: var(--color-cream-100);
  --color-text: var(--color-slate-900);
  --color-text-secondary: var(--color-slate-500);
  --color-primary: var(--color-teal-500);
  --color-primary-hover: var(--color-teal-600);
  --color-border: rgba(94, 82, 64, 0.2);
  --color-bg-1: rgba(59, 130, 246, 0.08);
  --color-bg-2: rgba(245, 158, 11, 0.08);
  --selection-pass-fill: rgba(33, 128, 141, 0.06);
  --selection-pass-stripe: rgba(33, 128, 141, 0.18);
  --text-selection-bg: rgba(59, 130, 246, 0.28);
  --editor-outline: #3b82f6;

  /* Typography */
  --font-family-base: Arial, "Helvetica Neue", Helvetica, sans-serif;
  --font-family-mono: "Berkeley Mono", ui-monospace, Consolas, monospace;
  --font-family-italic: Arial, "Helvetica Neue", Helvetica, sans-serif;
  --font-size-xs: 11px;
  --font-size-sm: 12px;
  --font-size-base: 14px;
  --font-weight-semibold: 600;
  --font-weight-medium: 500;
  --font-weight-bold: 600;

  /* Spacing */
  --space-4: 4px;
  --space-6: 6px;
  --space-8: 8px;
  --space-12: 12px;
  --space-16: 16px;

  /* Layout */
  --toolbar-height: 48px;
  --formula-bar-height: 48px;
  --chrome-offset: calc(var(--toolbar-height) + var(--formula-bar-height));

  /* Border & Effects */
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.04);
  --duration-fast: 150ms;
  --ease-standard: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) {
  --color-background: #000000;
  --color-surface: #000000;
  --color-surface-alt: #050505;
  --color-text: #f8f9fa;
  --color-text-secondary: rgba(248, 249, 250, 0.6);
  --color-primary: var(--color-teal-300);
  --color-primary-hover: var(--color-teal-400);
  --color-border: rgba(248, 249, 250, 0.24);
  --color-bg-1: rgba(45, 166, 178, 0.12);
  --color-bg-2: rgba(245, 158, 11, 0.22);
  --selection-pass-fill: rgba(255, 82, 82, 0.12);
  --selection-pass-stripe: rgba(255, 82, 82, 0.3);
  --text-selection-bg: rgba(255, 153, 0, 0.42);
  --editor-outline: #ff9900;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]):not(.has-theme-toggle) {
    --color-background: #000000;
    --color-surface: #000000;
    --color-surface-alt: #050505;
    --color-text: #f8f9fa;
    --color-text-secondary: rgba(248, 249, 250, 0.6);
    --color-primary: var(--color-teal-300);
    --color-primary-hover: var(--color-teal-400);
    --color-border: rgba(248, 249, 250, 0.24);
    --color-bg-1: rgba(45, 166, 178, 0.12);
    --color-bg-2: rgba(245, 158, 11, 0.22);
    --selection-pass-fill: rgba(255, 82, 82, 0.12);
    --selection-pass-stripe: rgba(255, 82, 82, 0.3);
    --text-selection-bg: rgba(255, 153, 0, 0.42);
    --editor-outline: #ff9900;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; }

html {
  font-size: var(--font-size-base);
  font-family: var(--font-family-base);
  color: var(--color-text);
  background: var(--color-background);
  -webkit-font-smoothing: antialiased;
}

body { margin: 0; padding: 0; }

body.tabs-only {
  min-height: 55px; /* Ensure minimum height for tab bar */
  display: flex;
  flex-direction: column;
  background: var(--color-background);
  color: var(--color-text);
}

body.tabs-only:has(.sheet-tabs--state a[id$="d"]:target) {
  --color-background: #000000;
  --color-surface: #000000;
  --color-surface-alt: #050505;
  --color-text: #f8f9fa;
  --color-primary: var(--color-teal-300);
  --color-border: rgba(248, 249, 250, 0.24);
  --color-bg-1: rgba(45, 166, 178, 0.12);
  color-scheme: dark;
}

/* No-JS first-sheet preview is opt-in for modern graphical engines only. */
.index-first-sheet-noscript {
  display: none !important;
}

@supports (display: grid) and (selector(:has(*))) and (container-type: inline-size) {
  html.no-js body.tabs-only {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
  }

  @media (min-height: 121px) {
    /* Hide top-level tabs in full-page no-JS GUI mode.
       Keep iframe-sized tabs (55px) untouched so embedded sheet bottom tabs stay visible. */
    html.no-js body.tabs-only > .sheet-tabs--state.sheet-tabs--dynamic {
      position: fixed;
      left: 0;
      right: 0;
      bottom: 0;
      z-index: 20;
      pointer-events: none;
      visibility: hidden;
    }
  }

  html.no-js body.tabs-only .index-first-sheet-noscript[hidden] {
    display: block !important;
    order: 1;
    width: 100%;
    margin: 0;
    padding: 0;
    flex: 1 1 auto;
    min-height: 0;
  }

  html.no-js body.tabs-only .index-first-sheet-object {
    display: block !important;
    width: 100%;
    border: 0;
    margin: 0;
    background: var(--color-surface);
    height: 100%;
    min-height: 100%;
  }

  /* Keep preview hidden inside tiny iframe contexts used for tab chrome. */
  @media (max-height: 120px) {
    html.no-js body.tabs-only .index-first-sheet-noscript[hidden] {
      display: none !important;
    }
  }
}

html:not(.no-js)[data-theme='light'] body.tabs-only,
body.tabs-only:has(.sheet-tabs--state a[id$="l"]:target) {
  --color-background: var(--color-cream-50);
  --color-surface: var(--color-cream-100);
  --color-surface-alt: var(--color-cream-100);
  --color-text: var(--color-slate-900);
  --color-primary: var(--color-teal-500);
  --color-border: rgba(94, 82, 64, 0.2);
  --color-bg-1: rgba(59, 130, 246, 0.08);
  color-scheme: light;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-16);
  border-radius: var(--radius-base);
  font-size: var(--font-size-base);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-standard);
  border: none;
}

.btn--sm {
  padding: var(--space-4) var(--space-12);
  font-size: var(--font-size-sm);
  border-radius: var(--radius-sm);
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Forms */
.form-control {
  display: block;
  width: 100%;
  padding: var(--space-8) var(--space-12);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  transition: border-color var(--duration-fast);
}

.form-control:focus {
  border-color: var(--color-primary);
  outline: 2px solid var(--color-primary);
}

/* Utilities */
.hidden { display: none; }

/* Spreadsheet */
.spreadsheet-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  overflow: hidden;
}

.theme-scope {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: var(--color-background);
  color: var(--color-text);
}

.theme-scope > noscript {
  display: block;
}

.noscript-credits-control {
  display: inline-block;
  position: relative;
  z-index: 4;
}

.noscript-credits-control[hidden] {
  display: none !important;
}

/* Re-enable in CSS-capable no-JS UAs (e.g. cha); elinks ignores CSS and keeps it hidden. */
html.no-js .sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control[hidden] {
  display: inline-block !important;
}

/* Keep credits controls after sheet links in source order but visually first. */
body.tabs-only .sheet-tabs--state .noscript-credits-control {
  order: -1;
}

.noscript-credits-control .button-container {
  position: relative;
  display: inline-block;
  overflow: visible;
}

.noscript-credits-control .button-container > .credits-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  padding: 15px 30px;
  font-size: 16px;
  cursor: pointer;
  background-color: transparent;
  color: var(--color-text);
  border: 1px solid var(--tab-border-color, var(--color-border));
  border-radius: 5px;
}

.sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control .button-container > .credits-trigger {
  display: inline-block !important;
  min-width: 3ch !important;
  width: 3ch !important;
  height: auto !important;
  line-height: 1 !important;
  padding: 0 !important;
  text-align: center;
}

.sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control .button-container > .credits-trigger--open {
  min-width: 3ch !important;
  width: 3ch !important;
}

/* Keep GUI-specific opener hidden by default; modern CSS-capable browsers opt in below. */
.sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control .button-container > .credits-trigger--open-gui {
  display: none !important;
}

@supports (display: grid) and (selector(:has(*))) {
  .sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control .button-container > .credits-trigger--open-gui {
    display: inline-block !important;
  }

  .sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control .button-container > .credits-trigger--open-tui {
    display: none !important;
  }
}

.sheet-tabs--state.sheet-tabs--dynamic > .noscript-credits-control {
  grid-column: 1;
  grid-row: 1;
}

/* Ensure only one trigger is visible at a time in dynamic no-JS tabs. */
.sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control .button-container > .credits-trigger--close {
  display: none !important;
}

.sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control:target .button-container > .credits-trigger--open {
  display: none !important;
}

.sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control .button-container > .credits-trigger--close:target ~ .credits-trigger--open {
  display: none !important;
}

.sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control:target .button-container > .credits-trigger--close {
  display: inline-block !important;
  border-color: #45a049;
  color: #45a049;
}

.sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control .button-container > .credits-trigger--close:target {
  display: inline-block !important;
  border-color: #45a049;
  color: #45a049;
}

/* Keep GUI close trigger hidden in terminal/text profiles by default. */
.sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control:target .button-container > .credits-trigger--close-gui,
.sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control .button-container > .credits-trigger--close-gui:target {
  display: none !important;
}

.noscript-credits-control .button-container > .credits-trigger .credits-trigger-fallback {
  display: inline;
}

/* Render fallback trigger labels via CSS so HTML can stay text-empty. */
#credits-close .credits-trigger-fallback::before {
  content: "OwO";
}

#credits-close-gui .credits-trigger-fallback::before {
  content: ">w<";
}

#credits-open .credits-trigger-fallback::before,
#credits-open-gui .credits-trigger-fallback::before {
  content: "\00a0\2764\00a0";
}

/* In modern no-JS GUI mode, keep hash untouched and show the "open" face on interaction. */
#credits-open-gui:active .credits-trigger-fallback::before {
  content: ">w<";
}

#credits-open-gui {
  position: relative;
  overflow: visible !important;
  z-index: 25;
}

#credits-open-gui:active::after {
  content: "I..it t-tickles!";
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  display: block;
  width: max-content;
  max-width: min(280px, calc(100vw - 48px));
  padding: 6px 10px;
  border: 1px solid #45a049;
  background: var(--color-surface);
  color: var(--color-text);
  line-height: 1.2;
  z-index: 24;
  pointer-events: none;
}

.noscript-credits-control .tui-text,
.noscript-credits-control .gui-text {
  display: none;
  margin-top: 0;
  padding: 0 1ch;
  background-color: transparent;
  border: 1px solid #45a049;
  border-radius: 3px;
  line-height: 1.4;
  white-space: normal;
  max-width: 34ch;
}

.noscript-credits-control .tui-text {
  position: absolute;
  left: 0;
  top: calc(100% + 1px);
  z-index: 20;
}

.noscript-credits-control .tui-text::before {
  content: none;
  display: none;
}

.noscript-credits-control .tui-text .tui-text-title {
  display: block;
  font-weight: 700;
  margin-bottom: 2px;
}

.noscript-credits-control .tui-text .tui-text-title::before {
  content: "Credits";
}

.noscript-credits-control .tui-text .tui-text-email {
  display: block;
}

.noscript-credits-control .tui-text .tui-text-email::before {
  content: "derberg@matrix.org";
}

.noscript-credits-control .tui-text::after {
  content: none;
  display: none;
}

.noscript-credits-control .tui-text .tui-corner-overlay {
  position: absolute;
  top: -2px;
  right: -2ch;
  line-height: 1;
  color: #45a049;
  pointer-events: none;
  z-index: 2;
  display: inline-block;
}

.noscript-credits-control .tui-text .tui-corner-overlay::before {
  content: "│";
}

.noscript-credits-control .tui-text .tui-corner-overlay::after {
  content: "┬";
  position: absolute;
  top: 0;
  left: 0;
  line-height: 1;
  color: var(--color-text);
  opacity: 0;
  transform: translateX(0);
  pointer-events: none;
}

@keyframes tuiCornerSpark {
  0% {
    opacity: 1;
    color: #d7ffd9;
    transform: translateX(0);
  }
  40% {
    opacity: 1;
    color: #a7e0b0;
    transform: translateX(0.6ch);
  }
  75% {
    opacity: 1;
    color: #6abd78;
    transform: translateX(1ch);
  }
  100% {
    opacity: 0;
    color: #45a049;
    transform: translateX(1.6ch);
  }
}

@keyframes tuiCornerCorner {
  0%, 14% {
    opacity: 1;
  }
  14.01%, 100% {
    opacity: 0;
  }
}

@keyframes tuiCornerJoint {
  0%, 14% {
    opacity: 0;
    transform: translateX(0);
  }
  14.01%, 85% {
    opacity: 1;
    transform: translateX(0);
  }
  85.01%, 100% {
    opacity: 1;
    transform: translateX(7ch);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .noscript-credits-control:target .tui-text::before,
  .noscript-credits-control .button-container > .credits-trigger--close:target ~ .tui-text::before {
    content: "█";
    display: block;
    position: absolute;
    top: -2px;
    right: -2ch;
    line-height: 1;
    color: #d7ffd9;
    z-index: 3;
    pointer-events: none;
    animation: tuiCornerSpark 0.6s linear forwards;
  }

  .noscript-credits-control:target .tui-text .tui-corner-overlay,
  .noscript-credits-control .button-container > .credits-trigger--close:target ~ .tui-text .tui-corner-overlay {
    animation: tuiCornerCorner 4.2s linear forwards;
  }

  .noscript-credits-control:target .tui-text .tui-corner-overlay::after,
  .noscript-credits-control .button-container > .credits-trigger--close:target ~ .tui-text .tui-corner-overlay::after {
    animation: tuiCornerJoint 4.2s linear forwards;
  }
}

.noscript-credits-control .gui-text::before {
  content: "Credits";
  display: block;
  font-weight: 700;
  margin-bottom: 2px;
}

.noscript-credits-control .gui-text::after {
  content: "derberg@matrix.org";
  display: block;
}

#credits-open-gui:active ~ .gui-text::before {
  content: "I..it t-tickles!";
}

#credits-open-gui:active ~ .gui-text::after {
  content: "";
}

.noscript-credits-control:target .tui-text {
  display: block;
}

.noscript-credits-control .button-container > .credits-trigger--close:target ~ .tui-text {
  display: block;
}

.noscript-credits-control:target .button-container > .credits-trigger {
  padding: 0 !important;
}

.noscript-credits-control .button-container > .credits-trigger--close:target,
.noscript-credits-control .button-container > .credits-trigger--close:target ~ .credits-trigger {
  padding: 0 !important;
}

.noscript-credits-control .credits-trigger:focus,
.noscript-credits-control .credits-trigger:focus-visible,
.noscript-credits-control .credits-trigger:active {
  outline: 2px solid #ffffff;
  outline-offset: 1px;
}

@media (pointer: fine) {
  .noscript-credits-control:target .tui-text {
    display: none;
  }

  .noscript-credits-control .button-container > .credits-trigger--close:target ~ .tui-text {
    display: none;
  }

  .noscript-credits-control .gui-text {
    display: none;
    position: absolute;
    left: 50%;
    bottom: calc(100% + 10px);
    transform: translateX(-50%);
    margin-top: 0;
    width: max-content;
    max-width: min(320px, calc(100vw - 24px));
    z-index: 20;
  }

  .noscript-credits-control:target .gui-text {
    display: block;
  }

  .noscript-credits-control .button-container > .credits-trigger--close:target ~ .gui-text {
    display: block;
  }

  .noscript-credits-control .button-container > .credits-trigger:hover ~ .gui-text,
  .noscript-credits-control .button-container > .credits-trigger:focus ~ .gui-text,
  .noscript-credits-control .button-container > .credits-trigger:focus-visible ~ .gui-text,
  .noscript-credits-control .button-container > .credits-trigger:active ~ .gui-text {
    display: block;
  }

  .noscript-credits-control .button-container > .credits-trigger:hover {
    background-color: var(--color-bg-1);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
  }
}

.noscript-credits-panel {
  display: none;
}

html.no-js .noscript-credits-control:focus-within .noscript-credits-panel {
  display: block;
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  margin: 0;
  transform: translate(-50%, -50%);
  z-index: 2000;
  overflow: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

html.no-js body.tabs-only .noscript-credits-control .noscript-credits-panel {
  display: none !important;
}

html:not(.no-js) .noscript-credits-panel {
  display: none !important;
}

.noscript-credits-panel__card {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: 12px;
}

.noscript-credits-panel__title {
  margin: 0 0 8px;
  font-size: 16px;
  line-height: 1.2;
}

.noscript-credits-panel__title::before {
  content: "Credits";
}

.noscript-credits-panel__text {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--color-text-secondary);
}

.noscript-credits-panel__text::before {
  content: "Made by derberg@matrix.org.";
}

.noscript-credits-panel__terminal {
  display: block;
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--color-text-secondary);
}

.noscript-credits-panel__terminal::before {
  content: "Thanks for visiting from a terminal browser.";
}

.noscript-credits-panel__actions {
  margin: 10px 0 0;
}

@media (pointer: fine) {
  .noscript-credits-panel__terminal {
    display: none;
  }
}

.sheet-tabs,
.sheet-tabs--noscript {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px; /* 8px top/bottom spacing */
  background: var(--color-surface);
  flex-shrink: 0;
  height: 55px; /* Fixed height to match iframe rendering */
  width: 100%;
  box-sizing: border-box;
  border-radius: 0 !important; /* Ensure no border radius */
}

html.no-js .sheet-tabs--js {
  display: none;
}

html.no-js body.tabs-only .sheet-tabs--js {
  display: none;
}

html.no-js .sheet-tabs--noscript[hidden] {
  display: none;
}

html:not(.no-js) .sheet-tabs--js[hidden] {
  display: flex !important;
}

html:not(.no-js) .sheet-tabs--state {
  display: none;
}

/* Keep no-JS state links out of the layout once JS is active. */
html:not(.no-js) body.tabs-only .sheet-tabs--state {
  display: none !important;
}

body.tabs-only .sheet-tabs--state {
  gap: 10px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

body.tabs-only .sheet-tabs--state > a {
  padding: 0 1ch;
  height: 20px;
  line-height: 20px;
  display: none;
  flex: 0 0 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

body.tabs-only .sheet-tabs--state > a.sheet-link {
  display: inline-flex !important;
  position: relative;
  z-index: 1;
}

body.tabs-only .sheet-tabs--state > a.sheet-route {
  display: none !important;
}

body.tabs-only .sheet-tabs--state > span[aria-hidden="true"] {
  display: none !important;
}

/* Add border to sheet-tabs when it's the main tabs (not in iframe) */
body.tabs-only .sheet-tabs,
body.tabs-only .sheet-tabs--noscript {
  border-top: 1px solid var(--color-border);
}

/* Specific rule for when sheet-tabs is inside an iframe */
.sheet-tabs-iframe .sheet-tabs {
  border-radius: 0 !important;
  overflow: hidden;
  border-top: none !important; /* Remove border when in iframe */
}

.sheet-tabs__list {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow-x: auto;
  padding: 0;
  height: 38px; /* Match tab height */
}

.sheet-tab,
.sheet-tabs--noscript a:not(.sheet-route),
.sheet-tabs--noscript::before {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid #ffffff;
  background: var(--color-surface-alt);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  line-height: 36px;
  text-decoration: none;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard);
  white-space: nowrap;
}

.heart-fallback {
  border: 1px solid var(--tab-border-color, var(--color-border));
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.sheet-tabs--noscript::before {
  content: none !important;
  display: none !important;
}

.sheet-tab:hover,
.sheet-tabs--noscript a:not(.sheet-route):hover {
  background: var(--color-bg-1);
  border-color: #ff4d4d;
  color: #ff4d4d;
}

@supports (display: grid) and (selector(:has(*))) {
  .sheet-tab:hover,
  .sheet-tabs--noscript a:not(.sheet-route):hover {
    border-color: #000000 !important;
    color: var(--color-text) !important;
  }

  .sheet-tab--active:hover,
  .sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal.sheet-tab--active:hover,
  .sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal[aria-current="page"]:hover,
  .sheet-tabs--noscript a:not(.sheet-route)[aria-current="page"]:hover {
    color: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
  }

  :is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tab:hover,
  :is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tabs--noscript a:not(.sheet-route):hover {
    border-color: #ffffff !important;
    color: var(--color-text) !important;
  }

  :is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tab--active:hover,
  :is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal.sheet-tab--active:hover,
  :is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal[aria-current="page"]:hover,
  :is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tabs--noscript a:not(.sheet-route)[aria-current="page"]:hover {
    color: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
  }
}

.sheet-tab:visited,
.sheet-tabs--noscript a:not(.sheet-route):visited,
body.tabs-only .sheet-tabs--state > a.sheet-link:visited,
.sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal:visited {
  color: var(--color-text);
}

.sheet-tab--active {
  background: var(--color-bg-1);
  border-color: var(--color-primary);
  color: var(--color-primary);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.sheet-tab--active:visited,
.sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal.sheet-tab--active,
.sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal.sheet-tab--active:visited,
.sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal[aria-current="page"],
.sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal[aria-current="page"]:visited,
.sheet-tabs--noscript a:not(.sheet-route)[aria-current="page"],
.sheet-tabs--noscript a:not(.sheet-route)[aria-current="page"]:visited {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.sheet-tab--add {
  min-width: 40px;
  height: 38px;
  padding: 0 10px;
  border-color: var(--color-border);
  color: var(--color-text);
  font-weight: var(--font-weight-bold);
}

body.tabs-only .sheet-tabs--state .noscript-credits-control .tui-text,
body.tabs-only .sheet-tabs--state .noscript-credits-control .gui-text {
  line-height: 1.2;
}

@supports (display: grid) and (selector(:has(*))) {
  .sheet-tab,
  .sheet-tabs--noscript a:not(.sheet-route),
  .sheet-tabs--noscript::before {
    border: 1px solid var(--color-border);
  }

  .sheet-tab--active,
  .sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal.sheet-tab--active,
  .sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal[aria-current="page"],
  .sheet-tabs--noscript a:not(.sheet-route)[aria-current="page"] {
    border-color: var(--color-primary);
    color: var(--color-primary);
  }

  .sheet-tab:hover,
  .sheet-tabs--noscript a:not(.sheet-route):hover {
    border-color: var(--color-border);
    color: var(--color-text);
  }
}

.sheet-tab--local {
  color: var(--color-red-500);
}

.sheet-tab[data-dirty="true"] {
  position: relative;
}

.sheet-tab[data-dirty="true"]::after {
  content: "*";
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  line-height: 1;
  pointer-events: none;
  color: var(--color-red-500);
  font-weight: var(--font-weight-bold);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tabs,
:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tabs--noscript {
  --tab-border-color: #141414;
  background: #000000;
  border-top: 1px solid #141414;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tab,
:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tabs--noscript a:not(.sheet-route),
:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .heart-fallback {
  background: #000000;
  border-color: #141414;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tab:not(.sheet-tab--active),
:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tabs--noscript a:not(.sheet-route):not([aria-current="page"]) {
  background: #000000;
  border-color: #141414;
}

/* Chawan-like profile: grid support, but no modern selector/container support.
   Keep this narrow so modern browsers with JS disabled still show sheet names. */
@supports (display: grid) and (not (container-type: inline-size)) and (not (selector(:has(*)))) {
  body.tabs-only .sheet-tabs--state {
    justify-content: flex-start;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0;
  }

  body.tabs-only .sheet-tabs--state.sheet-tabs--dynamic > .noscript-credits-control {
    position: relative;
    margin: 0;
  }

  body.tabs-only .sheet-tabs--state > a.sheet-link {
    display: inline-flex !important;
    min-width: 0;
    height: 20px;
    line-height: 20px;
    padding: 0;
    border: 1px solid var(--tab-border-color, #141414);
    background: #000000;
    color: var(--color-text);
  }

  body.tabs-only .sheet-tabs--state > a.sheet-link:hover {
    background: #111111;
    border-color: #ffffff;
    color: #ffffff;
  }

  body.tabs-only .sheet-tabs--state > a.sheet-link:focus,
  body.tabs-only .sheet-tabs--state > a.sheet-link:focus-visible,
  body.tabs-only .sheet-tabs--state > a.sheet-link:active {
    background: #111111;
    border-color: #ffffff;
    color: #ffffff;
    outline: none;
  }

  body.tabs-only .sheet-tabs--state .noscript-credits-control > .heart-fallback {
    display: inline-flex !important;
    min-width: 0;
    width: auto;
    height: 20px;
    line-height: 20px;
    padding: 0 1ch;
    border: 1px solid var(--tab-border-color, #141414);
    background: #000000;
  }

  body.tabs-only .sheet-tabs--state .noscript-credits-control > .heart-fallback:hover {
    background: #111111;
    border-color: #ffffff;
    color: #ffffff;
  }

  body.tabs-only .sheet-tabs--state .noscript-credits-control > .heart-fallback:focus,
  body.tabs-only .sheet-tabs--state .noscript-credits-control > .heart-fallback:focus-visible,
  body.tabs-only .sheet-tabs--state .noscript-credits-control > .heart-fallback:active {
    background: #111111;
    border-color: #ffffff;
    color: #ffffff;
    outline: none;
  }
}

/* Non-modern pointerless browsers (excluding cha in practice here):
   show text separators between tab links. */
@supports (display: grid) and (not (selector(:has(*)))) {
  @media (pointer: none) {
    body.tabs-only .sheet-tabs--state > a.sheet-link + a.sheet-link {
      position: relative;
      padding-left: calc(1ch + 8px);
    }

    body.tabs-only .sheet-tabs--state > a.sheet-link + a.sheet-link::before {
      content: "|";
      position: absolute;
      left: 0;
      color: var(--color-text-secondary);
      pointer-events: none;
    }
  }
}

/* Modern browser layout: use larger button geometry. */
@supports (display: grid) and (selector(:has(*))) {
  body.tabs-only .sheet-tabs--state > a.sheet-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 64px;
    height: 38px;
    line-height: 36px;
    padding: 0 12px;
    border: 1px solid var(--tab-border-color, var(--color-border));
    background: var(--color-surface);
    color: var(--color-text);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    text-decoration: none;
    text-align: center;
    white-space: nowrap;
  }
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tab--active {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: rgba(33, 128, 141, 0.12);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tab--local {
  color: var(--color-red-400);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tab[data-dirty="true"]::after {
  color: var(--color-red-400);
}

.sheet-tabs-embed {
  flex-shrink: 0;
  padding: 0;
  height: 55px; /* Specific height as requested */
  border-radius: 0 !important;
  border-top: 0 !important;
  overflow: hidden;
  position: relative;
}

/* Keep iframe-based no-JS chrome hidden by default.
   Text UAs (e.g. chawan) render these frames as box-art placeholders. */
html.no-js .toolbar--noscript,
html.no-js .noscript-toolbar-embed,
html.no-js .sheet-tabs-embed,
html.no-js .nojs-top-spacer,
html.no-js .corner-cell,
html.no-js .column-headers,
html.no-js .row-headers {
  display: none !important;
}

/* Re-enable no-JS chrome only for modern graphical engines. */
@supports (display: grid) and (selector(:has(*))) and (container-type: inline-size) {
  @media (hover: hover) and (pointer: fine) {
    html.no-js .toolbar--noscript {
      display: flex !important;
    }

    html.no-js .noscript-toolbar-embed,
    html.no-js .sheet-tabs-embed,
    html.no-js .nojs-top-spacer {
      display: block !important;
    }

    /* Keep fallback table headers as the single source of truth in no-JS mode.
       This avoids the duplicate corner Fuji glyph and stray header rail artifacts. */
    html.no-js .corner-cell,
    html.no-js .column-headers,
    html.no-js .row-headers {
      display: none !important;
    }

    html.no-js .grid-container {
      grid-template-columns: 0 1fr !important;
      grid-template-rows: 0 1fr !important;
    }

    html.no-js .main-grid {
      grid-column: 1 / span 2 !important;
      grid-row: 1 / span 2 !important;
    }
  }
}

@supports (display: grid) and (selector(:has(*))) {
  html.no-js.has-theme-toggle .sheet-tabs-embed::after {
    content: none !important;
    display: none !important;
  }
}

/* Terminal/text no-JS baseline for sheet pages.
   Keep table content in document flow so long tables stay reachable. */
.sheet-index-backlink {
  margin: 0;
  padding: 0 var(--space-16, 16px) var(--space-8, 8px);
}

.sheet-index-backlink--bottom {
  margin-top: var(--space-8, 8px);
}

/* Minimal-selector no-JS fallback for limited CSS parsers (e.g. chawan).
   Avoid :not(), :has(), and complex @supports so overrides always apply. */
html.no-js .spreadsheet-container {
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
}

html.no-js .theme-scope {
  flex: 0 0 auto !important;
  min-height: 0 !important;
}

html.no-js .grid-container {
  display: block !important;
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
}

html.no-js .main-grid {
  display: block !important;
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
  max-height: none !important;
}

html.no-js .grid-content {
  display: block !important;
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
  transform: none !important;
}

/* JS-enabled terminal UAs still need flow layout (inner scroll breaks). */
html.terminal-ua .spreadsheet-container {
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
}

html.terminal-ua .theme-scope {
  flex: 0 0 auto !important;
  min-height: 0 !important;
}

html.terminal-ua .grid-container {
  display: block !important;
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
}

html.terminal-ua .main-grid {
  display: block !important;
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
  max-height: none !important;
}

html.terminal-ua .grid-content {
  display: block !important;
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
  transform: none !important;
}

html.no-js body:not(.tabs-only) .spreadsheet-container {
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
}

html.no-js body:not(.tabs-only) .theme-scope {
  flex: 0 0 auto !important;
  min-height: 0 !important;
}

html.no-js body:not(.tabs-only) .grid-container {
  display: block !important;
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
}

html.no-js body:not(.tabs-only) .main-grid {
  display: block !important;
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
  max-height: none !important;
}

html.no-js body:not(.tabs-only) .grid-content {
  display: block !important;
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
  transform: none !important;
}

/* Mirror sheet-local no-JS fallback styles centrally so generated HTML can stay lean. */
@supports (display: grid) and (selector(:has(*))) and (container-type: inline-size) {
  @media (hover: hover) and (pointer: fine) {
    .toolbar--noscript {
      display: flex !important;
    }

    .sheet-index-backlink {
      display: none !important;
    }
  }
}

/* Terminal/touch no-JS fallback for modern CSS engines:
   keep layout in normal flow so long tables remain scrollable. */
@supports (display: grid) and (selector(:has(*))) and (container-type: inline-size) {
  @media (hover: none), (pointer: none), (any-hover: none), (any-pointer: none) {
    html.no-js body:not(.tabs-only) .spreadsheet-container {
      height: auto !important;
      min-height: 0 !important;
      overflow: visible !important;
    }

    html.no-js body:not(.tabs-only) .theme-scope {
      flex: 0 0 auto !important;
      min-height: 0 !important;
    }

    html.no-js body:not(.tabs-only) .grid-container {
      display: block !important;
      height: auto !important;
      min-height: 0 !important;
      overflow: visible !important;
    }

    html.no-js body:not(.tabs-only) .main-grid {
      display: block !important;
      height: auto !important;
      min-height: 0 !important;
      overflow: visible !important;
      max-height: none !important;
    }

    html.no-js body:not(.tabs-only) .grid-content {
      display: block !important;
      height: auto !important;
      min-height: 0 !important;
      overflow: visible !important;
      transform: none !important;
    }

    html.no-js body:not(.tabs-only) .grid-content > table[data-spreadsheet-export] {
      display: table !important;
      width: max-content !important;
      min-width: max-content !important;
      max-width: none !important;
      margin: 0 !important;
    }

    html.no-js body:not(.tabs-only) .spreadsheet-fallback {
      table-layout: fixed !important;
      width: max-content !important;
    }

    html.no-js body:not(.tabs-only) .spreadsheet-fallback thead,
    html.no-js body:not(.tabs-only) .spreadsheet-fallback tbody {
      display: table-row-group !important;
    }

    html.no-js body:not(.tabs-only) .spreadsheet-fallback tr,
    html.no-js body:not(.tabs-only) .spreadsheet-fallback th,
    html.no-js body:not(.tabs-only) .spreadsheet-fallback td {
      height: auto !important;
      min-height: 0 !important;
      line-height: 1 !important;
    }

    html.no-js body:not(.tabs-only) .spreadsheet-fallback th:not(:first-child),
    html.no-js body:not(.tabs-only) .spreadsheet-fallback td {
      width: auto !important;
      min-width: 6ch !important;
      max-width: none !important;
      vertical-align: middle !important;
    }

    html.no-js body:not(.tabs-only) .spreadsheet-fallback th,
    html.no-js body:not(.tabs-only) .spreadsheet-fallback td {
      padding: 0 1ch !important;
    }

    html.no-js body:not(.tabs-only) .spreadsheet-fallback .fallback-cell-content {
      display: inline !important;
      width: auto !important;
      min-width: 0 !important;
      height: auto !important;
      min-height: 0 !important;
      padding: 0 !important;
      line-height: 1 !important;
      white-space: pre !important;
      overflow: visible !important;
      text-overflow: clip !important;
      vertical-align: middle !important;
    }
  }
}

@supports (display: grid) and (not (container-type: inline-size)) {
  html.no-js body:not(.tabs-only) .spreadsheet-container {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  html.no-js body:not(.tabs-only) .theme-scope {
    flex: 0 0 auto !important;
    min-height: 0 !important;
  }

  html.no-js body:not(.tabs-only) .grid-container {
    display: table !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  html.no-js body:not(.tabs-only) .main-grid {
    display: table-row-group !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    max-height: none !important;
  }

  html.no-js body:not(.tabs-only) .table-title-badge {
    display: table-caption;
    caption-side: top;
    position: static;
    left: auto;
    bottom: auto;
    margin: 0 0 var(--space-8, 8px);
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    color: var(--color-text);
    box-shadow: none;
    backdrop-filter: none;
    pointer-events: auto;
    max-width: none;
    text-overflow: clip;
    white-space: nowrap;
    overflow: visible;
    opacity: 1;
    z-index: auto;
  }

  html.no-js body:not(.tabs-only) .grid-content {
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    transform: none !important;
  }

  html.no-js body:not(.tabs-only) .grid-content > table[data-spreadsheet-export] {
    display: table !important;
    width: max-content !important;
    min-width: max-content !important;
    max-width: none !important;
    margin: 0 !important;
  }

  /* Chawan-like terminal table normalization:
     keep empty columns visually consistent and avoid extra blank row lines. */
  html.no-js body:not(.tabs-only) .spreadsheet-fallback {
    table-layout: fixed !important;
    width: max-content !important;
  }

  html.no-js body:not(.tabs-only) .spreadsheet-fallback thead,
  html.no-js body:not(.tabs-only) .spreadsheet-fallback tbody {
    display: table-row-group !important;
  }

  html.no-js body:not(.tabs-only) .spreadsheet-fallback tr,
  html.no-js body:not(.tabs-only) .spreadsheet-fallback th,
  html.no-js body:not(.tabs-only) .spreadsheet-fallback td {
    height: auto !important;
    min-height: 0 !important;
    line-height: 1 !important;
  }

  html.no-js body:not(.tabs-only) .spreadsheet-fallback th:not(:first-child),
  html.no-js body:not(.tabs-only) .spreadsheet-fallback td {
    width: auto !important;
    min-width: 6ch !important;
    max-width: none !important;
    vertical-align: middle !important;
  }

  html.no-js body:not(.tabs-only) .spreadsheet-fallback th,
  html.no-js body:not(.tabs-only) .spreadsheet-fallback td {
    padding: 0 1ch !important;
  }

  html.no-js body:not(.tabs-only) .spreadsheet-fallback .fallback-cell-content {
    display: inline !important;
    width: auto !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
    white-space: pre !important;
    overflow: visible !important;
    text-overflow: clip !important;
    vertical-align: middle !important;
  }
}

@supports not (display: grid) {
  html.no-js body:not(.tabs-only) .spreadsheet-container {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  html.no-js body:not(.tabs-only) .theme-scope {
    flex: 0 0 auto !important;
    min-height: 0 !important;
  }

  html.no-js body:not(.tabs-only) .grid-container {
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  html.no-js body:not(.tabs-only) .main-grid {
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    max-height: none !important;
  }

  html.no-js body:not(.tabs-only) .grid-content {
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    transform: none !important;
  }

  html.no-js body:not(.tabs-only) .grid-content > table[data-spreadsheet-export] {
    display: table !important;
    width: max-content !important;
    min-width: max-content !important;
    max-width: none !important;
    margin: 0 !important;
  }

  html.no-js body:not(.tabs-only) .sheet-index-backlink.sheet-index-backlink--bottom {
    display: block !important;
    clear: both;
    margin: var(--space-8, 8px) 0 0 !important;
  }

  html.no-js body:not(.tabs-only) .spreadsheet-fallback {
    table-layout: fixed !important;
    width: max-content !important;
  }

  html.no-js body:not(.tabs-only) .spreadsheet-fallback thead,
  html.no-js body:not(.tabs-only) .spreadsheet-fallback tbody {
    display: table-row-group !important;
  }

  html.no-js body:not(.tabs-only) .spreadsheet-fallback tr,
  html.no-js body:not(.tabs-only) .spreadsheet-fallback th,
  html.no-js body:not(.tabs-only) .spreadsheet-fallback td {
    height: auto !important;
    min-height: 0 !important;
    line-height: 1 !important;
  }

  html.no-js body:not(.tabs-only) .spreadsheet-fallback th:not(:first-child),
  html.no-js body:not(.tabs-only) .spreadsheet-fallback td {
    width: auto !important;
    min-width: 6ch !important;
    max-width: none !important;
    vertical-align: middle !important;
  }

  html.no-js body:not(.tabs-only) .spreadsheet-fallback th,
  html.no-js body:not(.tabs-only) .spreadsheet-fallback td {
    padding: 0 1ch !important;
  }

  html.no-js body:not(.tabs-only) .spreadsheet-fallback .fallback-cell-content {
    display: inline !important;
    width: auto !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
    white-space: pre !important;
    overflow: visible !important;
    text-overflow: clip !important;
    vertical-align: middle !important;
  }
}

html.no-js .sheet-index-backlink {
  display: block !important;
  margin-left: 0 !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
}

html.no-js .sheet-index-backlink.sheet-index-backlink--bottom {
  clear: both;
  margin: var(--space-8, 8px) 0 0 !important;
}

/* Hide exported comment list when popovers are supported (modern graphical browsers) */
@supports selector(:popover-open) {
  .comment-export { display: none; }
}

@supports (display: grid) and (not (container-type: inline-size)) and (zoom: 1) {
  html.no-js body:not(.tabs-only) .grid-content {
    zoom: 1 !important;
  }
}

/* Re-enable viewport-constrained chrome on modern graphical no-JS engines. */
@supports (display: grid) and (selector(:has(*))) and (container-type: inline-size) {
  @media (hover: hover) and (pointer: fine) {
    html.no-js body:not(.tabs-only) .sheet-index-backlink {
      display: none !important;
    }

    html.no-js body:not(.tabs-only) .spreadsheet-container {
      height: 100vh !important;
      height: 100svh !important;
      height: 100dvh !important;
      min-height: 100vh !important;
      min-height: 100svh !important;
      min-height: 100dvh !important;
      overflow: hidden !important;
    }

    html.no-js body:not(.tabs-only) .theme-scope {
      flex: 1 1 auto !important;
      min-height: 0 !important;
    }

    html.no-js body:not(.tabs-only) .grid-container {
      display: grid !important;
      height: 100% !important;
      min-height: 0 !important;
      overflow: hidden !important;
    }

    html.no-js body:not(.tabs-only) .main-grid {
      position: relative !important;
      overflow: auto !important;
      max-height: none !important;
    }

    html.no-js body:not(.tabs-only) .grid-content {
      min-width: 0 !important;
      min-height: 0 !important;
      overflow: visible !important;
    }

    html.no-js body:not(.tabs-only) .table-title-badge {
      display: block;
      position: absolute;
      left: calc(50px + var(--space-16));
      bottom: var(--space-16);
      margin: 0;
      padding: 10px 16px;
      border: 1px solid rgba(255, 255, 255, 0.28);
      border-radius: 999px;
      background: linear-gradient(120deg, rgba(50, 184, 198, 0.18), rgba(19, 52, 59, 0.32));
      color: #f7fafc;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
      backdrop-filter: blur(8px);
      pointer-events: none;
      max-width: min(360px, 55vw);
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
      opacity: 0.92;
      z-index: 8;
    }

    :is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .table-title-badge {
      background: linear-gradient(120deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.18));
      color: #f7fafc;
      border-color: rgba(255, 255, 255, 0.22);
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    }
  }
}

@supports (display: grid) and (not (container-type: inline-size)) {
  html.no-js .sheet-index-backlink {
    display: block !important;
  }

  html.no-js .sheet-index-backlink.sheet-index-backlink--bottom {
    display: block !important;
  }
}

.sheet-tabs-iframe {
  display: block;
  width: 100%;
  height: 55px; /* Match sheet-tabs-embed height */
  border: none;
  border-radius: 0 !important; /* Force no border radius */
  overflow: hidden; /* Prevent any content from causing rounded corners */
}

.sheet-tabs-iframe:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
}

.sheet-tabs-object,
html.no-js .sheet-tabs-embed noscript iframe {
  display: block;
  width: 100%;
  height: 55px;
  border: none;
}

/* Avoid white iframe canvas in no-JS mode by tinting the embed area by current theme mode. */
html.no-js.has-theme-toggle .sheet-tabs-embed {
  background: #000000;
}

html.no-js.has-theme-toggle .sheet-tabs-embed noscript iframe {
  background: #000000;
}

/* Keep sheet-tab iframe canvas dark as well to avoid white pre-paint flashes. */
html.no-js .sheet-tabs-embed noscript iframe {
  background: #000000 !important;
}

html.no-js.has-theme-toggle .spreadsheet-container:has([id^="z"][id$="l"]:target) .sheet-tabs-embed,
html.no-js.has-theme-toggle .spreadsheet-container:has([id^="z"][id$="l"]:target) .sheet-tabs-embed noscript iframe {
  background: var(--color-cream-100);
}

.sheet-tabs-embed .sheet-tabs-object,
html.no-js .sheet-tabs-embed noscript iframe {
  position: absolute;
  inset: 0;
  z-index: 0;
}

html.no-js.has-theme-toggle .sheet-tabs-object,
html.no-js.has-theme-toggle .sheet-tabs-embed noscript iframe {
  display: none;
}

@supports (display: grid) and (selector(:has(*))) and (container-type: inline-size) {
  html.no-js.has-theme-toggle .sheet-tabs-object#z100d,
  html.no-js.has-theme-toggle .sheet-tabs-embed noscript iframe#z100d {
    display: block !important;
    z-index: 0;
  }

  html.no-js.has-theme-toggle .sheet-tabs-embed:has(:is(.sheet-tabs-object:target, noscript iframe:target)) :is(.sheet-tabs-object, noscript iframe) {
    display: none !important;
  }

  html.no-js.has-theme-toggle .sheet-tabs-embed:has(:is(.sheet-tabs-object:target, noscript iframe:target)) :is(.sheet-tabs-object:target, noscript iframe:target) {
    display: block !important;
    z-index: 1;
  }
}

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-16);
  padding: var(--space-8) var(--space-16);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  position: relative;
  z-index: 20;
}

.toolbar--noscript {
  display: none;
}

@supports (display: grid) and (selector(:has(*))) and (container-type: inline-size) {
  html.no-js .toolbar--noscript {
    display: flex !important;
    min-height: 49px;
    box-sizing: border-box;
  }
}

html.js .toolbar--noscript,
html.js .theme-toggle--noscript,
html.js .zoom-toggle--noscript {
  display: none !important;
}

.toolbar-section {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.toolbar-profile {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  padding-left: var(--space-8);
  border-left: 1px solid var(--color-border);
  min-width: 0;
  cursor: pointer;
}

.toolbar-profile--placeholder {
  visibility: hidden;
  cursor: default;
  pointer-events: none;
}

.toolbar-profile.toolbar-profile--loading {
  opacity: 0.8;
}

.toolbar-profile__avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 2px;
  box-sizing: border-box;
  border-radius: 50%;
  background: transparent;
  border: 2px solid var(--repo-status-offline);
  overflow: visible;
  flex-shrink: 0;
  box-shadow: none;
}

.toolbar-profile__avatar--offline {
  border: 2px solid var(--repo-status-offline);
}

.toolbar-profile__avatar--user {
  border: 2px solid var(--repo-status-user);
}

.toolbar-profile__avatar--org {
  border: 2px solid var(--repo-status-org);
}

.toolbar-profile__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  grid-area: 1 / 1;
  border-radius: 50%;
  clip-path: circle(50% at 50% 50%);
}

.toolbar-profile__initials {
  position: static;
  grid-area: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 28px;
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  line-height: 1;
  transform: translateY(-0.5px);
}

.toolbar-profile__repo {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 16px;
  height: 16px;
  padding: 1px;
  box-sizing: border-box;
  border-radius: 50%;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  z-index: 2;
}

.toolbar-profile__repo--offline {
  border-color: #2c2c2c;
}

.toolbar-profile__repo--user {
  border-color: #34d399;
}

.toolbar-profile__repo--org {
  border-color: #ef4444;
}

.toolbar-profile__repo-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  clip-path: circle(50% at 50% 50%);
}

.toolbar-profile__repo-initials {
  font-size: 9px;
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  line-height: 1;
}

.toolbar-profile__badge {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.toolbar-profile__badge.is-visible {
  display: flex;
}

.toolbar-profile__badge.hidden {
  display: none !important;
}

.toolbar-profile--minimal .toolbar-profile__meta,
.toolbar-profile--minimal .toolbar-profile__badge {
  display: none;
}

.toolbar-profile--local .toolbar-profile__initials,
.toolbar-profile--local .toolbar-profile__badge {
  display: none !important;
}

.toolbar-profile__meta {
  display: none !important;
}

.toolbar-profile__name {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar-profile__hint {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .toolbar-profile__avatar {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .toolbar-profile__repo {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

#zoomDisplay {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-width: 50px;
  height: 24px;
  padding: 0 var(--space-8);
  text-align: center;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.1px;
  line-height: 24px;
  color: var(--color-text);
  user-select: none;
  cursor: default;
}

#zoomDisplay.zoom-display--editing {
  cursor: text;
  padding: 0;
  line-height: normal;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  margin-left: var(--space-8);
  position: relative;
}

.theme-toggle--noscript svg a {
  text-decoration: none;
}

.theme-toggle__state {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: 0;
  opacity: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@supports (display: grid) and (selector(:has(*))) {
  .theme-toggle__state[hidden] {
    display: inline-block !important;
  }
}

.zoom-toggle__state {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: 0;
  opacity: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.zoom-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-8);
  --zoom-btn-bg: rgba(0, 0, 0, 0.02);
  --zoom-btn-bg-hover: rgba(0, 0, 0, 0.05);
  --zoom-btn-border: transparent;
}

.zoom-toggle > div {
  position: relative;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.zoom-toggle > div a,
.zoom-toggle > a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  background: var(--zoom-btn-bg);
  border: 1px solid var(--zoom-btn-border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-standard);
}

.zoom-toggle > a {
  width: 32px;
  height: 32px;
}

.zoom-toggle > div a {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.zoom-toggle > a:hover,
.zoom-toggle > div a:hover {
  background: var(--zoom-btn-bg-hover);
}

.spreadsheet-container > #themeToggle:checked ~ .theme-scope .zoom-toggle,
:root[data-theme='dark'] .zoom-toggle,
:root:has(#themeToggle:checked) .zoom-toggle {
  --zoom-btn-bg: #0f0f0f;
  --zoom-btn-bg-hover: #0f0f0f;
  --zoom-btn-border: #2c2c2c;
}

/* SVG-only controls for noscript mode */
.zoom-toggle--noscript svg,
.theme-toggle--noscript svg {
  width: 32px;
  height: 32px;
  display: block;
  color: var(--color-text);
}

.zoom-toggle--noscript svg a,
.theme-toggle--noscript svg a {
  cursor: pointer;
}

.zoom-toggle--noscript .noscript-stepper a {
  opacity: 0;
  pointer-events: none;
}

.theme-toggle--noscript .noscript-toggle a {
  display: none;
}

.zoom-toggle--noscript .noscript-reset a {
  opacity: 1;
  pointer-events: auto;
}

.zoom-toggle--noscript svg .noscript-btn-fill {
  fill: var(--zoom-btn-bg);
}

.zoom-toggle--noscript svg .noscript-btn-stroke {
  fill: none;
  stroke: var(--zoom-btn-border);
  stroke-width: 1px;
  shape-rendering: crispEdges;
}

.zoom-toggle--noscript svg a:hover .noscript-btn-fill {
  fill: var(--zoom-btn-bg-hover);
}

.theme-toggle--noscript {
  --theme-btn-bg: rgba(0, 0, 0, 0.02);
  --theme-btn-bg-hover: rgba(0, 0, 0, 0.05);
  --theme-btn-border: transparent;
}

.theme-toggle--noscript svg .noscript-btn-fill {
  fill: var(--theme-btn-bg);
}

.theme-toggle--noscript svg .noscript-btn-stroke {
  fill: none;
  stroke: var(--theme-btn-border);
  stroke-width: 1px;
  shape-rendering: crispEdges;
}

.theme-toggle--noscript svg a:hover .noscript-btn-fill {
  fill: var(--theme-btn-bg-hover);
}

.noscript-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

.noscript-btn-text {
  fill: currentColor;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  font-family: var(--font-family-base);
  pointer-events: none;
}

.noscript-btn-text--icon {
  font-size: 16px;
}

.noscript-btn-fo {
  pointer-events: none;
}

.noscript-btn-fo__text {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  font-family: var(--font-family-base);
  color: var(--color-text);
  line-height: normal;
  pointer-events: none;
}

.theme-toggle--noscript .noscript-btn-fo__text {
  font-size: 16px;
}

.theme-toggle--noscript .noscript-btn-text--icon {
  font-size: 16px;
}

.zoom-toggle--noscript .noscript-btn-fo__text {
  text-shadow: 0 0 0 currentColor;
}

.zoom-toggle--noscript .noscript-btn-text {
  text-shadow: 0 0 0 currentColor;
}

.zoom-display--noscript {
  min-width: 50px;
  text-align: center;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  counter-reset: zoom var(--zoom-step, 100);
}

.zoom-display--noscript::after {
  content: counter(zoom) '%';
}

html.no-js .spreadsheet-container {
  --zoom-step: 100;
  --zoom-scale: calc(var(--zoom-step) / 100);
}

/* Keep no-JS frame geometry in sync with JS zoom behavior. */
html.no-js .grid-container {
  grid-template-columns: calc(50px * var(--zoom-scale, 1)) 1fr;
  grid-template-rows: calc(32px * var(--zoom-scale, 1)) 1fr;
}

html.no-js .corner-cell {
  width: calc(50px * var(--zoom-scale, 1));
  height: calc(32px * var(--zoom-scale, 1));
  box-sizing: border-box;
  font-size: calc(20px * var(--zoom-scale, 1));
}

html.no-js .row-header {
  width: calc(50px * var(--zoom-scale, 1));
}

html.no-js .column-header {
  height: calc(32px * var(--zoom-scale, 1));
}

html.no-js .zoom-toggle--noscript {
  display: none;
}

html.no-js .spreadsheet-container:has([id^="z"][id$="d"]:target) .zoom-toggle--dark,
html.no-js .spreadsheet-container:has([id^="z"][id$="l"]:target) .zoom-toggle--light {
  display: inline-flex;
}

html.no-js .spreadsheet-container:not(:has([id^="z"][id$="d"]:target)):not(:has([id^="z"][id$="l"]:target)) .zoom-toggle--dark {
  display: inline-flex;
}

html.no-js .spreadsheet-container:not(:has([id^="z"][id$="d"]:target)):not(:has([id^="z"][id$="l"]:target)) .theme-toggle--noscript .noscript-toggle a[href="#z100d"] {
  display: block;
}

html.no-js .theme-scope .zoom-toggle > div a:nth-child(6) {
  opacity: 1;
  pointer-events: auto;
}

html.no-js .spreadsheet-container:has(:is([id^="z"][id$="d"]:target, [id^="z"][id$="l"]:target)) .zoom-toggle > div a {
  opacity: 0;
  pointer-events: none;
}

html.no-js .spreadsheet-container:has(:is([id^="z"][id$="d"]:target, [id^="z"][id$="l"]:target)) .zoom-toggle--noscript .noscript-reset a {
  opacity: 1;
  pointer-events: auto;
}

/* Combined zoom hash support */
html.no-js .spreadsheet-container:has(:is(#z50d:target, #z50l:target)) { --zoom-step: 50; }
html.no-js .spreadsheet-container:has(:is(#z60d:target, #z60l:target)) { --zoom-step: 60; }
html.no-js .spreadsheet-container:has(:is(#z70d:target, #z70l:target)) { --zoom-step: 70; }
html.no-js .spreadsheet-container:has(:is(#z80d:target, #z80l:target)) { --zoom-step: 80; }
html.no-js .spreadsheet-container:has(:is(#z90d:target, #z90l:target)) { --zoom-step: 90; }
html.no-js .spreadsheet-container:has(:is(#z100d:target, #z100l:target)) { --zoom-step: 100; }
html.no-js .spreadsheet-container:has(:is(#z110d:target, #z110l:target)) { --zoom-step: 110; }
html.no-js .spreadsheet-container:has(:is(#z120d:target, #z120l:target)) { --zoom-step: 120; }
html.no-js .spreadsheet-container:has(:is(#z130d:target, #z130l:target)) { --zoom-step: 130; }
html.no-js .spreadsheet-container:has(:is(#z140d:target, #z140l:target)) { --zoom-step: 140; }
html.no-js .spreadsheet-container:has(:is(#z150d:target, #z150l:target)) { --zoom-step: 150; }
html.no-js .spreadsheet-container:has(:is(#z160d:target, #z160l:target)) { --zoom-step: 160; }
html.no-js .spreadsheet-container:has(:is(#z170d:target, #z170l:target)) { --zoom-step: 170; }
html.no-js .spreadsheet-container:has(:is(#z180d:target, #z180l:target)) { --zoom-step: 180; }
html.no-js .spreadsheet-container:has(:is(#z190d:target, #z190l:target)) { --zoom-step: 190; }
html.no-js .spreadsheet-container:has(:is(#z200d:target, #z200l:target)) { --zoom-step: 200; }

html.no-js .spreadsheet-container:has([id^="z"][id$="d"]:target) .theme-scope,
html.no-js .spreadsheet-container:has([id^="z"][id$="d"]:target) > #themeToggle:checked ~ .theme-scope,
html.no-js .spreadsheet-container:not(:has([id^="z"][id$="d"]:target)):not(:has([id^="z"][id$="l"]:target)) .theme-scope,
html.no-js .spreadsheet-container:not(:has([id^="z"][id$="d"]:target)):not(:has([id^="z"][id$="l"]:target)) > #themeToggle:checked ~ .theme-scope,
html.no-js.has-theme-toggle .spreadsheet-container:not(:has([id^="z"][id$="d"]:target)):not(:has([id^="z"][id$="l"]:target)) .theme-scope,
html.no-js.has-theme-toggle .spreadsheet-container:not(:has([id^="z"][id$="d"]:target)):not(:has([id^="z"][id$="l"]:target)) > #themeToggle:checked ~ .theme-scope {
  --color-background: #000000;
  --color-surface: #000000;
  --color-surface-alt: #050505;
  --color-text: #f8f9fa;
  --color-text-secondary: rgba(248, 249, 250, 0.6);
  --color-primary: var(--color-teal-300);
  --color-primary-hover: var(--color-teal-400);
  --color-border: rgba(248, 249, 250, 0.24);
  --color-bg-1: rgba(45, 166, 178, 0.12);
  --color-bg-2: rgba(245, 158, 11, 0.22);
  --selection-pass-fill: rgba(255, 82, 82, 0.12);
  --selection-pass-stripe: rgba(255, 82, 82, 0.3);
  --text-selection-bg: rgba(255, 153, 0, 0.42);
  --editor-outline: #ff9900;
  color-scheme: dark;
}

html.no-js .spreadsheet-container:has([id^="z"][id$="l"]:target) .theme-scope,
html.no-js .spreadsheet-container:has([id^="z"][id$="l"]:target) > #themeToggle:checked ~ .theme-scope {
  --color-background: var(--color-cream-50);
  --color-surface: var(--color-cream-100);
  --color-surface-alt: var(--color-cream-100);
  --color-text: var(--color-slate-900);
  --color-text-secondary: var(--color-slate-500);
  --color-primary: var(--color-teal-500);
  --color-primary-hover: var(--color-teal-600);
  --color-border: rgba(94, 82, 64, 0.2);
  --color-bg-1: rgba(59, 130, 246, 0.08);
  --color-bg-2: rgba(245, 158, 11, 0.08);
  --selection-pass-fill: rgba(33, 128, 141, 0.06);
  --selection-pass-stripe: rgba(33, 128, 141, 0.18);
  --text-selection-bg: rgba(59, 130, 246, 0.28);
  --editor-outline: #3b82f6;
  color-scheme: light;
}

/* Keep no-JS toolbar visuals in sync with hash-driven mode changes. */
html.no-js .spreadsheet-container:has([id^="z"][id$="d"]:target) .toolbar--noscript {
  background: #000000;
  border-bottom-color: #2f2f2f;
}

html.no-js .spreadsheet-container:not(:has([id^="z"][id$="d"]:target)):not(:has([id^="z"][id$="l"]:target)) .toolbar--noscript {
  background: #000000;
  border-bottom-color: #2f2f2f;
}

html.no-js.has-theme-toggle .spreadsheet-container:not(:has([id^="z"][id$="d"]:target)):not(:has([id^="z"][id$="l"]:target)) .toolbar--noscript {
  background: #000000;
  border-bottom-color: #2f2f2f;
}

html.no-js .spreadsheet-container:has([id^="z"][id$="l"]:target) .toolbar--noscript {
  background: var(--color-cream-100);
}

/* Hard-stop white iframe flashes: keep iframe canvas dark even before srcdoc/content paints. */
html.no-js .noscript-toolbar-frame {
  background: #000000 !important;
}

html.no-js .spreadsheet-container:has([id^="z"][id$="d"]:target) .zoom-toggle {
  --zoom-btn-bg: #0f0f0f;
  --zoom-btn-bg-hover: #0f0f0f;
  --zoom-btn-border: #2c2c2c;
}

html.no-js.has-theme-toggle .spreadsheet-container:not(:has([id^="z"][id$="d"]:target)):not(:has([id^="z"][id$="l"]:target)) .zoom-toggle {
  --zoom-btn-bg: #0f0f0f;
  --zoom-btn-bg-hover: #0f0f0f;
  --zoom-btn-border: #2c2c2c;
}

html.no-js .spreadsheet-container:has([id^="z"][id$="d"]:target) > #themeToggle:checked ~ .theme-scope .zoom-toggle {
  --zoom-btn-bg: #0f0f0f;
  --zoom-btn-bg-hover: #0f0f0f;
  --zoom-btn-border: #2c2c2c;
}

html.no-js .spreadsheet-container:has([id^="z"][id$="l"]:target) .zoom-toggle {
  --zoom-btn-bg: rgba(0, 0, 0, 0.02);
  --zoom-btn-bg-hover: rgba(0, 0, 0, 0.05);
  --zoom-btn-border: transparent;
}

html.no-js .spreadsheet-container:has([id^="z"][id$="l"]:target) > #themeToggle:checked ~ .theme-scope .zoom-toggle {
  --zoom-btn-bg: rgba(0, 0, 0, 0.02);
  --zoom-btn-bg-hover: rgba(0, 0, 0, 0.05);
  --zoom-btn-border: transparent;
}

html.no-js .spreadsheet-container:has([id^="z"][id$="d"]:target) .theme-toggle--noscript {
  --theme-btn-bg: rgba(255, 255, 255, 0.06);
  --theme-btn-bg-hover: rgba(255, 255, 255, 0.12);
  --theme-btn-border: rgba(255, 255, 255, 0.12);
}

html.no-js.has-theme-toggle .spreadsheet-container:not(:has([id^="z"][id$="d"]:target)):not(:has([id^="z"][id$="l"]:target)) .theme-toggle--noscript {
  --theme-btn-bg: rgba(255, 255, 255, 0.06);
  --theme-btn-bg-hover: rgba(255, 255, 255, 0.12);
  --theme-btn-border: rgba(255, 255, 255, 0.12);
}

html.no-js .spreadsheet-container:has(:is(#z50d:target, #z50l:target)) .zoom-toggle > div a:nth-child(1) {
  opacity: 1;
  pointer-events: auto;
}
html.no-js .spreadsheet-container:has(:is(#z60d:target, #z60l:target)) .zoom-toggle > div a:nth-child(2) {
  opacity: 1;
  pointer-events: auto;
}
html.no-js .spreadsheet-container:has(:is(#z70d:target, #z70l:target)) .zoom-toggle > div a:nth-child(3) {
  opacity: 1;
  pointer-events: auto;
}
html.no-js .spreadsheet-container:has(:is(#z80d:target, #z80l:target)) .zoom-toggle > div a:nth-child(4) {
  opacity: 1;
  pointer-events: auto;
}
html.no-js .spreadsheet-container:has(:is(#z90d:target, #z90l:target)) .zoom-toggle > div a:nth-child(5) {
  opacity: 1;
  pointer-events: auto;
}
html.no-js .spreadsheet-container:has(:is(#z100d:target, #z100l:target)) .zoom-toggle > div a:nth-child(6) {
  opacity: 1;
  pointer-events: auto;
}
html.no-js .spreadsheet-container:has(:is(#z110d:target, #z110l:target)) .zoom-toggle > div a:nth-child(7) {
  opacity: 1;
  pointer-events: auto;
}
html.no-js .spreadsheet-container:has(:is(#z120d:target, #z120l:target)) .zoom-toggle > div a:nth-child(8) {
  opacity: 1;
  pointer-events: auto;
}
html.no-js .spreadsheet-container:has(:is(#z130d:target, #z130l:target)) .zoom-toggle > div a:nth-child(9) {
  opacity: 1;
  pointer-events: auto;
}
html.no-js .spreadsheet-container:has(:is(#z140d:target, #z140l:target)) .zoom-toggle > div a:nth-child(10) {
  opacity: 1;
  pointer-events: auto;
}
html.no-js .spreadsheet-container:has(:is(#z150d:target, #z150l:target)) .zoom-toggle > div a:nth-child(11) {
  opacity: 1;
  pointer-events: auto;
}
html.no-js .spreadsheet-container:has(:is(#z160d:target, #z160l:target)) .zoom-toggle > div a:nth-child(12) {
  opacity: 1;
  pointer-events: auto;
}
html.no-js .spreadsheet-container:has(:is(#z170d:target, #z170l:target)) .zoom-toggle > div a:nth-child(13) {
  opacity: 1;
  pointer-events: auto;
}
html.no-js .spreadsheet-container:has(:is(#z180d:target, #z180l:target)) .zoom-toggle > div a:nth-child(14) {
  opacity: 1;
  pointer-events: auto;
}
html.no-js .spreadsheet-container:has(:is(#z190d:target, #z190l:target)) .zoom-toggle > div a:nth-child(15) {
  opacity: 1;
  pointer-events: auto;
}
html.no-js .spreadsheet-container:has(:is(#z200d:target, #z200l:target)) .zoom-toggle > div a:nth-child(16) {
  opacity: 1;
  pointer-events: auto;
}

/* Combined theme toggle links */
html.no-js .spreadsheet-container:has(:is(#z50d:target, #z50l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z50d"], a[href="#z50l"]) {
  display: block;
}
html.no-js .spreadsheet-container:has(:is(#z60d:target, #z60l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z60d"], a[href="#z60l"]) {
  display: block;
}
html.no-js .spreadsheet-container:has(:is(#z70d:target, #z70l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z70d"], a[href="#z70l"]) {
  display: block;
}
html.no-js .spreadsheet-container:has(:is(#z80d:target, #z80l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z80d"], a[href="#z80l"]) {
  display: block;
}
html.no-js .spreadsheet-container:has(:is(#z90d:target, #z90l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z90d"], a[href="#z90l"]) {
  display: block;
}
html.no-js .spreadsheet-container:has(:is(#z100d:target, #z100l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z100d"], a[href="#z100l"]) {
  display: block;
}
html.no-js .spreadsheet-container:has(:is(#z110d:target, #z110l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z110d"], a[href="#z110l"]) {
  display: block;
}
html.no-js .spreadsheet-container:has(:is(#z120d:target, #z120l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z120d"], a[href="#z120l"]) {
  display: block;
}
html.no-js .spreadsheet-container:has(:is(#z130d:target, #z130l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z130d"], a[href="#z130l"]) {
  display: block;
}
html.no-js .spreadsheet-container:has(:is(#z140d:target, #z140l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z140d"], a[href="#z140l"]) {
  display: block;
}
html.no-js .spreadsheet-container:has(:is(#z150d:target, #z150l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z150d"], a[href="#z150l"]) {
  display: block;
}
html.no-js .spreadsheet-container:has(:is(#z160d:target, #z160l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z160d"], a[href="#z160l"]) {
  display: block;
}
html.no-js .spreadsheet-container:has(:is(#z170d:target, #z170l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z170d"], a[href="#z170l"]) {
  display: block;
}
html.no-js .spreadsheet-container:has(:is(#z180d:target, #z180l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z180d"], a[href="#z180l"]) {
  display: block;
}
html.no-js .spreadsheet-container:has(:is(#z190d:target, #z190l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z190d"], a[href="#z190l"]) {
  display: block;
}
html.no-js .spreadsheet-container:has(:is(#z200d:target, #z200l:target)) .theme-toggle--noscript .noscript-toggle :is(a[href="#z200d"], a[href="#z200l"]) {
  display: block;
}

html.no-js .spreadsheet-container:has(:is(#z50d:target, #z60d:target, #z70d:target, #z80d:target, #z90d:target, #z100d:target, #z110d:target, #z120d:target, #z130d:target, #z140d:target, #z150d:target, #z160d:target, #z170d:target, #z180d:target, #z190d:target, #z200d:target)) .theme-toggle--noscript .noscript-toggle a[href$="d"] {
  display: none;
  pointer-events: none;
}

html.no-js .spreadsheet-container:has(:is(#z50l:target, #z60l:target, #z70l:target, #z80l:target, #z90l:target, #z100l:target, #z110l:target, #z120l:target, #z130l:target, #z140l:target, #z150l:target, #z160l:target, #z170l:target, #z180l:target, #z190l:target, #z200l:target)) .theme-toggle--noscript .noscript-toggle a[href$="l"] {
  display: none;
  pointer-events: none;
}

.toolbar-btn--theme {
  min-width: 32px;
  width: 32px;
  gap: 0;
}

.toolbar-btn--icon {
  min-width: 32px;
  width: 32px;
  height: 32px;
  padding: var(--space-4);
  border-radius: 0;
}

.toolbar-btn--icon .toolbar-icon {
  width: 16px;
  height: 16px;
  display: block;
  color: currentColor;
}

.toolbar-icon__stroke {
  fill: none;
  stroke: currentColor;
  stroke-width: 2px;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toolbar-icon__fill {
  fill: currentColor;
  stroke: none;
}

.toolbar-icon--theme .theme-icon--sun {
  display: none;
}

.toolbar-btn--theme.active .toolbar-icon--theme .theme-icon--moon {
  display: none;
}

.toolbar-btn--theme.active .toolbar-icon--theme .theme-icon--sun {
  display: block;
}

.toolbar--noscript .toolbar-section {
  margin-left: auto;
}

.spreadsheet-container > #themeToggle:focus-visible ~ .theme-scope .toolbar-btn--theme {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .toolbar-btn--theme {
  background: var(--color-primary);
  color: var(--color-cream-50);
}

.toolbar-btn--theme.active {
  background: var(--color-primary);
  color: var(--color-cream-50);
}

.zoom-display-input {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  text-align: center;
  padding: var(--space-4);
  outline: none;
}

.zoom-display-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px var(--color-primary);
}

.toolbar-btn {
  min-width: 32px;
  height: 32px;
  padding: var(--space-4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  background: rgba(0, 0, 0, 0.02);
  border: 1px solid transparent;
  text-decoration: none;
}

.toolbar-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .toolbar-btn {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text);
  border-color: rgba(255, 255, 255, 0.12);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .toolbar-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.toolbar-btn.active {
  background: var(--color-primary);
  color: var(--color-cream-50);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .toolbar-btn.active {
  color: var(--color-cream-50);
  border-color: rgba(50, 184, 198, 0.8);
  box-shadow: 0 0 0 1px rgba(50, 184, 198, 0.6), 0 4px 10px rgba(0, 0, 0, 0.6);
}

.toolbar-btn.toolbar-btn--svg {
  padding: 0;
  background: transparent;
  border: none;
  min-width: 32px;
  width: 32px;
  height: 32px;
}

.toolbar-btn--svg .toolbar-svg {
  width: 32px;
  height: 32px;
  display: block;
  color: var(--color-text);
}

.toolbar-btn--svg .noscript-btn-fill {
  fill: rgba(0, 0, 0, 0.02);
}

.toolbar-btn--svg .noscript-btn-stroke {
  fill: none;
  stroke: transparent;
  stroke-width: 1px;
  shape-rendering: crispEdges;
}

.toolbar-btn--svg:hover .noscript-btn-fill {
  fill: rgba(0, 0, 0, 0.05);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .toolbar-btn--svg .noscript-btn-fill {
  fill: #0f0f0f;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .toolbar-btn--svg .noscript-btn-stroke {
  stroke: #2c2c2c;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .toolbar-btn--svg:hover .noscript-btn-fill {
  fill: #0f0f0f;
}

.toolbar-btn--svg .noscript-btn-fo__text {
  text-shadow: 0 0 0 currentColor;
}

.toolbar-btn__icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.save-indicator-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-orange-500);
  border: 2px solid var(--color-surface);
}

.toolbar-btn--dirty .toolbar-btn__icon {
  color: var(--color-orange-500);
}

.revision-lag-badge {
  position: absolute;
  left: -4px;
  bottom: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #d1433f;
  color: #fff;
  font-size: 11px;
  font-weight: var(--font-weight-bold);
  line-height: 18px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

.toolbar-btn--busy {
  opacity: 0.6;
  cursor: progress;
  pointer-events: none;
}

.cell-reference { min-width: 100px; }
.cell-reference input {
  text-align: center;
  font-weight: var(--font-weight-medium);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
}

.formula-bar {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  padding: var(--space-8) var(--space-16);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.nojs-top-spacer {
  display: none;
}

@supports (display: grid) and (selector(:has(*))) and (container-type: inline-size) {
  html.no-js .nojs-top-spacer {
    display: block;
    min-height: 49px;
    box-sizing: border-box;
  }
}

html.no-js .spreadsheet-container:has([id^="z"][id$="d"]:target) .nojs-top-spacer,
html.no-js .spreadsheet-container:not(:has([id^="z"][id$="d"]:target)):not(:has([id^="z"][id$="l"]:target)) .nojs-top-spacer,
html.no-js.has-theme-toggle .spreadsheet-container:not(:has([id^="z"][id$="d"]:target)):not(:has([id^="z"][id$="l"]:target)) .nojs-top-spacer {
  background: #000000;
  border-bottom: 1px solid #2f2f2f;
}

html.no-js .spreadsheet-container:has([id^="z"][id$="l"]:target) .nojs-top-spacer {
  background: var(--color-cream-100);
  border-bottom: 1px solid var(--color-border);
}

html.no-js .spreadsheet-container:has([id^="z"][id$="d"]:target) :is(.corner-cell, .column-headers, .row-headers, .column-header, .row-header),
html.no-js.has-theme-toggle .spreadsheet-container:not(:has([id^="z"][id$="d"]:target)):not(:has([id^="z"][id$="l"]:target)) :is(.corner-cell, .column-headers, .row-headers, .column-header, .row-header) {
  background: #000000 !important;
}

html.no-js .spreadsheet-container:has([id^="z"][id$="l"]:target) :is(.corner-cell, .column-headers, .row-headers, .column-header, .row-header) {
  background: var(--color-bg-1) !important;
}

.formula-bar .cell-reference { min-width: 120px; }
.formula-bar .cell-reference input { text-align: left; }

.formula-bar-label {
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-right: var(--space-12);
  font-weight: var(--font-weight-medium);
}

.formula-input {
  flex: 1;
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
}

.formula-input-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  min-width: 0;
}

.formula-input-wrapper .formula-input {
  flex: 1;
  width: 100%;
}

.formula-suggestions {
  position: absolute;
  top: calc(100% + var(--space-4));
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  box-shadow: var(--shadow-lg);
  padding: var(--space-8) 0;
  z-index: 40;
  max-height: 280px;
  overflow-y: auto;
}

.formula-suggestion-hint {
  padding: var(--space-8) var(--space-12);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.formula-suggestion-hint-name {
  font-family: var(--font-family-mono);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  display: block;
}

.formula-suggestion-params {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.formula-suggestion-param {
  font-family: var(--font-family-mono);
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.formula-suggestion-param.is-active {
  color: var(--color-primary);
  font-weight: var(--font-weight-medium);
}

.formula-suggestion-param-separator {
  color: var(--color-text-secondary);
}

.formula-suggestion-list {
  display: flex;
  flex-direction: column;
}

.formula-suggestion-item {
  padding: var(--space-6) var(--space-12);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  transition: background var(--duration-fast);
}

.formula-suggestion-item:hover,
.formula-suggestion-item.is-active {
  background: rgba(46, 105, 255, 0.08);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .formula-suggestion-item:hover,
:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .formula-suggestion-item.is-active {
  background: rgba(46, 105, 255, 0.16);
}

.formula-suggestion-name {
  font-family: var(--font-family-mono);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
}

.formula-suggestion-description {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .formula-suggestions {
  background: var(--color-surface-alt);
  border-color: rgba(255, 255, 255, 0.08);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .formula-suggestion-hint {
  border-color: rgba(255, 255, 255, 0.08);
}

.grid-container {
  flex: 1;
  display: grid;
  grid-template-columns: 50px 1fr;
  grid-template-rows: 32px 1fr;
  overflow: hidden;
  position: relative;
  background: var(--color-background);
}

.corner-cell {
  background: var(--color-bg-1);
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  box-sizing: border-box;
  z-index: 3;
  cursor: pointer;
  transition: background var(--duration-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.corner-cell::before {
  content: '🗻';
}

.corner-cell:hover { background: var(--color-bg-2); }

.column-headers, .row-headers {
  position: relative;
  overflow: hidden;
}

.column-headers {
  background: var(--color-bg-1);
  border-bottom: 1px solid var(--color-border);
  z-index: 2;
}

.row-headers {
  background: var(--color-bg-1);
  border-right: 1px solid var(--color-border);
  z-index: 2;
}

.header-content {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
}

.row-headers .header-content { flex-direction: column; }

.column-header, .row-header {
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--color-border);
  background: var(--color-bg-1);
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-sm);
  user-select: none;
  cursor: pointer;
  transition: background var(--duration-fast);
  position: absolute;
  box-sizing: border-box;
}

.column-header {
  height: 32px;
  border-bottom: 1px solid var(--color-border);
  top: 0;
}

.row-header {
  width: 50px;
  border-bottom: 1px solid var(--color-border);
  left: 0;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .column-header,
:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .row-header,
:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .corner-cell {
  background: var(--color-surface-alt);
}

.column-header:hover, .row-header:hover { background: var(--color-bg-2); }

.column-resize-handle {
  position: absolute;
  right: -3px;
  top: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
}

.row-resize-handle {
  position: absolute;
  bottom: -3px;
  left: 0;
  width: 100%;
  height: 6px;
  cursor: row-resize;
  z-index: 10;
}

.column-resize-handle:hover, .row-resize-handle:hover { background: var(--color-primary); opacity: 0.3; }

/* Resize indicator */
.resize-indicator {
    position: fixed;
    background: var(--color-primary);
    color: var(--color-surface);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    font-family: var(--font-family-mono);
    font-weight: var(--font-weight-medium);
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
}

.resize-guide {
    position: fixed;
    background: var(--color-primary);
    pointer-events: none;
    z-index: 999;
    opacity: 0.5;
}

.resize-guide--vertical {
    width: 2px;
    top: 0;
    bottom: 0;
}

.resize-guide--horizontal {
    height: 2px;
    left: 0;
    right: 0;
}

.main-grid {
  position: relative;
  overflow: auto;
  background: var(--color-background);
}

.grid-content {
  position: relative;
  min-width: 100%;
  min-height: 100%;
  background: var(--color-background);
}

html.no-js .grid-content {
  transform-origin: top left;
  transform: scale(var(--zoom-scale, 1));
}

@supports (zoom: 1) {
  html.no-js .grid-content {
    zoom: var(--zoom-scale, 1);
    transform: none;
  }
}

.table-title-badge {
  position: absolute;
  left: calc(50px + var(--space-16));
  bottom: var(--space-16);
  padding: 10px 16px;
  border-radius: 999px;
  background: linear-gradient(120deg, rgba(50, 184, 198, 0.18), rgba(19, 52, 59, 0.32));
  color: #f7fafc;
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  letter-spacing: 0.02em;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(8px);
  pointer-events: none;
  max-width: min(360px, 55vw);
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.28);
  opacity: 0.92;
  z-index: 8;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .table-title-badge {
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.18));
  color: #f7fafc;
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.cell {
  position: absolute;
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  cursor: cell;
  padding: var(--space-6) var(--space-8);
  font-size: var(--font-size-sm);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--duration-fast);
  box-sizing: border-box;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  pointer-events: auto;
}

.cell.has-comment {
  padding-right: calc(var(--space-12, 12px) + 10px);
}

.cell-comment-indicator {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 12px;
  color: var(--color-primary, #21808d);
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.cell:hover { background: rgba(33, 128, 141, 0.05); }

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .cell:hover {
  background: rgba(45, 166, 178, 0.15);
}

.cell.selected {
  outline: none;
  z-index: 1;
}

.cell.selected::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--selection-fill, rgba(33, 128, 141, 0.1));
  pointer-events: none;
}

.cell.primary-selected {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--selection-outline, var(--color-primary));
  z-index: 2;
}

.cell.format-painter-source {
  outline: none;
  z-index: 1;
}

.cell.format-painter-source::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(168, 75, 47, 0.08);
  pointer-events: none;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .cell.selected {
  outline: none;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .cell.selected::after {
  background: var(--selection-fill, rgba(255, 82, 82, 0.25));
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .cell.primary-selected {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--selection-outline, #ff5252);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .cell.format-painter-source {
  outline: none;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .cell.format-painter-source::after {
  background: rgba(230, 129, 97, 0.2);
}

/* Selection overlay drawn once per contiguous selection to avoid double-thick grid lines */
.selection-overlay-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 100;
}

.selection-overlay {
  position: absolute;
  border: 1px solid var(--selection-outline, var(--color-primary));
  box-sizing: border-box;
  pointer-events: none;
  z-index: 100;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .selection-overlay {
  border-color: var(--selection-outline, #ff5252);
}

.selection-overlay--clipboard {
  border-style: dashed;
  border-color: var(--selection-outline, var(--color-primary));
}

.selection-overlay--clipboard-cut {
  border-style: dashed;
  border-width: 2px;
  border-color: var(--selection-outline, var(--color-primary));
}

.selection-overlay--format {
  border-style: dashed;
  border-color: var(--color-gray-400);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .selection-overlay--format {
  border-color: var(--color-gray-300);
}

.selection-overlay--merged-pass {
  background-color: var(--selection-pass-fill, rgba(33, 128, 141, 0.06));
  background-image:
    repeating-linear-gradient(45deg,
      var(--selection-pass-stripe, rgba(33, 128, 141, 0.18)) 0,
      var(--selection-pass-stripe, rgba(33, 128, 141, 0.18)) 2px,
      transparent 2px,
      transparent 8px),
    repeating-linear-gradient(-45deg,
      var(--selection-pass-stripe, rgba(33, 128, 141, 0.18)) 0,
      var(--selection-pass-stripe, rgba(33, 128, 141, 0.18)) 2px,
      transparent 2px,
      transparent 8px);
  border-radius: 2px;
}

.cell.cut-preview {
  opacity: 0.25;
}

.cell.cut-ghost {
  pointer-events: none;
}

/* Explicit border overlay layer to keep applied borders aligned on grid lines */
.border-overlay-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 90;
}

.border-overlay-line {
  position: absolute;
  box-sizing: border-box;
  pointer-events: none;
}

.cell.editing { 
    padding: 0; 
    overflow: visible !important; 
}
.cell.editing::after { display: none; }

.cell-editor-wrapper {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    padding: var(--space-6) var(--space-8);
    overflow: visible;
    isolation: isolate;
}

.cell.editing .cell-editor-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--editor-overflow-offset, 0px);
    width: var(--editor-overflow-width, 100%);
    background: var(--cell-edit-background, transparent);
    pointer-events: none;
    z-index: 0;
}

.cell-editor {
    width: 100%;
    border: none;
    outline: 2px solid var(--editor-outline, var(--color-primary));
    padding: 0;
    font: inherit;
    font-size: inherit;
    font-weight: inherit;
    font-style: inherit;
    line-height: inherit;
    background: transparent;
    color: inherit;
    text-decoration: inherit;
    white-space: nowrap;
    caret-color: currentColor;
    height: auto;
    min-height: 0;
    box-sizing: border-box;
    z-index: 1;
    position: relative;
    flex: 0 0 auto;
    min-width: 0;
    max-width: none;
}

.cell-editor::selection,
.cell-editor *::selection,
.cell-text-wrapper::selection,
.cell-text-wrapper *::selection {
    background: var(--text-selection-bg);
    color: inherit;
}

.cell.merged-cell {
    z-index: 3;
}

.cell.merged-child {
    display: none;
}

.context-menu {
  position: fixed;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  min-width: 180px;
  padding: var(--space-4) 0;
}

.context-menu-item {
  padding: var(--space-8) var(--space-16);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-8);
  font-size: var(--font-size-sm);
  transition: background var(--duration-fast);
}

.context-menu-item:hover { background: rgba(94, 82, 64, 0.12); }

.context-menu-separator {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-4) 0;
}

.context-menu-icon { width: 16px; text-align: center; }

.comment-popover {
  position: fixed;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  box-shadow: var(--shadow-lg);
  padding: var(--space-12) var(--space-16);
  max-width: 320px;
  z-index: 1100;
}

.comment-popover.hidden { display: none; }

.comment-popover__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
  margin-bottom: var(--space-8);
}

.comment-popover__title {
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-base);
  color: var(--color-text, #111);
}

.comment-popover__body {
  white-space: pre-wrap;
  font-size: var(--font-size-sm);
  line-height: 1.4;
  color: var(--color-text, #111);
}

.comment-popover__close {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  color: inherit;
  margin-left: auto;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-popover__close {
  color: var(--color-text, #f8f9fa);
}

.comment-popover:popover-open {
  outline: none;
}

.comment-popover__meta {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin-bottom: var(--space-8);
}

.comment-popover__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--color-border);
  background: var(--color-surface-strong, #f3f3f3);
}

.comment-popover__meta-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.comment-popover__author {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text, #111);
}

.comment-popover__author a {
  color: inherit;
  text-decoration: none;
}

.comment-popover__author a:hover {
  text-decoration: underline;
}

.comment-popover__timestamp {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary, #666);
}

.comment-mention {
  display: inline-flex;
  align-items: center;
  padding: 0 4px;
  border-radius: var(--radius-sm, 6px);
  background: rgba(33, 128, 141, 0.12);
  color: var(--color-primary, #21808d);
  font-weight: var(--font-weight-medium, 500);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-popover__author a {
  color: var(--color-orange-400);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-popover__author a:visited {
  color: var(--color-orange-500);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-mention {
  background: rgba(45, 166, 178, 0.24);
  color: var(--color-primary, #2da6b2);
}

.comment-popover__thread {
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-8);
  padding-top: var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}

.comment-popover__actions {
  margin-top: var(--space-8);
  display: flex;
  justify-content: flex-end;
}

.comment-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm, 6px);
  padding: var(--space-12);
  background: var(--color-surface-alt, #f7f7f7);
}

.comment-card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
  margin-bottom: var(--space-8);
}

.comment-card__meta-left {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.comment-card__actions {
  position: relative;
  display: flex;
  align-items: center;
}

.comment-menu__toggle {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  padding: var(--space-4);
  color: var(--color-text);
}

.comment-menu {
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm, 6px);
  box-shadow: var(--shadow-lg);
  display: none;
  flex-direction: column;
  min-width: 140px;
  z-index: 2000;
}

.comment-menu.hidden {
  display: none;
}
.comment-menu.open {
  display: flex;
}

.comment-menu button {
  background: transparent;
  border: none;
  text-align: left;
  padding: var(--space-8) var(--space-12);
  cursor: pointer;
  color: var(--color-text);
}

.comment-menu button:hover {
  background: rgba(33, 128, 141, 0.08);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-menu {
  background: var(--color-surface-strong, #1f1f1f);
  border-color: var(--color-border, #444);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-menu button:hover {
  background: rgba(33, 128, 141, 0.18);
}

.comment-card__body {
  font-size: var(--font-size-sm);
  color: var(--color-text);
}

.comment-body {
  white-space: pre-wrap;
  line-height: 1.5;
}

.comment-editor-inline {
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}

.comment-editor__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-8);
}

.comment-editor-inline.hidden {
  display: none !important;
}

.comment-reply {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm, 6px);
  padding: var(--space-8);
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.comment-reply--highlight {
  box-shadow: 0 0 0 2px var(--color-primary, #21808d);
}

.comment-reply__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.comment-reply__body {
  margin-top: var(--space-4, 4px);
  font-size: var(--font-size-sm);
  color: var(--color-text);
  white-space: pre-wrap;
}

.comment-reply__timestamp {
  color: var(--color-text-secondary);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-reply {
  background: var(--color-surface-strong, #1f1f1f);
  border-color: var(--color-border, #444);
  color: var(--color-text, #f5f5f5);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-reply__meta,
:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-reply__timestamp {
  color: var(--color-text-secondary, #bbb);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-reply .comment-body {
  color: var(--color-text, #f5f5f5);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-reply {
  background: var(--color-surface-strong, #1f1f1f);
  border-color: var(--color-border, #444);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-reply__meta,
:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-reply__timestamp {
  color: var(--color-text-secondary, #bbb);
}

.comment-reactions {
  display: flex;
  gap: var(--space-6, 6px);
  flex-wrap: wrap;
  margin-top: var(--space-8, 8px);
}

.comment-reaction {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--color-border, #ccc);
  border-radius: var(--radius-sm, 6px);
  background: var(--color-surface, #fff);
  cursor: pointer;
  font-size: 12px;
  color: var(--color-text, #111);
}

.comment-reaction--active {
  border-color: var(--color-primary, #21808d);
  background: rgba(33, 128, 141, 0.12);
}

.comment-reaction--static {
  cursor: default;
}

.comment-reaction__count {
  color: var(--color-text-secondary);
  font-weight: var(--font-weight-medium, 500);
}

.comment-reaction__add {
  border-style: dashed;
  opacity: 0.8;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-reaction {
  background: var(--color-surface-strong, #1f1f1f);
  border-color: color-mix(in srgb, var(--color-border, #444) 80%, #ffffff 20%);
  color: var(--color-text, #f5f5f5);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-reaction__count {
  color: var(--color-text-secondary, #c8c8c8);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-reaction__add {
  border-color: var(--color-primary, #55d0ff);
  color: var(--color-primary, #55d0ff);
  background: color-mix(in srgb, var(--color-surface-strong, #1f1f1f) 85%, var(--color-primary, #55d0ff) 15%);
  opacity: 1;
}

.comment-reply-composer {
  margin-top: var(--space-12, 12px);
  display: flex;
  flex-direction: column;
  gap: var(--space-8, 8px);
}

.comment-reply-composer.hidden {
  display: none !important;
}

.comment-reply-composer__actions {
  justify-content: flex-end;
}

.comment-popover--static {
  position: absolute;
  inset: auto;
  max-width: 280px;
  display: none;
  left: 12px;
  right: auto;
  bottom: calc(100% + 6px);
  top: auto;
}

.comment-popover--static:popover-open {
  display: block;
}

@supports (position-anchor: --comment-flag-anchor) {
  .comment-popover--static {
    position: fixed;
    position-anchor: --comment-flag-anchor;
    inset: auto;
    top: anchor(top);
    left: anchor(left);
    right: auto;
    bottom: auto;
    transform: translate(12px, -8px);
  }
}

.comment-editor {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.35);
  z-index: 1200;
}

.comment-editor.hidden { display: none; }

.comment-editor__content {
  width: min(480px, 90vw);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  box-shadow: var(--shadow-lg);
  padding: var(--space-16);
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}

.comment-editor__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
}

.comment-editor__title {
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-base);
}

.comment-editor__close {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  color: inherit;
}

.comment-editor__label {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.comment-editor__textarea {
  min-height: 120px;
}

.comment-editor__checkbox {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  font-size: var(--font-size-sm);
  color: var(--color-text);
}

.comment-editor__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-8);
}

.color-palette, .font-color-palette {
  position: fixed;
  z-index: 1001;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  box-shadow: var(--shadow-lg);
  padding: var(--space-16);
}

.color-palette-title, .font-color-palette-title {
  font-weight: var(--font-weight-medium);
  margin-bottom: var(--space-12);
  font-size: var(--font-size-sm);
}

.color-palette-grid, .font-color-palette-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: var(--space-4);
  max-width: 280px;
}

.color-section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 24px);
  gap: var(--space-4);
  width: 100%;
  max-width: 252px;
  justify-content: flex-start;
}

.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--color-border);
  transition: transform var(--duration-fast);
}

.color-swatch:hover { transform: scale(1.1); }

.color-swatch.clear {
  background: linear-gradient(45deg, #f00 25%, transparent 25%, transparent 75%, #f00 75%),
              linear-gradient(45deg, #f00 25%, var(--color-surface) 25%, var(--color-surface) 75%, #f00 75%);
  background-size: 4px 4px;
  background-position: 0 0, 2px 2px;
}

.color-swatch-auto {
  background: var(--color-text) !important;
  color: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-xs);
}

/* Custom Color Picker */
.custom-color-picker {
    display: flex;
    flex-direction: column;
    gap: var(--space-16);
    padding: var(--space-16);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-base);
    box-shadow: var(--shadow-lg);
    position: fixed;
    z-index: 1002;
    width: 280px;
}

.custom-color-picker.hidden {
    display: none;
}F

.color-picker-canvas-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: crosshair;
    border: 1px solid var(--color-border);
}

.color-picker-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.color-picker-cursor {
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid white;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 10;
}

.color-picker-hue-slider {
    position: relative;
    width: 100%;
    height: 16px;
    border-radius: var(--radius-sm);
    background: linear-gradient(to right, 
        #ff0000 0%, 
        #ffff00 16.67%, 
        #00ff00 33.33%, 
        #00ffff 50%, 
        #0000ff 66.67%, 
        #ff00ff 83.33%, 
        #ff0000 100%
    );
    cursor: pointer;
    border: 1px solid var(--color-border);
}

.color-picker-hue-cursor {
    position: absolute;
    width: 4px;
    height: 100%;
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.3);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    transform: translateX(-50%);
}

.color-picker-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: var(--space-8);
}

.color-picker-input-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.color-picker-input-label {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.color-picker-input {
    width: 100%;
    padding: var(--space-6) var(--space-8);
    font-size: var(--font-size-sm);
    font-family: var(--font-family-mono);
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    text-align: center;
}

.color-picker-input:focus {
    border-color: var(--color-primary);
    outline: none;
}

.color-picker-hex-group {
    grid-column: span 3;
}

.color-picker-suggestions {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
}

.color-picker-suggestions-label {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-secondary);
}

.color-picker-swatches {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: var(--space-4);
}

.color-picker-swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    cursor: pointer;
    transition: transform var(--duration-fast);
}

.color-picker-swatch:hover {
    transform: scale(1.15);
}

.color-picker-actions .btn {
    flex: 1;
}

.main-grid::-webkit-scrollbar { width: 12px; height: 12px; }
.main-grid::-webkit-scrollbar-track { background: var(--color-bg-1); }
.main-grid::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-sm);
}
.main-grid::-webkit-scrollbar-thumb:hover { background: var(--color-text-secondary); }
.main-grid::-webkit-scrollbar-corner {
  background: var(--color-bg-1);
}

.cell.bold { font-weight: var(--font-weight-bold); }
.cell.italic {
  font-family: var(--font-family-italic);
  font-style: italic;
  font-synthesis: style;
}
@supports (font-style: oblique 12deg) {
  .cell.italic { font-style: oblique 12deg; }
}
.cell.italic .cell-text-wrapper,
.cell.italic .cell-text-wrapper span {
  font-style: inherit;
  font-family: inherit;
}
.cell.underline { text-decoration-line: underline; }
.cell.strikethrough { text-decoration-line: line-through; }
.cell.underline.strikethrough { text-decoration-line: underline line-through; }

.cell.align-left { justify-content: flex-start; }
.cell.align-center { justify-content: center; }
.cell.align-right { justify-content: flex-end; }
.cell.align-top { align-items: flex-start; }
.cell.align-middle { align-items: center; }
.cell.align-bottom { align-items: flex-end; }

.cell-text-inline {
  display: inline-block;
  width: 100%;
  font-weight: inherit;
  font-style: inherit;
  text-decoration: inherit;
  color: inherit;
}

/* Cell-level formatting (baseline) */
.cell.bold {
  font-weight: var(--font-weight-bold);
}

.cell.italic {
  font-style: italic;
}

.cell.underline {
  text-decoration-line: underline;
}

.cell.strikethrough {
  text-decoration-line: line-through;
}

.cell.underline.strikethrough {
  text-decoration-line: underline line-through;
}

/* Inline span overrides - only specify when different from cell default */
.cell-text-inline span {
  font-weight: inherit;
  font-style: inherit;
  text-decoration: inherit;
}

/* Override bold only when explicitly set to normal */
.cell.bold .cell-text-inline span[data-bold="false"] {
  font-weight: normal;
}
.cell.bold .cell-text-wrapper span[data-bold="false"] {
  font-weight: normal;
}

/* Override italic only when explicitly set to normal */
.cell.italic .cell-text-inline span[data-italic="false"] {
  font-style: normal;
}
.cell.italic .cell-text-wrapper span[data-italic="false"] {
  font-style: normal;
}

/* Override underline only when explicitly removed */
.cell.underline .cell-text-inline span[data-underline="false"] {
  text-decoration: none;
}
.cell.underline .cell-text-wrapper span[data-underline="false"] {
  text-decoration: none;
}

/* Override strikethrough only when explicitly removed */
.cell.strikethrough .cell-text-inline span[data-strikethrough="false"] {
  text-decoration: none;
}
.cell.strikethrough .cell-text-wrapper span[data-strikethrough="false"] {
  text-decoration: none;
}

@media (max-width: 768px) {
  .toolbar { flex-wrap: wrap; gap: var(--space-8); }
  .toolbar-section { gap: var(--space-4); }
  .grid-container { grid-template-columns: 40px 1fr; }
  .row-header { width: 40px; }
}

.cell.cell-link {
    color: #2563eb;
    text-decoration: underline;
    cursor: pointer;
}

.cell.cell-link:hover {
    color: #1d4ed8;
}

/* Link editor popup */
.link-editor {
    position: fixed;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-base);
    box-shadow: var(--shadow-lg);
    z-index: 1001;
    padding: var(--space-16);
    min-width: 320px;
}

.link-editor.hidden {
    display: none;
}

.link-editor:not(.hidden) {
    display: block;
}

.link-editor-title {
    font-weight: var(--font-weight-medium);
    margin-bottom: var(--space-12);
    font-size: var(--font-size-base);
}

.link-editor-field {
    margin-bottom: var(--space-12);
}

.link-editor-label {
    display: block;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-4);
}

.link-editor-actions {
    display: flex;
    gap: var(--space-8);
    justify-content: flex-end;
    margin-top: var(--space-16);
}

/* Border Menu */
.border-menu {
    position: fixed;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-base);
    box-shadow: var(--shadow-lg);
    z-index: 1001;
    padding: var(--space-16);
}

.border-menu-title {
    font-weight: var(--font-weight-medium);
    margin-bottom: var(--space-16);
    font-size: var(--font-size-base);
}

.border-menu-section {
    margin-bottom: var(--space-16);
}

.border-menu-section--compact {
    margin-bottom: var(--space-8);
}

.border-menu-section:last-child {
    margin-bottom: 0;
}

.border-menu-subtitle {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-8);
    font-weight: var(--font-weight-medium);
}

.border-menu-divider {
    width: 100%;
    height: 1px;
    background: var(--color-border);
    margin: var(--space-8) 0;
}

.border-menu-control-row {
    display: flex;
    align-items: center;
    gap: var(--space-8);
    width: 100%;
    margin: 0 auto;
    justify-content: space-between;
}

.border-menu-control-label {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
    text-align: left;
    flex: 0 0 auto;
}

.border-menu-control-select {
    flex: 0 0 auto;
    width: 180px;
    text-align: left;
}

.border-menu-color-sections {
    margin-top: var(--space-8);
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
}

.comment-flag {
    margin-left: 6px;
    font-size: 12px;
    color: var(--color-primary, #21808d);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    anchor-name: --comment-flag-anchor;
}

.comment-flag:focus-visible {
    outline: 2px solid var(--color-primary, #21808d);
    outline-offset: 2px;
    border-radius: var(--radius-sm, 6px);
}

.comment-flag-wrapper {
  position: relative;
  display: inline-block;
  anchor-scope: :scope;
}

.comment-export {
    margin-top: var(--space-24, 24px);
    padding: var(--space-16, 16px);
    border: 1px solid var(--color-border, #ccc);
    border-radius: var(--radius-base, 8px);
    background: var(--color-surface, #fdfdfd);
}

.comment-export__title {
    margin: 0 0 var(--space-8, 8px);
    font-size: var(--font-size-md, 16px);
}

.comment-export__list {
    list-style: decimal;
    padding-left: var(--space-20, 20px);
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-8, 8px);
}

.comment-export__item {
    background: var(--color-surface-strong, rgba(0, 0, 0, 0.02));
    border: 1px solid var(--color-border, #ccc);
    border-radius: var(--radius-sm, 6px);
    padding: var(--space-8, 8px);
}

.comment-export__address {
    font-weight: var(--font-weight-semibold, 600);
    margin-bottom: var(--space-4, 4px);
}

.comment-export__body {
    white-space: pre-wrap;
    color: var(--color-text, #111);
}

.comment-export__meta {
    display: flex;
    align-items: center;
    gap: var(--space-12, 12px);
    margin-bottom: var(--space-6, 6px);
}

.comment-export__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--color-border, #ccc);
    background: var(--color-surface, #fff);
}

.comment-export__meta-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.comment-export__author {
    font-weight: var(--font-weight-semibold, 600);
    color: var(--color-text, #111);
}

.comment-export__author a {
    color: inherit;
    text-decoration: none;
}

.comment-export__author a:hover {
    text-decoration: underline;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-export__author a {
    color: var(--color-orange-400);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .comment-export__author a:visited {
    color: var(--color-orange-500);
}

.comment-export__timestamp {
    font-size: var(--font-size-xs, 12px);
    color: var(--color-text-secondary, #666);
}

.comment-export__reactions {
    display: flex;
    gap: var(--space-6, 6px);
    flex-wrap: wrap;
    margin-top: var(--space-6, 6px);
}

.comment-export__reactions .comment-reaction {
    border: 1px solid var(--color-border, #ccc);
    padding: 2px 6px;
    border-radius: var(--radius-sm, 6px);
    font-size: var(--font-size-xs, 12px);
    background: var(--color-surface, #fff);
    cursor: default;
}

.comment-export__reactions .comment-reaction__count {
    color: var(--color-text-secondary, #666);
}

.comment-export__reactions .comment-reaction__add {
    display: none;
}

.comment-export__reaction {
    border: 1px solid var(--color-border, #ccc);
    padding: 2px 6px;
    border-radius: var(--radius-sm, 6px);
    font-size: var(--font-size-xs, 12px);
    background: var(--color-surface, #fff);
}

.author-preview {
    position: fixed;
    z-index: 6000;
    min-width: 240px;
    max-width: 320px;
    padding: var(--space-12, 12px);
    border-radius: var(--radius-md, 8px);
    border: 1px solid var(--color-border, #ddd);
    background: var(--color-surface, #fff);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    gap: var(--space-10, 10px);
}

.author-preview.hidden {
    display: none !important;
}

.author-preview__avatar-wrap {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    border: 1px solid var(--color-border, #ddd);
}

.author-preview__avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.author-preview__body {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.author-preview__name {
    font-weight: var(--font-weight-semibold, 600);
    color: var(--color-text, #111);
}

.author-preview__username {
    font-size: var(--font-size-sm, 12px);
    color: var(--color-text-secondary, #666);
}

.author-preview__bio {
    font-size: var(--font-size-sm, 12px);
    color: var(--color-text, #222);
    max-width: 260px;
    white-space: normal;
}

.author-preview__link {
    font-size: var(--font-size-sm, 12px);
    color: var(--color-primary, #21808d);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .author-preview {
    background: var(--color-surface-strong, #1f1f1f);
    border-color: color-mix(in srgb, var(--color-border, #444) 80%, #ffffff 20%);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .author-preview__name {
    color: var(--color-text, #f5f5f5);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .author-preview__username,
:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .author-preview__bio {
    color: var(--color-text-secondary, #c8c8c8);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .author-preview__link {
    color: var(--color-primary, #55d0ff);
}

.comment-export__replies {
    list-style: none;
    padding: 0;
    margin: var(--space-8, 8px) 0 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-6, 6px);
}

.comment-export__reply {
    border: 1px solid var(--color-border, #ccc);
    border-radius: var(--radius-sm, 6px);
    padding: var(--space-8, 8px);
    background: var(--color-surface-alt, rgba(0, 0, 0, 0.02));
}

.comment-export__reply-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-8, 8px);
    font-size: var(--font-size-xs, 12px);
    color: var(--color-text-secondary, #666);
}

.spreadsheet-fallback {
    width: max-content;
    min-width: max-content;
    max-width: none;
    display: inline-table;
    border-collapse: collapse;
    border: none;
    font-family: var(--font-family-base, sans-serif);
    font-size: var(--font-size-sm, 12px);
    table-layout: fixed;
    border-left: 0;
}

/* Terminal UAs: let cells size to content to avoid box-art collapse on caret move. */
html.terminal-ua .spreadsheet-fallback {
    width: max-content;
    min-width: max-content;
    max-width: none;
    table-layout: auto;
}

html.terminal-ua .spreadsheet-fallback tr,
html.terminal-ua .spreadsheet-fallback th,
html.terminal-ua .spreadsheet-fallback td {
    height: auto;
    min-height: 0;
    line-height: 1;
}

html.terminal-ua .spreadsheet-fallback th,
html.terminal-ua .spreadsheet-fallback td {
    padding: 0 1ch;
    vertical-align: middle;
}

html.terminal-ua .spreadsheet-fallback .fallback-cell-content {
    display: inline;
    width: auto;
    min-width: 0;
    height: auto;
    min-height: 0;
    padding: 0;
    line-height: 1;
    white-space: pre;
    overflow: visible;
    text-overflow: clip;
    vertical-align: middle;
}

.table-title-caption {
    display: none;
    caption-side: top;
    text-align: left;
    font-weight: var(--font-weight-semibold, 600);
    font-size: var(--font-size-sm, 12px);
    color: var(--color-text, #13343b);
    margin-bottom: var(--space-8, 8px);
}

html.no-js .table-title-badge {
    display: none;
}

html.no-js body:not(.tabs-only) .table-title-caption {
    display: table-caption;
}

html.no-js body:not(.tabs-only) .table-title-badge,
html.terminal-ua .table-title-badge {
    display: none !important;
}

@media (hover: hover) and (pointer: fine) {
    html.no-js body:not(.tabs-only) .table-title-caption {
        display: none;
    }

    html.no-js body:not(.tabs-only) .table-title-badge {
        display: block !important;
    }
}

.spreadsheet-fallback th,
.spreadsheet-fallback td {
    box-sizing: border-box;
    border: 1px solid var(--color-border, #ccc);
    text-align: left;
}

.spreadsheet-fallback th {
    padding: 0;
    white-space: nowrap;
    background: var(--color-bg-1, #f0f4ff);
    font-family: var(--font-family-base, sans-serif);
    font-weight: var(--font-weight-medium, 500);
    font-size: var(--font-size-sm, 12px);
    text-align: center;
    vertical-align: middle;
    color: var(--color-text, #13343b);
    line-height: 1;
    transition: background var(--duration-fast, 150ms);
}

.spreadsheet-fallback td {
    vertical-align: bottom;
    position: relative;
    padding: 0;
}

.spreadsheet-fallback :is(thead tr, tbody tr[data-header-row="true"]) > th {
    height: 32px;
}

.spreadsheet-fallback tbody tr[data-row] > th {
    width: 50px;
    min-width: 50px;
    max-width: 50px;
}

.spreadsheet-fallback :is(thead tr, tbody tr[data-header-row="true"]) > th:first-child {
    font-size: var(--font-size-lg, 18px);
    line-height: 1;
}

.spreadsheet-fallback :is(thead tr, tbody tr[data-header-row="true"]) > th:hover,
.spreadsheet-fallback tbody tr[data-row] > th:hover {
    background: var(--color-bg-2, rgba(245, 158, 11, 0.08));
}

.spreadsheet-fallback tr > *:first-child {
    border-left: none;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .spreadsheet-fallback th,
:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .spreadsheet-fallback tbody th,
:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .spreadsheet-fallback thead th {
    background: var(--color-surface-alt, #050505);
    color: var(--color-text, #f8f9fa);
}

.spreadsheet-fallback .fallback-cell-content {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: var(--space-6, 6px) var(--space-8, 8px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: inherit;
}

@supports (display: grid) {
    @media (hover: hover) and (pointer: fine) {
        .spreadsheet-fallback td:not([data-empty="true"]):hover .fallback-cell-content {
            position: absolute;
            top: 0;
            left: -1px;
            height: calc(100% + 1px);
            min-height: calc(100% + 1px);
            min-width: calc(100% + 2px);
            width: auto;
            max-width: none;
            white-space: nowrap;
            background: var(--color-surface, #fff);
            border: 1px solid var(--color-border, #ccc);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
            z-index: 2;
            display: flex;
            align-items: flex-end;
        }

        .spreadsheet-fallback td[data-align="right"]:hover .fallback-cell-content {
            left: auto;
            right: -1px;
            transform: none;
            text-align: right;
        }

        .spreadsheet-fallback td[data-align="center"]:hover .fallback-cell-content {
            left: 50%;
            right: auto;
            transform: translateX(-50%);
            text-align: center;
        }

        /* Keep hover popouts inside the viewport near the right edge. */
        .spreadsheet-fallback tbody tr > td:nth-last-child(-n+2):not([data-empty="true"]):hover .fallback-cell-content {
            left: auto;
            right: -1px;
            transform: none;
        }
    }
}

.spreadsheet-fallback td[data-empty="true"] .fallback-cell-content {
    padding: 0;
    width: 100%;
    height: 100%;
    min-height: 100%;
}

.spreadsheet-fallback td[data-empty="true"]:hover .fallback-cell-content {
    position: static;
    min-width: 0;
    width: 100%;
    max-width: none;
    white-space: nowrap;
    background: none;
    border: none;
    box-shadow: none;
    padding: 0;
}

.spreadsheet-fallback td[data-comment] .fallback-cell-content {
    padding-right: calc(var(--space-12, 12px) + 10px);
}

.spreadsheet-fallback td[data-comment] .comment-flag-wrapper {
    position: absolute;
    top: 4px;
    right: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
}

@supports not (display: grid) {
    .spreadsheet-fallback td:not([data-empty="true"]):hover .fallback-cell-content {
        position: static;
        top: auto;
        left: auto;
        right: auto;
        height: auto;
        min-height: 0;
        min-width: 0;
        width: 100%;
        max-width: none;
        white-space: nowrap;
        background: none;
        border: none;
        box-shadow: none;
        display: block;
        align-items: stretch;
        z-index: auto;
    }

    .spreadsheet-fallback td[data-align="right"]:hover .fallback-cell-content,
    .spreadsheet-fallback td[data-align="center"]:hover .fallback-cell-content,
    .spreadsheet-fallback tbody tr > td:nth-last-child(-n+2):not([data-empty="true"]):hover .fallback-cell-content {
        left: auto;
        right: auto;
        transform: none;
        text-align: inherit;
    }
}

.spreadsheet-fallback td[data-comment] .comment-flag {
    margin-left: 0;
    padding: 0;
    line-height: 1;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Hide JS-only chrome and tighten layout when the fallback table is present (JS disabled),
   but only in modern graphical engines. Text UAs should keep the table in flow. */
@supports (display: grid) and (selector(:has(*))) and (container-type: inline-size) {
  @media (hover: hover) and (pointer: fine) {
    html.no-js .spreadsheet-container:has(table[data-spreadsheet-export]) {
        padding-top: 0;
    }

    html.no-js .grid-container:has(table[data-spreadsheet-export]) {
        display: grid;
        grid-template-columns: 0 1fr;
        grid-template-rows: 0 1fr;
        height: 100%;
    }

    html.no-js .grid-container:has(table[data-spreadsheet-export]) .corner-cell,
    html.no-js .grid-container:has(table[data-spreadsheet-export]) .column-headers,
    html.no-js .grid-container:has(table[data-spreadsheet-export]) .row-headers {
        display: none;
    }

    html.no-js .grid-container:has(table[data-spreadsheet-export]) .main-grid {
        position: relative;
        overflow: auto;
        grid-column: 1 / span 2;
        grid-row: 1 / span 2;
    }

    html.no-js .grid-container:has(table[data-spreadsheet-export]) .grid-content {
        min-width: 0;
        min-height: 0;
    }

    html.no-js .grid-container:has(table[data-spreadsheet-export]) .grid-content > table[data-spreadsheet-export] {
        width: max-content;
        min-width: max-content;
        max-width: none;
        display: inline-table;
        margin: 0;
    }

    html.no-js .grid-container:has(table[data-spreadsheet-export]) .spreadsheet-fallback th:first-child,
    html.no-js .grid-container:has(table[data-spreadsheet-export]) .spreadsheet-fallback td:first-child {
        width: 50px;
        min-width: 50px;
        max-width: 50px;
        border-left: 0;
    }

    html.no-js .grid-container:has(table[data-spreadsheet-export]) .spreadsheet-fallback :is(thead tr, tbody tr[data-header-row="true"]) > th {
        position: sticky;
        top: 0;
        z-index: 5;
        box-shadow: none;
        border-top: 0;
        background: var(--color-surface, #f7f7f7);
    }

    html.no-js .grid-container:has(table[data-spreadsheet-export]) .spreadsheet-fallback tbody tr[data-row] > th {
        position: sticky;
        left: 0;
        z-index: 4;
        box-shadow: none;
        border-right: 1px solid var(--color-border, #ccc);
    }

    html.no-js .grid-container:has(table[data-spreadsheet-export]) .spreadsheet-fallback :is(thead tr, tbody tr[data-header-row="true"]) > th:first-child {
        left: 0;
        z-index: 6;
    }

    /* Keep only one divider between sticky row header column and first data column. */
    html.no-js .grid-container:has(table[data-spreadsheet-export]) .spreadsheet-fallback :is(thead tr, tbody tr[data-header-row="true"]) > th:nth-child(2),
    html.no-js .grid-container:has(table[data-spreadsheet-export]) .spreadsheet-fallback tbody td:first-of-type {
        border-left: 0;
    }
  }
}

/* If JS partially runs but leaves the fallback table in place,
   keep the table in document flow so terminal browsers can scroll. */
html.js body:not(.tabs-only) .spreadsheet-container:has(table[data-spreadsheet-export]) {
  height: auto;
  min-height: 0;
  overflow: visible;
}

html.js body:not(.tabs-only) .theme-scope:has(table[data-spreadsheet-export]) {
  flex: 0 0 auto;
  min-height: 0;
}

html.js body:not(.tabs-only) .grid-container:has(table[data-spreadsheet-export]) {
  display: block;
  height: auto;
  min-height: 0;
  overflow: visible;
}

html.js body:not(.tabs-only) .main-grid:has(table[data-spreadsheet-export]) {
  display: block;
  height: auto;
  min-height: 0;
  overflow: visible;
  max-height: none;
}

html.js body:not(.tabs-only) .grid-content:has(table[data-spreadsheet-export]) {
  display: block;
  height: auto;
  min-height: 0;
  overflow: visible;
  transform: none;
}

html.js body:not(.tabs-only) .grid-content > table[data-spreadsheet-export] {
  display: table;
  width: max-content;
  min-width: max-content;
  max-width: none;
  margin: 0;
}

.spreadsheet-fallback th {
    background-color: var(--color-surface, #f7f7f7);
    font-weight: 600;
}

.spreadsheet-fallback a {
    color: inherit;
    text-decoration: inherit;
}

.save-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.save-modal.hidden {
    display: none;
}

.save-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.45);
}

.save-modal__dialog {
    position: relative;
    background: var(--color-surface);
    border-radius: var(--radius-base);
    box-shadow: var(--shadow-lg);
    padding: var(--space-24);
    width: min(520px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-16);
}

.save-modal__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-8);
}

.save-modal__header h2 {
    margin: 0;
    font-size: var(--font-size-lg);
}

.save-modal__close {
    border: none;
    background: transparent;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    color: var(--color-text-secondary);
}

.save-modal__body {
    display: flex;
    flex-direction: column;
    gap: var(--space-16);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.save-modal__field {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.save-modal__field label {
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
}

.save-modal__field-hint {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

.save-modal__diff {
    display: flex;
    flex-direction: column;
    gap: var(--space-12);
    padding: var(--space-12);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-base);
    background: var(--color-surface);
}

.save-modal__diff-empty {
    text-align: center;
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

.save-modal__diff-title {
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

.save-modal__diff-title-group {
    display: flex;
    align-items: center;
    gap: var(--space-8);
    flex-wrap: wrap;
}

.save-modal__diff-tabs {
    display: inline-flex;
    gap: var(--space-8);
    margin: var(--space-8) 0;
}

.save-modal__diff-tab {
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--font-size-xs);
}

.save-modal__diff-tab.is-active {
    background: var(--color-bg-1);
    border-color: var(--color-primary);
}

.save-modal__diff-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-12);
    flex-wrap: wrap;
}

.save-modal__diff-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-12);
    max-height: 260px;
    overflow-y: auto;
    overflow-x: auto;
}

.save-modal__diff-item {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: var(--space-12);
    background: var(--color-surface);
}

.save-modal__diff-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-8);
}

.save-modal__diff-sheet {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    font-weight: var(--font-weight-medium);
}

.save-modal__diff-address {
    font-family: var(--font-family-mono);
    font-weight: var(--font-weight-bold);
    color: var(--color-text);
}

.save-modal__diff-tag {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    padding: 2px 8px;
    border-radius: 999px;
    text-transform: uppercase;
}

.save-modal__diff-tag--added {
    background: rgba(46, 204, 113, 0.18);
    color: #1f7a55;
}

.save-modal__diff-tag--removed {
    background: rgba(240, 82, 82, 0.2);
    color: #a11a2b;
}

.save-modal__diff-tag--modified {
    background: rgba(59, 130, 246, 0.18);
    color: #1d4ed8;
}

.save-modal__diff-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-12);
}

.save-modal__diff-column {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.save-modal__diff-column-title {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-secondary);
}

.save-modal__diff-cell {
    border: 1px dashed var(--color-border);
    min-height: 40px;
    padding: var(--space-8);
    display: flex;
    justify-content: flex-start;
    align-items: flex-end;
    background: var(--color-surface);
    color: inherit;
    overflow: hidden;
}

.save-modal__diff-cell-content {
    width: 100%;
    text-align: inherit;
}

.save-modal__diff-cell--empty {
    justify-content: center;
    align-items: center;
    background: var(--color-background);
    color: var(--color-text-secondary);
}

.save-modal__diff-cell a {
    color: inherit;
}

.save-modal__diff-placeholder {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

.save-modal__diff-changes {
    margin: 0;
    padding-left: 16px;
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

.save-modal__diff-changes li {
    line-height: 1.4;
}

.save-modal__diff-note {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

.save-modal__diff-more {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

.save-modal__discard-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.save-modal__discard-btn:hover:not(:disabled) {
    border-color: var(--color-red-500);
    color: var(--color-red-500);
}

.save-modal--busy .save-modal__dialog {
    cursor: progress;
}

.save-modal__actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-12);
}

.save-modal__actions button {
    width: 100%;
}

.save-modal__note {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    background: var(--color-muted);
    padding: var(--space-12);
    border-radius: var(--radius-base);
    line-height: 1.6;
}

.save-modal__note code {
    font-family: var(--font-family-mono);
    font-size: 0.95em;
}

.save-modal__status {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    min-height: 1.5em;
}

.save-modal__oauth {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    background: var(--color-surface-muted, rgba(17, 24, 39, 0.04));
    padding: var(--space-12);
    border-radius: var(--radius-base);
    border: 1px dashed var(--color-border, rgba(17, 24, 39, 0.15));
    line-height: 1.6;
    word-break: break-word;
}

.save-modal__oauth strong {
    color: var(--color-text-primary, #1f2937);
}

.save-modal__commit-warning {
    margin-left: var(--space-4);
    color: #d1433f;
    font-size: 0.95em;
    vertical-align: middle;
}

.save-modal__status--error {
    color: #d1433f;
}

.revision-drawer {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: flex-end;
  z-index: 2050;
}

.revision-drawer.hidden {
  display: none;
}

.revision-drawer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(19, 28, 40, 0.4);
  backdrop-filter: blur(2px);
}

.revision-drawer__panel {
  position: relative;
  width: min(440px, calc(100vw - 32px));
  height: 100%;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: -12px 0 28px rgba(0, 0, 0, 0.12);
  padding: var(--space-16);
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}

.revision-drawer__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-12);
}

.revision-drawer__titles {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.revision-drawer__title {
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  font-size: var(--font-size-base);
}

.revision-drawer__subtitle {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.revision-drawer__header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.revision-drawer__close {
  min-width: 32px;
}

.revision-drawer__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
  height: 100%;
  overflow: hidden;
}

.revision-drawer__summary {
  padding: var(--space-12);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  background: var(--color-surface-alt);
  font-size: var(--font-size-sm);
  color: var(--color-text);
  line-height: 1.5;
}

.revision-drawer__status {
  min-height: 18px;
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.revision-drawer__status--error {
  color: var(--color-red-500);
}

.revision-drawer__list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
  overflow: auto;
  padding-right: 2px;
}

.revision-drawer__hint,
.revision-drawer__empty {
  padding: var(--space-12);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-base);
  text-align: center;
  color: var(--color-text-secondary);
  background: var(--color-surface-alt);
}

.revision-item {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  padding: var(--space-12);
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
  background: var(--color-surface);
  transition: border-color var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard);
}

.revision-item:hover {
  border-color: var(--color-primary);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.08);
}

.revision-item--active {
  border-color: var(--color-primary);
  box-shadow: 0 14px 32px rgba(33, 128, 141, 0.18);
}

.revision-item__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-8);
}

.revision-item__title {
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
}

.revision-item__pill {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--color-bg-1);
  color: var(--color-primary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
}

.revision-item__meta {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.revision-item__range {
  font-size: var(--font-size-sm);
  color: var(--color-text);
}

.revision-item__actions {
  display: flex;
  justify-content: flex-end;
}

.revision-item__load {
  min-width: 96px;
}

.revision-item__no-table {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  text-align: right;
}

.revision-item__details {
  margin-top: 6px;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-8);
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.revision-item__details--inline {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}

.revision-item__details summary {
  cursor: pointer;
  font-size: var(--font-size-base);
  color: var(--color-text);
  font-weight: var(--font-weight-bold);
  outline: none;
  list-style: none;
}

.revision-item__details summary::-webkit-details-marker {
  display: none;
}

.revision-item__details-summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-8);
}

.revision-item__details-caret {
  font-size: 0.9em;
  opacity: 0.7;
  transition: transform var(--duration-fast) var(--ease-standard);
}

.revision-item__details[open] .revision-item__details-caret {
  transform: rotate(180deg);
}

.revision-item__details pre {
  margin: var(--space-8) 0 0 0;
  white-space: pre-wrap;
  font-family: var(--font-family-mono);
  font-size: var(--font-size-xs);
  color: var(--color-text);
}

.shortcuts-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.shortcuts-modal.hidden {
    display: none;
}

.shortcuts-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.45);
    cursor: pointer;
}

.shortcuts-modal__dialog {
    position: relative;
    background: var(--color-surface);
    border-radius: var(--radius-base);
    box-shadow: var(--shadow-lg);
    padding: var(--space-16) var(--space-16) var(--space-24) var(--space-16);
    width: min(600px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    overflow-y: auto;
}

.shortcuts-modal__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-8);
    margin-bottom: var(--space-16);
    padding-bottom: var(--space-12);
    border-bottom: 1px solid var(--color-border);
}

.shortcuts-modal__header h2 {
    margin: 0;
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-medium);
}

.shortcuts-modal__close {
    border: none;
    background: transparent;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    color: var(--color-text-secondary);
    padding: 0;
}

.shortcuts-modal__close:hover {
    color: var(--color-text);
}

.shortcuts-modal__body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--space-16);
}

.diff-preview {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2100;
}

.diff-preview.hidden {
    display: none;
}

.diff-preview__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.45);
    cursor: pointer;
}

.diff-preview__dialog {
    position: relative;
    background: var(--color-surface);
    border-radius: var(--radius-base);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    width: min(980px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.diff-preview__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-12);
    padding: var(--space-16);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
}

.diff-preview__header h2 {
    margin: 0 0 4px 0;
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-medium);
}

.diff-preview__subtitle {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

.diff-preview__actions {
    display: inline-flex;
    align-items: center;
    gap: var(--space-8);
}

.diff-preview__live-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--space-6);
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

.diff-preview__live-toggle input {
    accent-color: var(--color-text);
}

.diff-preview__modes {
    display: inline-flex;
    gap: var(--space-6);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    padding: 2px;
    background: var(--color-bg-1);
}

.diff-preview__mode {
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    padding: 4px 10px;
    border-radius: 999px;
    cursor: pointer;
    font-size: var(--font-size-xs);
}

.diff-preview__mode.is-active {
    background: var(--color-text);
    color: var(--color-surface);
}

.diff-preview__close {
    border: none;
    background: transparent;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    color: var(--color-text-secondary);
    padding: 0;
}

.diff-preview__tabs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-8);
    padding: var(--space-12) var(--space-16);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-1);
}

.diff-preview__tab {
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--font-size-xs);
}

.diff-preview__tab.is-active {
    background: var(--color-text);
    color: var(--color-surface);
    border-color: var(--color-text);
}

.diff-preview__body {
    padding: var(--space-16);
    overflow: auto;
}

.diff-preview--detached {
    align-items: flex-start;
    justify-content: flex-start;
    pointer-events: none;
    z-index: 7000;
}

.diff-preview--detached .diff-preview__backdrop {
    display: none;
}

.diff-preview--detached .diff-preview__dialog {
    position: absolute;
    top: 80px;
    left: 80px;
    pointer-events: auto;
}

.diff-preview--detached .diff-preview__header {
    cursor: move;
}

.diff-preview--collapsed .diff-preview__tabs,
.diff-preview--collapsed .diff-preview__body {
    display: none;
}

.diff-preview__panel {
    display: none;
}

.diff-preview__panel.is-active {
    display: block;
}

.diff-preview__panel-title {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-8);
}

.diff-preview__code {
    margin: 0;
    background: #11100f;
    color: #f7f0e6;
    padding: var(--space-12);
    border-radius: var(--radius-base);
    overflow: auto;
    white-space: pre;
    line-height: 1.4;
    font-family: var(--font-family-mono);
    font-size: var(--font-size-xs);
}

.diff-line {
    display: block;
    white-space: pre;
}

.diff-line--add {
    color: #c7f9c7;
    background: rgba(30, 120, 60, 0.18);
}

.diff-line--del {
    color: #ffb7b7;
    background: rgba(140, 40, 40, 0.2);
}

.diff-line--hunk {
    color: #c3b6ff;
}

.diff-line--meta {
    color: #9aa4b2;
}

.diff-preview__empty {
    text-align: center;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    padding: var(--space-24) 0;
}

.shortcuts-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
}

.shortcuts-section__title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
    margin: 0;
}

.shortcuts-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.shortcut-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-12);
    font-size: var(--font-size-sm);
}

.shortcut-item kbd {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    font-family: var(--font-family-mono);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
    background: var(--color-background);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: 0 1px 0 var(--color-border);
    white-space: nowrap;
}

.shortcut-item span {
    color: var(--color-text-secondary);
    text-align: right;
}

@media (max-width: 768px) {
    .shortcuts-modal__body {
        grid-template-columns: 1fr;
    }
}

.border-options-grid {
    display: grid;
    grid-template-columns: repeat(5, 44px);
    gap: var(--space-8);
}

.border-option {
    width: 44px;
    height: 44px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-slate-500);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast);
    padding: 0;
}

.border-option:hover {
    background: var(--color-bg-2);
    border-color: var(--color-primary);
}

.border-option svg {
    width: 24px;
    height: 24px;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .border-option {
    background: var(--color-surface-alt);
    border-color: rgba(248, 249, 250, 0.24);
    color: rgba(248, 249, 250, 0.88);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .border-option:hover {
    background: rgba(45, 166, 178, 0.18);
}

.border-preview {
    border: 2px solid var(--color-text);
    background: var(--color-surface-alt, var(--color-surface));
    display: flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    max-width: 100%;
}

.border-preview-stage {
    position: relative;
    display: inline-block;
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.04);
    overflow: hidden;
}

.border-preview-viewport {
    position: relative;
    overflow: hidden;
    border-radius: inherit;
}

.border-preview-grid {
    display: grid;
    position: absolute;
    top: 0;
    left: 0;
    grid-template-columns: repeat(3, var(--border-preview-cell-width, 80px));
    grid-template-rows: repeat(3, var(--border-preview-cell-height, 32px));
    background: var(--color-surface);
}

.border-preview-cell {
    position: relative;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
    box-sizing: border-box;
}

.border-preview-cell--edge-left {
    border-left: 1px solid var(--color-border);
}

.border-preview-cell--edge-top {
    border-top: 1px solid var(--color-border);
}

.border-preview-cell--edge-right {
    border-left: 1px solid var(--color-border);
}

.border-preview-cell--edge-bottom {
    border-top: 1px solid var(--color-border);
}

.border-preview-cell--suppress-right {
    border-right: none;
}

.border-preview-cell--suppress-bottom {
    border-bottom: none;
}

.border-preview-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    overflow: visible;
}

.border-preview-overlay line {
    vector-effect: non-scaling-stroke;
    shape-rendering: crispEdges;
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .border-preview {
    border-color: var(--color-text);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .border-preview-stage {
    background: var(--color-surface);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .border-preview-cell {
    background: var(--color-surface);
    border-color: rgba(248, 249, 250, 0.35);
}

@keyframes slideInError {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideOutError {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

html.no-js .text-browser-specific-message {
    display: block !important;
    visibility: visible !important;
    height: auto !important;
    overflow: visible !important;
}

@supports (display: flex) {
    html.no-js .text-browser-specific-message {
        display: none !important;
    }
}

.hide-elinks { /* also hides in chawan */
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
}

.show-for-links { /* else links will whine */
    display: none !important;
}

/* Real separator nodes for text browsers that ignore CSS pseudo-elements.
   Hidden when CSS is applied (modern browsers and cha). */
.sheet-sep {
  display: none !important;
}

/* Shared dynamic tabs behavior used by index-like sheet switchers.
   Keep per-sheet column/highlight selectors in each HTML page. */
html.js .text-browser-specific-message,
html.js .hide-elinks {
  display: none !important;
}

.sheet-tabs--state.sheet-tabs--dynamic {
  display: flex !important;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

html body.tabs-only nav.sheet-tabs.sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal {
  display: inline-flex !important;
}

.sheet-tabs--state.sheet-tabs--dynamic .sheet-state-groups {
  display: inline-block;
}

.sheet-tabs--state.sheet-tabs--dynamic .sheet-state-group {
  display: none;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  counter-reset: sheet-tab;
}

.sheet-tabs--state.sheet-tabs--dynamic:not(:has(.sheet-route:target)) .sheet-state-group--default {
  display: inline-flex;
}

.sheet-tabs--state.sheet-tabs--dynamic:has(.sheet-route:target) .sheet-state-group:has(.sheet-route:target) {
  display: inline-flex;
}

.sheet-tabs--state.sheet-tabs--dynamic .sheet-state-group > .sheet-route {
  display: inline-flex !important;
  counter-increment: sheet-tab;
}

.sheet-tabs--state.sheet-tabs--dynamic .sheet-state-group > .sheet-route::before {
  content: "";
}

@supports (display: grid) and (selector(:has(*))) {
  .sheet-tabs--state.sheet-tabs--dynamic {
    display: grid !important;
    align-items: center;
    gap: 10px;
    padding-left: 0;
  }

  .sheet-tabs--state.sheet-tabs--dynamic .sheet-state-groups {
    display: contents;
  }

  .sheet-tabs--state.sheet-tabs--dynamic .sheet-state-group {
    display: none;
  }

  .sheet-tabs--state.sheet-tabs--dynamic:not(:has(.sheet-route:target)) .sheet-state-group--default {
    display: contents;
  }

  .sheet-tabs--state.sheet-tabs--dynamic:has(.sheet-route:target) .sheet-state-group:has(.sheet-route:target) {
    display: contents;
  }

  /* Keep dynamic no-JS terminal labels visually aligned with JS-rendered tabs. */
  .sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal {
    min-width: 64px;
    width: auto;
    height: 38px;
    line-height: 36px;
    padding: 0 12px;
    border: 1px solid var(--tab-border-color, var(--color-border));
    background: var(--color-surface);
    color: var(--color-text);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    justify-self: start;
    z-index: 2;
  }

  .sheet-tabs--state.sheet-tabs--dynamic > .noscript-credits-control {
    grid-column: 1;
    grid-row: 1;
  }

  /* Avoid stretched overlay links forcing extra-wide grid columns. */
  .sheet-tabs--state.sheet-tabs--dynamic .sheet-state-group > .sheet-route {
    min-width: 0 !important;
    width: auto !important;
    height: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    line-height: 0 !important;
    font-size: 0 !important;
    justify-self: stretch !important;
    overflow: hidden !important;
    contain: size !important;
    z-index: 1 !important;
    opacity: 0;
    pointer-events: auto;
  }

:is(:root:is([data-theme='dark'], :has(#themeToggle:checked)), .spreadsheet-container > #themeToggle:checked ~ .theme-scope) .sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal {
    background: #000000;
    border-color: #141414;
  }
}

/* Hard terminal no-JS fallback: wrapped tab rows with a single divider underneath. */
@supports (display: grid) and (not (selector(:has(*)))) {
  html.no-js body.tabs-only .sheet-tabs--state.sheet-tabs--dynamic {
    display: flex !important;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 0 !important;
    height: auto !important;
    padding: 0 12px 0 5ch !important;
    position: relative !important;
    border-bottom: 1px solid var(--color-border);
  }

  html.no-js body.tabs-only .sheet-tabs--state.sheet-tabs--dynamic > .noscript-credits-control {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    bottom: auto !important;
    margin: 0 !important;
    float: none !important;
    order: -1 !important;
  }

  /* Keep closed trigger on first row; move open credits card to divider baseline. */
  html.no-js body.tabs-only .sheet-tabs--state.sheet-tabs--dynamic > .noscript-credits-control:target {
    top: auto !important;
    bottom: 0 !important;
  }

  html.no-js body.tabs-only .sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal {
    order: 1 !important;
  }
}

/* Modern no-JS browser layout should mirror JS-enabled tab geometry. */
@supports (display: grid) and (selector(:has(*))) {
  html.no-js body.tabs-only .sheet-tabs--state.sheet-tabs--dynamic {
    gap: 10px !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  html.no-js body.tabs-only .sheet-tabs--state.sheet-tabs--dynamic > .noscript-credits-control {
    position: relative !important;
    left: auto !important;
    top: auto !important;
    margin: 0 !important;
    float: none !important;
    order: 0 !important;
  }

  html.no-js body.tabs-only .sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control .button-container > .credits-trigger {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-width: 40px !important;
    width: 40px !important;
    max-width: 40px !important;
    height: 38px !important;
    line-height: 36px !important;
    padding: 0 !important;
    border-radius: 0 !important;
  }

  html.no-js body.tabs-only .sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control .button-container > a.credits-trigger--open-gui {
    display: inline-flex !important;
  }

  html.no-js body.tabs-only .sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control .button-container > a.credits-trigger--open-tui {
    display: none !important;
  }

  html.no-js body.tabs-only .sheet-tabs--state.sheet-tabs--dynamic .noscript-credits-control .button-container > a.credits-trigger--close {
    display: none !important;
  }
}

@supports (display: grid) and (selector(:has(*))) {
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme]):not(.has-theme-toggle) .sheet-tabs,
    :root:not([data-theme]):not(.has-theme-toggle) .sheet-tabs--noscript {
      --tab-border-color: #141414;
      background: #000000;
      border-top: 1px solid #141414;
    }

    :root:not([data-theme]):not(.has-theme-toggle) .sheet-tab,
    :root:not([data-theme]):not(.has-theme-toggle) .sheet-tabs--noscript a:not(.sheet-route),
    :root:not([data-theme]):not(.has-theme-toggle) .heart-fallback,
    :root:not([data-theme]):not(.has-theme-toggle) .sheet-tabs--state > a.sheet-link,
    :root:not([data-theme]):not(.has-theme-toggle) .sheet-tabs--state.sheet-tabs--dynamic > a.sheet-link--terminal {
      background: #000000;
      border-color: #141414;
    }
  }
}
/* NOSCRIPT_TOOLBAR_EMBED START */
.noscript-toolbar-embed {
  position: relative;
  width: 230px;
  height: 32px;
}

.noscript-toolbar-overlay {
  position: absolute;
  inset: 0;
  width: 230px;
  height: 32px;
  display: block;
  pointer-events: none;
  z-index: 3;
}

.noscript-toolbar-overlay path {
  fill: rgba(255, 255, 255, 0.12);
  fill-rule: evenodd;
}

html.no-js.has-theme-toggle .noscript-toolbar-embed {
  background: #000000;
}

html.no-js.has-theme-toggle .spreadsheet-container:has([id^="z"][id$="l"]:target) .noscript-toolbar-embed {
  background: var(--color-cream-100);
}

html.no-js.has-theme-toggle .spreadsheet-container:has([id^="z"][id$="l"]:target) .noscript-toolbar-overlay {
  opacity: 0;
}

.noscript-toolbar-frame {
  position: absolute;
  inset: 0;
  width: 230px;
  height: 32px;
  border: none;
  background: transparent;
  display: none;
  overflow: hidden;
  z-index: 0;
}

/* Keep iframes hidden in text UAs that don't support modern feature queries (e.g. cha). */
@supports (display: grid) and (selector(:has(*))) and (container-type: inline-size) {
  html.no-js.has-theme-toggle .noscript-toolbar-frame {
    display: block !important;
    opacity: 0;
    pointer-events: none;
  }

  html.no-js.has-theme-toggle .noscript-toolbar-frame#toolbar-z100d {
    z-index: 1 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has([id^="z"][id$="l"]:target) .noscript-toolbar-frame#toolbar-z100d {
    opacity: 0;
    pointer-events: none;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has([id^="z"][id$="l"]:target) .noscript-toolbar-frame#toolbar-z100l {
    z-index: 1 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z50d:target) .noscript-toolbar-frame#toolbar-z50d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z50l:target) .noscript-toolbar-frame#toolbar-z50l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z60d:target) .noscript-toolbar-frame#toolbar-z60d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z60l:target) .noscript-toolbar-frame#toolbar-z60l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z70d:target) .noscript-toolbar-frame#toolbar-z70d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z70l:target) .noscript-toolbar-frame#toolbar-z70l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z80d:target) .noscript-toolbar-frame#toolbar-z80d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z80l:target) .noscript-toolbar-frame#toolbar-z80l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z90d:target) .noscript-toolbar-frame#toolbar-z90d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z90l:target) .noscript-toolbar-frame#toolbar-z90l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z100d:target) .noscript-toolbar-frame#toolbar-z100d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z100l:target) .noscript-toolbar-frame#toolbar-z100l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z110d:target) .noscript-toolbar-frame#toolbar-z110d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z110l:target) .noscript-toolbar-frame#toolbar-z110l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z120d:target) .noscript-toolbar-frame#toolbar-z120d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z120l:target) .noscript-toolbar-frame#toolbar-z120l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z130d:target) .noscript-toolbar-frame#toolbar-z130d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z130l:target) .noscript-toolbar-frame#toolbar-z130l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z140d:target) .noscript-toolbar-frame#toolbar-z140d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z140l:target) .noscript-toolbar-frame#toolbar-z140l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z150d:target) .noscript-toolbar-frame#toolbar-z150d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z150l:target) .noscript-toolbar-frame#toolbar-z150l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z160d:target) .noscript-toolbar-frame#toolbar-z160d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z160l:target) .noscript-toolbar-frame#toolbar-z160l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z170d:target) .noscript-toolbar-frame#toolbar-z170d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z170l:target) .noscript-toolbar-frame#toolbar-z170l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z180d:target) .noscript-toolbar-frame#toolbar-z180d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z180l:target) .noscript-toolbar-frame#toolbar-z180l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z190d:target) .noscript-toolbar-frame#toolbar-z190d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z190l:target) .noscript-toolbar-frame#toolbar-z190l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z200d:target) .noscript-toolbar-frame#toolbar-z200d {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }

  html.no-js.has-theme-toggle .spreadsheet-container:has(#z200l:target) .noscript-toolbar-frame#toolbar-z200l {
    z-index: 2 !important;
    opacity: 1;
    pointer-events: auto;
  }
}

/* NOSCRIPT_TOOLBAR_EMBED END */
