:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c2330;
  --muted: #6b7686;
  --border: #e2e6ec;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eef0ff;
  --danger: #dc2626;
  --side-bg: #1f2433;
  --side-text: #c9d0de;
  --side-muted: #8590a6;
  --side-hover: #2a3043;
  --side-active: #4f46e5;
  --shadow: 0 1px 2px #0001, 0 6px 24px #0000000f;
  font-family:
    Inter,
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  font-size: 15px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171f;
    --surface: #1b1f2a;
    --surface-2: #232837;
    --text: #e8ebf2;
    --muted: #8f9ab0;
    --border: #2b3141;
    --accent: #7c83ff;
    --accent-text: #0e1020;
    --accent-soft: #262a4a;
    --side-bg: #11141b;
    --side-hover: #1b2030;
    --shadow: 0 1px 2px #0005, 0 6px 24px #0006;
  }
}
* {
  box-sizing: border-box;
}
/* Element rules (display:block / inline-block) would otherwise defeat the hidden attribute. */
[hidden],
.nav-toggle {
  display: none !important;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
h1,
h2,
h3 {
  line-height: 1.2;
}
code {
  background: var(--surface-2);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.9em;
  word-break: break-all;
}
.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- forms & buttons ---------- */
label {
  display: block;
  margin: 0.9rem 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}
input,
select,
textarea {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.6rem 0.75rem;
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}
button,
.btn {
  display: inline-block;
  padding: 0.6rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  color: var(--accent-text);
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  text-decoration: none;
}
button:hover,
.btn:hover {
  filter: brightness(1.08);
  text-decoration: none;
}
.btn.ghost,
button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary {
  background: var(--surface-2);
  color: var(--text);
}
button.small {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}
button.danger {
  background: var(--danger);
  color: #fff;
}
button.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-weight: 500;
}
.danger-text {
  color: var(--danger) !important;
}
form.inline {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  margin: 0;
}
.error {
  background: #fee2e2;
  color: #991b1b;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
}
.warn {
  background: #fef3c7;
  color: #92400e;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  word-break: break-all;
}
.badge {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.1rem 0.55rem;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 600;
}

