/* Kells Sheets · © Rohan Kells · https://github.com/kellsrohan */
@layer base, layout, controls, sheet, overlays, responsive;

@layer base {
  :root {
    color-scheme: dark;
    font-family: "Inter", "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    --page: #101817;
    --sidebar: #111a18;
    --panel: #17211e;
    --panel-raised: #1d2924;
    --panel-hover: #233129;
    --grid: #131d19;
    --header: #1b2521;
    --border: #2b3931;
    --border-subtle: #243029;
    --text: #edf4eb;
    --muted: #9fac9f;
    --faint: #738376;
    --accent: #a7e86e;
    --accent-hover: #baf389;
    --accent-ink: #1a2a10;
    --accent-soft: #a7e86e12;
    --accent-selected: #a7e86e16;
    --danger: #f99b91;
    --danger-bg: #512921;
    --shadow: 0 16px 48px #0006, 0 2px 8px #0002;
    --sidebar-width: 224px;
    --radius: 10px;
  }
  body[data-theme="light"] {
    color-scheme: light;
    --page: #f2f5ef;
    --sidebar: #f4f7f0;
    --panel: #fff;
    --panel-raised: #f7faf4;
    --panel-hover: #e9f0e4;
    --grid: #fff;
    --header: #f0f5ec;
    --border: #d4dece;
    --border-subtle: #e1e9dc;
    --text: #22301e;
    --muted: #5e7056;
    --faint: #76866d;
    --accent: #548126;
    --accent-hover: #426d1a;
    --accent-ink: #fff;
    --accent-soft: #5481260c;
    --accent-selected: #80b44c20;
    --danger: #af392d;
    --danger-bg: #fff0ed;
    --shadow: 0 16px 48px #263b181c, 0 2px 8px #263b180c;
  }
  *, *::before, *::after { box-sizing: border-box; }
  html, body { margin: 0; width: 100%; height: 100%; }
  body { background: var(--page); color: var(--text); font-size: 1rem; overflow: hidden; }
  button, input, textarea, select { font: inherit; }
  button { cursor: pointer; }
  button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
  button:disabled { opacity: .36; cursor: not-allowed; }
  a { color: var(--accent); text-decoration: none; }
  a:hover { text-decoration: underline; }
  button { color: inherit; }
  button, input, select, textarea { outline: none; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
  ::selection { background: #91d05f60; color: var(--text); }
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-track { background: var(--grid); }
  ::-webkit-scrollbar-thumb { background: var(--border); border: 2px solid var(--grid); border-radius: 10px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--faint); }
  ::-webkit-scrollbar-corner { background: var(--grid); }
  [hidden] { display: none !important; }
  .icon { display: inline-block; width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
  .visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }
  .mobile-only { display: none; }
  .skip-link { position: fixed; top: -60px; left: 16px; z-index: 120; padding: 12px 18px; border-radius: 6px; background: var(--accent); color: var(--accent-ink); font-size: 14px; font-weight: 600; }
  .skip-link:focus { top: 12px; }
  .noscript { position: fixed; inset: 0; z-index: 150; display: grid; place-content: center; padding: 30px; background: var(--page); color: var(--text); text-align: center; line-height: 1.8; }
  #print-view { display: none; }
  #constellation { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: .26; z-index: 0; }
}

@layer layout {
  .app-shell { position: relative; display: grid; grid-template-columns: var(--sidebar-width) minmax(0,1fr); width: 100%; height: 100vh; height: 100dvh; overflow: hidden; z-index: 1; }
  .sidebar { position: relative; display: flex; flex-direction: column; gap: 0; min-width: 0; min-height: 0; padding: 26px 14px 16px; border-right: 1px solid var(--border); background: color-mix(in srgb, var(--sidebar) 95%, transparent); }
  .brand { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 0 7px; margin: 0 0 34px; color: var(--text); text-decoration: none; }
  .brand:hover { text-decoration: none; }
  .brand > img, .brand > svg { width: 37px; height: 37px; flex: 0 0 37px; }
  .brand-name { display: block; font-size: 18px; font-weight: 680; line-height: 1.25; letter-spacing: -.65px; }
  .brand-accent { margin-left: 3px; color: var(--accent); font-weight: 480; }
  .brand-sub { display: block; color: var(--faint); font-size: 12px; font-weight: 500; line-height: 1.65; letter-spacing: .2px; }
  .workspace-label { padding: 0 11px; margin: 0 0 13px; color: var(--faint); font-size: 11px; font-weight: 650; letter-spacing: 1.6px; text-transform: uppercase; }
  .sidebar .new-workbook { width: 100%; justify-content: flex-start; margin: 0 0 29px; padding: 11px 12px; font-size: 14px; }
  .sidebar .new-workbook .shortcut { color: color-mix(in srgb,var(--accent-ink) 55%,transparent); }
  .nav-count { display: inline-flex; margin-left: auto; padding: 1px 6px; border-radius: 4px; background: var(--accent-soft); font-size: 11px; }
  .nav-button { display: flex; align-items: center; gap: 11px; width: 100%; min-height: 42px; padding: 10px 12px; margin: 0 0 4px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 500; text-align: left; transition: background .16s, border-color .16s, color .16s; }
  .nav-button:hover { background: var(--panel-hover); color: var(--text); }
  .nav-button.active { border-color: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); background: var(--accent-soft); }
  .nav-button .icon { width: 18px; height: 18px; }
  .nav-button .badge, .nav-button .shortcut { margin-left: auto; }
  .sidebar-section { display: flex; flex-direction: column; flex: 1; min-height: 0; margin-top: 30px; overflow: hidden; }
  .section-label { display: flex; flex-shrink: 0; justify-content: space-between; align-items: center; gap: 8px; padding: 0 11px; margin: 0 0 12px; color: var(--faint); font-size: 11px; font-weight: 650; letter-spacing: 1px; text-transform: uppercase; white-space: nowrap; }
  .section-label > span { min-width: 0; }
  .section-label button { padding: 0; border: 0; background: transparent; color: var(--faint); }
  .section-label .icon-button { width: 20px; height: 20px; }
  .section-label .icon-button .icon { width: 14px; height: 14px; }
  .workbook-list { display: flex; flex-direction: column; flex: 1; min-height: 0; gap: 5px; overflow: auto; max-height: none; }
  .workbook-item { position: relative; display: flex; flex-shrink: 0; align-items: center; gap: 0; width: 100%; padding: 0; border: 1px solid transparent; border-radius: 7px; background: transparent; text-align: left; color: var(--muted); }
  .workbook-item:hover { background: var(--panel-hover); color: var(--text); }
  .workbook-item.active { background: var(--panel-raised); border-color: var(--border); color: var(--text); }
  .workbook-item > .icon { color: var(--accent); }
  .workbook-item > div, .workbook-item > span:not(.icon) { min-width: 0; }
  .workbook-open { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; min-height: 58px; padding: 10px 5px 10px 10px; border: 0; border-radius: 6px; background: transparent; color: inherit; text-align: left; }
  .workbook-open > .icon { width: 16px; height: 16px; color: var(--accent); }
  .workbook-open > span { min-width: 0; }
  .workbook-more { width: 25px; height: 31px; margin-right: 4px; color: var(--faint); }
  .workbook-more .icon { width: 15px; height: 15px; }
  .workbook-item:hover .workbook-more, .workbook-more:focus-visible { color: var(--text); }
  .workbook-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 550; line-height: 1.5; }
  .workbook-meta { display: block; font-size: 11px; color: var(--faint); line-height: 1.6; }
  .empty-workbooks { padding: 12px 11px; font-size: 13px; line-height: 1.65; color: var(--faint); }
  .sidebar-bottom { flex-shrink: 0; margin-top: auto; padding-top: 22px; }
  .storage-card { position: relative; padding: 15px 13px 14px; margin: 0 4px 16px; border: 1px solid var(--border); border-radius: 9px; background: linear-gradient(120deg,var(--panel-raised),var(--sidebar)); }
  .storage-icon { display: flex; width: 29px; height: 29px; align-items: center; justify-content: center; margin-bottom: 11px; border-radius: 7px; background: var(--accent-soft); color: var(--accent); }
  .storage-icon .icon { width: 16px; height: 16px; }
  .storage-title { margin: 0 0 5px; font-size: 13px; font-weight: 600; }
  .storage-description { margin: 0; font-size: 12px; line-height: 1.6; color: var(--muted); }
  .credit { display: block; padding: 9px 8px 0; font-size: 10px; line-height: 1.7; color: var(--faint); overflow-wrap: anywhere; }
  .credit a { color: inherit; }
  .sidebar-footer { display: flex; align-items: center; gap: 11px; padding: 8px 4px 0; margin-top: 8px; border-top: 1px solid var(--border-subtle); }
  .sidebar-footer .icon-button { width: 29px; height: 29px; }
  .sidebar-footer .icon { width: 15px; height: 15px; }
  .version-label { margin-left: auto; color: var(--faint); font-size: 10px; }
  .main-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: color-mix(in srgb, var(--panel) 97%, transparent); }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex: 0 0 88px; padding: 17px 27px; border-bottom: 1px solid var(--border-subtle); }
  .document-heading { min-width: 0; flex: 1; }
  .document-icon { display: grid; place-items: center; width: 39px; height: 43px; flex-shrink: 0; border: 1px solid var(--border); border-radius: 7px; background: var(--accent-soft); color: var(--accent); }
  .document-icon .icon { width: 22px; height: 22px; }
  .document-title-row { display: flex; align-items: center; gap: 7px; }
  .document-title-row h1 { min-width: 0; }
  .star-current { width: 27px; height: 27px; margin-top: -5px; }
  .star-current .icon { width: 16px; height: 16px; }
  .star-current[aria-pressed="true"] { color: var(--accent); }
  .star-current[aria-pressed="true"] .icon { fill: var(--accent-soft); }
  .subtitle-divider { color: var(--border); }
  .avatar { display: inline-grid; place-items: center; width: 33px; height: 33px; margin-left: 10px; border: 1px solid #62744d; border-radius: 50%; background: #485938; color: #e4efd9; font-size: 11px; font-weight: 600; }
  .document-heading h1 { display: flex; align-items: center; gap: 10px; margin: 0 0 4px; font-size: 21px; line-height: 1.25; font-weight: 580; letter-spacing: -.65px; }
  #workbook-name { display: block; width: min(100%,420px); min-width: 70px; padding: 3px 5px; margin-left: -5px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--text); font-size: 21px; font-weight: 580; letter-spacing: -.65px; text-overflow: ellipsis; }
  #workbook-name:hover { border-color: var(--border); }
  #workbook-name:focus { border-color: var(--accent); background: var(--grid); outline: none; }
  .document-subtitle { display: flex; align-items: center; gap: 12px; color: var(--faint); font-size: 12px; line-height: 1.55; }
  .saved-state { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); white-space: nowrap; }
  .saved-state .icon { width: 13px; height: 13px; color: var(--accent); stroke-width: 1.8; }
  .saved-state.save-error, .saved-state.save-error .icon { color: var(--danger); }
  .topbar-actions { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
  .mobile-menu { display: none; }
  .menu-bar { display: flex; align-items: center; flex: 0 0 41px; gap: 2px; padding: 0 22px; border-bottom: 1px solid var(--border-subtle); }
  .menu-trigger { min-width: 43px; height: 29px; border: 0; border-radius: 5px; padding: 4px 9px; background: transparent; color: var(--muted); font-size: 14px; }
  .menu-trigger:hover, .menu-trigger[aria-expanded="true"] { color: var(--text); background: var(--panel-hover); }
  .menu-bar .menu-spacer { flex: 1; }
  .menu-bar > .badge { margin-left: auto; }
  .local-badge { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; color: var(--faint); font-size: 11px; white-space: nowrap; }
  .local-badge .icon { width: 12px; height: 12px; }
  .toolbar { display: flex; align-items: center; gap: 0; flex: 0 0 49px; min-width: 0; padding: 6px 19px; border-bottom: 1px solid var(--border); background: var(--panel); overflow-x: auto; scrollbar-width: none; }
  .toolbar::-webkit-scrollbar { display: none; }
  .tool-group { display: flex; flex-shrink: 0; align-items: center; gap: 3px; }
  .toolbar-spacer { flex: 1; min-width: 14px; }
  .separator { flex: 0 0 1px; align-self: center; height: 19px; margin: 0 12px; background: var(--border); }
  .formula-bar { display: flex; align-items: center; flex: 0 0 40px; min-width: 0; border-bottom: 1px solid var(--border); background: var(--grid); }
  .name-box { display: flex; align-items: center; justify-content: center; width: 103px; min-width: 103px; height: 39px; border-right: 1px solid var(--border); }
  .name-box input { width: 100%; height: 100%; padding: 7px 10px; border: 0; border-radius: 0; background: transparent; color: var(--text); text-align: center; font-size: 12px; font-weight: 500; }
  .name-box input:focus { box-shadow: inset 0 0 0 1px var(--accent); }
  .name-box > span { margin: 0 9px 0 -14px; pointer-events: none; color: var(--faint); }
  .name-box > span .icon { width: 11px; height: 11px; }
  .fx { flex: 0 0 43px; text-align: center; color: var(--faint); font-family: Georgia,serif; font-style: italic; font-size: 17px; }
  .formula-input { flex: 1; min-width: 0; height: 100%; padding: 7px 12px 7px 0; border: 0; background: transparent; color: var(--text); font-size: 13px; }
  .formula-input::placeholder { color: var(--faint); }
  .formula-input:focus { outline: none; }
  .formula-hint { flex-shrink: 0; padding: 0 17px; color: var(--faint); font-size: 10px; }
  .filter-notice { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 35px; padding: 7px 20px; border-bottom: 1px solid var(--border); background: var(--accent-soft); color: var(--accent); font-size: 12px; }
  .filter-notice button { border: 0; background: transparent; color: var(--accent); font-size: 12px; text-decoration: underline; }
  .sheet-area { flex: 1; position: relative; min-height: 0; overflow: hidden; background: var(--grid); }
  .sheet-bottom { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex: 0 0 47px; min-width: 0; padding: 0 16px; border-top: 1px solid var(--border); background: var(--panel); }
  .sheet-tabs { display: flex; align-self: stretch; align-items: stretch; gap: 4px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
  .sheet-tabs::-webkit-scrollbar { display: none; }
  .sheet-bottom-spacer { flex: 1; }
  .sheet-bottom .separator { margin: 0 2px; height: 17px; }
  .sheet-list-button { width: 27px; height: 30px; }
  .sheet-list-button .icon { width: 15px; height: 15px; }
  .sheet-tab { display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0; position: relative; padding: 0 15px; border: 0; border-radius: 0; background: transparent; color: var(--muted); font-size: 14px; }
  .sheet-tab:hover { background: var(--panel-hover); color: var(--text); }
  .sheet-tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 550; }
  .sheet-tab.active::after { content: ""; position: absolute; bottom: 0; left: 0; right: 0; height: 2px; background: var(--accent); }
  .sheet-tab button { display: flex; align-items: center; gap: 7px; min-height: 32px; padding: 2px; background: none; border: 0; color: inherit; font-size: inherit; }
  .sheet-tab button[role="tab"] { min-height: 44px; }
  .sheet-tab .icon { width: 13px; height: 13px; }
  .add-sheet { display: inline-flex; align-self: center; align-items: center; justify-content: center; width: 30px; height: 30px; flex: 0 0 30px; margin-left: 6px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); }
  .add-sheet:hover { background: var(--panel-hover); color: var(--accent); }
  .selection-summary { display: flex; align-items: center; gap: 16px; color: var(--muted); font-size: 12px; white-space: nowrap; }
  .selection-summary strong { color: var(--text); font-weight: 550; }
  .status-bar { display: flex; align-items: center; justify-content: space-between; flex: 0 0 32px; min-width: 0; gap: 15px; padding: 0 23px; border-top: 1px solid var(--border-subtle); background: var(--sidebar); color: var(--faint); font-size: 11px; }
  .status-left, .status-right { display: flex; align-items: center; gap: 14px; min-width: 0; white-space: nowrap; }
  .status-bar .icon { width: 13px; height: 13px; }
  .status-bar button { padding: 0; border: 0; color: var(--faint); background: transparent; font-size: 11px; }
  .status-bar button:hover { color: var(--accent); }
  .status-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
  .muted { color: var(--faint); }
  #selection-summary { display: flex; align-items: center; gap: 13px; color: var(--muted); }
  #selection-summary strong { font-weight: 550; color: var(--text); }
  body.focus-mode .app-shell { grid-template-columns: minmax(0,1fr); }
  body.focus-mode .sidebar { display: none; }
}

