:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d8dee8;
  --brand: #f6b21a;
  --brand-strong: #d99400;
  --blue: #1d4ed8;
  --amber: #b7791f;
  --danger: #b42318;
  --shadow: 0 10px 26px rgba(20, 31, 46, .08);
  --row-tool-col-width: 52px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

button, input, select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  white-space: nowrap;
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.history-range-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.history-range-control span {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.history-range-control select {
  width: 132px;
  height: 34px;
  padding: 6px 8px;
}

.personal-view-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.personal-view-tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.personal-view-tool span {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.personal-view-tool select {
  width: 128px;
  height: 34px;
  padding: 6px 8px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
}

.login-shell, .public-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(115deg, rgba(0, 0, 0, .92), rgba(16, 18, 21, .78)),
    url("https://images.unsplash.com/photo-1494412651409-8963ce7935a7?auto=format&fit=crop&w=1800&q=80") center/cover;
}

.login-panel, .query-panel {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: 36px;
  align-items: center;
  color: #f8fafc;
  background: rgba(13, 15, 19, .92);
  border: 1px solid rgba(246, 178, 26, .32);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 34px;
}

.query-panel {
  width: min(720px, 100%);
  grid-template-columns: 1fr;
}

.login-panel h1, .query-panel h1 {
  margin: 0 0 12px;
  font-size: 34px;
  line-height: 1.18;
}

.login-panel .muted, .query-panel .muted {
  color: #c9d0d8;
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 22px;
  color: #fff;
  letter-spacing: 0;
  font-size: 24px;
  font-weight: 900;
}

.brand-logo span {
  display: inline-grid;
  place-items: center;
  min-width: 82px;
  height: 40px;
  color: #111827;
  background: var(--brand);
}

.brand-logo strong {
  color: #fff;
  font-weight: 900;
}

.stack {
  display: grid;
  gap: 14px;
}

.primary, .secondary, .ghost {
  border-radius: 6px;
  padding: 9px 14px;
  min-height: 38px;
  white-space: nowrap;
}

.primary {
  color: #111827;
  background: var(--brand);
  font-weight: 700;
}

.primary:hover { background: var(--brand-strong); }

.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #111827;
  background: #fff4d6;
  text-decoration: none;
}

.ghost {
  color: var(--muted);
  background: #edf1f5;
}

.link {
  color: var(--brand);
  text-decoration: none;
  font-size: 14px;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px;
  color: #f8fafc;
  background: #111318;
}

.sidebar h2 {
  margin: 0;
  font-size: 24px;
}

.sidebar .eyebrow { color: var(--brand); }

nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  text-align: left;
  color: #cbd5e1;
  background: transparent;
  border-radius: 6px;
  padding: 10px 12px;
}

.nav-item.active {
  color: #fff;
  background: rgba(255, 255, 255, .12);
}

.account {
  margin-top: auto;
  display: grid;
  gap: 8px;
  color: #cbd5e1;
  font-size: 14px;
}

