:root {
  --bg: #f3efe8;
  --bg-alt: #dfe9f0;
  --panel: #fffdf8;
  --line: #d6dde8;
  --line-dark: #a3b0c5;
  --ink: #1f2937;
  --muted: #627085;
  --brand: #1a7f64;
  --brand-2: #0f5e4a;
  --accent: #d97706;
  --focus: #3b82f6;
  --danger: #c2410c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  background: #edf3f6;
  min-height: 100vh;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  gap: 12px;
  animation: appFadeIn 320ms ease-out;
}

@keyframes appFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: 0 12px 28px rgba(31, 41, 55, 0.1);
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  background: var(--brand);
}

.brand-wrap h1 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.01em;
}

.brand-wrap p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.action-cluster {
  display: flex;
  gap: 8px;
  padding: 6px;
  border: 1px solid #dde6f3;
  background: #f6f9ff;
  border-radius: 12px;
  transition: box-shadow 140ms ease, border-color 140ms ease;
}

.action-cluster:hover {
  border-color: #c6d5ed;
  box-shadow: 0 6px 14px rgba(30, 58, 138, 0.08);
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  border: 1px solid #c8d5ea;
  background: #edf4ff;
  color: #1e3a8a;
  font-weight: 600;
  font-size: 0.78rem;
  padding: 6px 10px;
}

.shortcut-hint {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  border: 1px solid #b9c7dc;
  color: #334155;
  background: #ffffff;
}

.btn {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  padding: 8px 12px;
  transition: transform 120ms ease, box-shadow 120ms ease, background 160ms ease, border-color 160ms ease;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
[role="tab"]:focus-visible,
[role="menuitem"]:focus-visible {
  outline: 3px solid #1d4ed8;
  outline-offset: 2px;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(26, 127, 100, 0.28);
}

.btn.ghost {
  background: #f2f7fb;
  color: var(--ink);
  border-color: var(--line-dark);
}

.btn.ghost:hover {
  background: #e8f1ff;
}

.btn.tool {
  min-width: 44px;
  padding: 7px 10px;
}

.btn.small {
  font-size: 0.8rem;
  padding: 6px 10px;
}

.underline {
  text-decoration: underline;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fffefb;
  padding: 12px;
  animation: panelRise 380ms ease-out;
}

@keyframes panelRise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid #d9e3f1;
  border-radius: 10px;
  background: #ffffff;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.tool-group:hover {
  border-color: #c8d7eb;
  box-shadow: 0 5px 12px rgba(30, 58, 138, 0.07);
}

.toolbar-overflow-wrap {
  display: none;
  position: relative;
}

.toolbar-overflow-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 60;
  min-width: 180px;
  border-radius: 10px;
  border: 1px solid #c8d7eb;
  background: #ffffff;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.16);
  padding: 8px;
  display: grid;
  gap: 6px;
}

.select,
.text-input,
.small-input {
  border: 1px solid var(--line-dark);
  border-radius: 8px;
  height: 32px;
  padding: 4px 8px;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  background: #fff;
}

.small-input {
  width: 60px;
}

.swatch-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.85rem;
  color: var(--muted);
}

.swatch-label input[type="color"] {
  width: 26px;
  height: 26px;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.formula-wrap {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  align-items: stretch;
}

.name-box {
  border: 1px solid var(--line-dark);
  border-radius: 10px;
  background: var(--panel);
  display: grid;
  place-items: center;
  font-weight: 700;
}

.name-input {
  text-align: center;
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 0.9rem;
  min-height: 44px;
}

.formula-stack {
  position: relative;
}

.formula-highlight,
.formula-input {
  width: 100%;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line-dark);
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 0.93rem;
  line-height: 1.25;
  padding: 10px 12px;
}

.formula-highlight {
  position: absolute;
  inset: 0;
  pointer-events: none;
  white-space: pre;
  overflow: hidden;
  color: #111827;
  background: #ffffff;
}

.formula-highlight .fx {
  color: #2563eb;
  font-weight: 600;
}

.formula-highlight .ref {
  color: #7c3aed;
}

.formula-input {
  position: relative;
  background: transparent;
  color: transparent;
  caret-color: #111827;
}