@layer controls {
  .button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 9px 14px; border: 1px solid var(--border); border-radius: 7px; background: var(--panel); color: var(--text); font-size: 14px; font-weight: 550; line-height: 1.3; white-space: nowrap; transition: background .16s, border-color .16s, transform .16s; }
  .button:hover { background: var(--panel-hover); border-color: var(--faint); text-decoration: none; }
  .button:active { transform: translateY(1px); }
  .button.primary { border-color: transparent; background: var(--accent); color: var(--accent-ink); }
  .button.primary:hover { background: var(--accent-hover); border-color: transparent; }
  .button.subtle { border-color: transparent; background: transparent; color: var(--muted); }
  .button.subtle:hover { background: var(--panel-hover); color: var(--text); }
  .button.danger { border-color: color-mix(in srgb,var(--danger) 30%,transparent); color: var(--danger); background: var(--danger-bg); }
  .button.danger-button { border-color: color-mix(in srgb,var(--danger) 30%,transparent); color: var(--danger); background: var(--danger-bg); }
  .button.danger-button:hover { border-color: var(--danger); }
  .button .icon { width: 16px; height: 16px; }
  .text-button { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 14px; }
  .text-button:hover { color: var(--accent); }
  .icon-button { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 36px; height: 36px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--muted); transition: background .16s,color .16s; }
  .icon-button:hover { background: var(--panel-hover); color: var(--text); }
  .sidebar-close { position: absolute; top: 10px; right: 8px; display: none; width: 28px; height: 28px; z-index: 1; }
  .tool-button { display: inline-flex; flex-shrink: 0; align-items: center; justify-content: center; gap: 5px; min-width: 30px; height: 31px; padding: 5px 7px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--muted); font-size: 14px; }
  .tool-button:hover { background: var(--panel-hover); color: var(--text); }
  .tool-button[aria-pressed="true"], .tool-button.active { color: var(--accent); background: var(--accent-selected); border-color: color-mix(in srgb,var(--accent) 16%,transparent); }
  .tool-button .icon { width: 16px; height: 16px; }
  .toolbar-select { min-width: 75px; height: 29px; padding: 4px 25px 4px 9px; border: 1px solid var(--border); border-radius: 5px; appearance: none; background: var(--panel); color: var(--muted); font-size: 14px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239fac9f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 7px center; }
  .toolbar-select:focus { border-color: var(--accent); }
  .toolbar-select.font-size { min-width: 53px; width: 53px; }
  .zoom-select { min-width: 75px; width: 75px; border-color: transparent; }
  .format-select { width: 132px; border-color: transparent; }
  .sigma { font-family: Georgia,serif; font-size: 18px; line-height: 1; }
  .color-input { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 31px; height: 31px; border-radius: 5px; cursor: pointer; }
  .color-input:hover { background: var(--panel-hover); }
  .color-input input[type="color"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
  .color-input .icon { width: 16px; height: 16px; color: var(--muted); }
  .color-tool { position: relative; overflow: hidden; cursor: pointer; }
  input.color-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; padding: 0; border: 0; cursor: pointer; }
  .format-swatch { position: absolute; height: 3px; width: 17px; bottom: 2px; left: 7px; border-radius: 1px; background: var(--accent); }
  .badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 7px; border: 1px solid var(--border); border-radius: 4px; color: var(--muted); font-size: 10px; font-weight: 500; line-height: 1.4; white-space: nowrap; letter-spacing: .15px; }
  .selection-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 5px; color: var(--accent); background: var(--accent-soft); font-size: 12px; }
  .search-input { width: 100%; min-height: 39px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 7px; background: var(--grid); color: var(--text); font-size: 14px; }
  .search-input:focus { border-color: var(--accent); }
  label.search-input { display: flex; flex-shrink: 0; align-items: center; gap: 7px; min-height: 32px; padding: 7px 10px; margin: 0 0 11px; border-color: transparent; background: transparent; }
  label.search-input:focus-within { border-color: var(--border); background: var(--grid); }
  label.search-input > span .icon { width: 13px; height: 13px; color: var(--faint); }
  label.search-input > input { width: 100%; min-width: 0; padding: 0; border: 0; background: transparent; color: var(--text); font-size: 12px; }
  label.search-input > input::placeholder { color: var(--faint); }
  label.search-input > input:focus { outline: none; }
  .field { display: flex; flex-direction: column; gap: 7px; min-width: 0; margin-bottom: 17px; }
  label.field { font-size: 14px; font-weight: 500; }
  .field label { display: block; color: var(--text); font-size: 14px; font-weight: 550; }
  .field input, .field select, .field textarea { width: 100%; min-height: 42px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 7px; background: var(--grid); color: var(--text); font-size: 14px; }
  label.field input, label.field select, label.field textarea { font-weight: 400; }
  .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
  .field textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
  .field input::placeholder, .field textarea::placeholder { color: var(--faint); }
  .field input[type="file"] { font-size: 13px; padding: 9px; }
  .field input[type="file"]::file-selector-button { margin-right: 12px; padding: 7px 9px; border: 0; border-radius: 5px; background: var(--panel-hover); color: var(--text); font: inherit; cursor: pointer; }
  .field select { appearance: none; padding-right: 35px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239fac9f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
  .form-row { display: flex; gap: 14px; }
  .form-row > * { flex: 1; min-width: 0; }
  .form-hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.65; }
  .form-error { margin: 10px 0 0; color: var(--danger) !important; font-size: 13px; line-height: 1.6; }
  .form-error:empty { display: none; }
  .check-field { display: flex; align-items: flex-start; gap: 9px; margin: 14px 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
  .check-field input { width: 16px; height: 16px; margin: 2px 0 0; flex-shrink: 0; accent-color: var(--accent); }
  .kbd, kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 23px; min-height: 22px; padding: 2px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--grid); color: var(--muted); font-family: inherit; font-size: 11px; }
  .data-notice { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; margin: 0 0 19px; border: 1px solid var(--border); border-radius: 7px; background: var(--accent-soft); color: var(--muted); font-size: 13px; line-height: 1.65; }
  .data-notice > .icon { width: 17px; height: 17px; margin-top: 2px; color: var(--accent); }
}

