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

body {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100vh;
  font-family: Tahoma, Verdana, sans-serif;
  font-size: 11px;
}

/* ==== Quick Access Toolbar ==== */
.qat {
  display: flex;
  align-items: center;
  padding: 1px 4px;
  background: var(--sz-color-active-title);
  gap: 1px;
  flex-shrink: 0;
  min-height: 20px;
}

.qat-btn {
  width: 20px;
  height: 18px;
  border: none;
  background: transparent;
  cursor: default;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  color: var(--sz-color-title-text);
  border-radius: 2px;
  padding: 0;
}

.qat-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.qat-btn:active {
  background: rgba(0, 0, 0, 0.15);
}

/* ==== Backstage (File menu) ==== */
.backstage {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5000;
  background: rgba(0, 0, 0, 0.3);
}

.backstage.visible {
  display: flex;
}

.backstage-sidebar {
  width: 220px;
  background: var(--sz-color-highlight);
  display: flex;
  flex-direction: column;
  padding: 4px 0;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3);
}

.backstage-back {
  border: none;
  background: transparent;
  color: var(--sz-color-highlight-text);
  font-size: 18px;
  padding: 8px 16px;
  text-align: left;
  cursor: default;
}

.backstage-back:hover {
  background: rgba(255, 255, 255, 0.15);
}

.backstage-item {
  border: none;
  background: transparent;
  color: var(--sz-color-highlight-text);
  font-size: 12px;
  padding: 8px 24px;
  text-align: left;
  cursor: default;
  width: 100%;
}

.backstage-item:hover {
  background: rgba(255, 255, 255, 0.15);
}

.backstage-sep {
  height: 1px;
  background: rgba(255, 255, 255, 0.2);
  margin: 4px 12px;
}

.backstage-spacer {
  flex: 1;
}

.backstage-exit {
  margin-top: auto;
}

/* ==== Ribbon Tab Bar ==== */
.ribbon-tabs {
  flex-shrink: 0;
  background: var(--sz-color-button-face);
  border-bottom: 1px solid var(--sz-color-button-shadow);
}

.ribbon-tab-bar {
  display: flex;
  align-items: flex-end;
  padding: 0 2px;
  gap: 0;
}

.ribbon-file-btn {
  padding: 4px 14px;
  font-size: 11px;
  font-weight: bold;
  border: none;
  background: var(--sz-color-highlight);
  color: var(--sz-color-highlight-text);
  cursor: default;
  border-radius: 3px 3px 0 0;
  margin-right: 2px;
}

.ribbon-file-btn:hover {
  filter: brightness(1.1);
}

.ribbon-tab {
  padding: 4px 12px;
  font-size: 11px;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  color: var(--sz-color-button-text);
  cursor: default;
  border-radius: 3px 3px 0 0;
  position: relative;
  top: 1px;
}

.ribbon-tab:hover {
  background: var(--sz-color-button-highlight);
  border-color: var(--sz-color-button-shadow);
}

.ribbon-tab.active {
  background: var(--sz-color-window);
  border-color: var(--sz-color-button-shadow);
  color: var(--sz-color-window-text);
  font-weight: bold;
}

/* ==== Ribbon Panels ==== */
.ribbon-panel {
  display: none;
  flex-direction: row;
  align-items: stretch;
  padding: 2px 4px 0;
  background: var(--sz-color-window);
  border-bottom: 1px solid var(--sz-color-button-shadow);
  flex-shrink: 0;
  min-height: 82px;
  overflow-x: auto;
  overflow-y: hidden;
  user-select: none;
}

.ribbon-panel.active {
  display: flex;
}

.ribbon-panel::-webkit-scrollbar {
  height: 4px;
}

.ribbon-panel::-webkit-scrollbar-thumb {
  background: var(--sz-color-button-shadow);
  border-radius: 2px;
}

/* ==== Ribbon Groups ==== */
.ribbon-group {
  display: flex;
  flex-direction: column;
  padding: 2px 4px 0;
  min-width: 0;
  flex-shrink: 0;
}

.ribbon-group-content {
  display: flex;
  align-items: flex-start;
  gap: 2px;
  flex: 1;
  min-height: 0;
}

