/* Clean Sheets — modern grey */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink: #1a1c1e;
  --ink-soft: #444746;
  --muted: #73767a;
  --accent: #202124;
  --accent-soft: rgba(32, 33, 36, 0.08);
  --sel-border: #3c4043;
  --border: #d5d7da;
  --grid-line: #e8e9eb;
  --header-bg: #f7f7f8;
  --header-fg: #6b6e73;
  --chrome: #f2f3f5;
  --card: #ffffff;
  --page: #f7f7f8;
  --danger: #b3261e;
  --header-w: 46px;
  --header-h: 26px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 21, 23, 0.08), 0 4px 16px rgba(20, 21, 23, 0.06);
  --shadow-pop: 0 8px 28px rgba(20, 21, 23, 0.18);
}

html, body { height: 100%; }

body {
  font-family: 'Inter', 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 13px;
  color: var(--ink);
  background: #fff;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }
.plain-link { text-decoration: none; color: inherit; }
.hidden { display: none !important; }

/* ============ shared chrome ============ */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.logo .logo-mark {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink-soft);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
.btn:hover { background: var(--chrome); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #3a3d40; }
.btn.small { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: #fdeceb; border-color: #f2b8b5; }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-solid:hover { background: #9a2019; }
.btn:disabled { opacity: 0.45; cursor: default; }
.wide-btn { width: 100%; padding: 10px; font-size: 14px; }
.btn.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.btn.icon-btn svg { flex: none; }

/* avatars */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 600;
  user-select: none;
  flex: none;
  letter-spacing: 0.02em;
}
.avatar-stack { display: flex; align-items: center; }
.avatar-stack .avatar {
  margin-left: -7px;
  box-shadow: 0 0 0 2px #fff;
}
.avatar-stack .avatar:first-child { margin-left: 0; }
.avatar-stack .more {
  margin-left: -7px;
  box-shadow: 0 0 0 2px #fff;
  background: #dcdee1;
  color: var(--ink-soft);
}

/* custom dropdown */
.dd { display: inline-flex; }
.dd-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  height: 28px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 7px;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--ink-soft);
  cursor: pointer;
}
.dd-btn:hover, .dd-btn.open { background: rgba(32, 33, 36, 0.07); }
.dd-btn.outline {
  border-color: var(--border);
  background: #fff;
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  min-width: 96px;
  justify-content: space-between;
}
.dd-btn.outline:hover, .dd-btn.outline.open { background: var(--chrome); }
.dd-chev { display: inline-flex; opacity: 0.6; }
.dd-label { display: inline-flex; align-items: center; gap: 6px; }
.dd-menu {
  position: fixed;
  background: #fff;
  border: 1px solid var(--grid-line);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  padding: 5px;
  z-index: 400;
  min-width: 130px;
  max-height: 320px;
  overflow-y: auto;
}
.dd-item {
  padding: 8px 30px 8px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  position: relative;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dd-item:hover { background: var(--chrome); }
.dd-item.sel { font-weight: 600; }
.dd-item.sel::after {
  content: '✓';
  position: absolute;
  right: 10px;
  font-size: 11px;
}

/* user menu */
.user-menu { position: relative; }
.user-menu-btn { cursor: pointer; }
.user-menu-btn:hover { filter: brightness(1.06); }
.user-dd {
  position: absolute;
  right: 0; top: 40px;
  background: #fff;
  border: 1px solid var(--grid-line);
  border-radius: 12px;
  box-shadow: var(--shadow-pop);
  min-width: 230px;
  padding: 6px;
  z-index: 200;
}
.user-dd-info { padding: 10px 12px 8px; border-bottom: 1px solid var(--grid-line); margin-bottom: 4px; }
.udd-name { font-weight: 600; font-size: 13.5px; }
.udd-mail { color: var(--muted); font-size: 12px; margin-top: 2px; }
.user-dd-item {
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.user-dd-item:hover { background: var(--chrome); }

/* ============ Home page ============ */
body.home { overflow: auto; background: var(--page); }

.home-header {
  background: #fff;
  border-bottom: 1px solid var(--grid-line);
  padding: 14px 32px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-crumb { color: var(--muted); font-size: 15px; font-weight: 500; }

.home-main { max-width: 1040px; margin: 0 auto; padding: 32px; }

.home-actions { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.home-actions h2 { font-size: 16px; font-weight: 650; letter-spacing: -0.01em; color: var(--ink); }

.doc-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }

.doc-card {
  background: var(--card);
  border: 1px solid var(--grid-line);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
  position: relative;
  min-height: 104px;
}
.doc-card:hover { box-shadow: var(--shadow); border-color: var(--border); transform: translateY(-1px); }
.doc-card .doc-name { font-weight: 600; font-size: 14px; margin-bottom: 6px; word-break: break-word; padding-right: 26px; }
.doc-card .doc-meta { color: var(--muted); font-size: 12px; }
.doc-card .doc-menu-btn {
  position: absolute; top: 10px; right: 10px;
  border: none; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 16px; padding: 2px 8px; border-radius: 6px;
}
.doc-card .doc-menu-btn:hover { background: var(--chrome); }
.doc-card .card-members {
  position: absolute;
  bottom: 12px; right: 14px;
}

.empty-note { color: var(--muted); padding: 40px 0; text-align: center; grid-column: 1 / -1; }

/* ============ Login ============ */
body.login-page {
  overflow: auto;
  background: var(--page);
}
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: #fff;
  border: 1px solid var(--grid-line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 36px;
  width: 100%;
  max-width: 400px;
}
.login-logo { margin-bottom: 26px; }
.login-card h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.02em; margin-bottom: 6px; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-card label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 14px;
}
.login-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.1s, box-shadow 0.1s;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(32,33,36,0.10); }
.login-error {
  background: #fdeceb;
  color: var(--danger);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 12.5px;
  margin-bottom: 14px;
}

/* ============ Admin ============ */
.admin-section {
  background: #fff;
  border: 1px solid var(--grid-line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
}
.admin-section h2 { font-size: 14px; font-weight: 650; margin-bottom: 14px; letter-spacing: -0.01em; }
.admin-create { display: flex; gap: 10px; flex-wrap: wrap; }
.admin-create input, .admin-create select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.admin-create input:focus { border-color: var(--accent); }
.admin-create input[type="email"] { min-width: 220px; }
.admin-error { color: var(--danger); font-size: 12.5px; margin-top: 10px; }

.user-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--grid-line);
}
.user-row:last-child { border-bottom: none; }
.user-info { flex: 1; min-width: 0; }
.ui-name { font-weight: 600; font-size: 13.5px; }
.ui-mail { color: var(--muted); font-size: 12px; }
.role-select {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 12.5px;
  font-family: inherit;
  background: #fff;
}
.role-help { display: flex; flex-direction: column; gap: 8px; color: var(--ink-soft); font-size: 13px; }