/* ---------- centered pages (login, signup, invite, errors) ---------- */
body:not(.app) {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1rem;
}
.card {
  background: var(--surface);
  padding: 2rem;
  border-radius: 16px;
  width: min(440px, 100%);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card.wide {
  width: min(720px, 100%);
}
.card h1 {
  margin-top: 0;
  font-size: 1.5rem;
}
.card button[type="submit"] {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.75rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.2rem;
  font-weight: 700;
}
.brand .ws-badge {
  width: 34px;
  height: 34px;
}
.card table {
  width: 100%;
}

/* ---------- app shell ---------- */
body.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}
.sidebar {
  width: 272px;
  flex-shrink: 0;
  background: var(--side-bg);
  color: var(--side-text);
  display: flex;
  flex-direction: column;
}
.sidebar-top {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 1rem;
  border-bottom: 1px solid #ffffff14;
}
.ws-badge {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--side-active);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  flex-shrink: 0;
}
.ws-name {
  font-weight: 700;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ws-role {
  font-size: 0.75rem;
  color: var(--side-muted);
  text-transform: capitalize;
}
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.6rem;
}
.side-section {
  margin: 0.6rem 0 1rem;
}
.side-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.2rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--side-muted);
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  color: var(--side-text);
  cursor: pointer;
  font-size: 1.1rem;
  text-decoration: none;
}
.icon-btn:hover {
  background: var(--side-hover);
  text-decoration: none;
}
.side-link {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.42rem 0.6rem;
  border-radius: 8px;
  color: var(--side-text);
  text-decoration: none;
}
.side-link:hover {
  background: var(--side-hover);
  text-decoration: none;
}
.side-link.active {
  background: var(--side-active);
  color: #fff;
}
.side-link.unread .side-label {
  color: #fff;
  font-weight: 700;
}
.side-icon {
  width: 1.1rem;
  text-align: center;
  opacity: 0.85;
  flex-shrink: 0;
}
.side-icon.dot::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
}
.side-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pill {
  background: #ef4444;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.05rem 0.45rem;
  border-radius: 99px;
}
.side-empty {
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
  color: var(--side-muted);
}
.sidebar-bottom {
  padding: 0.8rem 1rem;
  border-top: 1px solid #ffffff14;
}
.me {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.me-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
}
.me-actions {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
  font-size: 0.85rem;
}
.me-actions a,
.me-actions button.link {
  color: var(--side-muted);
}
.me-actions a:hover,
.me-actions button.link:hover {
  color: #fff;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}
.topbar-mobile {
  display: none;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
}
.menu-btn {
  color: var(--text);
  background: var(--surface-2);
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-weight: 700;
  color: #fff;
  background: hsl(var(--h, 240) 55% 48%);
}
.avatar.sm {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 0.8rem;
  background: #ffffff1f;
}

/* ---------- chat ---------- */
.chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 1.4rem;
  border-bottom: 1px solid var(--border);
}
.chat-head h1 {
  margin: 0;
  font-size: 1.15rem;
}
.chat-head-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}
.conn {
  background: #fef3c7;
  color: #92400e;
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
  font-size: 0.8rem;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.4rem 0.5rem;
  scroll-behavior: smooth;
}
.older {
  text-align: center;
  margin-bottom: 1rem;
}
.empty-room {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
}
.day {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin: 1.2rem 0 0.6rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}
.day::before,
.day::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.msg {
  display: flex;
  gap: 0.8rem;
  padding: 0.35rem 0.6rem;
  margin: 0 -0.6rem;
  border-radius: 10px;
  position: relative;
}
.msg:hover {
  background: var(--surface-2);
}
.msg.cont {
  padding-top: 0;
  padding-bottom: 0.1rem;
}
.msg.cont .avatar,
.msg.cont .msg-head strong {
  visibility: hidden;
  height: 0;
}
.msg.cont .avatar {
  height: 0;
  width: 38px;
}
.msg.cont .msg-head {
  height: 0;
  overflow: visible;
}
.msg.cont .msg-head time {
  visibility: hidden;
  position: absolute;
  left: 0.6rem;
  top: 0.3rem;
  width: 38px;
  text-align: center;
  font-size: 0.68rem;
}
.msg.cont:hover .msg-head time {
  visibility: visible;
}
.msg-main {
  min-width: 0;
  flex: 1;
}
.msg-head {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}
.msg-head time {
  color: var(--muted);
  font-size: 0.75rem;
}
.msg-del {
  margin-left: auto;
  padding: 0 0.3rem;
  background: none;
  border: 0;
  opacity: 0;
  cursor: pointer;
  font-size: 0.9rem;
}
.msg:hover .msg-del {
  opacity: 0.7;
}
.msg-del:hover {
  opacity: 1 !important;
  filter: none;
}
.msg-body {
  overflow-wrap: anywhere;
}
.msg-body p {
  margin: 0.1rem 0;
}
.msg-body pre {
  background: var(--surface-2);
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  overflow-x: auto;
}
.msg-body blockquote {
  margin: 0.3rem 0;
  padding-left: 0.8rem;
  border-left: 3px solid var(--border);
  color: var(--muted);
}
.msg-body ul,
.msg-body ol {
  margin: 0.2rem 0;
  padding-left: 1.4rem;
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  margin: 0.5rem 1.4rem 1rem;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.composer textarea {
  flex: 1;
  margin: 0;
  border: 0;
  resize: none;
  max-height: 200px;
  background: transparent;
  padding: 0.5rem 0.6rem;
}
.composer textarea:focus {
  outline: none;
}
.composer button {
  padding: 0.55rem 1.1rem;
}
.composer-note {
  text-align: center;
  color: var(--muted);
  padding: 0.4rem 1rem 1rem;
  font-size: 0.9rem;
}
.composer-error {
  margin: 0 1.4rem 0.5rem;
}
.empty-state {
  margin: auto;
  text-align: center;
  padding: 2rem;
}
.empty-emoji {
  font-size: 3rem;
}

/* members dropdown */
.menu {
  position: relative;
}
.menu summary {
  list-style: none;
  cursor: pointer;
}
.menu summary::-webkit-details-marker {
  display: none;
}
.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  width: 330px;
  max-width: 86vw;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 0.8rem;
}
.member-list {
  list-style: none;
  margin: 0 0 0.6rem;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
}
.member-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.add-member {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.add-member select {
  margin: 0;
}
.archive {
  margin-top: 0.8rem;
}

/* ---------- pages inside the shell (people, audit) ---------- */
.page {
  padding: 1.5rem 2rem 3rem;
  overflow-y: auto;
  max-width: 980px;
  width: 100%;
}
.page h1 {
  margin: 0 0 0.2rem;
  font-size: 1.5rem;
}
.page h2 {
  font-size: 1.1rem;
  margin: 2rem 0 0.6rem;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.2rem;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th {
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
th,
td {
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td {
  border-bottom: 0;
}
.invite-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0 1rem;
  align-items: end;
}
.invite-form button {
  margin-bottom: 0.9rem;
}
table select {
  margin: 0;
  width: auto;
  padding: 0.35rem 0.5rem;
}
.scroll-x {
  overflow-x: auto;
}

/* ---------- modals (pure CSS, :target) ---------- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  place-items: center;
}
.modal:target {
  display: grid;
}
.modal-bg {
  position: absolute;
  inset: 0;
  background: #0008;
}
.modal-box {
  position: relative;
  background: var(--surface);
  width: min(440px, 92vw);
  padding: 1.5rem;
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.modal-box h3 {
  margin-top: 0;
}
.modal-box fieldset {
  border: 0;
  padding: 0;
  margin: 0;
}
.radio {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  padding: 0.7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 0.5rem 0;
  cursor: pointer;
  font-weight: 400;
  color: var(--text);
}
.radio input {
  width: auto;
  margin: 0.25rem 0 0;
}
.radio small {
  display: block;
  color: var(--muted);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1rem;
}

/* ---------- mobile ---------- */
.nav-backdrop {
  display: none;
}
@media (max-width: 800px) {
  body.app {
    display: block;
    height: auto;
    overflow: visible;
  }
  .sidebar {
    position: fixed;
    z-index: 40;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform 0.2s;
    width: min(300px, 86vw);
  }
  .nav-toggle:checked ~ .sidebar {
    transform: none;
  }
  .nav-toggle:checked ~ .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 30;
    background: #0007;
  }
  .main {
    height: 100vh;
  }
  .topbar-mobile {
    display: flex;
  }
  .chat-head,
  .messages {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  .composer {
    margin: 0.5rem 0.6rem 0.8rem;
  }
  .page {
    padding: 1rem;
  }
}
.ws-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.8rem;
  margin: 0.5rem 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
}
.ws-row:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.card .ws-badge {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  font-weight: 800;
}

/* ---------- sheets list ---------- */
.sheet-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1rem;
}
.sheet-card {
  display: block;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  background: var(--surface);
}
.sheet-card:hover {
  box-shadow: var(--shadow);
  text-decoration: none;
  transform: translateY(-1px);
}
.sheet-thumb {
  height: 76px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 2rem;
  margin-bottom: 0.7rem;
}
.sheet-title {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.share-row {
  display: flex;
  gap: 0.7rem;
  align-items: flex-end;
}
.share-row button {
  margin-bottom: 0.9rem;
}
.modal-box h4 {
  margin: 1rem 0 0.3rem;
}

/* ---------- sheet editor ---------- */
.sheet-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.sheet-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-width: 0;
}
.sheet-title-wrap h1 {
  margin: 0;
  font-size: 1.15rem;
}
.rename input {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  border-color: transparent;
  background: transparent;
  padding: 0.3rem 0.5rem;
  min-width: 14rem;
}
.rename input:hover {
  border-color: var(--border);
}
.status {
  font-size: 0.8rem;
  color: var(--muted);
}
.status.err {
  color: var(--danger);
}
.sheet-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.file-btn {
  cursor: pointer;
  margin: 0;
}
.presence {
  display: flex;
}
.presence .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 0.75rem;
  margin-left: -6px;
  border: 2px solid var(--surface);
}
.formula-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  border-bottom: 1px solid var(--border);
}
.namebox {
  min-width: 4.2rem;
  text-align: center;
  font-weight: 600;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
}
.fx {
  color: var(--muted);
  font-style: italic;
  font-family: serif;
}
.formula-bar input {
  margin: 0;
  flex: 1;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.3rem 0.7rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  background: var(--surface);
}
.tb {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 0.45rem;
  margin: 0;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
.tb:hover {
  background: var(--surface-2);
  filter: none;
}
.tb.on {
  background: var(--accent-soft);
  color: var(--accent);
}
.tb.i {
  font-style: italic;
}
.tb.u {
  text-decoration: underline;
}
.tb.s {
  text-decoration: line-through;
}
.tb-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 0.3rem;
}
.tb-select {
  width: auto;
  margin: 0;
  padding: 0.25rem 0.4rem;
  font-size: 0.85rem;
  height: 30px;
}
.tb.color {
  position: relative;
  cursor: pointer;
}
.tb.color input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  cursor: pointer;
}
.swatch-a {
  border-bottom: 3px solid var(--sw, #000);
  line-height: 1;
  padding: 0 2px;
}
.swatch-fill {
  border-bottom: 3px solid var(--sw, #fff);
  line-height: 1;
}
.findbar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.8rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-wrap: wrap;
}
.findbar input[type="text"] {
  width: 11rem;
  margin: 0;
  padding: 0.35rem 0.5rem;
}
.findbar .chk {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0 0.3rem;
  font-size: 0.8rem;
  font-weight: 500;
}
.findbar .chk input {
  width: auto;
  margin: 0;
}

.sheet-grid {
  --rh: 26px;
  --hw: 52px;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--hw) 1fr;
  grid-template-rows: var(--rh) 1fr;
  outline: none;
  background: var(--surface);
  user-select: none;
  -webkit-user-select: none;
}
.corner {
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.colhead,
.rowhead {
  overflow: hidden;
  position: relative;
  background: var(--surface-2);
}
.colhead {
  border-bottom: 1px solid var(--border);
}
.rowhead {
  border-right: 1px solid var(--border);
}
#colhead-in,
#rowhead-in {
  position: absolute;
  inset: 0;
}
.hcell {
  position: absolute;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
  background: var(--surface-2);
  cursor: pointer;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}