.ribbon-group-label {
  text-align: center;
  font-size: 9px;
  color: var(--sz-color-gray-text);
  padding: 1px 4px 2px;
  white-space: nowrap;
  border-top: 1px solid var(--sz-color-button-light, transparent);
}

.ribbon-sep {
  width: 1px;
  background: var(--sz-color-button-shadow);
  margin: 2px 3px;
  align-self: stretch;
  flex-shrink: 0;
  opacity: 0.4;
}

/* ==== Ribbon Buttons ==== */
.rb-btn {
  border: 1px solid transparent;
  background: transparent;
  cursor: default;
  color: var(--sz-color-button-text);
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 3px;
  border-radius: 2px;
  white-space: nowrap;
}

.rb-btn:hover {
  background: var(--sz-color-button-highlight);
  border-color: var(--sz-color-button-shadow);
}

.rb-btn:active {
  background: var(--sz-color-button-shadow);
}

.rb-btn.active {
  background: var(--sz-color-highlight);
  color: var(--sz-color-highlight-text);
  border-color: var(--sz-color-button-shadow);
}

.rb-btn-lg {
  flex-direction: column;
  padding: 4px 8px;
  min-width: 44px;
  height: 100%;
  gap: 2px;
}

.rb-btn-lg .rb-icon-lg {
  font-size: 20px;
  line-height: 1;
}

.rb-btn-lg .rb-label {
  font-size: 9px;
}

.rb-btn-sm {
  gap: 4px;
  padding: 1px 4px;
  min-height: 20px;
  justify-content: flex-start;
}

