:root {
  color-scheme: light;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f3f6fb;
  color: #0f172a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.16), transparent 32%),
    linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 280px) 1fr;
  gap: 24px;
  align-items: end;
  padding: 20px 24px 16px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(148, 163, 184, 0.3);
}

.toolbar h1,
.toolbar p {
  margin: 0;
}

.eyebrow {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #2563eb;
}

.formula-wrap {
  display: grid;
  gap: 8px;
}

.formula-wrap label {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
}

.formula-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
}

.cell-label,
#formula {
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #fff;
  min-height: 44px;
  padding: 10px 14px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

.cell-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

#formula {
  width: 100%;
  font: inherit;
}

#formula:focus,
.cell-input:focus,
.row-action:focus {
  outline: 2px solid #2563eb;
  outline-offset: 0;
}

.grid-shell {
  overflow: auto;
  padding: 18px 24px 24px;
}

.sheet {
  border-collapse: separate;
  border-spacing: 0;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.1);
  border: 1px solid rgba(148, 163, 184, 0.32);
  border-radius: 18px;
  overflow: hidden;
}

.sheet th,
.sheet td {
  min-width: 104px;
  height: 36px;
  border-right: 1px solid #e2e8f0;
  border-bottom: 1px solid #e2e8f0;
  padding: 0;
}

.sheet tr:last-child td,
.sheet tr:last-child th,
.sheet td:last-child,
.sheet th:last-child {
  border-right: none;
}

.col-header,
.row-header {
  position: sticky;
  background: #f8fafc;
  z-index: 1;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.col-header {
  top: 0;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
}

.row-header {
  left: 0;
  min-width: 52px;
  padding: 0 6px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px;
}

.row-action {
  width: 18px;
  height: 18px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #fff;
  color: #2563eb;
  font: inherit;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.col-action {
  width: 18px;
  height: 18px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #fff;
  color: #2563eb;
  font: inherit;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.row-action-delete,
.col-action-delete {
  color: #b91c1c;
}

.sheet tr:first-child th:first-child {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 2;
  min-width: 52px;
  background: #f1f5f9;
}

.cell-input {
  width: 100%;
  height: 100%;
  border: none;
  padding: 8px 10px;
  background: transparent;
  font: inherit;
  color: inherit;
  text-align: right;
}

.cell-input.text-value {
  text-align: left;
}

.cell-input.error-value {
  color: #b91c1c;
  font-weight: 700;
}

td.is-active {
  position: relative;
  background: rgba(37, 99, 235, 0.08);
}

td.is-selected {
  background: rgba(37, 99, 235, 0.14);
}

td.is-active::after {
  content: '';
  position: absolute;
  inset: -1px;
  border: 2px solid #2563eb;
  pointer-events: none;
}

@media (max-width: 720px) {
  .toolbar {
    grid-template-columns: 1fr;
  }

  .grid-shell {
    padding: 12px;
  }

  .sheet th,
  .sheet td {
    min-width: 88px;
  }
}