.formula-input:focus {
  outline: 2px solid rgba(59, 130, 246, 0.3);
  border-color: var(--focus);
}

.sheet-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: #fffefb;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  position: relative;
}

.sheet-grid-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.sheet-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: auto;
  max-width: 620px;
}

.sheet-menu-panel {
  position: absolute;
  right: 116px;
  top: calc(100% - 2px);
  z-index: 50;
  border: 1px solid #cdd8eb;
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 12px 22px rgba(15, 23, 42, 0.14);
  padding: 8px;
  display: grid;
  gap: 6px;
  max-width: 280px;
  max-height: 220px;
  overflow: auto;
}

.sheet-menu-item {
  width: 100%;
  text-align: left;
}

.sheet-tab {
  border: 1px solid #d1dcec;
  background: #f5f8fc;
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 150ms ease;
}

.sheet-tab.active {
  border-color: #1a7f64;
  background: #e8f7f2;
  color: #0f5e4a;
  box-shadow: 0 6px 14px rgba(26, 127, 100, 0.2);
}

.sheet-tab:hover {
  transform: translateY(-1px);
}

.btn.tool.active-tool {
  border-color: #14532d;
  background: #1b8f70;
  box-shadow: 0 6px 16px rgba(20, 83, 45, 0.32);
}

.sheet-tab button {
  border: none;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  padding: 0;
}

.grid-wrap {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  height: 62vh;
}

.sheet-table {
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 1200px;
  width: max-content;
}

.sheet-table th,
.sheet-table td {
  border: 1px solid var(--line);
  min-width: 112px;
  height: 30px;
  padding: 5px 7px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  position: relative;
}

.sheet-table th {
  background: #f4f7fb;
  text-align: center;
  font-weight: 700;
  color: #374151;
  user-select: none;
}

.sheet-table th.corner {
  position: sticky;
  left: 0;
  top: 0;
  z-index: 12;
  min-width: 44px;
  width: 44px;
}

.sheet-table th.row-header {
  position: sticky;
  left: 0;
  z-index: 11;
  min-width: 44px;
  width: 44px;
  background: #eef2f7;
}

.sheet-table th.col-header {
  position: sticky;
  top: 0;
  z-index: 10;
}

.sheet-table td {
  background: #fff;
}

.sheet-table td.selected {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
  background: #eef5ff;
}

.sheet-table td.active {
  outline: 2px solid #2563eb;
  outline-offset: -2px;
  z-index: 2;
}

.sheet-table td.invalid {
  box-shadow: inset 0 0 0 2px #ef4444;
}

.sheet-table td[contenteditable="true"]:focus {
  background: #fff;
}

.fill-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #2563eb;
  border: 1px solid #fff;
  border-radius: 2px;
  display: none;
  z-index: 30;
  pointer-events: auto;
  cursor: crosshair;
}

.context-menu {
  position: fixed;
  z-index: 90;
  border: 1px solid var(--line-dark);
  border-radius: 10px;
  padding: 4px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.context-menu button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 7px 12px;
  border-radius: 7px;
  cursor: pointer;
}

.context-menu button:hover {
  background: #f0f5ff;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.48);
  display: grid;
  place-items: center;
  z-index: 100;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  width: min(860px, 92vw);
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 12px;
}

.command-palette-content {
  width: min(680px, 94vw);
}

.command-palette-input {
  width: 100%;
  margin-bottom: 10px;
}

.command-palette-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid #d9e3f1;
  border-radius: 10px;
  overflow: hidden;
  max-height: 340px;
  overflow-y: auto;
}

.command-palette-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid #eef2f7;
  background: #ffffff;
  padding: 10px 12px;
  cursor: pointer;
  text-align: left;
}

.command-palette-item:hover,
.command-palette-item.active {
  background: #eff6ff;
}

.command-palette-item:last-child {
  border-bottom: 0;
}

.command-palette-shortcut {
  color: #475569;
  font-size: 0.76rem;
  border: 1px solid #c7d4e7;
  border-radius: 999px;
  padding: 1px 6px;
}

.self-fix-modal-content {
  max-height: 84vh;
  overflow: auto;
}