.rb-btn-sm .rb-icon {
  font-size: 12px;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.rb-btn-sm .rb-label {
  font-size: 10px;
}

.rb-fmt {
  min-width: 22px;
  height: 22px;
  padding: 0 3px;
  font-size: 12px;
  line-height: 22px;
}

.rb-stack {
  display: flex;
  flex-direction: column;
  gap: 1px;
  justify-content: flex-start;
}

.rb-row {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: nowrap;
}

.rb-sep-v {
  width: 1px;
  height: 18px;
  background: var(--sz-color-button-shadow);
  margin: 0 2px;
  opacity: 0.3;
  flex-shrink: 0;
}

/* ==== Ribbon Selects ==== */
.rb-select {
  height: 22px;
  padding: 1px 4px;
  font-size: 11px;
  border: 1px solid var(--sz-color-button-shadow);
  background: var(--sz-color-window);
  color: var(--sz-color-window-text);
  cursor: default;
  border-radius: 2px;
}

.rb-font-family {
  width: 120px;
}

.rb-font-size {
  width: 52px;
}

.rb-numfmt-select {
  width: 120px;
}

.rb-font-group {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

/* ==== Color button ==== */
.rb-color-btn {
  position: relative;
  padding-bottom: 5px !important;
}

.rb-color-btn .rb-color-ind {
  position: absolute;
  bottom: 1px;
  left: 3px;
  right: 3px;
  height: 3px;
}

/* ==== Formula bar ==== */
.formula-bar {
  display: flex;
  align-items: center;
  padding: 2px 4px;
  background: var(--sz-color-button-face);
  border-bottom: 1px solid var(--sz-color-button-shadow);
  flex-shrink: 0;
  gap: 4px;
}

.cell-ref {
  width: 72px;
  padding: 1px 4px;
  background: var(--sz-color-window);
  font-size: 11px;
  font-family: inherit;
  text-align: center;
  flex-shrink: 0;
  border: 1px solid var(--sz-color-button-shadow);
}

.formula-separator {
  width: 1px;
  height: 18px;
  background: var(--sz-color-button-shadow);
  flex-shrink: 0;
}

.formula-fx {
  border: 1px solid transparent;
  background: transparent;
  cursor: default;
  font-size: 11px;
  padding: 1px 4px;
  color: var(--sz-color-button-text);
  flex-shrink: 0;
}

.formula-fx:hover {
  border-color: var(--sz-color-button-shadow);
  background: var(--sz-color-button-light);
}

.formula-input {
  flex: 1;
  padding: 1px 4px;
  background: var(--sz-color-window);
  font-size: 11px;
  font-family: inherit;
  outline: none;
  border: 1px solid var(--sz-color-button-shadow);
}

/* ==== Grid container ==== */
.grid-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.grid-scroll {
  flex: 1;
  overflow: auto;
  position: relative;
}

.grid-table {
  border-collapse: collapse;
  table-layout: fixed;
}

/* ==== Column headers ==== */
.grid-table thead {
  position: sticky;
  top: 0;
  z-index: 3;
}

.grid-table thead th {
  background: var(--sz-color-button-face);
  border: 1px solid var(--sz-color-button-shadow);
  border-top: none;
  padding: 2px 4px;
  font-weight: normal;
  font-size: 11px;
  text-align: center;
  color: var(--sz-color-button-text);
  user-select: none;
  cursor: default;
  position: relative;
  min-width: 64px;
  height: 20px;
  white-space: nowrap;
  overflow: hidden;
}

.grid-table thead th.corner {
  min-width: 40px;
  width: 40px;
  position: sticky;
  left: 0;
  z-index: 4;
}

.grid-table thead th.col-header {
  min-width: 64px;
}

.grid-table thead th.col-header.selected {
  background: var(--sz-color-highlight);
  color: var(--sz-color-highlight-text);
}

.grid-table thead th.col-header.hidden-col {
  width: 4px !important;
  min-width: 4px !important;
  max-width: 4px !important;
  padding: 0;
  overflow: hidden;
  font-size: 0;
}

.grid-table thead th.col-header.filtered::after {
  content: '\25BC';
  font-size: 8px;
  position: absolute;
  right: 2px;
  top: 4px;
  color: var(--sz-color-highlight);
}

.col-resize-handle {
  position: absolute;
  right: -2px;
  top: 0;
  width: 5px;
  height: 100%;
  cursor: col-resize;
  z-index: 5;
}

/* ==== Row headers ==== */
.grid-table tbody td.row-header {
  background: var(--sz-color-button-face);
  border: 1px solid var(--sz-color-button-shadow);
  border-left: none;
  padding: 2px 4px;
  font-size: 11px;
  text-align: center;
  color: var(--sz-color-button-text);
  user-select: none;
  cursor: default;
  position: sticky;
  left: 0;
  z-index: 2;
  width: 40px;
  min-width: 40px;
  white-space: nowrap;
}

.grid-table tbody td.row-header.selected {
  background: var(--sz-color-highlight);
  color: var(--sz-color-highlight-text);
}

.grid-table tbody tr.hidden-row {
  display: none;
}

.row-resize-handle {
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 4px;
  cursor: row-resize;
  z-index: 5;
}

/* ==== Data cells ==== */
.grid-table tbody td.cell {
  border: 1px solid var(--sz-color-button-shadow);
  padding: 1px 3px;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--sz-color-window);
  color: var(--sz-color-window-text);
  cursor: cell;
  height: 20px;
  max-height: 20px;
  position: relative;
}

.grid-table tbody td.cell.wrap-text {
  white-space: pre-wrap;
  word-break: break-all;
  max-height: none;
}

.grid-table tbody td.cell.selected {
  outline: 2px solid var(--sz-color-highlight);
  outline-offset: -1px;
  z-index: 1;
}

.grid-table tbody td.cell.in-range {
  background: rgba(51, 102, 255, 0.12);
}

.grid-table tbody td.cell.editing {
  outline: 2px solid var(--sz-color-highlight);
  outline-offset: -1px;
  padding: 0;
  overflow: visible;
  z-index: 1;
}

.grid-table tbody td.cell.error {
  color: #c00;
}

.grid-table tbody td.cell.merged-hidden {
  display: none;
}

.grid-table tbody td.cell.has-comment::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-top: 6px solid #f00;
}

.grid-table tbody td.cell.has-hyperlink {
  color: var(--sz-color-hot-tracking);
  text-decoration: underline;
  cursor: pointer;
}

/* Fill handle */
.fill-handle {
  position: absolute;
  bottom: -3px;
  right: -3px;
  width: 6px;
  height: 6px;
  background: var(--sz-color-highlight);
  cursor: crosshair;
  z-index: 10;
}

.grid-table tbody td.cell.hidden-col-cell {
  width: 4px !important;
  min-width: 4px !important;
  max-width: 4px !important;
  padding: 0;
  overflow: hidden;
  font-size: 0;
}

/* Freeze pane lines */
.freeze-line-col {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--sz-color-button-dark-shadow);
  z-index: 6;
  pointer-events: none;
}

