:root {
  --bg: #0a0d13;
  --bg-soft: #111621;
  --bg-elevated: #141b26;
  --line: #2a3443;
  --line-strong: #3d4b5f;
  --text: #dee5ef;
  --text-muted: #9aa8bb;
  --danger: #d17a7a;
  --accent-cyan: #5ec7ff;
  --accent-teal: #59d2c4;
  --accent-indigo: #8ea7ff;
  --accent-amber: #e0b064;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 16% 14%, rgba(94, 199, 255, 0.17) 0%, rgba(94, 199, 255, 0) 35%),
    radial-gradient(circle at 86% 8%, rgba(89, 210, 196, 0.14) 0%, rgba(89, 210, 196, 0) 30%),
    radial-gradient(circle at top left, #192131 0%, #0b1018 46%, #090d14 100%);
  color: var(--text);
  font-family: "Bahnschrift", "Segoe UI Variable Text", "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.screen {
  min-height: 100vh;
}

.panel {
  width: min(620px, 94vw);
  margin: 8vh auto;
  padding: 2.2rem;
  border: 1px solid #4b5f78;
  border-radius: 16px;
  background:
    linear-gradient(140deg, rgba(94, 199, 255, 0.08) 0%, rgba(94, 199, 255, 0) 34%),
    linear-gradient(160deg, #141c2a 0%, #0f1521 100%);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.42);
}

.panel h1 {
  margin: 0;
  font-size: 2.05rem;
  letter-spacing: 0.02em;
  color: #f0f6ff;
}

.panel p {
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-size: 1rem;
}

.field {
  display: grid;
  gap: 0.5rem;
  margin-top: 1.05rem;
}

.field span {
  color: var(--text-muted);
  font-size: 0.98rem;
}

input {
  background: #0c121d;
  color: var(--text);
  border: 1.5px solid #4f5f77;
  border-radius: 10px;
  min-height: 50px;
  padding: 0.75rem 0.9rem;
  font-size: 1rem;
  box-shadow: inset 0 0 0 1px rgba(32, 44, 61, 0.55);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:hover {
  border-color: #6e829f;
}

input:focus {
  outline: none;
  border-color: #c1d0e4;
  box-shadow: 0 0 0 4px rgba(162, 179, 204, 0.24), inset 0 0 0 1px #c1d0e4;
}

button:focus,
summary:focus {
  outline: 3px solid #9cb0cd;
  outline-offset: 1px;
}

.ghost-btn,
.menu-list button {
  border: 1px solid #5a6b84;
  background: rgba(18, 27, 40, 0.7);
  color: var(--text);
  border-radius: 10px;
  min-height: 44px;
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.ghost-btn:hover,
.menu-list button:hover {
  background: #1a2434;
  border-color: #b7c4d7;
  box-shadow: 0 0 0 3px rgba(162, 179, 204, 0.2);
}

.ghost-btn:active,
.menu-list button:active {
  transform: translateY(1px);
}

.full-width {
  width: 100%;
}

.login-btn {
  margin-top: 1.2rem;
  background: transparent;
}

.login-btn:hover,
.login-btn:focus-visible {
  background: transparent;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(94, 199, 255, 0.35);
}

#loginForm .error {
  margin-top: 0.85rem;
}

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

.sidebar {
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(89, 210, 196, 0.06) 0%, rgba(89, 210, 196, 0) 26%),
    rgba(14, 20, 30, 0.9);
  padding: 0.9rem;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
  margin-bottom: 0.85rem;
}

.brand {
  font-size: 1.22rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #edf6ff;
  text-shadow: 0 0 16px rgba(94, 199, 255, 0.18);
}

#logoutButton {
  min-width: 118px;
}

.sheet-list {
  margin: 0.8rem 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.42rem;
}

.sheet-list button {
  width: 100%;
  border: 1px solid #3e4c62;
  border-radius: 10px;
  background: #0f1621;
  color: var(--text);
  text-align: left;
  padding: 0.7rem 0.78rem;
  cursor: pointer;
  font-size: 0.95rem;
}

.sheet-list button:hover {
  border-color: #b4c1d4;
  box-shadow: 0 0 0 3px rgba(162, 179, 204, 0.2);
}

.sheet-list button.active {
  border-color: var(--accent-indigo);
  background:
    linear-gradient(160deg, rgba(142, 167, 255, 0.18) 0%, rgba(142, 167, 255, 0.04) 45%),
    #172233;
}

.sheet-list .time {
  display: block;
  margin-top: 0.26rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.editor {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  background:
    linear-gradient(180deg, rgba(94, 199, 255, 0.06) 0%, rgba(94, 199, 255, 0) 20%),
    rgba(11, 16, 24, 0.88);
}

.editor-head {
  border-bottom: 1px solid var(--line);
  padding: 0.8rem 1rem;
  background:
    linear-gradient(90deg, rgba(94, 199, 255, 0.08) 0%, rgba(94, 199, 255, 0) 36%),
    rgba(14, 20, 30, 0.95);
  position: sticky;
  top: 0;
  z-index: 5;
}

.editor-topline {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.7rem;
}

#backToMenuButton {
  min-width: 128px;
}

.sheet-headline h2 {
  margin: 0;
  font-size: 1.02rem;
}

.sheet-headline p {
  margin: 0.2rem 0 0;
  color: var(--text-muted);
  font-size: 0.84rem;
}

#saveStatus {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: right;
}

