:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #eef2f6;
  --text: #172026;
  --muted: #596773;
  --line: #cfd8e2;
  --primary: #166b8f;
  --primary-strong: #0f5471;
  --danger: #a34135;
  --danger-strong: #7f2f27;
  --focus: rgb(22 107 143 / 28%);
  --shadow: 0 16px 42px rgb(23 32 38 / 10%);
  --radius: 6px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

body,
button,
input {
  font: inherit;
}

button,
input {
  color: inherit;
}

a {
  color: inherit;
}

.skip-link {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 10;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--surface);
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.topbar,
.section-heading,
.sheet-actions,
.site-footer {
  display: flex;
}

.topbar {
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.topbar h1,
.sheet-panel h2 {
  margin: 0;
  line-height: 1.05;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(1.35rem, 3vw, 1.9rem);
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  gap: 0.35rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.nav a {
  min-width: 6rem;
  padding: 0.55rem 0.75rem;
  border-radius: calc(var(--radius) - 2px);
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}

.nav a:hover,
.nav a:focus-visible,
.nav a[aria-current="page"] {
  background: var(--surface);
  color: var(--text);
  outline: none;
}

main {
  display: grid;
  min-width: 0;
  min-height: 0;
  padding: clamp(0.75rem, 2vw, 1.25rem);
}

.sheet-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sheet-toolbar {
  display: grid;
  gap: 0.9rem;
  padding: 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.section-heading {
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.sheet-panel h2 {
  font-size: clamp(1.3rem, 2vw, 1.8rem);
}

.sheet-actions {
  flex-wrap: wrap;
  gap: 0.6rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.55rem;
  padding: 0.65rem 0.9rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.button.secondary {
  border-color: var(--line);
  background: var(--surface-muted);
}

.button.secondary:hover,
.button.secondary:focus-visible {
  border-color: var(--primary);
  color: var(--primary-strong);
}

.button.danger {
  border-color: color-mix(in srgb, var(--danger), transparent 56%);
  background: color-mix(in srgb, var(--danger), transparent 92%);
  color: var(--danger);
}

.button.danger:hover,
.button.danger:focus-visible {
  border-color: var(--danger);
  color: var(--danger-strong);
}

button:focus-visible,
a:focus-visible,
input:focus {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.save-state {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  white-space: nowrap;
}

.sheet-wrap {
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: var(--surface);
}

.spreadsheet {
  position: relative;
  min-width: 100%;
  min-height: 100%;
  background: var(--surface);
}

.grid-corner,
.grid-header,
.grid-cell {
  position: absolute;
  top: 0;
  left: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.grid-corner,
.grid-header {
  z-index: 2;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 40px;
  text-align: center;
  user-select: none;
}

.grid-corner {
  position: sticky;
  z-index: 4;
  width: 56px;
  height: 40px;
  transform: translate(0, 0);
}

.column-header {
  position: sticky;
  z-index: 3;
  width: 116px;
  height: 40px;
  top: 0;
}

.row-header {
  position: sticky;
  z-index: 3;
  width: 56px;
  height: 42px;
  left: 0;
  line-height: 42px;
}

.grid-cell {
  width: 116px;
  height: 42px;
  background: var(--surface);
}

.spreadsheet input {
  width: 100%;
  height: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0.5rem 0.65rem;
}

.spreadsheet input:focus {
  position: relative;
  z-index: 1;
  background: #f7fbfd;
}

.site-footer {
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem clamp(1rem, 3vw, 2rem);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

@media (max-width: 760px) {
  .topbar,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .nav {
    overflow-x: auto;
  }

  .nav a {
    flex: 1;
  }

  .button {
    flex: 1 1 10rem;
  }

  .site-footer {
    align-items: flex-start;
    flex-direction: column;
  }
}