.self-fix-summary {
  margin: 8px 0 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f6f9ff;
  border: 1px solid #dbe7ff;
  color: #1e3a8a;
  font-weight: 500;
}

.self-fix-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(210px, 1fr));
  gap: 8px 12px;
  margin-bottom: 12px;
}

.self-fix-list {
  margin: 0;
  padding-left: 20px;
  max-height: 220px;
  overflow: auto;
}

.self-fix-list li {
  margin: 3px 0;
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 0.86rem;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

canvas#chartCanvas {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.hidden-row {
  display: none;
}

@media (max-width: 980px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .action-cluster {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .grid-wrap {
    height: 58vh;
  }

  .self-fix-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1199px) {
  .tool-group.low-priority {
    display: none;
  }

  .toolbar-overflow-wrap {
    display: block;
    margin-left: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* Navigation redesign from scratch */
:root {
  --nav-surface: #ffffff;
  --nav-subtle: #f6f9ff;
  --nav-line: #d8e2f1;
  --nav-ink: #0f172a;
  --nav-muted: #51627b;
  --nav-accent: #0f766e;
  --nav-accent-2: #155e75;
}

body {
  background: #edf3f6;
}

.app-shell {
  max-width: 1420px;
  gap: 14px;
}

.nav-shell {
  border: 1px solid var(--nav-line);
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.08);
  overflow: hidden;
}

.nav-upper {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
  padding: 10px 14px;
}

.brand-wrap {
  min-width: 228px;
}

.brand-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--nav-accent);
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.25);
}

.brand-wrap h1 {
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}

.brand-wrap p {
  color: var(--nav-muted);
  font-size: 0.78rem;
}

.command-launch {
  flex: 1 1 280px;
  min-width: 240px;
  max-width: 560px;
  width: 100%;
  border: 1px solid #c8d6eb;
  border-radius: 12px;
  background: #f2f7ff;
  color: #1e293b;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.command-launch:hover {
  border-color: #9db5d8;
  box-shadow: 0 8px 16px rgba(30, 58, 138, 0.12);
  transform: translateY(-1px);
}

.topbar-meta {
  gap: 6px;
  flex-wrap: nowrap;
}

.meta-pill {
  border-color: #b9cae6;
  background: #eaf1fb;
  color: #1d3b72;
}

.topbar-actions {
  flex: 1 1 420px;
  justify-content: flex-end;
  gap: 6px;
}

.action-cluster {
  border: 1px solid #d4e0f1;
  background: #f5f9ff;
  border-radius: 12px;
  padding: 4px;
  gap: 6px;
}

.topbar-actions .btn {
  padding: 6px 9px;
  font-size: 0.8rem;
}

.topbar-actions .shortcut-hint {
  margin-left: 4px;
  padding: 1px 5px;
}

.shortcut-hint {
  background: #ffffff;
}

.nav-ribbon {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  border-top: 1px solid #e2e8f4;
  padding: 8px 14px 10px;
  background: #f8fafc;
}

.ribbon-tab-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  overflow-x: auto;
}

.ribbon-tab {
  border: 1px solid #cad8ed;
  border-radius: 999px;
  background: #f2f6fc;
  color: #1f2937;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  padding: 7px 14px;
  cursor: pointer;
  transition: all 140ms ease;
}

.ribbon-tab:hover {
  transform: translateY(-1px);
  border-color: #9fb4d6;
}

.ribbon-tab.active {
  border-color: #176b63;
  background: #dff5ef;
  color: #0f5e4a;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.22);
}