@layer sheet {
  .grid-scroll { width: 100%; height: 100%; overflow: auto; position: relative; overscroll-behavior: contain; scrollbar-color: var(--border) var(--grid); scrollbar-width: thin; }
  #sheet-grid { table-layout: fixed; border-collapse: separate; border-spacing: 0; width: max-content; font-size: 13px; line-height: 1.3; background: var(--grid); user-select: none; }
  #sheet-grid th, #sheet-grid td { padding: 0; border: 0; border-right: 1px solid var(--border-subtle); border-bottom: 1px solid var(--border-subtle); }
  #sheet-grid tr.spacer td { border: 0; padding: 0; background: var(--grid); pointer-events: none; }
  #sheet-grid th.corner { position: sticky; top: 0; left: 0; z-index: 6; width: 48px; min-width: 48px; height: 32px; background: var(--header); color: var(--faint); cursor: pointer; }
  #sheet-grid th.corner::after { content: ""; display: block; position: absolute; right: 6px; bottom: 6px; width: 0; height: 0; border-left: 8px solid transparent; border-bottom: 8px solid var(--faint); opacity: .55; }
  #sheet-grid th.corner > button { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; border: 0; background: transparent; cursor: pointer; }
  #sheet-grid th.column-header { position: sticky; top: 0; z-index: 4; height: 32px; min-width: 48px; background: var(--header); color: var(--faint); font-size: 12px; font-weight: 500; text-align: center; cursor: pointer; }
  #sheet-grid th.row-header { position: sticky; left: 0; z-index: 3; width: 48px; min-width: 48px; height: inherit; background: var(--header); color: var(--faint); font-size: 12px; font-weight: 450; text-align: center; cursor: pointer; }
  #sheet-grid th.column-header:hover, #sheet-grid th.row-header:hover { background: var(--panel-hover); color: var(--text); }
  #sheet-grid th.column-header.selected, #sheet-grid th.row-header.selected { background: color-mix(in srgb,var(--header) 80%,var(--accent) 20%); color: var(--accent); }
  #sheet-grid th.column-header.selected-header, #sheet-grid th.row-header.selected-header { background: color-mix(in srgb,var(--header) 80%,var(--accent) 20%); color: var(--accent); }
  #sheet-grid td.cell { position: relative; height: 32px; min-width: 48px; background: var(--grid); color: var(--text); cursor: cell; }
  #sheet-grid td.cell.selected { background: var(--accent-selected); }
  #sheet-grid td.cell.active { z-index: 2; outline: 2px solid var(--accent); outline-offset: -2px; background: var(--accent-soft); }
  #sheet-grid td.cell.active::after { content: ""; position: absolute; right: 0; bottom: 0; width: 5px; height: 5px; background: var(--accent); border: 1px solid var(--grid); pointer-events: none; }
  #sheet-grid td.cell.error { color: var(--danger); }
  #sheet-grid td.cell.numeric { text-align: right; }
  #sheet-grid td.cell.error::before { content: ""; position: absolute; right: 1px; top: 1px; width: 0; height: 0; border-top: 5px solid var(--danger); border-left: 5px solid transparent; }
  .cell-content { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0 9px; overflow: hidden; text-overflow: clip; white-space: nowrap; min-height: 0; line-height: var(--row-height,32px); }
  input.cell-editor { position: absolute; top: 0; left: 0; z-index: 8; display: block; width: 100%; min-width: 100%; height: 100%; min-height: 0; margin: 0; padding: 3px 7px; border: 2px solid var(--accent); border-radius: 0; background: var(--grid); color: var(--text); font-size: inherit; line-height: normal; box-shadow: 2px 4px 10px #0002; outline: none; user-select: text; }
  .resize-handle { position: absolute; top: 0; right: -3px; bottom: 0; z-index: 8; width: 7px; cursor: col-resize; }
  .resize-handle:hover { background: var(--accent); opacity: .7; }
  .welcome-card { position: absolute; z-index: 7; top: 52px; right: 40px; width: 300px; max-height: calc(100% - 74px); overflow: auto; padding: 23px 22px 20px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); box-shadow: 0 16px 55px #0003; animation: welcome-in .4s ease-out; scrollbar-width: thin; }
  .welcome-card::before { content: none; }
  .welcome-mark { display: grid; place-items: center; width: 36px; height: 36px; margin-bottom: 20px; border: 1px solid color-mix(in srgb,var(--accent) 20%,transparent); border-radius: 9px; background: var(--accent-soft); color: var(--accent); }
  .welcome-mark .icon { width: 20px; height: 20px; }
  .welcome-card .eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 10px; letter-spacing: 1.7px; font-weight: 650; text-transform: uppercase; }
  .welcome-card h2 { margin: 0 0 10px; color: var(--text); font-size: 24px; line-height: 1.2; letter-spacing: -.8px; font-weight: 550; }
  .welcome-card p { margin: 0 0 20px; color: var(--muted); font-size: 13px; line-height: 1.75; }
  .welcome-action { display: flex; align-items: center; gap: 11px; width: 100%; min-height: 44px; margin-top: 8px; padding: 10px 11px; border: 1px solid var(--border); border-radius: 6px; background: transparent; color: var(--text); text-align: left; font-size: 13px; font-weight: 500; transition: background .16s,border-color .16s; }
  .welcome-action:hover { border-color: var(--faint); background: var(--panel-hover); }
  .welcome-action .icon { color: var(--accent); width: 17px; height: 17px; }
  .welcome-action > span:not([data-icon]) { min-width: 0; }
  .welcome-action strong { display: block; font-size: 12px; font-weight: 550; line-height: 1.5; }
  .welcome-action small { display: block; margin-top: 2px; color: var(--faint); font-size: 10px; font-weight: 400; line-height: 1.5; }
  .welcome-action kbd { min-width: 22px; min-height: 21px; margin-left: auto; padding: 2px 4px; font-size: 9px; }
  .welcome-card .dismiss { position: absolute; top: 12px; right: 11px; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 5px; background: transparent; color: var(--faint); }
  .welcome-card .dismiss:hover { color: var(--text); background: var(--panel-hover); }
  .welcome-card .dismiss .icon { width: 15px; height: 15px; }
  .welcome-card .welcome-footer { padding-top: 17px; margin: 18px 0 0; border-top: 1px solid var(--border); font-size: 11px; color: var(--faint); line-height: 1.6; }
  .welcome-card .welcome-footer .icon { width: 12px; height: 12px; margin-right: 5px; }
  .welcome-foot { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 19px; padding-top: 17px; border-top: 1px solid var(--border); color: var(--faint); font-size: 10px; }
  .welcome-foot .icon { width: 12px; height: 12px; }
  @keyframes welcome-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
}

