:root {
  color-scheme: dark;
  --bg: #0b1020;
  --bg2: #121933;
  --panel: rgba(17, 24, 39, 0.92);
  --panel2: rgba(15, 23, 42, 0.9);
  --line: rgba(148, 163, 184, 0.16);
  --line-strong: rgba(148, 163, 184, 0.28);
  --text: #e5eefc;
  --muted: #8ea2c8;
  --accent: #60a5fa;
  --accent2: #3b82f6;
  --good: #34d399;
  --warn: #f59e0b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  background: radial-gradient(circle at top, #13213f, var(--bg) 45%);
  color: var(--text);
}
button, input, select { font: inherit; }
button {
  border: 1px solid var(--line);
  background: #18233f;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}
button.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  color: white;
  border: none;
}
button.active {
  background: #1d4ed8;
  border-color: rgba(255,255,255,0.12);
}
button.full { width: 100%; }
input, select {
  background: #0f172a;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.hidden { display: none !important; }
.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}
.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel2);
  padding: 20px;
}
.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 20px;
}
.brand h1, .brand p { margin: 0; }
.brand p { color: var(--muted); font-size: 13px; }
.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: linear-gradient(180deg, #60a5fa, #2563eb);
}
.workbook-list {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.workbook-item {
  width: 100%;
  text-align: left;
  background: #0f172a;
}
.workbook-item.active {
  outline: 2px solid var(--accent);
}
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 18px 22px 10px;
}
.workbook-title {
  font-size: 26px;
  font-weight: 700;
  background: transparent;
  border: none;
  padding: 0;
  min-width: 300px;
}
.statusline { color: var(--muted); font-size: 13px; margin-top: 4px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.formula-bar {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 10px;
  padding: 0 22px 12px;
}
.cell-ref, .formula-bar input {
  background: #0f172a;
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 14px;
}
.formula-bar input { width: 100%; }
.sheet-tabs {
  display: flex;
  gap: 8px;
  padding: 0 22px 10px;
  flex-wrap: wrap;
}
.sheet-tab {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sheet-tab.active { background: #1d4ed8; }
.sheet-tab select {
  min-width: 96px;
  padding: 4px 8px;
  border-radius: 8px;
}
.table-controls {
  display: grid;
  grid-template-columns: minmax(220px, 320px) auto 1fr;
  gap: 14px;
  align-items: center;
  padding: 0 22px 12px;
}
.table-controls input {
  padding: 10px 14px;
}
.table-tools {
  display: flex;
  gap: 10px;
}
.table-meta {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}
.grid-wrap {
  flex: 1;
  min-height: 0;
  padding: 0 22px 22px;
}
#grid {
  overflow: auto;
  height: 100%;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.7);
  border-radius: 14px;
}
table.sheet-grid, table.table-view {
  border-collapse: collapse;
  min-width: 100%;
}
.sheet-grid th, .sheet-grid td, .table-view th, .table-view td {
  border: 1px solid rgba(148, 163, 184, 0.12);
}
.sheet-grid th, .table-view th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #0f172a;
  color: var(--muted);
  font-size: 12px;
  min-width: 120px;
  height: 36px;
}
.sheet-grid th.row-header {
  left: 0;
  z-index: 3;
  min-width: 48px;
}
.sheet-grid td, .table-view td {
  min-width: 120px;
  height: 36px;
  padding: 0;
  background: rgba(15, 23, 42, 0.55);
}
.sheet-grid td.selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.sheet-grid td.active-cell {
  box-shadow: inset 0 0 0 2px var(--good);
}
.sheet-grid input, .table-view input {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  padding: 8px 10px;
  background: transparent;
}
.sheet-grid input:focus, .table-view input:focus { outline: none; }
.table-view th button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 10px;
  border-radius: 0;
}
.table-view td.table-number {
  text-align: right;
  padding: 0 10px;
  font-variant-numeric: tabular-nums;
}
.table-view td.table-text,
.table-view td.table-date,
.table-view td.table-percent {
  padding: 0;
}
.table-view input.table-input,
.table-view input.table-date-input,
.table-view input.table-number-input {
  padding: 8px 10px;
}
.table-type-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
}
.view-empty {
  padding: 32px;
  color: var(--muted);
}
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); }
  .topbar { flex-direction: column; align-items: stretch; }
  .workbook-title { min-width: 0; width: 100%; }
  .table-controls { grid-template-columns: 1fr; }
  .table-meta { text-align: left; }
  .table-tools { flex-wrap: wrap; }
}
