:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-soft: #eef1f4;
  --cell: #ffffff;
  --line: #d4dae2;
  --text: #151922;
  --muted: #687386;
  --accent: #2bbf8a;
  --accent-strong: #0ea5e9;
  --danger: #d92d4c;
  --primary-text: #04100b;
  --font-scale: 1;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #14171c;
  --panel-soft: #1a1e24;
  --cell: #0f1216;
  --line: #2c323b;
  --text: #f1f4f8;
  --muted: #9aa5b4;
  --accent: #62d0a8;
  --accent-strong: #38bdf8;
  --danger: #fb7185;
  --primary-text: #05100c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-size: calc(16px * var(--font-scale));
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 13px;
  cursor: pointer;
}

button:hover,
button.active {
  border-color: var(--accent);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--primary-text);
  font-weight: 700;
}

button.danger {
  color: var(--danger);
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--cell);
  color: var(--text);
  padding: 0 12px;
}

input.column-name {
  min-height: 40px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 8px;
  text-align: center;
  font-weight: 700;
}

input:focus,
textarea:focus {
  border-color: var(--accent-strong);
  outline: none;
}

.login {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.login form {
  width: min(100%, 380px);
  display: grid;
  gap: 12px;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 14px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 14px;
}

.brand,
.toolbar,
.row,
.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand {
  justify-content: space-between;
}

.brand h1,
.sheet-title {
  margin: 0;
  font-size: 1.05rem;
}

.toolbar {
  flex-wrap: wrap;
}

.project-list,
.sheet-tabs {
  display: grid;
  gap: 8px;
  overflow: auto;
  align-content: start;
}

.project {
  width: 100%;
  min-height: 44px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  text-align: left;
}

.project span,
.sheet-tab span,
.sheet-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content {
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-width: 0;
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 12px;
  align-items: center;
}

.topbar .toolbar {
  justify-content: flex-end;
}

.sheet-tabs {
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.sheet-tab {
  display: flex;
  gap: 8px;
  align-items: center;
}

.grid-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 14px;
}

table {
  border-collapse: collapse;
  min-width: 720px;
  background: var(--cell);
}

td,
th {
  border: 1px solid var(--line);
  min-width: 140px;
  height: 42px;
  padding: 0;
}

th {
  min-width: 42px;
  width: 42px;
  background: var(--panel);
  color: var(--muted);
  font-weight: 600;
  text-align: center;
}

td textarea {
  display: block;
  width: 100%;
  min-width: 140px;
  height: 42px;
  resize: vertical;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 10px;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 60vh;
  color: var(--muted);
}

.error {
  min-height: 20px;
  color: var(--danger);
}

@media (max-width: 760px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    grid-template-rows: auto auto auto;
  }

  .project-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(180px, 1fr);
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .toolbar {
    justify-content: flex-start;
  }

  table {
    min-width: 560px;
  }
}