.toolbar {
  flex: 1 1 620px;
  min-width: 360px;
  border: 1px solid #d5deeb;
  border-radius: 14px;
  background: #ffffff;
  padding: 8px;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.tool-group {
  flex: 0 0 auto;
  border: 1px solid #d8e2f0;
  background: #ffffff;
  border-radius: 10px;
  padding: 7px 9px;
}

.tool-group:hover {
  box-shadow: 0 5px 12px rgba(30, 64, 175, 0.08);
}

.ribbon-hidden {
  display: none !important;
}

.toolbar-overflow-wrap {
  margin-left: 0;
}

.toolbar-overflow-panel {
  top: calc(100% + 6px);
}

.formula-wrap {
  padding: 0 14px 14px;
  gap: 8px;
}

.name-input {
  border: 1px solid #c3d1e6;
  background: #f4f8ff;
  color: #0f172a;
  font-weight: 700;
  min-height: 42px;
}

.formula-highlight,
.formula-input {
  border-color: #c3d1e6;
  min-height: 42px;
}

.sheet-controls {
  border: 1px solid #d4dfef;
  background: #f6faff;
  border-radius: 16px;
  padding: 10px;
}

.sheet-controls-main {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  width: 100%;
  flex-wrap: wrap;
}

.sheet-grid-actions {
  padding: 6px;
  border: 1px solid #d8e2f0;
  border-radius: 12px;
  background: #f8fbff;
}

.sheet-navigator {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}

.sheet-tabs {
  max-width: 720px;
  padding: 2px 1px;
}

.sheet-tab {
  border-radius: 999px;
  border: 1px solid #cfdaea;
  background: #f4f8fd;
  padding: 6px 12px;
}

.sheet-tab.active {
  border-color: #0f766e;
  box-shadow: 0 6px 14px rgba(15, 118, 110, 0.2);
}

.sheet-menu-panel {
  top: calc(100% + 8px);
  right: 10px;
  width: min(320px, calc(100% - 20px));
}

.grid-wrap {
  border-radius: 14px;
}

@media (max-width: 1280px) {
  .nav-upper {
    gap: 8px;
  }

  .topbar-meta {
    order: 3;
  }

  .topbar-actions {
    order: 4;
    flex-basis: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 1080px) {
  .command-launch {
    max-width: none;
    flex-basis: 100%;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .action-cluster {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .sheet-tabs {
    max-width: 520px;
  }
}

@media (max-width: 900px) {
  .tool-group.low-priority {
    display: none;
  }

  .toolbar-overflow-wrap {
    display: block;
  }

  .sheet-grid-actions {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .command-launch:hover,
  .ribbon-tab:hover,
  .btn:hover,
  .tool-group:hover,
  .sheet-tab:hover {
    transform: none;
  }
}

/* Responsive navigation system */
:root {
  --nav-height: 64px;
  --nav-surface-strong: #0f172a;
  --nav-surface-mid: #172554;
  --nav-highlight: #f59e0b;
  --nav-border: rgba(148, 163, 184, 0.28);
  --nav-soft-border: #d7e1ee;
}

[hidden] {
  display: none !important;
}

.app-shell {
  max-width: 1480px;
  padding: 16px 20px 24px;
  gap: 12px;
}

.nav-shell {
  border: 1px solid var(--nav-border);
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.12);
}

.nav-upper {
  min-height: var(--nav-height);
  padding: 10px 14px;
  gap: 10px 16px;
  background: var(--nav-surface-strong);
}

.brand-wrap {
  min-width: 220px;
  gap: 10px;
}

.brand-badge {
  width: 40px;
  height: 40px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 11px;
  background: #ea580c;
  box-shadow: 0 7px 18px rgba(245, 158, 11, 0.28);
}

.brand-wrap h1,
.brand-wrap p {
  color: #ffffff;
}

.brand-wrap h1 {
  font-size: 1rem;
  letter-spacing: 0;
}

.brand-wrap p {
  color: #cbd5e1;
}

.command-launch {
  flex: 1 1 300px;
  max-width: 520px;
  min-height: 40px;
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.command-launch:hover {
  border-color: rgba(245, 158, 11, 0.8);
  background: rgba(255, 255, 255, 0.16);
  box-shadow: 0 8px 20px rgba(2, 6, 23, 0.22);
}

.shortcut-hint {
  border-color: rgba(148, 163, 184, 0.45);
  background: rgba(15, 23, 42, 0.45);
  color: #f8fafc;
}

.topbar-meta {
  margin-left: auto;
  gap: 6px;
}

.meta-pill {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
  white-space: nowrap;
}

.topbar-actions {
  flex: 0 1 auto;
  gap: 6px;
}

.action-cluster {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
}

.topbar-actions .btn.ghost {
  border-color: rgba(255, 255, 255, 0.18);
  background: transparent;
  color: #e2e8f0;
}

.topbar-actions .btn.ghost:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.nav-ribbon {
  align-items: stretch;
  gap: 12px;
  padding: 8px 14px;
  border-top-color: var(--nav-soft-border);
  background: #f8fafc;
}

.ribbon-tab-strip {
  flex: 0 0 auto;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--nav-soft-border);
  border-radius: 11px;
  background: #eef3f8;
}

.ribbon-tab {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #475569;
  padding: 8px 14px;
}

.ribbon-tab:hover {
  background: #ffffff;
  color: #0f172a;
  transform: none;
}

.ribbon-tab.active {
  border: 0;
  background: #ffffff;
  color: #0f766e;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.toolbar {
  min-width: 0;
  padding: 5px;
  border: 1px solid var(--nav-soft-border);
  border-radius: 11px;
  background: #ffffff;
  box-shadow: inset 0 1px 0 #ffffff;
}

.tool-group {
  border-color: #e1e8f1;
  border-radius: 8px;
  padding: 5px 7px;
  box-shadow: none;
}

.tool-group:hover {
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.btn,
.select,
.text-input,
.small-input {
  min-height: 34px;
}

.sheet-controls {
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
}

.sheet-grid-actions {
  border-color: var(--nav-soft-border);
  background: #f8fafc;
}

.sheet-tab {
  border-radius: 8px;
}

.sheet-tab.active {
  background: #e6f7f3;
  color: #075e54;
}

@media (max-width: 1100px) {
  .nav-upper {
    align-items: center;
  }

  .brand-wrap {
    min-width: 190px;
  }

  .topbar-meta {
    order: 3;
    flex-basis: auto;
    margin-left: 0;
  }

  .topbar-actions {
    order: 4;
    margin-left: auto;
  }
}

@media (min-width: 768px) {
  html,
  body {
    height: 100%;
  }

  body {
    overflow: hidden;
  }

  .app-shell {
    width: 100%;
    max-width: none;
    height: 100vh;
    min-height: 100vh;
    margin: 0;
    padding: 0;
    gap: 0;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
  }

  .nav-shell,
  .sheet-controls,
  .grid-wrap {
    border-radius: 0;
  }

  .grid-wrap {
    height: auto;
    min-height: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }
}

.workbook-statusbar {
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 12px;
  border-top: 1px solid #cbd5e1;
  background: #e2e8f0;
  color: #475569;
  font-size: 0.74rem;
  font-family: "IBM Plex Mono", Consolas, monospace;
}

.statusbar-item {
  white-space: nowrap;
}

.statusbar-ready {
  color: #0f766e;
  font-weight: 600;
}

.statusbar-spacer {
  flex: 1;
}

.statusbar-zoom {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #334155;
  font-weight: 600;
}

.statusbar-zoom-btn {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid #b8c6d8;
  border-radius: 5px;
  background: #f8fafc;
  color: #334155;
  cursor: pointer;
  line-height: 1;
}

.statusbar-zoom-btn:hover {
  border-color: #0f766e;
  color: #0f766e;
}

.find-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px 10px;
  border-top: 1px solid #e2e8f0;
  background: #ffffff;
}

.find-label {
  color: #475569;
  font-size: 0.78rem;
  font-weight: 700;
}

.find-bar .text-input {
  flex: 1 1 260px;
  max-width: 460px;
}

.find-count {
  min-width: 70px;
  color: #64748b;
  font: 0.72rem "IBM Plex Mono", Consolas, monospace;
}

.sheet-table td.find-match {
  box-shadow: inset 0 0 0 2px #f59e0b;
  background: #fff7df;
}

.sheet-table td.active.find-match {
  box-shadow: inset 0 0 0 2px #ea580c;
}


/* Production polish additions */
.status-dirty {
  color: #b45309 !important;
  font-weight: 700;
}

.self-fix-grid {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.sheet-table td.invalid {
  background: #fff1f2 !important;
}

/* Better focus for accessibility */
.sheet-table td:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: -2px;
  z-index: 5;
}

/* Smooth status transitions */
.statusbar-item {
  transition: color 180ms ease;
}

/* Disabled controls (e.g. Undo/Redo with nothing to do) */
.btn:disabled,
.btn:disabled:hover {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