.hcell.sel {
  background: var(--accent-soft);
  color: var(--accent);
}
.hcell.frozen-edge {
  box-shadow: 2px 0 0 var(--muted);
}
.hcell .resizer {
  position: absolute;
  right: -3px;
  top: 0;
  bottom: 0;
  width: 7px;
  cursor: col-resize;
  z-index: 2;
}
.hcell .row-resizer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -3px;
  height: 7px;
  cursor: row-resize;
  z-index: 2;
}
.bodywrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.grid-body {
  position: absolute;
  inset: 0;
  overflow: auto;
  cursor: cell;
}
#sizer {
  position: relative;
}
.fz {
  position: absolute;
  overflow: hidden;
  background: var(--surface);
  pointer-events: none;
  z-index: 4;
  display: none;
}
#fz-top {
  border-bottom: 2px solid var(--muted);
}
#fz-left {
  border-right: 2px solid var(--muted);
}
#fz-corner {
  border-bottom: 2px solid var(--muted);
  border-right: 2px solid var(--muted);
  z-index: 5;
}
.line-v {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
}
.line-h {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
}
.cell {
  position: absolute;
  padding: 0 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  font-size: 0.88rem;
  box-sizing: border-box;
  display: flex;
  align-items: center;
}
.cell > span {
  overflow: hidden;
  text-overflow: clip;
  max-width: 100%;
}
.cell.num {
  justify-content: flex-end;
}
.cell.bool {
  justify-content: center;
}
.cell.err {
  color: var(--danger);
}
.cell.wrap {
  white-space: normal;
  line-height: 1.2;
  align-items: flex-start;
  padding-top: 4px;
}
.sel-range {
  position: absolute;
  pointer-events: none;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid var(--accent);
  z-index: 2;
  box-sizing: border-box;
}
.sel-active {
  position: absolute;
  pointer-events: none;
  border: 2px solid var(--accent);
  z-index: 3;
  box-sizing: border-box;
}
.cell-editor {
  position: absolute;
  z-index: 8;
  margin: 0;
  padding: 0 5px;
  border: 2px solid var(--accent);
  border-radius: 0;
  font-size: 0.88rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  box-sizing: border-box;
}
.remote-cursor {
  position: absolute;
  pointer-events: none;
  border: 2px solid var(--c);
  z-index: 2;
  box-sizing: border-box;
}
.remote-cursor span {
  position: absolute;
  top: -17px;
  left: -2px;
  background: var(--c);
  color: #fff;
  font-size: 0.68rem;
  padding: 0 5px;
  border-radius: 3px 3px 3px 0;
  white-space: nowrap;
}