@layer overlays {
  .overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 24px; background: #061009b8; backdrop-filter: blur(4px); animation: fade-in .12s ease-out; }
  .modal { display: flex; flex-direction: column; width: 560px; max-width: 90vw; max-height: 90vh; max-height: 90dvh; overflow: hidden; border: 1px solid var(--border); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); }
  .modal.wide, .modal.modal-wide { width: 800px; }
  .modal-header { display: flex; flex-shrink: 0; align-items: center; justify-content: space-between; gap: 15px; padding: 22px 24px 19px; border-bottom: 1px solid var(--border); }
  .modal-header h2 { margin: 0; font-size: 20px; font-weight: 580; letter-spacing: -.6px; line-height: 1.3; }
  .modal-header .eyebrow { display: block; margin: 0 0 7px; color: var(--faint); font-size: 10px; font-weight: 600; letter-spacing: 1.4px; }
  .modal-close { display: flex; align-items: center; justify-content: center; width: 29px; height: 29px; flex-shrink: 0; padding: 0; border: 0; border-radius: 5px; background: transparent; color: var(--muted); }
  .modal-close:hover { background: var(--panel-hover); color: var(--text); }
  .modal-close .icon { width: 18px; height: 18px; }
  .modal-body { padding: 23px 24px; overflow: auto; min-height: 0; font-size: 14px; line-height: 1.65; }
  .modal-body > p:first-child { margin-top: 0; }
  .modal-body > p { color: var(--muted); }
  .modal-intro { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.7; }
  .modal-body h3 { font-size: 15px; font-weight: 600; margin-top: 24px; margin-bottom: 10px; }
  .modal-body ul, .modal-body ol { padding-left: 20px; color: var(--muted); }
  .modal-body li { margin-bottom: 7px; }
  .modal-body code { padding: 2px 5px; border-radius: 4px; background: var(--grid); color: var(--accent); font-size: 12px; }
  .modal-body pre { max-width: 100%; overflow: auto; padding: 13px; border-radius: 6px; background: var(--grid); color: var(--accent); font-size: 12px; line-height: 1.8; }
  .modal-body pre code { padding: 0; }
  .modal-body table { width: 100%; border-collapse: collapse; font-size: 13px; }
  .modal-body th { font-weight: 550; color: var(--text); text-align: left; }
  .modal-body th, .modal-body td { padding: 9px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
  .modal-body td { color: var(--muted); }
  .modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: 9px; flex-shrink: 0; padding: 16px 24px; border-top: 1px solid var(--border); background: var(--panel-raised); }
  .modal-footer .form-hint { margin-right: auto; }
  .dropdown { position: fixed; z-index: 45; width: 238px; max-width: calc(100vw - 20px); max-height: min(75dvh,600px); padding: 5px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-raised); box-shadow: var(--shadow); animation: fade-in .1s ease-out; }
  .dropdown-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 35px; padding: 8px 9px; border: 0; border-radius: 4px; background: transparent; color: var(--text); text-align: left; font-size: 14px; white-space: nowrap; }
  .dropdown-item:hover { background: var(--panel-hover); }
  .dropdown-item:disabled:hover { background: transparent; }
  .dropdown-item .icon { width: 15px; height: 15px; color: var(--muted); }
  .dropdown-item.danger { color: var(--danger); }
  .dropdown-item.danger .icon { color: var(--danger); }
  .shortcut { margin-left: auto; color: var(--faint); font-size: 10px; font-weight: 400; }
  .dropdown-divider { height: 1px; margin: 5px 3px; background: var(--border); }
  .toast-container { position: fixed; left: 50%; bottom: 60px; z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 9px; transform: translateX(-50%); pointer-events: none; }
  .toast { display: flex; align-items: center; gap: 9px; max-width: min(560px,calc(100vw - 32px)); padding: 12px 17px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-raised); color: var(--text); box-shadow: var(--shadow); font-size: 13px; line-height: 1.45; animation: toast-in .18s ease-out; pointer-events: auto; }
  .toast .icon { color: var(--accent); width: 16px; height: 16px; }
  .toast.error { border-color: color-mix(in srgb,var(--danger) 40%,transparent); }
  .toast.error .icon { color: var(--danger); }
  .templates-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
  .template-card { display: flex; flex-direction: column; align-items: flex-start; min-height: 162px; padding: 20px; border: 1px solid var(--border); border-radius: 9px; background: var(--grid); color: var(--text); text-align: left; transition: border-color .16s,background .16s,transform .16s; }
  .template-card:hover { transform: translateY(-2px); border-color: var(--accent); background: var(--accent-soft); }
  .template-icon { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; margin-bottom: 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); color: var(--accent); }
  .template-icon .icon { width: 19px; height: 19px; }
  .template-card h3 { margin: 0 0 6px; font-size: 15px; line-height: 1.3; font-weight: 550; }
  .template-card p { margin: 0; font-size: 12px; line-height: 1.65; color: var(--muted); }
  .template-label { display: block; margin-top: 17px; padding-top: 10px; border-top: 1px solid var(--border); width: 100%; color: var(--accent); font-size: 11px; font-weight: 500; }
  .templates-grid + .form-hint { margin-top: 17px; }
  .chart-container { width: 100%; min-height: 280px; margin: 18px 0 0; padding: 15px; border: 1px solid var(--border); border-radius: 8px; background: var(--grid); }
  .chart-container svg { display: block; width: 100%; height: auto; overflow: visible; }
  .chart-container svg text { fill: var(--muted); font-family: inherit; font-size: 12px; }
  .chart-empty { display: flex; min-height: 240px; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.65; }
  .chart-empty .icon { width: 30px; height: 30px; color: var(--faint); }
  .help-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
  .help-card { padding: 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--grid); }
  .help-card h3 { margin: 0 0 12px; }
  .help-card p { color: var(--muted); font-size: 13px; line-height: 1.7; }
  .help-card dl { margin: 0; }
  .help-card dt { font-size: 13px; }
  .help-card dd { margin: 4px 0 13px; color: var(--muted); font-size: 12px; }
  .shortcuts-list { border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
  .shortcuts-list > div { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 39px; padding: 8px 12px; border-bottom: 1px solid var(--border-subtle); font-size: 13px; }
  .shortcuts-list > div:last-child { border-bottom: 0; }
  .shortcuts-list > div:nth-child(even) { background: var(--accent-soft); }
  .shortcuts-list > div > span { color: var(--muted); }
  .shortcuts-list kbd { text-align: center; flex-shrink: 0; }
  .help-links { display: flex; align-items: center; flex-wrap: wrap; gap: 18px; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 13px; }
  .about-brand { display: flex; align-items: center; gap: 15px; margin-bottom: 22px; }
  .about-brand h3 { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 21px; font-weight: 580; letter-spacing: -.5px; }
  .about-brand img { flex-shrink: 0; }
  .formula-functions { display: flex; flex-wrap: wrap; gap: 6px; padding: 13px; border: 1px solid var(--border); border-radius: 7px; background: var(--grid); }
  .formula-functions code { border: 1px solid var(--border-subtle); }
  .find-results { display: flex; flex-direction: column; gap: 5px; max-height: 350px; overflow: auto; }
  .find-result { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--grid); color: var(--text); text-align: left; font-size: 13px; }
  .find-result:hover { border-color: var(--accent); background: var(--accent-soft); }
  .find-result .selection-chip { flex-shrink: 0; min-width: 41px; justify-content: center; }
  .find-result > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sort-options { display: flex; gap: 12px; }
  .sort-options label { display: flex; flex: 1; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 7px; font-size: 13px; }
  .sort-options input { accent-color: var(--accent); }
  .details-list { margin: 0; }
  details.details-list { margin-top: 21px; padding-top: 16px; border-top: 1px solid var(--border); }
  details.details-list summary { cursor: pointer; color: var(--text); font-size: 14px; font-weight: 550; }
  details.details-list summary:hover { color: var(--accent); }
  details.details-list > p { color: var(--muted); font-size: 13px; }
  .details-list > div { display: flex; justify-content: space-between; gap: 20px; padding: 12px 0; border-bottom: 1px solid var(--border-subtle); }
  .details-list dt { color: var(--muted); font-size: 13px; }
  .details-list dd { margin: 0; text-align: right; font-size: 13px; overflow-wrap: anywhere; }
  @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
  @keyframes toast-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
}

