:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --surface: #ffffff;
  --surface-2: #edf4f1;
  --ink: #18201c;
  --muted: #5f6b63;
  --line: #cad5ce;
  --line-strong: #9fb0a6;
  --accent: #167d63;
  --accent-2: #2f6db3;
  --accent-3: #c57a18;
  --danger: #ba3f3f;
  --active: #d8ece6;
  --selected: #e7f1ff;
  --header: #ecf0e9;
  --shadow: 0 20px 60px rgba(30, 42, 35, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  overflow: hidden;
  min-width: 1120px;
  height: 100vh;
  margin: 0;
  color: var(--ink);
  background: #f8fafc;
}

button,
input,
textarea {
  font: inherit;
}

button,
.file-button {
  min-height: 28px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 9px;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}

button:hover,
.file-button:hover {
  border-color: #dce3ea;
  background: #ffffff;
  color: #0f5f4a;
}

button:disabled {
  color: #9aa49e;
  background: #eef1ed;
  cursor: not-allowed;
}

button.is-active {
  border-color: #8fcab7;
  background: #e8f4ef;
  color: #0f5f4a;
  box-shadow: inset 0 0 0 1px #8fcab7;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid #174b69;
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  height: 100vh;
  min-height: 0;
  padding: 0 10px 10px;
  gap: 8px;
}

.sheet-chrome,
.formula-row,
.workspace,
.status-strip {
  width: min(2040px, 100%);
  min-width: 0;
  margin: 0 auto;
}

.sheet-chrome {
  display: grid;
  gap: 3px;
  padding: 8px 0 0;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  gap: 16px;
}

.document-identity {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 7px;
  color: #ffffff;
  background: #2fa34a;
  font-weight: 800;
  letter-spacing: 0;
}

.document-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  overflow: hidden;
  max-width: 520px;
  font-size: 18px;
  line-height: 1.1;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-copy p {
  color: var(--muted);
  font-size: 11px;
}

.chrome-icon {
  width: 28px;
  min-width: 28px;
  padding: 0;
  color: #4d575f;
  font-size: 17px;
}

.chrome-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.local-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border-radius: 999px;
  padding: 0 16px;
  color: #174b69;
  background: #c9e7ff;
  font-weight: 700;
  font-size: 13px;
}

.locale-toggle {
  min-height: 32px;
  border-color: #d5dee8;
  border-radius: 999px;
  padding: 0 12px;
  background: #ffffff;
  color: #26323c;
  font-size: 12px;
  font-weight: 750;
}

.user-avatar {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: #ffffff;
  background: #38424d;
  font-weight: 800;
}

.account-menu {
  position: absolute;
  top: 48px;
  right: 16px;
  z-index: 30;
  width: 240px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 10px 28px rgba(33, 42, 37, 0.18);
}

.account-menu[hidden] {
  display: none;
}

.account-menu-title {
  font-weight: 800;
}