.freeze-line-row {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--sz-color-button-dark-shadow);
  z-index: 6;
  pointer-events: none;
}

.cell-editor {
  position: absolute;
  top: -1px;
  left: -1px;
  width: calc(100% + 2px);
  min-width: 100%;
  height: calc(100% + 2px);
  border: none;
  outline: none;
  font-size: 11px;
  font-family: inherit;
  padding: 1px 3px;
  background: var(--sz-color-window);
  z-index: 10;
}

/* ==== Bottom bar (sheet tabs + status) ==== */
.bottom-bar {
  display: flex;
  align-items: stretch;
  background: var(--sz-color-button-face);
  border-top: 1px solid var(--sz-color-button-shadow);
  flex-shrink: 0;
  min-height: 24px;
}

.sheet-tabs {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 2px;
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  min-width: 180px;
  max-width: 50%;
  border-right: 1px solid var(--sz-color-button-shadow);
}

.sheet-tab {
  padding: 3px 12px;
  cursor: default;
  font-size: 11px;
  color: var(--sz-color-button-text);
  background: var(--sz-color-button-face);
  border: 1px solid var(--sz-color-button-shadow);
  border-bottom: none;
  white-space: nowrap;
  position: relative;
}

.sheet-tab.active {
  background: var(--sz-color-window);
  font-weight: bold;
  border-bottom: 1px solid var(--sz-color-window);
  margin-bottom: -1px;
}

.sheet-tab:hover:not(.active) {
  background: var(--sz-color-button-light);
}

.sheet-tab .tab-color-bar {
  position: absolute;
  bottom: 0;
  left: 1px;
  right: 1px;
  height: 3px;
}

.sheet-nav-btn {
  min-width: 20px;
  height: 20px;
  border: 1px solid var(--sz-color-button-shadow);
  background: var(--sz-color-button-face);
  cursor: default;
  font-size: 13px;
  color: var(--sz-color-button-text);
  margin-right: 4px;
  flex-shrink: 0;
}

.sheet-nav-btn:hover {
  background: var(--sz-color-button-light);
}

/* ==== Status bar ==== */
.status-bar {
  display: flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--sz-color-button-text);
  flex: 1;
  gap: 16px;
}

.status-bar .status-section {
  white-space: nowrap;
}

.status-spacer {
  flex: 1;
}

/* ==== Dialogs ==== */
.dialog-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3);
  z-index: 5000;
  justify-content: center;
  align-items: center;
}

.dialog-overlay.visible {
  display: flex;
}

.dialog {
  background: var(--sz-color-button-face);
  border: 2px outset var(--sz-color-button-highlight);
  min-width: 300px;
  max-width: 500px;
  box-shadow: 3px 3px 8px rgba(0,0,0,0.3);
}

.dialog-title {
  background: var(--sz-color-highlight);
  color: var(--sz-color-highlight-text);
  padding: 4px 8px;
  font-weight: bold;
  font-size: 11px;
  user-select: none;
}

.dialog-body {
  padding: 12px;
  font-size: 11px;
}

.dialog-body p {
  margin-bottom: 8px;
}

.dialog-body label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}

.dialog-body input[type="text"],
.dialog-body input[type="number"],
.dialog-body select {
  padding: 2px 4px;
  font-size: 11px;
  font-family: inherit;
}

.dialog-body input[type="text"] {
  width: 100%;
}

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding: 8px 12px;
}

.dialog-buttons button {
  min-width: 72px;
  padding: 3px 12px;
  font-size: 11px;
  cursor: default;
}

/* ==== Format Cells tabs ==== */
.fc-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--sz-color-button-shadow);
}

.fc-tab {
  padding: 3px 10px;
  cursor: default;
  font-size: 11px;
  border: 1px solid transparent;
  border-bottom: none;
  margin-bottom: -1px;
}

.fc-tab:hover {
  background: var(--sz-color-button-light);
}

.fc-tab.active {
  background: var(--sz-color-button-face);
  border-color: var(--sz-color-button-shadow);
  border-bottom: 1px solid var(--sz-color-button-face);
  font-weight: bold;
}

.fc-panel {
  display: none;
}

.fc-panel.active {
  display: block;
}

