/* sheets.css — Spreadsheet styles */

/* Grid layout */
.sheets-editor {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

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

.sheets-formula-bar .cell-ref {
  font-family: "SF Mono", monospace;
  font-size: 0.875rem;
  min-width: 60px;
  padding: var(--space-1) var(--space-2);
  background: var(--color-surface-1);
  border-radius: 4px;
  text-align: center;
}

.sheets-formula-bar input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: "SF Mono", monospace;
  font-size: 0.875rem;
  outline: none;
}

/* Grid container */
.grid-container {
  flex: 1;
  overflow: auto;
  position: relative;
}

.grid-viewport {
  position: relative;
}

/* Headers */
.grid-corner {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 30;
  width: 50px;
  height: 28px;
  background: var(--color-surface-1);
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
}

.grid-col-headers {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  height: 28px;
  margin-left: 50px;
}

.grid-col-header {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  background: var(--color-surface-1);
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-text-muted);
  user-select: none;
  position: relative;
}

.grid-col-header.selected {
  background: oklch(0.85 0.08 260);
  color: var(--color-primary);
  font-weight: 600;
}

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

.grid-col-header .resize-handle:hover {
  background: var(--color-primary);
}

.grid-row-headers {
  position: sticky;
  left: 0;
  z-index: 20;
  width: 50px;
}

.grid-row-header {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  background: var(--color-surface-1);
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  font-size: 0.75rem;
  color: var(--color-text-muted);
  user-select: none;
  position: relative;
}

.grid-row-header.selected {
  background: oklch(0.85 0.08 260);
  color: var(--color-primary);
  font-weight: 600;
}

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

/* Cells */
.grid-cells {
  position: relative;
  margin-left: 50px;
  margin-top: 28px;
}

.grid-cell {
  position: absolute;
  box-sizing: border-box;
  border-right: 1px solid oklch(0.9 0 0 / 0.5);
  border-bottom: 1px solid oklch(0.9 0 0 / 0.5);
  padding: 2px 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8125rem;
  line-height: 1.4;
  cursor: cell;
}

.grid-cell.align-left { text-align: left; }
.grid-cell.align-center { text-align: center; }
.grid-cell.align-right { text-align: right; }
.grid-cell.bold { font-weight: 700; }
.grid-cell.error { color: oklch(0.5 0.2 25); }

/* Active cell */
.grid-cell.active {
  outline: 2px solid var(--color-primary);
  outline-offset: -1px;
  z-index: 10;
}

/* Selection range */
.grid-selection-overlay {
  position: absolute;
  background: oklch(0.7 0.1 260 / 0.1);
  border: 1px solid var(--color-primary);
  pointer-events: none;
  z-index: 5;
}

/* Fill handle */
.grid-fill-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--color-primary);
  border: 1px solid white;
  cursor: crosshair;
  z-index: 15;
}

/* Cell editing */
.grid-cell-editor {
  position: absolute;
  z-index: 20;
  background: white;
  border: 2px solid var(--color-primary);
  padding: 2px 4px;
  font-size: 0.8125rem;
  font-family: inherit;
  outline: none;
  box-shadow: 0 2px 8px oklch(0 0 0 / 0.1);
}

/* Frozen pane border */
.grid-frozen-col-border {
  position: sticky;
  left: 50px;
  width: 2px;
  background: var(--color-border);
  z-index: 25;
}

.grid-frozen-row-border {
  position: sticky;
  top: 28px;
  height: 2px;
  background: var(--color-border);
  z-index: 25;
}

/* Sheet tabs */
.sheet-tabs {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 var(--space-2);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-0);
  height: 32px;
  overflow-x: auto;
}

.sheet-tab {
  display: flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  font-size: 0.75rem;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast);
}

.sheet-tab:hover {
  background: var(--color-surface-1);
}

.sheet-tab.active {
  background: var(--color-surface-2);
  border-color: var(--color-border);
  font-weight: 600;
}

.sheet-tab-add {
  padding: var(--space-1);
  font-size: 1rem;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: 4px;
}

.sheet-tab-add:hover {
  background: var(--color-surface-1);
}

/* Formatting toolbar */
.sheets-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface-0);
  flex-wrap: wrap;
}

.sheets-toolbar .toolbar-group {
  display: flex;
  gap: 2px;
  padding: 0 var(--space-1);
  border-right: 1px solid var(--color-border);
}

.sheets-toolbar select {
  font-size: 0.75rem;
  padding: 2px 4px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-surface-0);
}

/* Sort indicators */
.grid-col-header .sort-asc::after { content: " ▲"; font-size: 0.6em; }
.grid-col-header .sort-desc::after { content: " ▼"; font-size: 0.6em; }

/* Filter dropdown */
.grid-filter-dropdown {
  position: absolute;
  z-index: 50;
  min-width: 200px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 4px 16px oklch(0 0 0 / 0.12);
  backdrop-filter: blur(20px);
  padding: var(--space-2);
}

/* Context menu for rows/cols */
.grid-context-menu {
  position: fixed;
  z-index: 60;
  min-width: 160px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 4px 16px oklch(0 0 0 / 0.12);
  backdrop-filter: blur(20px);
  padding: var(--space-1);
}

.grid-context-menu-item {
  padding: var(--space-1) var(--space-3);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8125rem;
  transition: background var(--transition-fast);
}

.grid-context-menu-item:hover {
  background: var(--color-surface-1);
}

/* Dark mode */
.dark .grid-cell {
  border-color: oklch(0.3 0 0 / 0.5);
}

.dark .grid-cell-editor {
  background: var(--color-surface-1);
}

.dark .grid-col-header.selected,
.dark .grid-row-header.selected {
  background: oklch(0.3 0.08 260);
  color: oklch(0.7 0.15 260);
}