.account-menu p {
  margin: 2px 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.account-menu button {
  justify-content: flex-start;
  width: 100%;
  min-height: 30px;
  border: 0;
  background: transparent;
}

.menu-row {
  display: flex;
  align-items: center;
  min-height: 24px;
  gap: 2px;
  padding-left: 44px;
}

.menu-row button {
  min-height: 24px;
  padding: 0 8px;
  border-radius: 5px;
  font-size: 13px;
}

.menu-row button.is-open {
  background: #e8edf4;
}

.menu-popover {
  position: fixed;
  z-index: 20;
  width: min(360px, calc(100vw - 24px));
  border: 1px solid #dde3ea;
  border-radius: 8px;
  padding: 8px 0;
  background: #ffffff;
  box-shadow: 0 16px 36px rgba(20, 31, 43, 0.18);
}

.menu-popover[hidden] {
  display: none;
}

.menu-popover section {
  display: grid;
  gap: 2px;
  padding: 6px 0;
  border-bottom: 1px solid #e4e8ed;
}

.menu-popover section:last-child {
  border-bottom: 0;
}

.menu-popover button {
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  min-height: 36px;
  width: 100%;
  border: 0;
  border-radius: 0;
  padding: 0 18px;
  color: #1f252b;
  background: transparent;
  font-size: 14px;
  text-align: left;
}

.menu-popover button:hover {
  background: #eef3f9;
  color: #1f252b;
}

.menu-popover span {
  color: #4b5560;
  font-weight: 750;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  overflow-x: auto;
  overflow-y: hidden;
  min-height: 42px;
  min-width: 0;
  border-radius: 999px;
  padding: 4px 10px;
  gap: 0;
  background: #edf2f8;
  scrollbar-width: thin;
}

.tool-group {
  display: inline-flex;
  position: relative;
  align-items: center;
  flex: 0 0 auto;
  min-height: 30px;
  gap: 2px;
  padding: 0 8px;
  border-right: 1px solid #d4dbe3;
}

.tool-group:last-child {
  border-right: 0;
}

.toolbar [aria-label="Table operations"],
.toolbar [aria-label="Filter"],
.toolbar [aria-label="Clipboard and fill"],
.toolbar [aria-label="Text display"],
#demoButton,
#clearButton,
#saveButton,
#narrowColumnButton,
#widenColumnButton,
#shortenRowButton,
#heightenRowButton,
[data-vertical-align],
[data-border-style="none"],
#createBoxButton,
#clearBoxesButton,
[data-format-painter],
#exportJsonButton,
#exportCsvButton,
#exportExcelButton,
.toolbar .file-button {
  display: none;
}

.toolbar-menu-button { max-width: 132px; }
.toolbar-menu-button.compact { width: 58px; }
.toolbar-menu-button.color-tool { width: 34px; min-width: 34px; font-weight: 800; }

.toolbar-popover {
  position: absolute;
  top: calc(100% + 6px);
  z-index: 20;
  width: 230px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 8px 20px rgba(33, 42, 37, 0.18);
}

.font-menu { left: 82px; }
.size-menu { left: 178px; width: 96px; }
.color-palette { left: 230px; display: grid; grid-template-columns: repeat(4, 28px); gap: 6px; width: 140px; }
.toolbar-popover[hidden] { display: none; }

.toolbar-popover button {
  justify-content: flex-start;
  width: 100%;
  border: 0;
  background: transparent;
}

.color-palette button {
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 50%;
  padding: 0;
  color: transparent;
}

.color-palette button:first-child {
  grid-column: 1 / -1;
  width: 100%;
  border-radius: 4px;
  color: var(--ink);
}

[data-color-value="#000000"] { background-color: #000000 !important; }
[data-color-value="#ffffff"] { background-color: #ffffff !important; }
[data-color-value="#5f6368"] { background-color: #5f6368 !important; }
[data-color-value="#d93025"] { background-color: #d93025 !important; }
[data-color-value="#f9ab00"] { background-color: #f9ab00 !important; }
[data-color-value="#188038"] { background-color: #188038 !important; }
[data-color-value="#1967d2"] { background-color: #1967d2 !important; }
[data-color-value="#9334e6"] { background-color: #9334e6 !important; }
[data-color-value="#fce8e6"] { background-color: #fce8e6 !important; }
[data-color-value="#fef7e0"] { background-color: #fef7e0 !important; }
[data-color-value="#e6f4ea"] { background-color: #e6f4ea !important; }
[data-color-value="#e8f0fe"] { background-color: #e8f0fe !important; }
[data-color-value="#f3e8fd"] { background-color: #f3e8fd !important; }
[data-color-value="#e0f2f1"] { background-color: #e0f2f1 !important; }

.toolbar button,
.toolbar .file-button,
.toolbar .color-button {
  min-height: 28px;
  border-radius: 6px;
  padding: 0 8px;
  font-size: 13px;
  white-space: nowrap;
}

.toolbar-input {
  width: 112px;
  min-height: 28px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0 12px;
  background: #ffffff;
  font-size: 13px;
}

.toolbar-select {
  width: 104px;
  min-height: 28px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0 8px;
  background: #ffffff;
  color: var(--ink);
  font-size: 12px;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.color-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 28px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 10px;
  background: transparent;
  cursor: pointer;
}

.color-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.formula-row {
  display: grid;
  grid-template-columns: 88px 1fr 88px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

.name-box,
.formula-bar {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 11px;
  color: var(--ink);
  background: var(--surface);
}

.name-box {
  text-transform: uppercase;
  text-align: center;
  font-weight: 700;
}

.formula-bar {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  min-width: 0;
}

.workspace {
  display: block;
  overflow: hidden;
  min-height: 0;
  min-width: 0;
}

.sheet-frame {
  position: relative;
  overflow: auto;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sheet-tabs-bar {
  display: flex;
  position: sticky;
  bottom: 32px;
  z-index: 18;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 5px 10px;
  border: 1px solid var(--line-strong);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background: #f7f9fb;
}

.sheet-tabs {
  display: flex;
  flex: 1 1 auto;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
}

.sheet-tabs-bar button {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--ink);
  background: #ffffff;
  font-size: 13px;
  white-space: nowrap;
}

.sheet-tabs button.is-active {
  border-color: var(--accent);
  color: #0f5f4a;
  background: #d9f0e8;
  font-weight: 800;
}

.fill-handle {
  position: absolute;
  z-index: 5;
  width: 10px;
  min-width: 10px;
  height: 10px;
  min-height: 10px;
  border: 1px solid #ffffff;
  border-radius: 2px;
  padding: 0;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(22, 125, 99, 0.4);
  cursor: crosshair;
}

.fill-handle.is-dragging {
  background: var(--accent-2);
}

.shape-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  transform-origin: top left;
}

.sheet-shape {
  position: absolute;
  box-sizing: border-box;
  border: 2px solid var(--accent);
  border-radius: 4px;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(33, 42, 37, 0.1);
}

.sheet-grid {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  table-layout: fixed;
  font-size: 13px;
}

.sheet-grid th,
.sheet-grid td {
  width: 112px;
  min-width: 112px;
  height: 34px;
  padding: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.sheet-grid th {
  position: sticky;
  top: 0;
  z-index: 3;
  color: #425048;
  background: var(--header);
  font-weight: 700;
  text-align: center;
  user-select: none;
}

.sheet-grid .corner,
.row-head {
  width: 48px;
  min-width: 48px;
}

.sheet-grid .corner {
  left: 0;
  z-index: 4;
  cursor: cell;
}

.row-head {
  position: sticky;
  left: 0;
  z-index: 2;
  color: #536059;
  background: var(--header);
  text-align: center;
  font-weight: 700;
  cursor: cell;
}

.sheet-grid th[data-col] {
  cursor: cell;
}

.sheet-grid th.filtered-column {
  color: #0f5f4a;
  background: #d9f0e8;
}

.sheet-grid th.filtered-column::after {
  content: " ▾";
  color: var(--accent);
  font-size: 10px;
}

.cell-input {
  width: 100%;
  height: 33px;
  border: 0;
  outline: none;
  padding: 0 8px;
  color: var(--ink);
  background: transparent;
  font-size: 13px;
  line-height: 32px;
  resize: none;
}

.cell-input[data-text-wrap="overflow"] {
  overflow: visible;
  white-space: pre;
}

.cell-input[data-text-wrap="clip"] {
  overflow: hidden;
  text-overflow: clip;
  white-space: pre;
}

.cell-input[data-text-wrap="wrap"] {
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 17px;
  padding-top: 7px;
  padding-bottom: 7px;
}

.cell-input:focus {
  background: var(--active);
  box-shadow: inset 0 0 0 2px var(--accent);
}

td.active-cell {
  background: var(--active);
}

td.selected-cell {
  background: var(--selected);
}

td.formula-cell .cell-input {
  color: #204f8f;
}

td.error-cell .cell-input {
  color: var(--danger);
  font-weight: 700;
}

.status-strip {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid #dce4dc;
  border-radius: 8px;
  padding: 0 10px;
  gap: 14px;
  background: #ffffff;
  color: #3f4a43;
  font-size: 12px;
}

.status-strip b {
  color: #657068;
  font-weight: 700;
}

.status-error-button {
  min-height: 24px;
  margin-left: auto;
  border-color: #dce4dc;
  background: #f8fafc;
  font-size: 12px;
}

.status-error-button.has-errors {
  border-color: #e6b8b8;
  color: var(--danger);
  background: #fff1f1;
}

.error-panel {
  position: absolute;
  right: 0;
  bottom: 36px;
  z-index: 25;
  width: min(420px, calc(100vw - 24px));
  border: 1px solid #dde3ea;
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
  box-shadow: 0 16px 36px rgba(20, 31, 43, 0.18);
}

.error-panel-title {
  margin-bottom: 8px;
  font-weight: 750;
}

.error-list {
  display: grid;
  gap: 4px;
  max-height: 240px;
  overflow: auto;
}

.error-list button {
  justify-content: flex-start;
  border-color: #e6edf2;
  background: #f8fafc;
  text-align: left;
}

.command-bank {
  display: none;
}

#errorCount.has-errors {
  color: var(--danger);
  font-weight: 800;
}

@media (max-width: 900px) {
  body {
    min-width: 0;
  }

  .app-shell {
    padding: 10px;
  }

  .title-row {
    align-items: stretch;
    flex-direction: column;
  }

  .menu-row {
    overflow-x: auto;
    padding-left: 0;
  }

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

  .formula-row {
    grid-template-columns: 70px 1fr;
  }

  .formula-row button {
    grid-column: 1 / -1;
  }

  .sheet-frame {
    min-height: 58vh;
  }
}
