:root {
  --accent: #2f6f55; --accent-dark: #23503f; --accent-light: #e3eee8; --accent-border: #a9c7b8; --sel: #2f6f55;
  --ink: #2b2f36; --muted: #6b717c; --line: #dee1e6; --bg: #e5e7eb; --panel: #fcfcfd; --hover: #eef1f3;
  --field: #ffffff; --grid-hdr: #f3f4f6; --grid-hdr-line: #d5d8de; color-scheme: light;
}
:root[data-theme="dark"] {
  --accent: #8cc4a8; --accent-dark: #1b2a24; --accent-light: #2b3a33; --accent-border: #47604f; --sel: #2f8a63;
  --ink: #e6e8ec; --muted: #a2a8b3; --line: #353a44; --bg: #16181d; --panel: #1d2026; --hover: #262a32; --field: #262a32;
  --grid-hdr: #23262d; --grid-hdr-line: #3a3f49; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 13px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); display: flex; flex-direction: column; overflow: hidden; }
button, select, input, textarea { font: inherit; color: inherit; }
svg { display: block; }

/* title strip */
.strip { background: var(--accent-dark); color: #fff; display: flex; align-items: center; gap: 8px; padding: 0 10px; height: 44px; flex: none; }
.logo { display: grid; place-items: center; width: 30px; height: 30px; flex: none; }
.logo img { width: 26px; height: 26px; border-radius: 6px; }
.strip .pill { background: rgba(255,255,255,.18); border: 0; color: #fff; border-radius: 8px; padding: 5px 14px; cursor: pointer; }
.strip .pill:hover { background: rgba(255,255,255,.28); }
.strip .icon-btn { background: transparent; border: 0; color: #fff; width: 32px; height: 32px; border-radius: 8px; cursor: pointer; display: grid; place-items: center; }
.strip .icon-btn:hover { background: rgba(255,255,255,.16); }
.strip .icon-btn svg { width: 18px; height: 18px; }
.docname { width: min(360px, 40vw); background: transparent; border: 1px solid transparent; color: #fff; border-radius: 6px; padding: 4px 8px; }
.docname:hover, .docname:focus { border-color: rgba(255,255,255,.35); outline: none; background: rgba(255,255,255,.08); }
.grow { flex: 1; }
.strip select { background: rgba(255,255,255,.14); color: #fff; border: 0; border-radius: 8px; padding: 5px 6px; max-width: 130px; }
.strip select option { color: #000; background: #fff; }
.get-app { color: #fff; text-decoration: none; background: #ffffff26; border-radius: 8px; padding: 5px 12px; white-space: nowrap; }
.get-app:hover { background: #fff4; }

/* toolbar */
.ribbon { background: var(--panel); border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: center; padding: 5px 6px; row-gap: 4px; flex: none; gap: 0; }
.group { display: flex; align-items: center; gap: 2px; padding: 0 7px; border-right: 1px solid var(--line); flex: none; }
.group:last-child { border-right: 0; }
.tb { min-width: 28px; height: 30px; border: 1px solid transparent; background: transparent; border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 0 4px; position: relative; color: var(--ink); white-space: nowrap; }
.tb:hover { background: var(--hover); }
.tb.on { background: var(--accent-light); border-color: var(--accent-border); }
.tb svg { width: 18px; height: 18px; flex: none; }
.tb.text { padding: 0 8px 0 6px; }
.tb.split { border-radius: 6px 0 0 6px; padding-right: 2px; }
.tb.caret-btn { min-width: 14px; width: 14px; padding: 0; border-radius: 0 6px 6px 0; font-size: 9px; color: var(--muted); margin-right: 2px; }
.tb .swatch { position: absolute; left: 6px; right: 4px; bottom: 3px; height: 3px; border-radius: 2px; }
.ribbon select { height: 28px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); padding: 0 4px; color: var(--ink); }
.ribbon select option { background: var(--panel); color: var(--ink); }
.w-font { width: 128px; } .w-size { width: 56px; } .w-fmt { width: 118px; }

/* formula bar */
.fbar { display: flex; align-items: stretch; gap: 0; background: var(--panel); border-bottom: 1px solid var(--line); flex: none; min-height: 30px; }
.namebox { width: 110px; border: 0; border-right: 1px solid var(--line); background: var(--field); padding: 0 8px; outline: none; font-size: 13px; }
.namebox:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.fx { border: 0; border-right: 1px solid var(--line); background: transparent; width: 38px; cursor: pointer; color: var(--muted); font: italic 600 14px Georgia, serif; }
.fx:hover { background: var(--hover); color: var(--accent); }
.formula { flex: 1; border: 0; resize: none; outline: none; padding: 6px 10px; background: var(--field); font: 13px/18px Consolas, "SF Mono", Menlo, monospace; max-height: 140px; overflow: auto; white-space: pre-wrap; }
.formula:focus { box-shadow: inset 0 0 0 2px var(--accent); }

/* grid */
.gridwrap { flex: 1; position: relative; overflow: hidden; background: #fff; min-height: 0; }
.gridwrap canvas { position: absolute; left: 0; top: 0; }
.scroller { position: absolute; inset: 0; overflow: scroll; cursor: cell; }
.spacer { width: 1px; height: 1px; }
.cell-editor { position: absolute; left: 0; top: 0; width: 2px; height: 2px; opacity: 0; resize: none; border: 0; outline: none; padding: 0; margin: 0; overflow: hidden; white-space: pre; z-index: 3; background: #fff; color: #1f2328; line-height: 1.22; pointer-events: none; }
.cell-editor.on { opacity: 1; border: 2px solid var(--sel); box-shadow: 0 2px 10px rgba(0,0,0,.18); pointer-events: auto; white-space: pre-wrap; word-break: break-word; }

/* sheet tabs + status */
.sheetbar { display: flex; align-items: center; height: 32px; background: var(--panel); border-top: 1px solid var(--line); flex: none; gap: 4px; padding: 0 6px; }
.addsheet { width: 26px; height: 24px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; font-size: 18px; color: var(--muted); line-height: 1; }
.addsheet:hover { background: var(--hover); color: var(--accent); }
.sheettabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1 1 auto; min-width: 60px; align-self: stretch; align-items: stretch; }
.sheettabs button { border: 0; background: transparent; padding: 0 14px; cursor: pointer; white-space: nowrap; color: var(--muted); border-bottom: 3px solid transparent; }
.sheettabs button:hover { background: var(--hover); }
.sheettabs button.on { color: var(--accent); font-weight: 600; border-bottom-color: var(--accent); background: var(--field); }
.sheettabs input { width: 120px; border: 1px solid var(--accent); border-radius: 4px; padding: 0 6px; margin: 4px 0; background: var(--field); outline: none; }
.status { color: var(--muted); white-space: nowrap; font-size: 12px; display: flex; gap: 14px; padding: 0 8px; }
.status b { color: var(--ink); font-weight: 600; }
.zoom { display: flex; align-items: center; gap: 2px; }
.zoom button { border: 0; background: transparent; min-width: 24px; height: 24px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 12px; }
.zoom button:hover { background: var(--hover); color: var(--ink); }

/* popups */
.menu { position: fixed; z-index: 50; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 4px; min-width: 200px; max-height: 70vh; overflow: auto; }
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; border: 0; background: transparent; padding: 6px 10px; border-radius: 5px; cursor: pointer; text-align: left; white-space: nowrap; }
.menu button:hover, .menu button.focus { background: var(--hover); }
.menu button:disabled { opacity: .45; cursor: default; }
.menu button svg { width: 16px; height: 16px; flex: none; color: var(--muted); }
.menu button .k { margin-left: auto; color: var(--muted); font-size: 12px; padding-left: 18px; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }
.menu .pal { display: grid; grid-template-columns: repeat(10, 20px); gap: 3px; padding: 6px; }
.menu .pal button { width: 20px; height: 20px; padding: 0; border-radius: 3px; border: 1px solid rgba(0,0,0,.15); }
.menu .pal button:hover { outline: 2px solid var(--accent); }
.menu input.search { width: calc(100% - 8px); margin: 4px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); outline: none; }
.tip { position: fixed; z-index: 60; background: #2b2f36; color: #fff; padding: 4px 8px; border-radius: 5px; font-size: 12px; pointer-events: none; white-space: nowrap; }
.toast { position: fixed; left: 50%; bottom: 52px; transform: translateX(-50%); background: #2b2f36; color: #fff; padding: 8px 16px; border-radius: 8px; z-index: 70; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 80vw; }
.findbar { position: fixed; right: 18px; top: 128px; z-index: 40; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 8px; display: flex; flex-direction: column; gap: 6px; width: 380px; }
.findbar .row { display: flex; gap: 6px; }
.findbar input:not([type]) { flex: 1; min-width: 0; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); outline: none; }
.findbar input:not([type]):focus { border-color: var(--accent); }
.findbar button { border: 1px solid var(--line); background: var(--field); border-radius: 6px; padding: 4px 10px; cursor: pointer; white-space: nowrap; }
.findbar button:hover { background: var(--hover); }
.findbar .x { border: 0; background: transparent; font-size: 18px; padding: 0 6px; color: var(--muted); }
.findbar .chk { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.drop { position: fixed; inset: 0; z-index: 80; background: rgba(35,80,63,.55); display: grid; place-items: center; color: #fff; font-size: 22px; pointer-events: none; }
.drop div { border: 3px dashed #fff; border-radius: 16px; padding: 40px 60px; }
[hidden] { display: none !important; }
#printArea { display: none; }

@media print {
  @page { margin: 12mm; }
  body { display: block; background: #fff; overflow: visible; height: auto; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block; }
  #printArea table { border-collapse: collapse; table-layout: fixed; font: 11pt Calibri, Carlito, Arial, sans-serif; color: #000; }
  #printArea td { padding: 1px 4px; overflow: hidden; white-space: nowrap; vertical-align: bottom; }
  #printArea.grid td { border: 0.5pt solid #c8c8c8; }
  #printArea h2 { font: 600 12pt "Segoe UI", Arial, sans-serif; margin: 0 0 6pt; break-after: avoid; }
  #printArea section + section { break-before: page; }
}
.native-app .get-app { display: none !important; }
@media (max-width: 1560px) { .tb.text span { display: none; } .tb.text { padding: 0 4px; } .w-font { width: 112px; } .w-fmt { width: 104px; } }
@media (max-width: 760px) { .get-app { display: none; } .docname { width: 30vw; } }