.account strong { color: #fff; }

.content {
  min-width: 0;
  padding: 22px;
  overflow-x: hidden;
  overflow-y: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 28px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.inline-add {
  color: #2563eb;
  background: transparent;
  font-weight: 700;
  padding: 8px 10px;
  min-width: max-content;
}

.group-tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: clamp(150px, 22vw, 240px);
  min-width: 150px;
}

.group-tool span {
  margin: 0;
  white-space: nowrap;
}

.select-filter-tool { width: auto; max-width: none; }
.select-filter-tool select { max-width: 150px; }

.search {
  flex: 1 1 260px;
  max-width: 520px;
  min-width: 180px;
}

.status-line {
  min-height: 22px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.sheet-wrap {
  height: clamp(220px, calc(100dvh - 250px), 62vh);
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  background: #fff;
  scrollbar-gutter: stable both-edges;
  overscroll-behavior: contain;
  will-change: scroll-position;
  transform: translate3d(0, 0, 0);
}

.sheet {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.sheet th, .sheet td {
  border: 1px solid var(--line);
  padding: 0;
  min-width: 116px;
  height: 34px;
  background: #fff;
}

.sheet th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 9px;
  color: #344054;
  background: #eef2f6;
  text-align: left;
  user-select: none;
}

.virtual-spacer-row td {
  min-height: 0;
  height: 0;
  border-top: 0;
  border-bottom: 0;
  padding: 0;
  background: transparent;
}

.sheet tbody {
  will-change: contents;
}

.sheet tbody tr {
  backface-visibility: hidden;
}

.sheet tbody tr.is-shell-row td {
  contain: paint;
}

.virtual-shell-cell {
  color: #0f172a;
  background: #fff;
}

.virtual-shell-text {
  display: block;
  width: 100%;
  overflow: hidden;
  padding: 0 6px;
  line-height: calc(var(--sheet-row, 28px) - 2px);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet tbody tr.is-active-row td {
  position: relative;
  z-index: 11;
  background: #eaf4ff !important;
  box-shadow: inset 0 2px 0 #2196f3, inset 0 -2px 0 #2196f3;
}

.sheet tbody tr.is-active-row td:first-child {
  border-left: 2px solid #2196f3 !important;
}

.sheet tbody tr.is-active-row td:last-child {
  border-right: 2px solid #2196f3 !important;
}

.sheet.has-personal-freeze tbody tr.is-active-row td.row-tool-col,
.sheet.has-personal-freeze tbody tr.is-active-row td.personal-frozen-col {
  z-index: 26;
  background: #eaf4ff !important;
}

.sheet th.lock-col, .sheet td.lock-col,
.sheet th.row-tool-col, .sheet td.row-tool-col {
  min-width: var(--row-tool-col-width);
  width: var(--row-tool-col-width);
  max-width: var(--row-tool-col-width);
  text-align: center;
}

.sheet th.add-col-edge, .sheet td.add-col-edge {
  min-width: 44px;
  width: 44px;
  text-align: center;
  background: #fbfcfe;
}

.top-add, .edge-add-column {
  width: 32px;
  height: 32px;
  color: #667085;
  background: transparent;
  border-radius: 4px;
  font-size: 20px;
}

.top-add:hover, .edge-add-column:hover {
  color: #111827;
  background: #eef2f6;
}

.column-head {
  display: grid;
  gap: 6px;
  min-width: 140px;
}

.draggable-col.dragging {
  opacity: .5;
}

.draggable-col[draggable="true"] {
  cursor: grab;
}

.draggable-col[draggable="true"]:active {
  cursor: grabbing;
}

.draggable-col.drag-over-col {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
  background: rgba(255, 184, 0, .12);
}

.drag-handle {
  cursor: grab;
}

.drag-handle:active {
  cursor: grabbing;
}

.sort-button {
  padding: 0;
  color: #344054;
  background: transparent;
  text-align: left;
  font-weight: 700;
}

.column-tools {
  display: flex;
  gap: 5px;
  align-items: center;
  flex-wrap: wrap;
}

.color-tool {
  width: 26px;
  height: 26px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.color-tool input {
  width: 34px;
  height: 34px;
  margin: -4px;
  padding: 0;
  border: 0;
}

.color-tool.text {
  border-color: #667085;
}

.column-access, .currency-select, .decimal-select {
  min-width: 112px;
  height: 26px;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.access-menu {
  position: relative;
  z-index: 8;
}

.access-menu summary {
  min-width: 112px;
  height: 26px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  font-size: 12px;
  cursor: pointer;
  list-style: none;
}

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

.access-options {
  position: absolute;
  z-index: 30;
  top: 30px;
  left: 0;
  display: grid;
  gap: 4px;
  min-width: 150px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: var(--shadow);
}

.access-options label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #344054;
  white-space: nowrap;
  font-size: 12px;
}

.access-options input {
  width: auto;
}

.access-options span {
  display: inline-block;
  width: 14px;
  color: var(--brand);
  font-weight: 800;
}

.access-trigger {
  min-width: 112px;
  height: 26px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: #101828;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}

.access-floating {
  position: fixed;
  z-index: 1000;
  display: grid;
  gap: 4px;
  min-width: 170px;
  max-height: 260px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: var(--shadow);
}

.access-floating label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #344054;
  white-space: nowrap;
  font-size: 12px;
}

.access-floating input {
  width: auto;
}

.access-floating span {
  display: inline-block;
  width: 14px;
  color: var(--brand);
  font-weight: 800;
}

.currency-select, .decimal-select {
  min-width: 52px;
}

.formula-edit {
  height: 26px;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.formula-builder {
  display: grid;
  grid-template-columns: 1fr 46px 1fr;
  gap: 4px;
}

.formula-builder select {
  height: 26px;
  padding: 3px 5px;
  border-radius: 4px;
  font-size: 12px;
}

.formula-open {
  min-height: 26px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: #344054;
  text-align: left;
  font-size: 12px;
}

.mini {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 4px;
  color: #fff;
  background: #667085;
}

.mini.danger {
  background: #b42318;
}

.formula-chip {
  display: inline-block;
  max-width: 150px;
  overflow: hidden;
  color: #7c2d12;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.column-form {
  display: grid;
  grid-template-columns: 1.1fr 110px 1.1fr 110px 160px 90px;
  gap: 10px;
  margin-bottom: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #fff;
}

.select-option-builder { grid-column: 1 / -1; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: #f8fafc; }
.select-option-builder-head, .select-options-head, .select-options-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.select-option-builder-head span { color: var(--muted); font-size: 12px; }
.select-option-rows { display: grid; gap: 7px; margin-bottom: 8px; }
.select-option-row { display: grid; grid-template-columns: 38px minmax(140px, 1fr) auto auto auto; gap: 6px; align-items: center; }
.select-option-row input[type="color"] { width: 38px; height: 32px; padding: 2px; }
.select-options-modal { position: fixed; inset: 0; z-index: 1200; display: grid; place-items: center; padding: 20px; background: rgba(15, 23, 42, .42); }
.select-options-panel { width: min(560px, 100%); max-height: calc(100vh - 40px); overflow: auto; padding: 16px; border-radius: 10px; background: #fff; box-shadow: 0 18px 55px rgba(15, 23, 42, .25); }
.select-options-actions { justify-content: flex-end; margin: 12px 0 0; }
.select-option-cell { display: flex; align-items: center; height: calc(var(--sheet-row, 28px) - 2px); padding: 2px 6px; }
.select-option-cell select { width: 100%; color: inherit; font-weight: 600; }
.select-option-tag { display: inline-flex; align-items: center; max-width: 100%; padding: 2px 8px; overflow: hidden; border-radius: 999px; color: #fff; font-size: 12px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.column-options-btn { min-width: 44px; }

.sheet-settings {
  display: grid;
  grid-template-columns: 240px minmax(260px, 1fr) 280px 130px;
  gap: 12px;
  align-items: end;
  margin-bottom: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #fff;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.check-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.check-grid label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #f8fafc;
  font-size: 12px;
}

.check-grid input {
  width: auto;
}

.check-grid span {
  display: inline-block;
  width: 14px;
  color: var(--brand);
  font-weight: 800;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 90px;
  gap: 8px;
}

.money-cell {
  display: flex;
  align-items: center;
  height: 34px;
}

.money-cell span {
  padding-left: 8px;
  color: #667085;
  font-weight: 700;
}

.progress-cell {
  display: grid;
  grid-template-columns: minmax(54px, 1fr) 44px 12px;
  align-items: center;
  gap: 6px;
  min-width: 118px;
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 2px;
  background: #eef1f5;
}

.progress-track span {
  display: block;
  height: 100%;
  transition: width .16s ease;
}

.sheet td input.progress-value {
  width: 44px;
  min-width: 44px;
  padding: 2px 0;
  border: 0;
  background: transparent;
  text-align: right;
}

.progress-symbol {
  color: #475467;
  font-size: 12px;
}

.image-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 190px;
  max-width: 300px;
  padding: 4px 8px;
  min-height: 38px;
  border: 1px dashed transparent;
}

.image-thumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  max-width: 210px;
}

.image-thumb {
  position: relative;
  display: inline-flex;
  overflow: visible;
}

.image-cell img {
  width: 34px;
  height: 28px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: zoom-in;
}

.image-cell span {
  color: #98a2b3;
  font-size: 12px;
}

.image-cell.drag-over {
  border-color: #2563eb;
  background: #eff6ff;
}

.image-delete {
  position: absolute;
  top: -7px;
  right: -7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 999px;
  line-height: 1;
  opacity: 0;
  box-shadow: 0 2px 6px rgba(15, 23, 42, .18);
  pointer-events: none;
  transform: scale(.86);
  transition: opacity .12s ease, transform .12s ease;
  z-index: 5;
}

.image-thumb:hover .image-delete,
.image-thumb:focus-within .image-delete {
  opacity: .96;
  pointer-events: auto;
  transform: scale(1);
}

.image-count {
  color: #667085;
  font-size: 11px;
}

.upload-btn {
  position: relative;
  overflow: hidden;
  color: #2563eb;
  font-size: 12px;
  cursor: pointer;
}

.upload-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.image-preview-modal {
  z-index: 2600;
}

.image-preview-panel {
  position: relative;
  max-width: min(92vw, 1100px);
  max-height: 88vh;
  padding: 44px 14px 14px;
  border-radius: 8px;
  background: #111827;
  box-shadow: 0 20px 70px rgba(0, 0, 0, .35);
}

.image-preview-panel img {
  display: block;
  max-width: calc(92vw - 28px);
  max-height: calc(88vh - 58px);
  object-fit: contain;
}

#imagePreviewCloseBtn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  background: #fff;
  color: #111827;
}

.group-row td {
  height: 42px;
  padding: 8px;
  background: #f7f9fc;
  border-top: 8px solid #eef2f6;
  font-weight: 700;
}

.group-row button {
  margin-right: 8px;
  color: #667085;
  background: transparent;
}

.group-row em {
  margin-left: 10px;
  color: #667085;
  font-style: normal;
  font-weight: 400;
}

.group-row small {
  margin-left: 18px;
  color: #667085;
  font-weight: 400;
}

.bottom-scroller {
  position: sticky;
  bottom: 0;
  z-index: 10;
  height: 22px;
  min-height: 22px;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--line);
  border-top: 0;
  background: #fff;
}

.bottom-scroller div {
  height: 1px;
}

.row-context-menu {
  position: fixed;
  z-index: 1800;
  width: 190px;
  overflow: hidden;
  border: 1px solid #d9dee7;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 44px rgba(15, 23, 42, .18);
}

.row-context-menu button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 0 18px;
  border: 0;
  border-radius: 0;
  color: #1f2937;
  background: #fff;
  font-size: 18px;
  text-align: left;
}

.row-context-menu button:hover {
  background: #f4f7fb;
}

.context-icon {
  width: 22px;
  color: #111827;
  font-size: 22px;
  line-height: 1;
}

.record-drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1700;
  display: flex;
  justify-content: flex-end;
  background: rgba(15, 23, 42, .18);
}

.record-drawer-panel {
  display: flex;
  flex-direction: column;
  width: clamp(380px, 42vw, 620px);
  max-width: 100vw;
  height: 100dvh;
  background: #fff;
  box-shadow: -18px 0 44px rgba(15, 23, 42, .18);
}

.record-drawer-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 8px;
  padding: 22px 24px 16px;
  border-bottom: 1px solid #edf0f5;
  background: #fff;
}

.record-drawer-head h2 {
  margin: 0;
  color: #0f172a;
  font-size: 28px;
  font-weight: 600;
}

.record-drawer-close,
.record-drawer-more {
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: #111827;
  font-size: 26px;
  line-height: 1;
}

.record-drawer-more {
  font-size: 22px;
}

.record-drawer-fields {
  flex: 1;
  overflow: auto;
  padding: 16px 24px 20px;
}

.record-field {
  display: grid;
  grid-template-columns: minmax(132px, 38%) 1fr;
  gap: 18px;
  align-items: start;
  min-height: 48px;
  padding: 8px 0;
}

.record-field-label {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 8px;
  align-items: start;
  color: #1f2937;
  font-size: 18px;
  line-height: 1.35;
}

.record-field-icon {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  border: 1px solid #8b949e;
  border-radius: 4px;
  color: #68717c;
  font-size: 13px;
  font-weight: 700;
}

.record-field-control {
  min-width: 0;
}

.record-drawer-input {
  width: 100%;
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #0f172a;
  background: #fff;
  font-size: 16px;
}

.record-drawer-input:focus {
  border-color: #3b82f6;
  outline: 2px solid rgba(59, 130, 246, .16);
}

.record-drawer-input:disabled,
.record-drawer-readonly {
  color: #9aa3af;
  background: transparent;
}

.record-drawer-textarea {
  min-height: 76px;
  resize: vertical;
}

.record-drawer-foot {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid #edf0f5;
  background: #fff;
}

.record-drawer-backdrop.is-saving .record-drawer-panel {
  opacity: .68;
  pointer-events: none;
}

@media (max-width: 760px) {
  .record-drawer-panel {
    width: 100vw;
  }

  .record-drawer-head {
    padding: 18px 16px 12px;
  }

  .record-drawer-head h2 {
    font-size: 24px;
  }

  .record-drawer-fields {
    padding: 12px 16px 18px;
  }

  .record-field {
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 10px 0;
  }

  .record-field-label {
    font-size: 16px;
  }

  .record-drawer-foot {
    padding: 12px 16px;
  }
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, .28);
}