/* ==== Find panel ==== */
.find-panel {
  display: none;
  position: fixed;
  top: 120px;
  right: 4px;
  z-index: 4000;
  background: var(--sz-color-button-face);
  border: 2px outset var(--sz-color-button-highlight);
  box-shadow: 2px 2px 6px rgba(0,0,0,0.25);
  min-width: 320px;
  font-size: 11px;
}

.find-panel.visible {
  display: block;
}

.find-panel-title {
  background: var(--sz-color-highlight);
  color: var(--sz-color-highlight-text);
  padding: 3px 8px;
  font-weight: bold;
  font-size: 11px;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.find-panel-title .fp-close {
  cursor: default;
  padding: 0 4px;
  font-size: 13px;
  line-height: 1;
}

.find-panel-title .fp-close:hover {
  background: rgba(255,255,255,0.2);
}

.find-panel-body {
  padding: 8px;
}

.fp-field {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
  gap: 6px;
}

.fp-field label {
  min-width: 60px;
  text-align: right;
  font-size: 11px;
}

.fp-field input[type="text"],
.fp-field select {
  flex: 1;
  padding: 2px 4px;
  font-size: 11px;
  font-family: inherit;
}

.fp-buttons {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  margin-top: 4px;
}

.fp-buttons button {
  min-width: 72px;
  padding: 3px 8px;
  font-size: 11px;
  cursor: default;
}

.fp-status {
  font-size: 10px;
  color: var(--sz-color-gray-text);
  margin-top: 4px;
  min-height: 14px;
}

/* ==== Color palette popup ==== */
.color-palette {
  display: none;
  position: absolute;
  z-index: 4500;
  background: var(--sz-color-button-face);
  border: 2px outset var(--sz-color-button-highlight);
  padding: 4px;
  box-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.color-palette.visible {
  display: grid;
  grid-template-columns: repeat(8, 16px);
  gap: 2px;
}

.color-swatch {
  width: 16px;
  height: 16px;
  border: 1px solid var(--sz-color-button-shadow);
  cursor: default;
}

.color-swatch:hover {
  border-color: var(--sz-color-window-text);
  outline: 1px solid var(--sz-color-window);
}

/* ==== Cell styles grid ==== */
.cell-styles-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.cell-style-item {
  padding: 6px 10px;
  border: 1px solid var(--sz-color-button-shadow);
  cursor: default;
  text-align: center;
  font-size: 11px;
}

.cell-style-item:hover {
  border-color: var(--sz-color-highlight);
  background: var(--sz-color-button-light);
}

/* ==== Data bars (conditional formatting) ==== */
.cf-data-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  opacity: 0.3;
  z-index: 0;
  pointer-events: none;
}

/* ==== Icon sets (conditional formatting) ==== */
.grid-table tbody td.cell[data-cf-icon]::before {
  content: attr(data-cf-icon);
  margin-right: 4px;
}

/* ==== Table styles grid ==== */
.table-styles-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.table-style-item {
  border: 1px solid var(--sz-color-button-shadow);
  cursor: default;
  font-size: 10px;
  overflow: hidden;
}

.table-style-item:hover {
  border-color: var(--sz-color-highlight);
  box-shadow: 0 0 3px rgba(0,0,0,0.2);
}

.table-style-item .ts-header,
.table-style-item .ts-band {
  padding: 2px 6px;
  border-bottom: 1px solid rgba(0,0,0,0.1);
}

.table-style-item .ts-name {
  padding: 3px 6px;
  text-align: center;
  background: var(--sz-color-button-face);
  font-size: 9px;
}

/* ==== Name Manager table ==== */
.nm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.nm-table th {
  background: var(--sz-color-button-face);
  border: 1px solid var(--sz-color-button-shadow);
  padding: 3px 6px;
  font-weight: bold;
  text-align: left;
  font-size: 10px;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.nm-table td {
  border: 1px solid var(--sz-color-button-shadow);
  padding: 2px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.nm-table tr:hover td {
  background: var(--sz-color-button-light);
}

/* ==== Print styles ==== */
@media print {
  .qat,
  .ribbon-tabs,
  .ribbon-panel,
  .backstage,
  .formula-bar,
  .bottom-bar,
  .find-panel,
  .color-palette,
  .dialog-overlay {
    display: none !important;
  }

  .grid-container {
    overflow: visible;
  }

  .grid-scroll {
    overflow: visible;
  }
}