.tabbar {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.tabs {
  display: flex;
  gap: 0.15rem;
  overflow-x: auto;
  flex: 1;
}
.tab {
  padding: 0.3rem 0.9rem;
  border-radius: 6px 6px 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  border: 0;
  background: transparent;
  margin: 0;
}
.tab:hover {
  background: var(--surface);
}
.tab.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
}
.tab-edit {
  width: 9rem;
  margin: 0;
  padding: 0.2rem 0.4rem;
  font-size: 0.85rem;
}
.ctx {
  position: fixed;
  z-index: 60;
  min-width: 210px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.3rem;
}
.ctx button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  font-weight: 500;
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  font-size: 0.88rem;
}
.ctx button:hover {
  background: var(--accent-soft);
  filter: none;
}
.ctx button:disabled {
  color: var(--muted);
  cursor: default;
  background: transparent;
}
.ctx hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 0.25rem 0;
}
@media (max-width: 800px) {
  .sheet-head {
    padding: 0.5rem 0.8rem;
  }
  .rename input {
    min-width: 8rem;
  }
}

/* ---------- scripts ---------- */
.script-page {
  max-width: 1200px;
}
.script-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}
.script-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.script-actions button {
  padding: 0.5rem 1rem;
}
.inline-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
}
.inline-label input {
  margin: 0;
  padding: 0.4rem 0.6rem;
  font-family: ui-monospace, Menlo, monospace;
}
.editor-wrap {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  margin-top: 0.8rem;
}
.gutter {
  width: 3.2rem;
  padding: 0.8rem 0.5rem;
  text-align: right;
  color: var(--muted);
  background: var(--surface-2);
  font:
    0.85rem/1.5 ui-monospace,
    Menlo,
    monospace;
  white-space: pre;
  overflow: hidden;
  user-select: none;
}
.code {
  flex: 1;
  margin: 0;
  border: 0;
  border-radius: 0;
  resize: vertical;
  min-height: 22rem;
  padding: 0.8rem;
  font:
    0.85rem/1.5 ui-monospace,
    Menlo,
    monospace;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  background: var(--surface);
}
.code:focus {
  outline: none;
}
.output {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 0.8rem 1rem;
  font:
    0.82rem/1.5 ui-monospace,
    Menlo,
    monospace;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0.4rem 0;
  max-height: 22rem;
  overflow: auto;
}
.output.err {
  color: var(--danger);
}
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
@media (max-width: 900px) {
  .two-col {
    grid-template-columns: 1fr;
  }
}
.run summary {
  cursor: pointer;
  display: flex;
  gap: 0.8rem;
  align-items: center;
  padding: 0.4rem 0;
  list-style: none;
}
.run summary::-webkit-details-marker {
  display: none;
}
.run + .run {
  border-top: 1px solid var(--border);
}
.run-status {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 99px;
  background: var(--surface-2);
}
.run-ok {
  background: #dcfce7;
  color: #166534;
}
.run-error,
.run-timeout,
.run-killed,
.run-denied {
  background: #fee2e2;
  color: #991b1b;
}
.ref summary {
  cursor: pointer;
  font-weight: 600;
}