.modal-panel {
  width: min(720px, calc(100vw - 36px));
  min-height: 520px;
  overflow: hidden;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(15, 23, 42, .24);
}

.modal-panel header,
.modal-panel footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
}

.modal-panel header h2 {
  margin: 0;
  font-size: 20px;
}

#formulaCloseBtn {
  width: 34px;
  height: 34px;
  background: transparent;
  font-size: 24px;
}

#formulaInput {
  width: calc(100% - 48px);
  height: 180px;
  margin: 0 24px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  resize: none;
  font-size: 18px;
}

.formula-help {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 210px;
  border-bottom: 1px solid var(--line);
}

.formula-list {
  overflow: auto;
  padding: 12px;
  border-right: 1px solid var(--line);
  background: #f8fafc;
}

.formula-column-item {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 5px;
  padding: 8px 10px;
  border-radius: 4px;
  color: #344054;
  background: transparent;
  text-align: left;
}

.formula-column-item:hover {
  background: #e8f0fe;
}

.formula-column-item span {
  color: #98a2b3;
  font-size: 11px;
}

.formula-preview {
  padding: 18px;
}

.sheet td input, .sheet td select {
  height: 34px;
  border: 0;
  border-radius: 0;
  padding: 7px 9px;
  background: transparent;
}

