/* Yang Spreadsheet — styles.
   Excel-like on purpose: flat grey chrome, the sheet is white, the accent is
   Excel's own green. One accent token so a recolour is a one-line change. */
:root {
  --accent: #217346;
  --accent-soft: #cfe0cd;
  --accent-wash: rgba(33, 115, 70, 0.08);
  --chrome: #f3f2f1;
  --chrome-2: #ececec;
  --line: #d4d4d4;
  --line-soft: #e6e6e6;
  --text: #232323;
  --muted: #6b7280;
  --head: #f5f5f5;
  --head-on: #d5e3d0;
  --bad: #b91c1c;
  --good: #217346;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: #fff;
  -webkit-text-size-adjust: 100%;
}

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ------------------------------- title bar ------------------------------ */
.titlebar {
  display: flex; align-items: center; gap: 12px;
  height: 38px; padding: 0 10px; flex: 0 0 auto;
  background: var(--accent); color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; white-space: nowrap; }
.brand-mark { width: 20px; height: 20px; }
.title-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.doc-title { font-size: 12px; opacity: .85; margin-right: 6px; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 3px; padding: 4px 10px; font: inherit; cursor: pointer;
}
.btn:hover { background: var(--chrome); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1a5c38; }
.btn.big { padding: 10px 18px; font-size: 14px; }
.titlebar .btn { border-color: rgba(255,255,255,.45); background: rgba(255,255,255,.12); color: #fff; }
.titlebar .btn:hover { background: rgba(255,255,255,.25); }
.titlebar .btn.primary { background: #fff; color: var(--accent); border-color: #fff; font-weight: 600; }
.titlebar .btn.primary:hover { background: var(--chrome); }

/* --------------------------------- ribbon ------------------------------- */
.ribbon-tabs { display: flex; gap: 2px; padding: 0 8px; background: var(--chrome); border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.rtab {
  border: 0; background: transparent; font: inherit; padding: 6px 12px; cursor: pointer;
  border-bottom: 2px solid transparent; color: var(--text);
}
.rtab:hover { background: var(--chrome-2); }
.rtab.on { border-bottom-color: var(--accent); font-weight: 600; }

.ribbon { display: flex; gap: 0; align-items: stretch; padding: 4px 6px 0; background: var(--chrome); border-bottom: 1px solid var(--line); flex: 0 0 auto; overflow-x: auto; }
.rgroup { display: flex; flex-direction: column; padding: 0 8px 2px; border-right: 1px solid var(--line); }
.rgroup:last-child { border-right: 0; }
.ritems { display: flex; align-items: center; gap: 3px; min-height: 26px; flex-wrap: wrap; }
.rgroup-name { font-size: 10px; color: var(--muted); text-align: center; padding-top: 2px; }
.ritem {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid transparent; background: transparent; border-radius: 3px;
  padding: 3px 7px; font: inherit; cursor: pointer; white-space: nowrap; color: var(--text);
}
.ritem:hover { background: #fff; border-color: var(--line); }
.ritem.on { background: var(--accent-soft); border-color: var(--accent); }
.ritem.bold { font-weight: 700; }
.ritem.italic { font-style: italic; }
.ritem.underline { text-decoration: underline; }
.ritem.strike { text-decoration: line-through; }
.rlabel { font-size: 12px; }

/* ------------------------------- formula bar ---------------------------- */
.formulabar { display: flex; align-items: center; gap: 6px; padding: 3px 8px; background: #fff; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.namebox { width: 96px; padding: 3px 6px; border: 1px solid var(--line); border-radius: 2px; font: inherit; }
.fx { color: var(--muted); font-style: italic; padding: 0 4px; }
.formula-input { flex: 1; padding: 3px 6px; border: 1px solid var(--line); border-radius: 2px; font: inherit; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.namebox:focus, .formula-input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* ---------------------------------- grid -------------------------------- */
.grid-host { position: relative; flex: 1 1 auto; min-height: 0; background: #fff; }
.sheet-wrap { position: absolute; inset: 0; }
.sheet-scroll { position: absolute; inset: 0; overflow: auto; outline: none; }

.sheet-content { position: absolute; top: 0; left: 0; }

.pane { position: absolute; top: 0; left: 0; will-change: transform; }
.pane-fr, .pane-fc, .pane-frc { background: #fff; }
.layer { position: absolute; top: 0; left: 0; }

.cell {
  position: absolute; display: flex; align-items: flex-end; justify-content: flex-start;
  padding: 0 4px 1px; background: #fff; overflow: hidden; white-space: nowrap;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  line-height: 1.25; font-size: 13px;
}
.cell.text { justify-content: flex-start; }
.cell.num { justify-content: flex-end; }
.cell.wrap { white-space: pre-wrap; word-break: break-word; align-items: flex-start; padding-top: 2px; }
.cell.bd { border-color: #000; }
.cell.err { color: var(--bad); }
.cell.filled { background-clip: padding-box; }

.sel-rect { position: absolute; background: var(--accent-wash); border: 1px solid var(--accent); pointer-events: none; z-index: 2; }
.active-rect { position: absolute; outline: 2px solid var(--accent); outline-offset: -1px; pointer-events: none; z-index: 3; background: transparent; }
.fill-handle {
  position: absolute; width: 7px; height: 7px; background: var(--accent); border: 1px solid #fff;
  cursor: crosshair; z-index: 5; pointer-events: auto;
}

.cell-editor { position: absolute; z-index: 9; background: #fff; border: 2px solid var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.editor-input {
  width: 100%; height: 100%; border: 0; outline: none; resize: none; font: inherit; font-size: 13px;
  padding: 0 3px; background: transparent; overflow: hidden; line-height: 1.25;
}

/* headers */
.viewport-overlay { position: sticky; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; pointer-events: none; z-index: 6; }
.heads-top, .heads-left { position: absolute; overflow: hidden; background: var(--head); pointer-events: auto; }
.heads-top { left: 0; right: 0; top: 0; height: 24px; border-bottom: 1px solid #b9b9b9; }
.heads-left { left: 0; top: 0; bottom: 0; width: 48px; border-right: 1px solid #b9b9b9; }
.heads-top-inner, .heads-left-inner { position: absolute; top: 0; left: 0; will-change: transform; }
.corner { position: absolute; left: 0; top: 0; width: 48px; height: 24px; background: var(--head); border-right: 1px solid #b9b9b9; border-bottom: 1px solid #b9b9b9; z-index: 3; }

.col-head, .row-head {
  position: absolute; display: flex; align-items: center; justify-content: center;
  font-size: 11.5px; color: #444; user-select: none; background: var(--head);
  border-right: 1px solid #d9d9d9; border-bottom: 1px solid #d9d9d9;
}
.row-head { left: 0; width: 48px; border-right: 1px solid #c9c9c9; border-bottom: 1px solid #d9d9d9; }
.col-head.on, .row-head.on { background: var(--head-on); font-weight: 600; color: #123d24; }
.col-head .resize, .row-head .resize { position: absolute; right: -2px; top: 0; bottom: 0; width: 5px; cursor: col-resize; }
.row-head .resize { right: 0; left: 0; top: auto; bottom: -2px; height: 5px; width: auto; cursor: row-resize; }
.fh-filter {
  position: absolute; right: 5px; top: 2px; width: 14px; height: 16px; padding: 0;
  border: 0; background: transparent; color: #555; font-size: 9px; cursor: pointer; line-height: 1;
}
.fh-filter.on { color: var(--accent); font-weight: 700; }

.freeze-line-h { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid #8a8a8a; pointer-events: none; display: none; }
.freeze-line-v { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px solid #8a8a8a; pointer-events: none; display: none; }

/* ------------------------------ sheet tabs ------------------------------ */
.sheet-tabs { display: flex; align-items: center; gap: 2px; padding: 0 6px; height: 30px; background: var(--chrome); border-top: 1px solid var(--line); flex: 0 0 auto; overflow-x: auto; }
.tabs-list { display: flex; gap: 2px; }
.stab {
  border: 1px solid transparent; border-bottom: 0; background: transparent; font: inherit; cursor: pointer;
  padding: 4px 12px; border-radius: 3px 3px 0 0; color: #444; white-space: nowrap;
}
.stab:hover { background: var(--chrome-2); }
.stab.on { background: #fff; border-color: var(--line); font-weight: 600; color: var(--accent); }
.stab.add { font-weight: 700; padding: 4px 10px; }

/* ------------------------------ status bar ------------------------------ */
.statusbar { display: flex; align-items: center; gap: 12px; height: 24px; padding: 0 10px; background: var(--chrome); border-top: 1px solid var(--line); font-size: 11.5px; color: #444; flex: 0 0 auto; }
.spacer { flex: 1; }
.status-hint { color: var(--muted); }
.status-stats { display: flex; gap: 10px; }
.stat b { font-weight: 600; color: var(--muted); margin-right: 3px; }
.zoom-label { color: var(--muted); }

/* ------------------------------ start screen ---------------------------- */
.start-screen { position: absolute; inset: 0; background: rgba(255,255,255,.96); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 20px; }
.start-screen.hidden { display: none; }
.start-card { max-width: 620px; text-align: center; }
.start-card h1 { font-size: 26px; margin: 0 0 10px; color: var(--accent); }
.lede { font-size: 14px; line-height: 1.5; color: #333; }
.start-actions { display: flex; gap: 10px; justify-content: center; margin: 18px 0 10px; flex-wrap: wrap; }
.start-limits { margin-top: 20px; font-size: 12px; color: var(--muted); line-height: 1.5; border-top: 1px solid var(--line-soft); padding-top: 12px; text-align: left; }
.link { border: 0; background: transparent; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; }
.muted { color: var(--muted); }

body.dragging::after {
  content: "Drop the file to open it";
  position: fixed; inset: 12px; z-index: 100;
  border: 3px dashed var(--accent); border-radius: 8px; background: rgba(33,115,70,.05);
  display: flex; align-items: center; justify-content: center; font-size: 18px; color: var(--accent);
  pointer-events: none;
}

/* -------------------------------- dialogs ------------------------------- */
.dlg-back { position: fixed; inset: 0; background: rgba(0,0,0,.28); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.dlg { background: #fff; border-radius: 6px; box-shadow: 0 18px 50px rgba(0,0,0,.28); width: 420px; max-width: 100%; max-height: 90vh; display: flex; flex-direction: column; }
.dlg.wide { width: 640px; }
.dlg-head { display: flex; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); }
.dlg-title { font-weight: 600; }
.dlg-x { margin-left: auto; border: 0; background: transparent; font-size: 20px; line-height: 1; cursor: pointer; color: var(--muted); }
.dlg-body { padding: 14px; overflow: auto; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--line-soft); }
.dlg-body h4 { margin: 14px 0 6px; }
.dlg-body h4:first-child { margin-top: 0; }
.dlg-body ul { margin: 6px 0; padding-left: 20px; }
.dlg-body li { margin-bottom: 4px; line-height: 1.45; }
.dlg-body p { line-height: 1.5; }
.dlg-body code { background: var(--chrome); padding: 1px 4px; border-radius: 3px; }

.feature-list { margin: 6px 0 10px; }
.feature-list li { color: var(--bad); }

.fc-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.fc-label { width: 92px; color: var(--muted); flex: 0 0 auto; }
.fc-input { flex: 1; padding: 4px 6px; border: 1px solid var(--line); border-radius: 3px; font: inherit; }
.fc-input.small { width: 70px; flex: 0 0 auto; }
.fc-check { display: inline-flex; align-items: center; gap: 6px; margin-right: 14px; margin-bottom: 6px; cursor: pointer; }
.fc-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line-soft); margin-bottom: 12px; }
.fc-tab { border: 0; background: transparent; padding: 6px 10px; cursor: pointer; font: inherit; border-bottom: 2px solid transparent; }
.fc-tab.on { border-bottom-color: var(--accent); font-weight: 600; }
.fc-pane { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.fc-list { display: flex; flex-direction: column; gap: 3px; flex: 0 0 160px; }
.fc-opt { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 3px; padding: 4px 8px; cursor: pointer; font: inherit; margin-right: 4px; }
.fc-opt.on { background: var(--accent-soft); border-color: var(--accent); }
.fc-right { flex: 1; min-width: 220px; }
.fc-preview { margin-top: 8px; padding: 8px 10px; border: 1px dashed var(--line); border-radius: 3px; font-size: 14px; background: var(--chrome); }

.palette { display: grid; grid-template-columns: repeat(8, 30px); gap: 5px; margin-bottom: 10px; }
.swatch { width: 30px; height: 22px; border: 1px solid var(--line); border-radius: 2px; cursor: pointer; }
.swatch.on { outline: 2px solid var(--accent); }

.filter-menu { min-width: 280px; }
.filter-title { font-weight: 600; margin-bottom: 8px; }
.filter-list { max-height: 300px; overflow: auto; display: flex; flex-direction: column; gap: 2px; }
.filter-list .fc-check { display: flex; margin: 0; }
.filter-count { margin-left: auto; color: var(--muted); font-size: 11px; }

.shortcut-list { display: flex; flex-direction: column; gap: 5px; }
.shortcut-row { display: flex; gap: 12px; align-items: baseline; }
.shortcut-row kbd { flex: 0 0 210px; background: var(--chrome); border: 1px solid var(--line); border-radius: 3px; padding: 2px 6px; font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; }
.shortcut-row span { color: #333; }

.menu { position: fixed; z-index: 80; background: #fff; border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 4px; min-width: 190px; }
.menu-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 6px 10px; border-radius: 3px; cursor: pointer; font: inherit; }
.menu-item:hover { background: var(--chrome); }
.menu-item.danger { color: var(--bad); }
.menu-item.disabled { color: #b9b9b9; cursor: default; }
.menu-sep { height: 1px; background: var(--line-soft); margin: 4px 6px; }

.toast { position: fixed; left: 50%; bottom: 60px; transform: translateX(-50%); background: #232323; color: #fff; padding: 9px 16px; border-radius: 20px; font-size: 12.5px; z-index: 90; box-shadow: 0 8px 20px rgba(0,0,0,.25); transition: opacity .4s; }
.toast.bad { background: var(--bad); }
.toast.out { opacity: 0; }

/* --------------------------------- mobile -------------------------------- */
@media (max-width: 760px) {
  .status-hint, .doc-title { display: none; }
  .ribbon { overflow-x: auto; }
  .rgroup { padding: 0 6px 2px; }
  .ritem { padding: 3px 6px; }
  .title-actions .btn { padding: 3px 6px; }
  .dlg { width: 100%; }
  .fc-label { width: 74px; }
  .shortcut-row { flex-direction: column; gap: 2px; }
  .shortcut-row kbd { flex: 0 0 auto; }
}