/* ==========================================================================
   TRAX SHEET — THE EXCEL KILLER
   Ultra-Responsive Formula Bar, High Performance Grid, Realtime Calculation
   ========================================================================== */

.sheet-top-controls {
  display: flex;
  flex-direction: column;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  user-select: none;
}

.sheet-ribbon {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto;
}

.sheet-tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 28px;
  padding: 0 8px;
  background: var(--bg-primary);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.sheet-tool-btn svg {
  width: 14px;
  height: 14px;
}

.sheet-tool-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent-blue);
}

.btn-benchmark {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.15), rgba(37, 99, 235, 0.2)) !important;
  border-color: var(--accent-cyan) !important;
  color: var(--accent-cyan) !important;
}

.btn-benchmark:hover {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.3), rgba(37, 99, 235, 0.35)) !important;
}

/* Formula Bar */
.formula-bar-container {
  display: flex;
  align-items: center;
  height: 36px;
  padding: 0 10px;
  gap: 8px;
  background-color: var(--bg-secondary);
}

.active-cell-box {
  width: 90px;
  height: 26px;
  text-align: center;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-cyan);
  outline: none;
  text-transform: uppercase;
}

.active-cell-box:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 1px var(--accent-blue);
}

.formula-fx-icon {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-muted);
  user-select: none;
  cursor: pointer;
}

#sheet-formula-input {
  flex: 1;
  height: 26px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0 10px;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
}

#sheet-formula-input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 1px var(--accent-blue);
}

/* Grid Wrapper & High-Performance Virtualized Table */
.sheet-grid-wrapper {
  flex: 1;
  overflow: auto;
  position: relative;
  background-color: var(--bg-primary);
}

.sheet-virtual-spacer {
  position: relative;
  min-width: 100%;
}

.trax-grid-table {
  position: sticky;
  top: 0;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  background-color: var(--bg-secondary);
  font-size: 13px;
}

/* Sticky Headers */
.trax-grid-table th {
  background-color: var(--bg-secondary);
  color: var(--text-muted);
  font-weight: 600;
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  text-align: center;
  user-select: none;
  position: sticky;
  top: 0;
  z-index: 20;
}

/* The Top-Left Corner Box */
.grid-corner-cell {
  width: 70px;
  min-width: 70px;
  height: 26px;
  left: 0;
  z-index: 30 !important;
  background-color: var(--bg-tertiary) !important;
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
}

/* Column Header (A, B, C...) */
.col-header-cell {
  height: 26px;
  min-width: 100px;
  max-width: 100px;
  font-size: 11px;
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
  background-color: var(--bg-secondary);
  transition: background-color 0.1s;
}

.col-header-cell.active-col {
  background-color: var(--bg-hover) !important;
  color: var(--accent-blue);
  font-weight: 800;
}

/* Row Header (1, 2, 3...) */
.row-header-cell {
  width: 70px;
  min-width: 70px;
  background-color: var(--bg-secondary);
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font-mono);
  text-align: center;
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  left: 0;
  z-index: 10;
  user-select: none;
}

.row-header-cell.active-row {
  background-color: var(--bg-hover) !important;
  color: var(--accent-blue);
  font-weight: 800;
}

/* Data Cells */
.grid-cell {
  height: 25px;
  min-width: 100px;
  max-width: 100px;
  border-right: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 6px;
  background-color: var(--bg-secondary);
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  outline: none;
  cursor: cell;
  font-size: 12px;
}

/* Selected Active Cell (Sleek Blue Outline) */
.grid-cell.selected {
  outline: 2px solid var(--accent-blue);
  outline-offset: -2px;
  z-index: 5;
  position: relative;
  background-color: rgba(59, 130, 246, 0.08) !important;
}

/* Range Selection */
.grid-cell.in-range {
  background-color: rgba(59, 130, 246, 0.16) !important;
}

.grid-cell.cell-bordered {
  border: 1px solid var(--text-muted) !important;
}

/* Cell alignment helpers */
.align-left { text-align: left; }
.align-center { text-align: center; }
.align-right { text-align: right; }
.font-bold { font-weight: 700; }
.font-italic { font-style: italic; }

/* Status Bar & Instant Calculators */
.sheet-statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 30px;
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 0 12px;
  font-size: 11px;
  color: var(--text-muted);
  user-select: none;
  flex-shrink: 0;
}

.sheet-status-left, .sheet-status-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sheet-tabs-container {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  max-width: 48vw;
}

.sheet-tab-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.sheet-tab-pill:hover {
  color: var(--text-main);
  border-color: var(--text-muted);
}

.sheet-tab-pill.active {
  background: var(--bg-tertiary);
  color: var(--text-main);
  border-color: var(--accent-blue);
}

.sheet-tab-close {
  margin-left: 4px;
  font-size: 13px;
  line-height: 1;
  color: var(--text-faint);
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0 2px;
}

.sheet-tab-close:hover {
  color: var(--accent-rose);
}

.sheet-capacity-badge b {
  color: var(--accent-green) !important;
}

.sheet-tab-pill svg {
  width: 12px;
  height: 12px;
  color: var(--accent-green);
}

.sheet-add-tab-btn {
  background: transparent;
  border: 1px dashed var(--border-color);
  border-radius: 4px;
  color: var(--text-muted);
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.sheet-add-tab-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.calc-metric {
  font-family: var(--font-mono);
  background: var(--bg-primary);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.calc-metric b {
  color: var(--accent-cyan);
}