.sheet td input[readonly], .sheet td select:disabled {
  color: #667085;
  background: #f8fafc;
}

.locked {
  color: var(--amber);
  font-weight: 700;
}

.split {
  display: grid;
  grid-template-columns: 320px 1fr 360px;
  gap: 16px;
  align-items: start;
}

.mini-form {
  display: grid;
  grid-template-columns: 1fr 80px;
  gap: 8px;
}

.inline-select {
  min-width: 130px;
  padding: 5px 8px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.compact {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.compact th, .compact td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
}

.query-form {
  display: flex;
  gap: 10px;
}

.query-form input {
  font-size: 16px;
}

.query-result {
  min-height: 90px;
  margin: 18px 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #f8fafc;
}

.result-status {
  display: block;
  margin: 8px 0;
  color: var(--brand);
  font-size: 26px;
  font-weight: 800;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 12px 14px;
  color: #fff;
  background: #1d2939;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.toast.error { background: var(--danger); }

.language-switch-slot {
  padding: 0 12px 6px;
}

.language-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 6px;
  background: rgba(255,255,255,.06);
}

.language-switch button {
  min-width: 0;
  height: 28px;
  border: 0;
  border-radius: 4px;
  padding: 0 8px;
  background: transparent;
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.language-switch button.active {
  background: var(--brand);
  color: #111318;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 190px 1fr;
  }

  .sidebar {
    padding: 16px;
  }

  .content {
    padding: 18px;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar > button,
  .toolbar > a,
  .toolbar > .secondary,
  .toolbar > .inline-add {
    flex: 0 0 auto;
  }

  .column-form,
  .sheet-settings {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 860px) {
  .login-panel {
    grid-template-columns: 1fr;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 12px;
    padding: 8px 12px;
  }

  .sidebar h2 {
    font-size: 16px;
    grid-column: 1;
  }

  nav {
    grid-column: 1;
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-item {
    flex: 0 0 auto;
    min-width: 72px;
    padding: 6px 10px;
    font-size: 13px;
    text-align: center;
  }

  .account {
    grid-column: 2;
    grid-row: 1 / 3;
    margin-top: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    font-size: 12px;
  }

  .content {
    padding: 8px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 8px;
  }

  .topbar h1 {
    font-size: 18px;
  }

  .toolbar-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--muted);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    cursor: pointer;
  }

  .toolbar-toggle::after {
    content: " ▼";
    font-size: 10px;
  }

  .toolbar-toggle.open::after {
    content: " ▲";
  }

  .toolbar {
    display: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    gap: 6px;
    margin-bottom: 6px;
  }

  .toolbar.visible {
    display: grid;
  }

  .toolbar > *,
  .group-tool,
  .search {
    width: 100%;
    max-width: none;
    min-width: 0;
    font-size: 12px;
  }

  .toolbar button,
  .toolbar .primary,
  .toolbar .secondary,
  .toolbar .ghost,
  .toolbar .inline-add {
    padding: 7px 8px;
    font-size: 12px;
    min-height: 32px;
  }

  .inline-add,
  .primary,
  .secondary,
  .ghost {
    justify-content: center;
    padding-left: 10px;
    padding-right: 10px;
  }

  .split, .query-form {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .column-form,
  .sheet-settings {
    grid-template-columns: 1fr;
  }

  .sheet-wrap {
    height: clamp(220px, calc(100dvh - 210px), 60vh);
    min-height: 0;
    -webkit-overflow-scrolling: touch;
  }

  .sheet {
    font-size: 12px;
  }

  .sheet th,
  .sheet td {
    min-width: 96px;
    height: 30px;
  }

  .sheet th {
    padding: 5px;
  }

  .sheet th.lock-col, .sheet td.lock-col,
  .sheet th.row-tool-col, .sheet td.row-tool-col {
    min-width: var(--row-tool-col-width);
    width: var(--row-tool-col-width);
    max-width: var(--row-tool-col-width);
  }

  .column-head {
    min-width: 110px;
  }

  .access-trigger {
    min-width: 80px;
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
  }

  .color-tool {
    width: 22px;
    height: 22px;
  }

  .access-floating {
    max-width: calc(100vw - 24px);
    max-height: 220px;
  }

  .sheet td input {
    font-size: 12px;
    padding: 5px 7px;
  }

  .bottom-scroller {
    height: 22px;
    min-height: 22px;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 14px;
  }

  .login-shell, .public-shell {
    padding: 10px;
  }

  .login-panel, .query-panel {
    padding: 16px;
  }

  .sidebar {
    padding: 6px 10px;
  }

  .sidebar h2 {
    font-size: 14px;
  }

  .nav-item {
    min-width: 60px;
    padding: 5px 8px;
    font-size: 12px;
  }

  .account {
    font-size: 11px;
  }

  .content {
    padding: 6px;
  }

  .topbar h1 {
    font-size: 16px;
  }

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

  .toolbar-toggle {
    font-size: 12px;
    padding: 5px 8px;
  }

  .status-line {
    font-size: 11px;
    margin-bottom: 4px;
  }

  .brand-logo {
    font-size: 16px;
  }

  .sheet-wrap {
    height: clamp(200px, calc(100dvh - 170px), 60vh);
    min-height: 0;
  }

  .sheet {
    font-size: 11px;
  }

  .sheet th,
  .sheet td {
    min-width: 80px;
    height: 28px;
  }

  .sheet th {
    padding: 4px;
    font-size: 11px;
  }

  .column-head {
    min-width: 90px;
    gap: 3px;
  }

  .access-trigger {
    min-width: 64px;
    max-width: 72px;
    font-size: 10px;
    padding: 2px 4px;
  }

  .sheet td input {
    font-size: 11px;
    padding: 4px 5px;
  }

  .sort-button {
    font-size: 11px;
  }

  .column-tools {
    gap: 2px;
  }

  .color-tool {
    width: 20px;
    height: 20px;
  }

  .bottom-scroller {
    height: 22px;
    min-height: 22px;
  }

  .access-floating {
    max-height: 180px;
  }

  .toast {
    max-width: 280px;
    right: 8px;
    bottom: 8px;
    font-size: 13px;
  }
}

/* ── P6: operator chips, result fields, panel check-grid ── */
.operator-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #e8edf2;
  color: #17202a;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 12px;
  margin: 2px;
  white-space: nowrap;
}
.operator-chip .mini { padding: 0 3px; font-size: 10px; }
.operator-add-input {
  width: 90px; padding: 2px 6px; font-size: 12px;
}

.result-field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #eaecef;
  font-size: 14px;
}
.result-field:last-of-type { border-bottom: none; }
.result-field span:first-child { color: #5a6a7a; }
.result-value { font-weight: 600; color: #17202a; }
.result-value-empty { color: #9aa5b1; font-style: italic; }
.result-time { margin-top: 12px; text-align: center; }

.check-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}
.check-grid label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 10px;
  border: 1px solid #d5dce5;
  border-radius: 6px;
  background: #f7f8fa;
  transition: background .15s;
}
.check-grid label:hover { background: #e8edf2; }
.check-grid input[type="checkbox"] { cursor: pointer; }


/* Round 2 fixes */
.row-number { display:block; margin-bottom:3px; color:#667085; font-size:12px; font-weight:700; }
.group-row td { position: static; z-index: 3; }
.group-content {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  width: max-content;
  max-width: calc(100vw - 320px);
  white-space: nowrap;
  will-change: transform;
  pointer-events: auto;
}
.modal { z-index: 2000; }
.modal-panel { max-height: calc(100vh - 40px); display:flex; flex-direction:column; }
.formula-help { min-height:0; flex:1; }
.formula-list { max-height:320px; }
.online-badge { color:#667085; font-size:12px; }
.online-badge.online { color:#067647; font-weight:700; }

.summary-row td {
  height: var(--sheet-row, 28px);
  min-height: var(--sheet-row, 28px);
  max-height: var(--sheet-row, 28px);
  box-sizing: border-box;
  padding: 0 6px;
  background: #fff8e6;
  color: #17202a;
  font-size: var(--sheet-font, 12px);
  line-height: calc(var(--sheet-row, 28px) - 2px);
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
}

.summary-row .summary-label,
.summary-row .summary-cell {
  padding-top: 0;
  padding-bottom: 0;
  text-overflow: ellipsis;
}

.summary-row .summary-number {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.summary-row .summary-empty {
  color: #8a94a3;
}

.group-summary-row td {
  height: var(--sheet-row, 28px);
  min-height: var(--sheet-row, 28px);
  max-height: var(--sheet-row, 28px);
  border-top: 1px solid #edf0f5;
  border-bottom: 1px solid #edf0f5;
  background: #f8fafc;
  font-weight: 500;
}

.group-summary-row .summary-label,
.group-summary-row .summary-cell {
  padding-top: 0;
  padding-bottom: 0;
}

.group-summary-row .summary-number {
  font-weight: 700;
}

.total-summary-row td {
  position: sticky;
  bottom: 0;
  z-index: 9;
  height: var(--sheet-row, 28px);
  min-height: var(--sheet-row, 28px);
  max-height: var(--sheet-row, 28px);
  background: #fff8e6;
  border-top: 1px solid #e8c76d;
  box-shadow: none;
}

/* Dense spreadsheet workspace layout */
body[data-table-font-size="small"] {
  --sheet-font: 12px;
  --sheet-row: 28px;
  --sheet-head: 96px;
  --sheet-control: 24px;
}

body[data-table-font-size="medium"] {
  --sheet-font: 13px;
  --sheet-row: 34px;
  --sheet-head: 112px;
  --sheet-control: 28px;
}

body[data-table-font-size="large"] {
  --sheet-font: 15px;
  --sheet-row: 42px;
  --sheet-head: 132px;
  --sheet-control: 32px;
}

html, body {
  height: 100%;
}

.app-shell {
  height: 100dvh;
  min-height: 0;
  grid-template-columns: 184px minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  gap: 14px;
  padding: 14px;
  overflow: auto;
}

.sidebar h2 {
  font-size: 18px;
}

.nav-item {
  padding: 8px 10px;
}

.content {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 8px;
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  align-items: center;
  min-height: 32px;
  margin-bottom: 6px;
}

.topbar h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

#permissionHint {
  display: none;
}

.topbar .secondary {
  min-height: 30px;
  padding: 5px 10px;
  font-size: 12px;
}

#workspaceTab {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.toolbar {
  flex: 0 0 auto;
  flex-wrap: nowrap;
  gap: 6px;
  margin-bottom: 6px;
  padding: 4px 0;
  overflow-x: auto;
  overflow-y: visible;
}

.toolbar > * {
  flex: 0 0 auto;
}

.toolbar input,
.toolbar select,
.toolbar button,
.toolbar .secondary,
.toolbar .inline-add {
  min-height: 30px;
  padding: 5px 9px;
  border-radius: 4px;
  font-size: 12px;
}

.toolbar .search {
  flex: 1 1 360px;
  max-width: none;
  min-width: 220px;
}

.group-tool {
  width: auto;
  min-width: 0;
  gap: 5px;
}

.group-tool span {
  font-size: 12px;
}

.group-tool select {
  width: 150px;
}

.font-size-control {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.font-size-btn {
  min-width: 30px;
  min-height: 24px;
  padding: 2px 7px;
  color: #475467;
  background: transparent;
  border-radius: 3px;
  font-size: 12px;
}

.font-size-btn.active {
  color: #111827;
  background: #fff4d6;
  font-weight: 700;
}

.settings-popover {
  position: absolute;
  top: 42px;
  right: 8px;
  z-index: 1200;
  width: min(760px, calc(100vw - 230px));
  max-height: min(72vh, 620px);
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(15, 23, 42, .18);
}

.settings-popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.settings-popover-head .ghost {
  min-height: 28px;
  padding: 4px 9px;
}

.sheet-settings,
.column-form {
  margin: 0;
  padding: 0 0 12px;
  border: 0;
  background: transparent;
}

.sheet-settings {
  grid-template-columns: minmax(180px, 1fr) minmax(240px, 1.5fr);
  align-items: start;
}

.sheet-actions {
  grid-column: 1 / -1;
}

.danger-soft {
  grid-column: 1 / -1;
  color: #b42318;
  background: #fff1f0;
}

.column-form {
  grid-template-columns: minmax(180px, 1fr) 110px minmax(180px, 1fr) 100px minmax(140px, .8fr) 90px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.status-line {
  flex: 0 0 auto;
  min-height: 18px;
  margin-bottom: 4px;
  font-size: 12px;
  line-height: 18px;
}

.sheet-wrap {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  border-radius: 0;
}

.sheet {
  font-size: var(--sheet-font, 12px);
}

.sheet th,
.sheet td {
  min-width: var(--sheet-head, 96px);
  height: var(--sheet-row, 28px);
}

.sheet th {
  padding: 5px;
}

.sheet th.lock-col,
.sheet td.lock-col,
.sheet th.row-tool-col,
.sheet td.row-tool-col {
  min-width: var(--row-tool-col-width);
  width: var(--row-tool-col-width);
  max-width: var(--row-tool-col-width);
}

.sheet th.add-col-edge,
.sheet td.add-col-edge {
  min-width: 32px;
  width: 32px;
}

.top-add,
.edge-add-column {
  width: 26px;
  height: 26px;
  font-size: 18px;
}

.column-head {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: flex-start;
  gap: 2px 3px;
  min-width: calc(var(--sheet-head, 96px) + 4px);
  min-height: 40px;
  max-height: 44px;
  overflow: visible;
}

.column-label-btn {
  flex: 1 1 100%;
  max-width: calc(var(--sheet-head, 96px) + 18px);
  height: 17px;
  min-height: 17px;
  padding: 0 2px;
  line-height: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.column-resize-handle {
  position: absolute;
  top: -5px;
  right: -6px;
  bottom: -5px;
  width: 10px;
  cursor: col-resize;
  z-index: 4;
}

.column-resize-handle:hover {
  background: rgba(29, 78, 216, .18);
}

.column-resizing,
.column-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

.column-tools {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 2px;
  min-width: 0;
  max-width: 100%;
  flex-wrap: nowrap;
  overflow: visible;
}

.color-tool {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  border-radius: 3px;
}

.color-tool input {
  width: 28px;
  height: 28px;
  margin: -5px;
}

.access-trigger {
  flex: 0 1 48px;
  min-width: 38px;
  max-width: 58px;
  height: 20px;
  padding: 1px 4px;
  font-size: 10px;
  line-height: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.currency-select,
.decimal-select,
.formula-open,
.formula-edit,
.formula-builder select {
  height: 20px;
  min-height: 20px;
  padding: 1px 4px;
  font-size: 10px;
  line-height: 18px;
}

.currency-select {
  flex: 0 0 42px;
  min-width: 42px;
  max-width: 42px;
}

.decimal-select {
  flex: 0 0 48px;
  min-width: 48px;
  max-width: 48px;
}

.formula-open {
  flex: 0 0 28px;
  min-width: 28px;
  max-width: 48px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.column-head > .formula-open,
.column-head > .formula-chip {
  position: absolute;
  top: 20px;
  left: 0;
  flex: 0 0 auto;
  height: 20px;
  max-width: 48px;
  margin: 0;
  padding: 1px 4px;
  line-height: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.column-head > .formula-open + .column-tools,
.column-head > .formula-chip + .formula-open + .column-tools,
.column-head > .formula-chip + .column-tools {
  flex: 1 1 100%;
  margin-left: 30px;
  max-width: calc(100% - 30px);
}

.column-head > .formula-chip + .formula-open {
  left: 28px;
}

.column-head > .formula-chip + .formula-open + .column-tools {
  margin-left: 58px;
  max-width: calc(100% - 58px);
}

.column-tools .mini {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
}

.money-cell {
  height: var(--sheet-row, 28px);
}

.sheet td input,
.sheet td select,
.cell-input {
  height: calc(var(--sheet-row, 28px) - 2px);
  min-height: calc(var(--sheet-row, 28px) - 2px);
  padding: 3px 6px;
  border-radius: 0;
  font-size: inherit;
}

.cell-text-display {
  height: calc(var(--sheet-row, 28px) - 2px);
  min-height: calc(var(--sheet-row, 28px) - 2px);
  padding: 3px 6px;
  overflow: hidden;
  border: 1px solid transparent;
  color: inherit;
  background: transparent;
  font-size: inherit;
  line-height: calc(var(--sheet-row, 28px) - 9px);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-text-display.is-editable {
  cursor: text;
}

.cell-text-display.is-editable:focus {
  border-color: #5b8def;
  outline: none;
  background: #fff;
}

.cell-text-display.is-editing {
  padding: 0;
  border-color: #5b8def;
  background: #fff;
}

.column-autocomplete-btn.active {
  color: #1769d2;
  border-color: #75a7e8;
  background: #eaf3ff;
}

.autocomplete-menu {
  position: fixed;
  z-index: 1400;
  max-height: 240px;
  overflow: auto;
  padding: 4px;
  border: 1px solid #c9d5e6;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(31, 55, 86, 0.2);
}

.autocomplete-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 10px;
  padding: 7px 9px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.autocomplete-option:hover {
  background: #edf5ff;
}

.autocomplete-option span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.autocomplete-option small {
  flex: 0 0 auto;
  color: #8492a6;
}

.inline-text-editor {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 100%;
  padding: 3px 6px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: calc(var(--sheet-row, 28px) - 9px);
  white-space: pre-wrap;
  overflow: hidden;
}

.progress-cell {
  min-width: 104px;
}

.image-cell {
  min-width: 150px;
  min-height: var(--sheet-row, 28px);
  padding: 2px 6px;
}

.image-cell img {
  width: 30px;
  height: 24px;
}

.group-row td {
  height: calc(var(--sheet-row, 28px) + 4px);
  padding: 5px 8px;
  border-top: 4px solid #eef2f6;
}

.bottom-scroller {
  flex: 0 0 auto;
  height: 14px;
  min-height: 14px;
}

.group-fold-actions {
  display: inline-flex;
  gap: 4px;
}

.group-fold-actions .ghost {
  min-height: 30px;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.floating-text-editor {
  position: fixed;
  z-index: 3000;
  padding: 10px;
  border: 1px solid #98a2b3;
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 18px 46px rgba(15, 23, 42, .22);
  font: 13px/1.5 "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  resize: both;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 8px;
  }

  .sidebar > div:first-child {
    display: none;
  }

  .sidebar nav {
    display: flex;
    overflow-x: auto;
  }

  .account {
    margin-left: auto;
    margin-top: 0;
    grid-auto-flow: column;
    align-items: center;
  }

  .settings-popover {
    left: 8px;
    right: 8px;
    width: auto;
  }

  .column-form,
  .sheet-settings {
    grid-template-columns: 1fr;
  }
}

/* Final mobile overrides: keep desktop layout untouched, make phones usable. */
.mobile-menu-btn,
.toolbar-toggle {
  display: none;
}

@media (max-width: 760px) {
  :root {
    --mobile-header: 56px;
  }

  html,
  body {
    width: 100%;
    min-width: 0;
    overflow-x: hidden;
    font-size: 15px;
  }

  body[data-table-font-size="small"],
  body[data-table-font-size="medium"],
  body[data-table-font-size="large"] {
    --sheet-font: 14px;
    --sheet-row: 42px;
    --sheet-head: 136px;
    --sheet-control: 36px;
  }

  button,
  input,
  select,
  textarea {
    font-size: 16px;
  }

  button,
  .primary,
  .secondary,
  .ghost,
  .mini,
  .inline-add,
  .upload-btn {
    min-height: 44px;
    padding: 9px 12px;
  }

  input,
  select,
  textarea {
    min-height: 44px;
    padding: 9px 10px;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .sidebar {
    position: relative;
    z-index: 80;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    flex: 0 0 auto;
    gap: 8px 10px;
    min-height: var(--mobile-header);
    max-height: 100dvh;
    padding: 8px 10px;
    overflow: visible;
  }

  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    grid-column: 1;
    grid-row: 1;
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 6px;
    color: #fff;
    background: rgba(255, 255, 255, .08);
    font-size: 13px;
  }

  .sidebar > div:first-of-type {
    display: block;
    grid-column: 2;
    min-width: 0;
  }

  .sidebar .eyebrow {
    display: none;
  }

  .sidebar h2 {
    margin: 0;
    overflow: hidden;
    font-size: 17px;
    line-height: 44px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sidebar nav,
  .sidebar .account {
    display: none;
  }

  .sidebar.mobile-open {
    overflow-y: auto;
  }

  .sidebar.mobile-open nav {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    max-height: 45dvh;
    overflow-y: auto;
    padding-top: 4px;
  }

  .sidebar.mobile-open .account {
    display: grid;
    grid-column: 1 / -1;
    gap: 6px;
    margin: 0;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, .12);
    font-size: 13px;
  }

  .nav-item {
    min-width: 0;
    min-height: 44px;
    padding: 10px 8px;
    text-align: center;
    white-space: normal;
  }

  .content {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: 0;
    padding: 8px;
    overflow: hidden;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    min-height: 0;
    margin: 0 0 8px;
  }

  .topbar h1 {
    font-size: 18px;
    line-height: 1.25;
  }

  .topbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .topbar-actions > * {
    flex: 1 1 auto;
    min-width: max-content;
  }

  #workspaceTab {
    min-height: 0;
  }

  .toolbar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 100%;
    min-height: 44px;
    margin: 0 0 6px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--ink);
    background: #fff;
    font-size: 14px;
  }

  .toolbar-toggle::after {
    content: " ▼";
    margin-left: 4px;
    font-size: 11px;
  }

  .toolbar-toggle.open::after {
    content: " ▲";
  }

  .toolbar {
    display: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    max-height: 42dvh;
    margin-bottom: 6px;
    padding: 0 0 6px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .toolbar.visible {
    display: grid;
  }

  .toolbar > *,
  .toolbar .search,
  .group-tool,
  .history-range-control,
  .group-fold-actions,
  .font-size-control,
  #simulateUserSelect {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .toolbar .search,
  .group-tool,
  .history-range-control {
    grid-column: 1 / -1;
  }

  .group-tool,
  .history-range-control {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 8px;
    align-items: center;
  }

  .group-tool span,
  .history-range-control span {
    margin: 0;
    font-size: 13px;
  }

  .group-tool select,
  .history-range-control select {
    width: 100%;
    height: 44px;
  }

  .group-fold-actions,
  .font-size-control {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .font-size-control {
    grid-template-columns: repeat(3, 1fr);
    padding: 0;
    border: 0;
    background: transparent;
  }

  .font-size-btn {
    min-height: 44px;
  }

  .status-line {
    min-height: 20px;
    margin-bottom: 6px;
    overflow: hidden;
    font-size: 12px;
    line-height: 18px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sheet-wrap {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: 260px;
    max-height: none;
    overflow: auto;
    border-radius: 6px;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    overscroll-behavior: contain;
  }

  .sheet {
    width: max-content;
    min-width: max-content;
    table-layout: fixed;
    font-size: var(--sheet-font);
  }

  .sheet th,
  .sheet td {
    min-width: var(--sheet-head);
    height: var(--sheet-row);
    max-width: none;
  }

  .sheet th {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 6px;
    background: #eef2f6;
  }

  .sheet th.row-tool-col,
  .sheet td.row-tool-col {
    position: sticky;
    left: 0;
    z-index: 18;
    min-width: var(--row-tool-col-width);
    width: var(--row-tool-col-width);
    max-width: var(--row-tool-col-width);
    background: #fff;
  }

  .sheet th.row-tool-col {
    z-index: 30;
    background: #eef2f6;
  }

  .sheet tr > .mobile-priority-col:first-child,
  .sheet th.row-tool-col + .mobile-priority-col,
  .sheet td.row-tool-col + .mobile-priority-col {
    position: sticky;
    left: 0;
    z-index: 16;
    background: #fff;
    box-shadow: 1px 0 0 var(--line);
  }

  .sheet th.row-tool-col + .mobile-priority-col,
  .sheet td.row-tool-col + .mobile-priority-col {
    left: var(--row-tool-col-width);
  }

  .sheet thead .mobile-priority-col {
    z-index: 28;
    background: #eef2f6;
  }

  .sheet tfoot .mobile-priority-col,
  .total-summary-row td {
    z-index: 24;
    background: #fff8e6;
  }

  .column-head {
    min-height: 54px;
    max-height: none;
  }

  .column-label-btn {
    height: 22px;
    min-height: 22px;
    line-height: 22px;
  }

  .column-tools {
    gap: 4px;
  }

  .access-trigger,
  .currency-select,
  .decimal-select,
  .formula-open,
  .formula-edit {
    min-height: 28px;
    height: 28px;
    font-size: 11px;
  }

  .color-tool {
    width: 24px;
    height: 24px;
  }

  .sheet td input,
  .sheet td select,
  .cell-input,
  .cell-text-display,
  .inline-text-editor {
    height: calc(var(--sheet-row) - 2px);
    min-height: calc(var(--sheet-row) - 2px);
    font-size: 14px;
    line-height: 24px;
  }

  .cell-text-display,
  .inline-text-editor {
    padding: 8px;
  }

  .image-cell {
    min-width: 170px;
    padding: 4px 6px;
  }

  .image-cell img {
    width: 42px;
    height: 34px;
  }

  .group-row td {
    position: static;
    padding: 6px 8px;
  }

  .group-content {
    max-width: calc(100vw - 28px);
    width: max-content;
    min-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .summary-row td,
  .total-summary-row td,
  .group-summary-row td {
    height: var(--sheet-row);
    min-height: var(--sheet-row);
    max-height: var(--sheet-row);
  }

  .bottom-scroller {
    height: 18px;
    min-height: 18px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .settings-popover {
    position: fixed;
    inset: 8px;
    width: auto;
    max-height: none;
    padding: 12px;
    border-radius: 8px;
  }

  .settings-popover-head {
    position: sticky;
    top: -12px;
    z-index: 2;
    margin: -12px -12px 10px;
    padding: 12px;
    background: #fff;
    border-bottom: 1px solid var(--line);
  }

  .sheet-settings,
  .column-form,
  .split {
    grid-template-columns: 1fr;
  }

  .sheet-actions,
  .mini-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .panel {
    min-width: 0;
    padding: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .compact {
    width: max-content;
    min-width: 100%;
  }

  .compact th,
  .compact td {
    min-width: 120px;
    padding: 8px;
  }

  .modal {
    align-items: stretch;
    justify-content: stretch;
    padding: 8px;
  }

  .modal-panel {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - 16px);
    border-radius: 8px;
  }

  .modal-panel header,
  .modal-panel footer {
    flex-wrap: wrap;
    gap: 8px;
  }

  .formula-builder {
    grid-template-columns: 1fr;
  }

  .image-preview-panel {
    width: calc(100vw - 16px);
    max-width: none;
    max-height: calc(100dvh - 16px);
  }

  .image-preview-panel img {
    max-width: calc(100vw - 32px);
    max-height: calc(100dvh - 80px);
  }

  .access-floating {
    position: fixed !important;
    left: 8px !important;
    right: 8px !important;
    top: auto !important;
    bottom: 8px !important;
    width: auto !important;
    max-height: 56dvh;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .floating-text-editor {
    left: 8px !important;
    right: 8px !important;
    top: auto !important;
    bottom: 8px !important;
    width: auto !important;
    max-width: none !important;
    max-height: 55dvh;
    resize: vertical;
  }
}

/* Column width resizing: header tools must not define the minimum column width. */
.sheet th,
.sheet td {
  box-sizing: border-box;
}

.column-head {
  width: 100%;
  min-width: 0 !important;
  max-width: 100%;
  overflow: hidden;
}

.column-label-btn {
  min-width: 0;
  max-width: 100% !important;
}

.column-head-readonly {
  display: block;
  min-height: 20px;
}

.column-label-text {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  color: var(--text);
}

.column-tools {
  width: 100%;
  min-width: 0 !important;
  max-width: 100%;
  flex-wrap: nowrap;
  overflow: hidden !important;
}

.column-tools > * {
  flex-shrink: 0;
}

.column-tools .local-hide-column {
  flex: 0 0 22px;
  width: 22px;
  color: #475467;
  background: #eef2f6;
}

.column-tools .local-hide-column:hover {
  color: #101828;
  background: #dbe4ee;
}

.local-hidden-restore {
  min-height: 28px;
  padding: 4px 9px;
}

.access-trigger,
.currency-select,
.decimal-select,
.formula-open,
.column-tools .mini,
.color-tool {
  min-width: 0;
}

.access-trigger {
  width: 42px;
  max-width: 42px;
}

.currency-select {
  width: 38px;
  max-width: 38px;
}

.decimal-select {
  width: 42px;
  max-width: 42px;
}

.formula-open {
  width: 28px;
  max-width: 28px;
}

.sheet.has-personal-freeze .personal-frozen-col {
  position: sticky;
  left: 0;
  z-index: 12;
  background: #fff;
  box-shadow: 1px 0 0 var(--line);
}

.sheet.has-personal-freeze thead .personal-frozen-col {
  z-index: 32;
  background: #eef2f6;
}

.sheet.has-personal-freeze tfoot .personal-frozen-col,
.sheet.has-personal-freeze .total-summary-row .personal-frozen-col {
  z-index: 24;
  background: #fff8e6;
}

.sheet.has-personal-freeze.has-row-tools th.row-tool-col,
.sheet.has-personal-freeze.has-row-tools td.row-tool-col {
  position: sticky;
  left: 0;
  z-index: 14;
  background: #fff;
}

.sheet.has-personal-freeze.has-row-tools th.row-tool-col {
  z-index: 34;
  background: #eef2f6;
}

.sheet.has-personal-freeze.has-row-tools .personal-frozen-col {
  left: var(--row-tool-col-width);
}

.sheet.has-personal-freeze.has-row-tools tbody tr.is-active-row td.row-tool-col,
.sheet.has-personal-freeze.has-row-tools tbody tr.is-active-row td.personal-frozen-col {
  z-index: 29;
  background: #eaf4ff !important;
  box-shadow: inset 0 2px 0 #2196f3, inset 0 -2px 0 #2196f3;
}

@media (max-width: 760px) {
  .personal-view-controls,
  .personal-view-tool {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .personal-view-controls {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .personal-view-tool {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 8px;
    align-items: center;
  }

  .personal-view-tool select {
    width: 100%;
    height: 44px;
  }

  .sheet.has-personal-freeze.has-row-tools .personal-frozen-col {
    left: var(--row-tool-col-width);
  }
}