/* ---------- ⋯ row menus ---------- */
.side-row {
  display: flex;
  align-items: center;
  position: relative;
}
.side-row .side-link {
  flex: 1;
  min-width: 0;
}
.dots {
  position: relative;
}
.dots summary {
  list-style: none;
  cursor: pointer;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  font-size: 1.1rem;
  line-height: 1;
  opacity: 0;
  color: var(--side-text);
  user-select: none;
}
.dots summary::-webkit-details-marker {
  display: none;
}
.side-row:hover .dots summary,
.dots[open] summary,
.dots summary:focus-visible {
  opacity: 1;
}
.dots summary:hover {
  background: var(--side-hover);
}
.dots-menu {
  position: fixed;
  z-index: 70;
  min-width: 170px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.3rem;
  display: none;
}
.dots[open] .dots-menu {
  display: block;
}
.dots-menu a {
  display: block;
  padding: 0.45rem 0.7rem;
  border-radius: 6px;
  color: var(--text);
  font-size: 0.88rem;
  text-decoration: none;
}
.dots-menu a:hover {
  background: var(--accent-soft);
  text-decoration: none;
}
.sheet-card-wrap {
  position: relative;
}
.card-dots {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
}
.card-dots .dots summary {
  opacity: 1;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
}
.card-dots .dots summary:hover {
  background: var(--surface-2);
}
@media (hover: none) {
  .dots summary {
    opacity: 1;
  }
}