.menu-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-top: 0.72rem;
}

.menu {
  position: relative;
}

.menu > summary {
  list-style: none;
  border: 1px solid #3d4d63;
  border-radius: 10px;
  padding: 0.45rem 0.86rem;
  color: var(--text-muted);
  cursor: pointer;
  background: rgba(18, 27, 40, 0.6);
  font-weight: 600;
}

.menu > summary::-webkit-details-marker {
  display: none;
}

.menu[open] > summary {
  border-color: var(--accent-cyan);
  color: var(--text);
  background: #192334;
  box-shadow: 0 0 0 3px rgba(94, 199, 255, 0.22);
}

.menu-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 240px;
  border: 1px solid #3f4f65;
  border-radius: 10px;
  padding: 0.46rem;
  background: #111925;
  display: grid;
  gap: 0.35rem;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.38);
}

.inside-sheet-menu .menu-list button {
  width: 100%;
  text-align: left;
}

.sheet-quick-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.72rem;
}

.sheet-quick-actions .ghost-btn:first-child {
  border-color: var(--accent-teal);
  box-shadow: inset 0 0 0 1px rgba(89, 210, 196, 0.24);
}

.sheet-quick-actions .ghost-btn:nth-child(2) {
  border-color: var(--accent-indigo);
  box-shadow: inset 0 0 0 1px rgba(142, 167, 255, 0.2);
}

.sheet-quick-actions .ghost-btn:nth-child(3) {
  border-color: var(--accent-amber);
  box-shadow: inset 0 0 0 1px rgba(224, 176, 100, 0.22);
}

.sheet-wrap {
  overflow: auto;
  padding: 0.75rem;
}

#sheetTable {
  border-collapse: collapse;
  min-width: max-content;
}

#sheetTable th,
#sheetTable td {
  border: 1px solid var(--line);
}

#sheetTable th {
  background: #141d2a;
  color: var(--text-muted);
  font-weight: 500;
  text-align: center;
  min-width: 58px;
  height: 30px;
  padding: 0 0.35rem;
  position: sticky;
  top: 0;
  z-index: 2;
}

#sheetTable .row-head {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 44px;
}

#sheetTable .corner {
  left: 0;
  z-index: 3;
}

#sheetTable td {
  background: #0e151f;
  color: var(--text);
  min-width: 124px;
  max-width: 280px;
  height: 31px;
  padding: 0.25rem 0.44rem;
  white-space: pre;
  overflow: hidden;
  font-family: "Consolas", "Cascadia Mono", monospace;
  font-size: 0.9rem;
}

#sheetTable td:focus {
  outline: none;
}

#sheetTable td.selected {
  box-shadow: inset 0 0 0 1px var(--accent-cyan), 0 0 0 1px rgba(94, 199, 255, 0.18);
  background: linear-gradient(180deg, rgba(94, 199, 255, 0.1) 0%, #182231 56%);
}

.sheet-wrap.gridless #sheetTable th,
.sheet-wrap.gridless #sheetTable td {
  border-color: transparent;
}

.sheet-wrap.compact #sheetTable td,
.sheet-wrap.compact #sheetTable th {
  height: 24px;
  min-width: 52px;
  font-size: 0.83rem;
}

.empty-note {
  color: var(--text-muted);
  padding: 1.15rem 0.5rem;
}

#appScreen.menu-only .workspace {
  grid-template-columns: 1fr;
}

#appScreen.menu-only .sidebar {
  border-right: 0;
}

#appScreen.menu-only .editor {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 1rem;
}

.modal-card {
  width: min(430px, 96vw);
  border: 1px solid #475a72;
  border-radius: 12px;
  padding: 1rem;
  background: #111925;
}

.modal-card h3 {
  margin: 0;
}

.modal-card p {
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.error {
  color: var(--danger);
  min-height: 1.35rem;
  margin-top: 0.64rem;
  font-size: 0.93rem;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 280px 1fr;
  }
}

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

  #appScreen:not(.menu-only) .sidebar {
    display: none;
  }

  #appScreen:not(.menu-only) .editor {
    display: grid;
  }

  .editor-head {
    padding: 0.7rem 0.75rem;
  }

  .editor-topline {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  #saveStatus {
    text-align: left;
  }

  .sheet-quick-actions {
    flex-wrap: wrap;
  }

  .panel {
    margin-top: 7vh;
    padding: 1.55rem;
  }
}