@layer responsive {
  @media (min-width: 1051px) {
    .mobile-menu, .sidebar-close { display: none; }
  }
  @media (min-width: 1600px) {
    :root { --sidebar-width: 240px; }
    .sidebar { padding-left: 18px; padding-right: 18px; }
    .topbar { padding-left: 32px; padding-right: 32px; }
    .welcome-card { right: 60px; top: 76px; }
  }
  @media (max-width: 1190px) {
    .topbar { padding-left: 20px; padding-right: 20px; }
    .topbar-actions { gap: 6px; }
    .welcome-card { right: 25px; width: 278px; padding: 23px 20px 20px; }
    .selection-summary { gap: 10px; }
    .status-bar { padding-left: 18px; padding-right: 18px; }
  }
  @media (max-width: 1050px) {
    .app-shell { grid-template-columns: minmax(0,1fr); }
    .sidebar { position: absolute; inset: 0 auto 0 0; z-index: 30; width: 248px; max-width: calc(100vw - 54px); transform: translateX(-100%); transition: transform .2s; background: var(--sidebar); box-shadow: var(--shadow); }
    body.sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-close { display: inline-flex; }
    .sidebar .brand { margin-bottom: 24px; }
    .sidebar .new-workbook { margin-bottom: 22px; }
    .sidebar-section { margin-top: 18px; }
    .sidebar-bottom { padding-top: 12px; }
    body.sidebar-open .main-panel::before { content: ""; position: fixed; inset: 0; z-index: 29; background: #0006; }
    .mobile-menu { display: inline-flex; width: 34px; height: 34px; margin-left: -6px; }
    .mobile-only { display: inline-flex; }
    .topbar { gap: 14px; }
    .document-icon { display: none; }
    body.focus-mode .mobile-menu { display: inline-flex; }
  }
  @media (max-width: 760px) {
    .topbar { flex-basis: 80px; padding: 14px 16px; gap: 9px; }
    #workbook-name { font-size: 18px; letter-spacing: -.45px; }
    .document-subtitle { gap: 8px; font-size: 11px; }
    .document-subtitle > span:not(.saved-state):not(:first-child) { display: none; }
    .topbar-actions .button { min-width: 36px; padding-left: 9px; padding-right: 9px; }
    .topbar-actions .button.subtle { display: none; }
    .topbar-actions .button .button-label, .topbar-actions .button > span:not([data-icon]) { display: none; }
    .topbar-actions .icon-button { width: 31px; }
    .menu-bar { padding-left: 10px; padding-right: 10px; gap: 0; overflow-x: auto; scrollbar-width: none; }
    .menu-trigger { font-size: 14px; min-width: 40px; padding-left: 8px; padding-right: 8px; flex-shrink: 0; }
    .menu-bar > .badge { display: none; }
    .local-badge { display: none; }
    .toolbar { padding-left: 10px; padding-right: 10px; }
    .separator { margin-left: 8px; margin-right: 8px; }
    .welcome-card { right: 20px; top: 48px; width: 260px; }
    .welcome-card h2 { font-size: 23px; }
    .sheet-bottom { padding-left: 8px; padding-right: 10px; gap: 6px; }
    .selection-summary { font-size: 11px; }
    .selection-summary > span:not(:last-child) { display: none; }
    .status-bar { padding-left: 12px; padding-right: 12px; gap: 8px; font-size: 10px; }
    .status-left, .status-right { gap: 9px; }
    .status-left > span:not(:first-child) { display: none; }
    .status-right > span:not(:last-child) { display: none; }
    .overlay { padding: 14px; }
    .modal { max-width: 100%; max-height: 94dvh; }
    .modal-header { padding: 18px 18px 15px; }
    .modal-body { padding: 19px 18px; }
    .modal-footer { padding: 14px 18px; }
    .help-layout { grid-template-columns: 1fr; }
    .shortcuts-list > div { gap: 12px; font-size: 12px; }
    .shortcuts-list kbd { max-width: 50%; font-size: 10px; }
  }
  @media (max-width: 600px) {
    .topbar-actions .avatar { display: none; }
    .sheet-bottom .selection-chip { display: none; }
    .sheet-tabs { flex: 0 1 auto; }
  }
  @media (max-width: 480px) {
    .topbar { padding: 10px 11px; flex-basis: 74px; gap: 7px; }
    .mobile-menu { width: 29px; margin-left: -2px; }
    .topbar-actions { gap: 2px; }
    .topbar-actions .icon-button { width: 29px; }
    .topbar-actions .button { width: 35px; height: 35px; min-height: 35px; padding: 8px; }
    #workbook-name { font-size: 16px; padding-left: 2px; margin-left: -2px; letter-spacing: -.4px; }
    .document-subtitle { font-size: 10px; }
    .document-subtitle .saved-state { gap: 4px; }
    .document-subtitle .saved-state .icon { width: 11px; height: 11px; }
    .menu-bar { flex-basis: 37px; padding-left: 6px; }
    .menu-trigger { min-width: 36px; padding-left: 6px; padding-right: 6px; }
    .toolbar { flex-basis: 47px; }
    .formula-bar { flex-basis: 38px; }
    .formula-hint { display: none; }
    .name-box { width: 77px; min-width: 77px; height: 37px; }
    .fx { flex-basis: 34px; }
    .formula-input { font-size: 12px; }
    #sheet-grid th.corner, #sheet-grid th.row-header { width: 40px; min-width: 40px; }
    .welcome-card { right: 16px; top: 51px; width: min(260px,calc(100% - 72px)); padding: 21px 18px 18px; }
    .welcome-card::before { margin-bottom: 18px; }
    .welcome-mark { width: 30px; height: 30px; margin-bottom: 15px; }
    .welcome-card h2 { font-size: 22px; }
    .welcome-card p { font-size: 12px; margin-bottom: 15px; }
    .welcome-action { min-height: 42px; font-size: 12px; }
    .welcome-card .welcome-footer { margin-top: 15px; padding-top: 13px; font-size: 10px; }
    .sheet-bottom { flex-basis: 45px; }
    .sheet-tab { padding-left: 11px; padding-right: 11px; }
    .status-bar { flex-basis: 29px; }
    .templates-grid { gap: 9px; }
    .template-card { padding: 15px; min-height: 160px; }
    .template-card h3 { font-size: 14px; }
    .template-card p { font-size: 11px; }
    .form-row { flex-direction: column; gap: 0; }
    .modal-footer { flex-wrap: wrap; }
    .modal-footer .form-hint { flex: 0 0 100%; }
    .toast-container { bottom: 48px; width: calc(100vw - 24px); }
    .toast { font-size: 12px; max-width: 100%; }
  }
  @media (max-height: 720px) and (min-width: 1051px) {
    .sidebar { padding-top: 20px; }
    .brand { margin-bottom: 24px; }
    .sidebar-section { margin-top: 22px; }
    .storage-card { padding: 12px; }
    .storage-icon { display: none; }
    .storage-description { font-size: 11px; }
    .brand { margin-bottom: 22px; }
    .sidebar .new-workbook { margin-bottom: 22px; }
    .workbook-list { max-height: none; }
    .topbar { flex-basis: 79px; }
    .welcome-card { top: 49px; padding-top: 20px; }
    .welcome-card::before { margin-bottom: 17px; }
    .welcome-mark { display: none; }
    .welcome-foot { margin-top: 12px; padding-top: 12px; }
    .welcome-card p { margin-bottom: 15px; }
  }
  @media (max-height: 850px) {
    .sidebar .storage-card { display: none; }
    .sidebar-bottom { padding-top: 12px; }
    .sidebar-section { margin-top: 18px; }
  }
  @media (max-height: 900px) {
    .welcome-mark { display: none; }
    .welcome-card { padding-top: 23px; }
    .welcome-card h2 { margin-top: 8px; }
    .welcome-card p { margin-bottom: 14px; line-height: 1.6; }
    .welcome-action { padding: 8px 10px; }
    .welcome-action small { font-size: 10px; line-height: 1.4; }
    .welcome-foot { margin-top: 15px; padding-top: 13px; }
  }
  @media (max-height: 650px) {
    .welcome-card { top: 45px; }
    .welcome-mark, .welcome-foot { display: none; }
    .welcome-card h2 { font-size: 22px; }
    .welcome-card p { margin-bottom: 13px; }
    .welcome-action { min-height: 40px; padding-top: 7px; padding-bottom: 7px; }
    .welcome-action small { display: none; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
    #constellation { display: none; }
  }
  @media print {
    @page { size: landscape; margin: 12mm; }
    body { color: #111; background: #fff; overflow: visible; }
    .app-shell { display: none !important; }
    #print-view { display: block; width: 100%; height: auto; padding: 0; color: #182018; background: #fff; font-size: 10pt; }
    #print-view h1 { margin: 0 0 5px; font-size: 19pt; line-height: 1.2; }
    #print-view h2 { margin: 0 0 18px; font-size: 12pt; font-weight: 500; color: #526052; }
    #print-view table { width: 100%; border-collapse: collapse; font-size: 9pt; }
    #print-view thead { display: table-header-group; }
    #print-view th, #print-view td { padding: 6px 8px; border: 1px solid #c8d2c8; text-align: left; overflow-wrap: anywhere; color: #182018 !important; background: #fff !important; }
    #print-view th { background: #eef2ec !important; font-weight: 600; }
    #print-view tr { break-inside: avoid; }
    #print-view footer { margin-top: 20px; padding-top: 10px; border-top: 1px solid #d5ddd2; color: #526052; font-size: 8pt; }
    .sidebar, .topbar, .menu-bar, .toolbar, .formula-bar, .sheet-bottom, .status-bar, .welcome-card, #constellation, .overlay, .toast-container { display: none !important; }
    #sheet-grid, #sheet-grid td.cell { background: #fff; color: #111; }
    #sheet-grid th.column-header, #sheet-grid th.row-header, #sheet-grid th.corner { position: static; background: #f2f2f2; color: #555; }
    #sheet-grid th, #sheet-grid td { border-color: #ddd; }
    #sheet-grid td.cell.active { outline: none; }
  }
}