.ok {
  background: #dcfce7;
  color: #166534;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
}
label.check {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  font-weight: 500;
  color: var(--text);
}
label.check input {
  width: auto;
  margin: 0.3rem 0 0;
}
label.check small {
  display: block;
  color: var(--muted);
  font-weight: 400;
}
.danger-zone {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
}
.card.wide h2 {
  font-size: 1.05rem;
  margin: 1.6rem 0 0.5rem;
}

/* Inline form rows inside the centered cards: buttons keep their natural width. */
.card .share-row {
  align-items: flex-end;
}
.card .share-row button[type="submit"],
.card form.inline button[type="submit"] {
  width: auto;
  margin: 0 0 0.9rem;
  padding: 0.6rem 1.1rem;
}
.card form.inline {
  display: inline-flex;
}
.import-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin: -0.8rem 0 1.5rem;
}

/* ---------- filters ---------- */
.fbtn {
  margin-left: auto;
  padding-left: 0.4rem;
  color: var(--accent);
  font-size: 0.8rem;
  opacity: 0.75;
}
.fbtn.on {
  opacity: 1;
  font-weight: 900;
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 0 0.3rem;
}
.fpop {
  position: fixed;
  z-index: 80;
  width: 280px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.fpop-title {
  font-weight: 700;
  font-size: 0.9rem;
}
.fpop-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.fpop-foot {
  justify-content: flex-end;
}
.fpop-search {
  margin: 0;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}
.fpop-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.25rem;
}
.fpop-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0.25rem 0.4rem;
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}
.fpop-item:hover {
  background: var(--surface-2);
}
.fpop-item input {
  width: auto;
  margin: 0;
}
.fpop-item span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fpop-item em {
  color: var(--muted);
  font-style: normal;
  font-size: 0.75rem;
}

/* ---------- data validation ---------- */
.jsmodal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
}
.jsmodal[hidden] {
  display: none;
}
.jsmodal-bg {
  position: absolute;
  inset: 0;
  background: #0008;
}
.vchip {
  margin-left: auto;
  padding-left: 0.4rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.vcheck {
  justify-content: center;
}
.vbox {
  width: 15px;
  height: 15px;
  border: 2px solid var(--muted);
  border-radius: 4px;
  display: inline-grid;
  place-items: center;
  font-size: 11px;
  line-height: 1;
  color: var(--accent-text);
}
.vbox.on {
  background: var(--accent);
  border-color: var(--accent);
}
.vbad {
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  border-top: 9px solid var(--danger);
  border-left: 9px solid transparent;
}
.dpop {
  width: 220px;
  gap: 0.3rem;
}
.dpop-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  font-weight: 500;
  font-size: 0.88rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
}
.dpop-item:hover {
  background: var(--accent-soft);
  filter: none;
}
.dpop-item.cur {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