/* ============ Landing page ============ */
body.landing {
  overflow: auto;
  background:
    radial-gradient(circle at 50% -10%, #eceef1 0%, rgba(236, 238, 241, 0) 55%),
    #fff;
}
.landing-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 44px;
  max-width: 1160px;
  margin: 0 auto;
}
.landing-main { max-width: 1160px; margin: 0 auto; padding: 0 44px 40px; }

.eyebrow {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--muted);
  border: 1px solid var(--grid-line);
  background: #fff;
  border-radius: 999px;
  padding: 6px 14px;
  margin-bottom: 22px;
}

.hero {
  text-align: center;
  padding: 84px 0 56px;
  position: relative;
}
.hero::before {
  content: '';
  position: absolute;
  inset: -40px 0 0;
  background-image: radial-gradient(circle, #dfe1e5 1px, transparent 1.2px);
  background-size: 24px 24px;
  mask-image: radial-gradient(ellipse 60% 60% at 50% 30%, #000 0%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse 60% 60% at 50% 30%, #000 0%, transparent 70%);
  pointer-events: none;
}
.hero > * { position: relative; }
.hero h1 {
  font-size: clamp(38px, 5.6vw, 64px);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.04;
  max-width: 760px;
  margin: 0 auto 22px;
}
.hero p {
  color: var(--muted);
  font-size: 17px;
  line-height: 1.6;
  max-width: 560px;
  margin: 0 auto 32px;
}
.btn.big { padding: 13px 28px; font-size: 14.5px; border-radius: 11px; }
.btn.light { background: #fff; border-color: #fff; color: var(--ink); }
.btn.light:hover { background: #e8e9eb; }

.hero-pills { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 30px; }
.pill {
  font-size: 12.5px;
  color: var(--ink-soft);
  background: #fff;
  border: 1px solid var(--grid-line);
  border-radius: 999px;
  padding: 6px 14px;
}

/* --- product mockup --- */
.mock-window {
  max-width: 860px;
  margin: 26px auto 0;
  background: #fff;
  border: 1px solid var(--grid-line);
  border-radius: 18px;
  box-shadow: 0 30px 70px -24px rgba(20, 21, 23, 0.28), 0 4px 18px rgba(20, 21, 23, 0.06);
  overflow: hidden;
}
.mock-chrome {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--grid-line);
}
.mdot { width: 10px; height: 10px; border-radius: 50%; background: #e3e4e7; }
.mock-title { margin-left: 10px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.mock-presence { margin-left: auto; display: flex; }
.mav {
  width: 22px; height: 22px;
  border-radius: 50%;
  color: #fff;
  font-size: 8.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: -5px;
  box-shadow: 0 0 0 2px #fff;
  flex: none;
}
.mav:first-child { margin-left: 0; }
.mav.big { width: 30px; height: 30px; font-size: 11px; }
.mock-toolbar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--grid-line);
}
.mtb { height: 8px; border-radius: 4px; background: #eceef0; display: inline-block; }
.mtb.w1 { width: 26px; }
.mtb.w2 { width: 44px; }
.mtb.w3 { width: 60px; }
.mtb-sep { width: 1px; height: 14px; background: var(--grid-line); }
.mock-grid { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.mock-grid th {
  background: var(--header-bg);
  color: var(--header-fg);
  font-size: 10.5px;
  font-weight: 500;
  border: 1px solid var(--grid-line);
  padding: 5px 8px;
  width: 34px;
}
.mock-grid tr th:first-child { width: 30px; }
.mock-grid td {
  border: 1px solid var(--grid-line);
  padding: 6px 10px;
  min-width: 90px;
}
.mg-hdr { font-weight: 650; background: #f2f3f5; }
.mg-num { text-align: right; font-variant-numeric: tabular-nums; }
.mg-bold { font-weight: 650; }
.mg-sel { position: relative; box-shadow: inset 0 0 0 2px var(--accent); }
.mg-handle {
  position: absolute;
  right: -4px; bottom: -4px;
  width: 7px; height: 7px;
  background: var(--accent);
  border: 1.5px solid #fff;
}
.mock-formula {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  border-top: 1px solid var(--grid-line);
  font-size: 12.5px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.mock-fx { font-style: italic; font-family: Georgia, serif; color: var(--muted); }

/* --- sections --- */
.section { padding: 90px 0 10px; text-align: center; }
.section h2 {
  font-size: clamp(26px, 3.4vw, 38px);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 44px;
}
.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
  text-align: left;
}
.feature {
  background: #fff;
  border: 1px solid var(--grid-line);
  border-radius: 16px;
  padding: 26px 24px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.feature:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.feature .f-ic {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}
.feature h3 { font-size: 15px; font-weight: 650; margin-bottom: 7px; letter-spacing: -0.01em; }
.feature p { color: var(--muted); font-size: 13px; line-height: 1.55; }

/* --- split sections --- */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 60px;
  align-items: center;
  text-align: left;
  padding: 80px 0 10px;
}
.split.reverse .split-text { order: 2; }
.split.reverse .split-card { order: 1; }
.split h2 { margin-bottom: 16px; }
.split-text p { color: var(--muted); font-size: 15px; line-height: 1.65; max-width: 440px; }
.split-card {
  background: #fff;
  border: 1px solid var(--grid-line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 26px;
}
@media (max-width: 800px) {
  .split { grid-template-columns: 1fr; gap: 28px; }
  .split.reverse .split-text { order: 1; }
  .split.reverse .split-card { order: 2; }
}

.hist-mock { display: flex; flex-direction: column; gap: 14px; }
.hm-row { display: flex; align-items: center; gap: 12px; font-size: 13.5px; color: var(--ink-soft); }
.hm-row .mav { margin-left: 0; }
.hm-time { color: var(--muted); font-size: 11.5px; margin-left: 8px; }
.hm-diff {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 34px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}
.hm-before { background: #fdeceb; border-radius: 6px; padding: 4px 10px; text-decoration: line-through; }
.hm-after { background: #e6f4ea; border-radius: 6px; padding: 4px 10px; font-weight: 600; }

.share-mock { display: flex; flex-direction: column; }
.sm-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--grid-line);
}
.sm-row:last-child { border-bottom: none; }
.sm-info { flex: 1; display: flex; flex-direction: column; font-size: 13.5px; }
.sm-info span { color: var(--muted); font-size: 12px; }
.sm-check {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sm-check.dim { background: #e3e4e7; color: var(--muted); }

/* --- CTA panel --- */
.cta-panel {
  margin: 100px 0 30px;
  background: var(--accent);
  color: #fff;
  border-radius: 24px;
  text-align: center;
  padding: 70px 40px;
}
.cta-panel h2 {
  font-size: clamp(26px, 3.4vw, 40px);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 12px;
}
.cta-panel p { color: rgba(255, 255, 255, 0.65); font-size: 15px; margin-bottom: 30px; }

.landing-foot {
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  padding: 26px 0;
  border-top: 1px solid var(--grid-line);
}

/* ============ Sheet page layout ============ */
.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px 2px;
}
.topbar .logo .logo-mark { width: 34px; height: 34px; font-size: 14px; border-radius: 9px; }
.topbar a { text-decoration: none; }

.title-block { display: flex; flex-direction: column; min-width: 0; }
.title-row { display: flex; align-items: center; gap: 8px; }

.menubar { display: flex; margin-left: 2px; }
.menu-btn {
  border: none;
  background: transparent;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
}
.menu-btn:hover, .menu-btn.open { background: var(--chrome); }
.ctx-menu .item.item-disabled { opacity: 0.4; pointer-events: none; }

#docTitle {
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  padding: 2px 8px;
  min-width: 80px;
  max-width: 420px;
  background: transparent;
  font-family: inherit;
}
#docTitle:hover { border-color: var(--border); }
#docTitle:focus { border-color: var(--accent); outline: none; }

#saveStatus { color: var(--muted); font-size: 12px; min-width: 70px; }

.topbar-spacer { flex: 1; }

.view-badge {
  background: var(--chrome);
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 999px;
  padding: 4px 12px;
  letter-spacing: 0.02em;
}

.presence { display: flex; align-items: center; margin-right: 4px; }
.presence .avatar { margin-left: -6px; box-shadow: 0 0 0 2px #fff; }
.presence .avatar:first-child { margin-left: 0; }

/* ---- toolbar ---- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  margin: 4px 10px 6px;
  padding: 4px 8px;
  background: var(--chrome);
  border-radius: 999px;
  flex-wrap: nowrap;
  overflow: hidden;
}

.tb-btn {
  border: none;
  background: transparent;
  border-radius: 7px;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.tb-btn:hover { background: rgba(32, 33, 36, 0.07); }
.tb-btn.active { background: rgba(32, 33, 36, 0.14); color: var(--ink); }
.tb-btn:disabled { opacity: 0.4; cursor: default; }
.tb-btn:disabled:hover { background: transparent; }
.tb-btn svg { display: block; flex: none; }
.tb-btn.tb-glyph { font-size: 11.5px; letter-spacing: -0.02em; }

.tb-sep { width: 1px; height: 20px; background: #d3d5d8; margin: 0 5px; flex: none; }

.tb-select {
  border: none;
  background: transparent;
  height: 28px;
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0 4px;
  font-family: inherit;
}
.tb-select:hover { background: rgba(32, 33, 36, 0.07); }

.tb-btn .swatch {
  position: absolute;
  bottom: 3px;
  left: 7px;
  right: 7px;
  height: 3px;
  border-radius: 1px;
}
.tb-btn.has-swatch { position: relative; }

/* view-only mode */
.view-only .toolbar { opacity: 0.5; pointer-events: none; }
.view-only .add-sheet { display: none; }
.view-only #docTitle { pointer-events: none; }

/* ---- formula bar ---- */
.formula-row {
  display: flex;
  align-items: center;
  border-top: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--border);
  height: 30px;
}
#nameBox {
  width: 90px;
  border: none;
  outline: none;
  padding: 0 10px;
  font-size: 13px;
  color: var(--ink);
  height: 100%;
  font-family: inherit;
}
.fx-label {
  color: var(--muted);
  font-style: italic;
  font-family: Georgia, serif;
  padding: 0 10px;
  border-left: 1px solid var(--grid-line);
  user-select: none;
}
#formulaInput {
  flex: 1;
  border: none;
  outline: none;
  font-size: 13px;
  height: 100%;
  padding: 0 8px;
  font-family: inherit;
}

/* ---- grid ---- */
.grid-area {
  flex: 1;
  display: grid;
  grid-template-columns: var(--header-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  overflow: hidden;
  position: relative;
}

.corner {
  background: var(--header-bg);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  z-index: 4;
  cursor: pointer;
}

.col-headers, .row-headers {
  overflow: hidden;
  position: relative;
  background: var(--header-bg);
  z-index: 3;
  user-select: none;
}
.col-headers { border-bottom: 1px solid var(--border); }
.row-headers { border-right: 1px solid var(--border); }

.hdr-cell {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  color: var(--header-fg);
  background: var(--header-bg);
  overflow: hidden;
}
.col-headers .hdr-cell { border-right: 1px solid var(--grid-line); height: 100%; top: 0; }
.row-headers .hdr-cell { border-bottom: 1px solid var(--grid-line); width: 100%; left: 0; }
.hdr-cell.sel { background: #e2e3e6; color: var(--ink); font-weight: 600; }

.viewport {
  overflow: auto;
  position: relative;
  background: #fff;
}
.canvas { position: relative; }

.cells-layer .cell {
  position: absolute;
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  padding: 0 4px;
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: nowrap;
  font-size: 13px;
  background: #fff;
  cursor: default;
}
.cell > span { overflow: hidden; text-overflow: clip; width: 100%; text-align: inherit; }

.selection-layer { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 2; }
.sel-range {
  position: absolute;
  background: rgba(32, 33, 36, 0.07);
  border: 1px solid var(--sel-border);
}
.sel-active {
  position: absolute;
  border: 2px solid var(--accent);
  background: transparent;
}
.fill-handle {
  position: absolute;
  width: 7px;
  height: 7px;
  background: var(--accent);
  border: 1px solid #fff;
  pointer-events: auto;
  cursor: crosshair;
  z-index: 3;
}
.fill-preview {
  position: absolute;
  border: 1.5px dashed var(--sel-border);
  background: transparent;
}
.cut-marker {
  position: absolute;
  border: 1.5px dashed #909399;
}

/* in-cell editor */
.editor {
  position: absolute;
  z-index: 5;
  display: none;
}
.editor input {
  border: 2px solid var(--accent);
  outline: none;
  font-size: 13px;
  font-family: inherit;
  padding: 0 3px;
  background: #fff;
  min-width: 100%;
  height: 100%;
  box-shadow: 0 2px 8px rgba(20, 21, 23, 0.20);
}

/* resize guides */
.resize-guide {
  position: absolute;
  background: var(--accent);
  z-index: 10;
  display: none;
  pointer-events: none;
}
body.col-resizing { cursor: col-resize !important; }
body.row-resizing { cursor: row-resize !important; }
body.col-resizing .hdr-cell, body.row-resizing .hdr-cell { cursor: inherit; }

/* ---- typed columns in the grid ---- */
.hdr-tic { color: #9aa0a6; margin-right: 4px; display: inline-flex; vertical-align: -1px; }
.hdr-tic svg { width: 10px; height: 10px; }
.cell-link { color: #0b57d0; text-decoration: none; }
.cell-link:hover { text-decoration: underline; }
.pwd-dots { color: var(--muted); letter-spacing: 2px; }
.link-sec { color: var(--muted); font-size: 12px; margin-right: 6px; vertical-align: middle; }
.modal-msg { color: var(--ink-soft); font-size: 13.5px; line-height: 1.55; padding: 4px 0 6px; }
.chip.link-chip { cursor: pointer; }
.chip.link-chip:hover { text-decoration: underline; }

/* record card */
.rec-src { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.rec-row {
  display: flex;
  gap: 14px;
  padding: 9px 0;
  border-bottom: 1px solid var(--grid-line);
}
.rec-row:last-child { border-bottom: none; }
.rec-label {
  width: 135px;
  flex: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rec-val {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  word-break: break-word;
  white-space: normal;
  line-height: 1.5;
}
.rec-val .chip { margin-bottom: 3px; }
.rec-empty { color: #c0c3c7; font-size: 12.5px; }
.rec-secret { font-family: Consolas, monospace; font-size: 12.5px; }
.rec-eye {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  vertical-align: middle;
  margin-left: 6px;
}
.rec-eye:hover { background: var(--chrome); color: var(--ink); }
.rec-back { display: inline-flex; align-items: center; gap: 5px; margin-right: 10px; }

.hdr-cell.named { font-weight: 600; color: var(--ink-soft); padding: 0 4px; }
.hdr-cell { text-overflow: ellipsis; white-space: nowrap; }

/* choice color popover */
.choice-color-pop {
  position: fixed;
  background: #fff;
  border: 1px solid var(--grid-line);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  padding: 10px;
  z-index: 500;
  display: grid;
  grid-template-columns: repeat(5, 24px);
  gap: 6px;
}
.ccp-sw {
  width: 24px; height: 24px;
  border-radius: 6px;
  border: 1.5px solid;
  cursor: pointer;
}
.ccp-sw:hover { transform: scale(1.1); }
.ccp-sw.on { outline: 2px solid var(--accent); outline-offset: 1px; }
.ccp-custom {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--ink-soft);
  cursor: pointer;
  padding-top: 4px;
  border-top: 1px solid var(--grid-line);
  margin-top: 2px;
}
.ccp-custom input[type="color"] {
  width: 26px; height: 26px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px;
  background: #fff;
  cursor: pointer;
}

.chip {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11.5px;
  font-weight: 500;
  margin-right: 4px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}
.chip.link-chip { background: var(--chrome); color: var(--ink-soft); }
.uchip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--chrome);
  border-radius: 999px;
  padding: 1px 8px 1px 2px;
  font-size: 11.5px;
  vertical-align: middle;
}
.uchip-av {
  width: 16px; height: 16px;
  border-radius: 50%;
  color: #fff;
  font-size: 7px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tcheck {
  display: inline-flex;
  width: 15px; height: 15px;
  border: 1.5px solid #b7bbc0;
  border-radius: 4px;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  cursor: pointer;
}
.tcheck svg { width: 11px; height: 11px; }
.tcheck.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* pickers */
.tpick {
  position: fixed;
  background: #fff;
  border: 1px solid var(--grid-line);
  border-radius: 12px;
  box-shadow: var(--shadow-pop);
  z-index: 400;
  min-width: 240px;
  max-width: 330px;
  padding: 8px;
}
.tpick-search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 11px;
  font: inherit;
  font-size: 13px;
  outline: none;
  margin-bottom: 6px;
}
.tpick-search:focus { border-color: var(--accent); }
.tpick-list { max-height: 280px; overflow-y: auto; }
.tpick-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.tpick-item:hover { background: var(--chrome); }
.tpick-item .chip { margin-right: 0; }
.tpick-check { margin-left: auto; font-size: 11px; color: var(--ink); }
.tpick-add { color: #0b57d0; font-size: 12.5px; }
.tpick-done { display: flex; justify-content: flex-end; padding: 6px 2px 2px; }
.tpick-tic { display: inline-flex; color: #9aa0a6; margin-right: 2px; }

/* field dialog */
.fld-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 14px 0 6px;
}
.fld-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font: inherit;
  font-size: 13px;
  outline: none;
}
.fld-input:focus { border-color: var(--accent); }
.fld-note { color: var(--muted); font-size: 12.5px; padding: 4px 0; }
.fld-choice { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.fld-choice .fld-input.choice { flex: 1; padding: 7px 10px; }
.fld-choice-sw {
  width: 22px; height: 22px;
  border-radius: 6px;
  border: 1.5px solid;
  cursor: pointer;
  flex: none;
}
.fld-choice-x {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
  border-radius: 6px;
  padding: 0 7px;
}
.fld-choice-x:hover { background: var(--chrome); color: var(--danger); }

/* ---- tab bar (below the toolbar, above the grid) ---- */
.tabbar {
  display: flex;
  align-items: center;
  background: #fff;
  height: 34px;
  padding: 0 12px;
  gap: 2px;
}
.tabbar .add-sheet {
  border: none; background: transparent; font-size: 17px;
  width: 30px; height: 28px; border-radius: 50%; cursor: pointer; color: var(--ink-soft);
}
.tabbar .add-sheet:hover { background: rgba(32,33,36,0.08); }

.sheet-tab {
  padding: 0 14px;
  height: 27px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--ink-soft);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  user-select: none;
}
.sheet-tab:hover { background: rgba(32,33,36,0.06); }
.sheet-tab.active {
  background: var(--chrome);
  color: var(--ink);
  font-weight: 600;
}
.sheet-tab .lock { display: inline-flex; opacity: 0.7; }
.sheet-tab .lock svg { display: block; }
.sheet-tab input {
  border: none; outline: none; background: #fff;
  font-size: 12.5px; width: 90px; padding: 2px 4px;
  font-family: inherit;
}

.tab-spacer { flex: 1; }

#statusBar {
  color: var(--muted);
  font-size: 12px;
  padding-right: 12px;
  white-space: nowrap;
}

/* ---- context menu ---- */
.ctx-menu {
  position: fixed;
  background: #fff;
  border: 1px solid var(--grid-line);
  border-radius: 12px;
  box-shadow: var(--shadow-pop);
  padding: 6px;
  z-index: 100;
  min-width: 200px;
  font-size: 13px;
}
.ctx-menu .item {
  padding: 8px 14px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  border-radius: 8px;
}
.ctx-menu .item:hover { background: var(--chrome); }
.ctx-menu .item .kbd { color: #9aa0a6; font-size: 11.5px; }
.ctx-menu .sep { height: 1px; background: var(--grid-line); margin: 5px 8px; }
.ctx-menu .item.danger { color: var(--danger); }

/* ---- color picker popover ---- */
.color-pop {
  position: fixed;
  background: #fff;
  border: 1px solid var(--grid-line);
  border-radius: 12px;
  box-shadow: var(--shadow-pop);
  padding: 10px;
  z-index: 100;
  display: grid;
  grid-template-columns: repeat(8, 22px);
  gap: 4px;
}
.color-pop .cs {
  width: 22px; height: 22px; border-radius: 5px; cursor: pointer;
  border: 1px solid rgba(0,0,0,0.12);
}
.color-pop .cs:hover { transform: scale(1.12); }
.color-pop .cs.none { background: #fff; position: relative; }
.color-pop .cs.none::after {
  content: '';
  position: absolute; left: -2px; right: -2px; top: 50%;
  height: 2px; background: var(--danger); transform: rotate(-45deg);
}

/* ---- modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 21, 23, 0.42);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal {
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow-pop);
  width: 100%;
  max-width: 440px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.modal.wide { max-width: 760px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 12px;
}
.modal-title { font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.modal-x {
  border: none; background: transparent; font-size: 22px; line-height: 1;
  cursor: pointer; color: var(--muted); border-radius: 6px; padding: 2px 8px;
}
.modal-x:hover { background: var(--chrome); }
.modal-body { padding: 4px 22px; overflow-y: auto; flex: 1; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px 20px;
}

.share-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--grid-line);
}
.share-row:last-child { border-bottom: none; }
.share-row .user-info { flex: 1; min-width: 0; }
.share-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.restrict-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 2px;
  font-weight: 600;
  font-size: 13.5px;
  border-bottom: 1px solid var(--grid-line);
  margin-bottom: 6px;
}
.restrict-toggle input { width: 16px; height: 16px; accent-color: var(--accent); }
.restrict-note { color: var(--muted); font-size: 12px; font-weight: 400; margin-top: 2px; }

/* ---- history drawer ---- */
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 340px;
  background: #fff;
  border-left: 1px solid var(--grid-line);
  box-shadow: -6px 0 24px rgba(20,21,23,0.10);
  z-index: 250;
  display: flex;
  flex-direction: column;
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 10px;
}
.drawer-title { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.drawer-body { flex: 1; overflow-y: auto; padding: 4px 12px 16px; }

.hist-rec {
  padding: 10px 8px;
  border-radius: 10px;
  margin-bottom: 2px;
}
.hist-rec:hover { background: var(--page); }
.hist-head { display: flex; align-items: center; gap: 9px; margin-bottom: 5px; }
.hist-who { font-weight: 600; font-size: 12.5px; }
.hist-when { color: var(--muted); font-size: 11.5px; }
.hist-sub {
  color: var(--ink-soft);
  font-size: 12.5px;
  padding: 2px 0 2px 32px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.hist-view {
  color: #0b57d0;
  cursor: pointer;
  font-size: 12px;
  text-decoration: none;
}
.hist-view:hover { text-decoration: underline; }
.hist-empty { color: var(--muted); text-align: center; padding: 40px 10px; }

/* diff view */
.diff-cols { display: flex; gap: 16px; margin: 10px 0 16px; }
.diff-col { flex: 1; min-width: 0; overflow-x: auto; }
.diff-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 6px;
}
.diff-grid { border-collapse: collapse; font-size: 12px; }
.diff-grid th, .diff-grid td {
  border: 1px solid var(--grid-line);
  padding: 3px 8px;
  min-width: 52px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}
.diff-grid th { background: var(--header-bg); color: var(--header-fg); font-weight: 500; font-size: 11px; text-align: center; }
.diff-grid td.chg-before { background: #fdeceb; }
.diff-grid td.chg-after { background: #e6f4ea; }
.diff-list { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 8px 0 16px; }
.diff-list th, .diff-list td {
  border-bottom: 1px solid var(--grid-line);
  padding: 6px 10px;
  text-align: left;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.diff-list th { color: var(--muted); font-weight: 600; font-size: 11.5px; }
.diff-note { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
