/* Excel Editor — SharePoint / Excel-for-the-web look. Light + dark themes. */
:root {
  --green: #107C41;
  --green-dark: #0E6A38;
  --green-darker: #0C5A30;
  --green-soft: #CAEAD8;
  --green-soft-2: #E4F3EC;
  --bg: #ffffff;
  --bg-2: #f5f6f7;
  --bg-3: #eceef0;
  --text: #242424;
  --text-2: #616161;
  --line: #e1e1e1;
  --line-2: #d1d1d1;
  --grid-line: #e0e3e6;
  --head-bg: #f8f9fa;
  --head-text: #444;
  --head-line: #cfd4d9;
  --head-active: #CAEAD8;
  --head-active-text: #0C5A30;
  --sel-border: #107C41;
  --sel-fill: rgba(16, 124, 65, 0.09);
  --cell-bg: #ffffff;
  --chat-bg: #fafbfb;
  --bubble-user: #E4F3EC;
  --bubble-ai: #f0f1f3;
  --accent-link: #0F6CBD;
  --danger: #c50f1f;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  color-scheme: light;
}
[data-theme="dark"] {
  --green: #1a9e56;
  --green-dark: #17894b;
  --green-darker: #128042;
  --green-soft: #1e4632;
  --green-soft-2: #172f23;
  --bg: #1d1f21;
  --bg-2: #26282b;
  --bg-3: #2e3134;
  --text: #e8e8e8;
  --text-2: #a5a5a5;
  --line: #3a3d40;
  --line-2: #46494d;
  --grid-line: #34373a;
  --head-bg: #26282b;
  --head-text: #b5b5b5;
  --head-line: #3f4245;
  --head-active: #1e4632;
  --head-active-text: #7fd7a8;
  --sel-border: #2fbf71;
  --sel-fill: rgba(47, 191, 113, 0.12);
  --cell-bg: #1d1f21;
  --chat-bg: #202225;
  --bubble-user: #1e4632;
  --bubble-ai: #2b2d30;
  --accent-link: #6cb2f0;
  --danger: #ff6b7a;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.mono { font-family: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace; }
.small { font-size: 11.5px; }
.muted { color: var(--text-2); }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ======= top bar ======= */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--green);
  color: #fff;
  height: 44px;
  padding: 0 10px 0 14px;
  flex: none;
  gap: 10px;
}
[data-theme="dark"] #topbar { background: #0d3d24; }
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.applogo { color: #fff; flex: none; }
.apptitle { font-weight: 600; font-size: 15px; white-space: nowrap; }
.doc-sep { width: 1px; height: 20px; background: rgba(255, 255, 255, 0.35); }
.doc-name {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: #fff;
  font-size: 13.5px;
  padding: 3px 8px;
  min-width: 60px;
  max-width: 320px;
  width: 21ch;
}
.doc-name:hover { border-color: rgba(255, 255, 255, 0.45); }
.doc-name:focus { outline: none; border-color: #fff; background: rgba(255, 255, 255, 0.12); }
.save-state { font-size: 11.5px; opacity: 0.85; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.credits { font-size: 12px; background: rgba(255, 255, 255, 0.16); border-radius: 10px; padding: 3px 9px; }
.topup { color: #fff; font-size: 12px; text-decoration: underline; }
.top-icon-btn, .top-ghost-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12.5px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.top-icon-btn { padding: 4px 8px; }
.top-icon-btn:hover, .top-ghost-btn:hover { background: rgba(255, 255, 255, 0.14); }
.top-signin-btn {
  background: #fff;
  color: var(--green-darker);
  border: none;
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 600;
}
.top-signin-btn:hover { background: #eef7f1; }
.chat-toggle.active { background: rgba(255, 255, 255, 0.22); }

/* theme toggle icon via pseudo content */
#btn-theme::before { content: "☀"; font-size: 14px; }
[data-theme="dark"] #btn-theme::before { content: "☾"; }

/* ======= ribbon ======= */
#ribbon-tabs {
  display: flex;
  align-items: center;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 0 8px;
  flex: none;
  height: 32px;
  gap: 2px;
}
.rtab {
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 4px 4px 0 0;
  position: relative;
}
.rtab:hover { background: var(--bg-2); }
.rtab.active { font-weight: 600; color: var(--green); }
.rtab.active::after {
  content: "";
  position: absolute;
  left: 10px; right: 10px; bottom: -1px;
  height: 2.5px;
  background: var(--green);
  border-radius: 2px 2px 0 0;
}
.rtab-spacer { flex: 1; }
.rtab-download {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 12px;
}
.rtab-download:hover { background: var(--green-dark); }

#ribbon {
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  flex: none;
  min-height: 40px;
  padding: 3px 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}
.rpane { display: flex; align-items: stretch; gap: 2px; }
.rgroup { display: flex; align-items: center; gap: 2px; padding: 0 4px; position: relative; }
.rgroup-label { display: none; }
.rsep { width: 1px; background: var(--line); margin: 4px 4px; }
.rbtn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text);
  font-size: 12.5px;
  padding: 5px 8px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 28px;
}
.rbtn:hover:not(:disabled) { background: var(--bg-3); border-color: var(--line-2); }
.rbtn:disabled { opacity: 0.4; cursor: default; }
.rbtn.icon { padding: 5px 7px; min-width: 28px; justify-content: center; }
.rbtn.big { padding: 6px 12px; }
.rbtn.on { background: var(--green-soft); border-color: var(--green); color: var(--green-darker); }
[data-theme="dark"] .rbtn.on { color: #9fe6c2; }
.fmt-b span { font-weight: 700; }
.fmt-i span { font-style: italic; font-family: Georgia, serif; }
.fmt-u span { text-decoration: underline; }
.fmt-s span { text-decoration: line-through; font-size: 11px; }
.rselect {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  font-size: 12.5px;
  height: 28px;
  padding: 0 4px;
  max-width: 130px;
}
.rselect.narrow { max-width: 86px; }
.color-split { display: inline-flex; align-items: center; }
.color-split input[type="color"] {
  width: 16px; height: 26px;
  border: none; background: transparent;
  padding: 0 1px;
  cursor: pointer;
}
.color-a { font-weight: 700; font-size: 12px; }
.color-bar { display: block; position: absolute; bottom: 3px; left: 7px; right: 7px; height: 3px; border-radius: 2px; background: #c00000; }
.color-split .rbtn { position: relative; flex-direction: column; gap: 0; }
#fill-color-bar { background: #ffff00; }

/* ======= formula bar ======= */
#formula-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  flex: none;
  height: 30px;
}
#name-box {
  width: 86px;
  border: none;
  border-right: 1px solid var(--line);
  height: 100%;
  padding: 0 8px;
  font-size: 12.5px;
  background: var(--bg);
  color: var(--text);
  text-align: center;
}
#name-box:focus { outline: 2px solid var(--green); outline-offset: -2px; }
.fx-label {
  font-style: italic;
  font-family: Georgia, serif;
  color: var(--text-2);
  padding: 0 8px;
  border-right: 1px solid var(--line);
  height: 100%;
  display: flex;
  align-items: center;
  font-size: 13px;
}
#formula-input {
  flex: 1;
  border: none;
  height: 100%;
  padding: 0 10px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
}
#formula-input:focus { outline: 2px solid var(--green); outline-offset: -2px; }

/* ======= main layout ======= */
#main { flex: 1; display: flex; min-height: 0; }
#grid-area { flex: 1; min-width: 0; position: relative; display: flex; }

/* empty state */
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--bg-2); overflow-y: auto; padding: 16px 0; }
.feature-strip { display: flex; gap: 16px; max-width: 900px; margin: 20px 20px 8px; flex-wrap: wrap; justify-content: center; }
.feature { flex: 1 1 220px; max-width: 280px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 13px 16px; }
.feature h3 { margin: 0 0 6px; font-size: 13.5px; color: var(--green); }
[data-theme="dark"] .feature h3 { color: #7fd7a8; }
.feature p { margin: 0; font-size: 12.5px; color: var(--text-2); line-height: 1.5; }
.tut-link { color: var(--green); font-weight: 600; }
[data-theme="dark"] .tut-link { color: #7fd7a8; }
#btn-help { text-decoration: none; font-weight: 700; }
.drop-card {
  max-width: 520px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 36px 40px;
  text-align: center;
  margin: 20px;
}
.drop-logo { margin-bottom: 10px; }
.drop-card h2 { margin: 8px 0 10px; font-size: 21px; }
.drop-card p { color: var(--text-2); line-height: 1.5; margin: 0 0 18px; }
.drop-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 12px; }
button.primary {
  background: var(--green);
  border: 1px solid var(--green);
  color: #fff;
  border-radius: 5px;
  padding: 7px 16px;
  font-size: 13.5px;
  font-weight: 600;
}
button.primary:hover:not(:disabled) { background: var(--green-dark); }
button.primary:disabled { opacity: 0.5; cursor: default; }
button.ghost {
  background: transparent;
  border: 1px solid var(--line-2);
  color: var(--text);
  border-radius: 5px;
  padding: 7px 14px;
  font-size: 13.5px;
}
button.ghost:hover { background: var(--bg-2); }
button.big { padding: 9px 18px; }

/* ======= grid ======= */
#grid {
  flex: 1;
  display: grid;
  grid-template-columns: 46px 1fr;
  grid-template-rows: 24px 1fr;
  min-width: 0;
  background: var(--bg);
  position: relative;
}
#grid-corner {
  grid-column: 1; grid-row: 1;
  background: var(--head-bg);
  border-right: 1px solid var(--head-line);
  border-bottom: 1px solid var(--head-line);
  z-index: 3;
  cursor: pointer;
  position: relative;
}
#grid-corner::after { /* Excel's select-all triangle */
  content: "";
  position: absolute;
  right: 3px; bottom: 3px;
  border-style: solid;
  border-width: 0 0 11px 11px;
  border-color: transparent transparent var(--head-line) transparent;
}
#grid-corner:hover::after { border-bottom-color: var(--green); }
#col-headers {
  grid-column: 2; grid-row: 1;
  overflow: hidden;
  position: relative;
  background: var(--head-bg);
  border-bottom: 1px solid var(--head-line);
  z-index: 2;
  user-select: none;
}
#row-headers {
  grid-column: 1; grid-row: 2;
  overflow: hidden;
  position: relative;
  background: var(--head-bg);
  border-right: 1px solid var(--head-line);
  z-index: 2;
  user-select: none;
}
#col-headers-inner, #row-headers-inner { position: absolute; top: 0; left: 0; will-change: transform; }
.col-h, .row-h {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  color: var(--head-text);
  background: var(--head-bg);
  border-right: 1px solid var(--head-line);
  border-bottom: 1px solid var(--head-line);
  overflow: hidden;
}
.col-h.sel, .row-h.sel { background: var(--head-active); color: var(--head-active-text); font-weight: 600; }
.col-h:hover, .row-h:hover { background: var(--bg-3); }
.col-h.sel:hover, .row-h.sel:hover { background: var(--head-active); }
.col-resize { position: absolute; top: 0; width: 7px; cursor: col-resize; z-index: 3; }
.row-resize { position: absolute; left: 0; height: 7px; cursor: row-resize; z-index: 3; }
.col-resize:hover, .row-resize:hover { background: var(--green); opacity: 0.55; }

#grid-scroller {
  grid-column: 2; grid-row: 2;
  overflow: auto;
  position: relative;
  background: var(--cell-bg);
}
#grid-spacer { position: absolute; top: 0; left: 0; width: 1px; height: 1px; }
#cells-layer, #charts-layer, #selection-layer { position: absolute; top: 0; left: 0; }
.cell {
  position: absolute;
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  padding: 0 4px;
  font-size: 13px;
  line-height: 1.25;
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: pre;
  color: var(--text);
  background: var(--cell-bg);
}
.cell.wrap { white-space: pre-wrap; word-break: break-word; align-items: flex-start; padding-top: 2px; }
.cell.overflow { overflow: visible; z-index: 1; border-right-color: transparent; }
.cell .ov { pointer-events: none; }

#selection-layer { pointer-events: none; z-index: 2; }
#sel-fill { position: absolute; background: var(--sel-fill); display: none; }
#sel-border { position: absolute; border: 2px solid var(--sel-border); display: none; }
#fill-handle {
  position: absolute;
  width: 7px; height: 7px;
  background: var(--sel-border);
  border: 1px solid var(--bg);
  display: none;
  pointer-events: auto;
  cursor: crosshair;
  z-index: 3;
}
.freeze-pane {
  position: absolute;
  z-index: 3;
  background: var(--cell-bg);
  overflow: hidden;
  display: none;
}
#pane-top { border-bottom: 1px solid var(--head-line); }
#pane-left { border-right: 1px solid var(--head-line); }
#pane-corner { border-right: 1px solid var(--head-line); border-bottom: 1px solid var(--head-line); }
.psel-fill { position: absolute; background: var(--sel-fill); display: none; pointer-events: none; }
.psel-border { position: absolute; border: 2px solid var(--sel-border); display: none; pointer-events: none; }

#cell-editor {
  position: absolute;
  z-index: 4;
  border: 2px solid var(--sel-border);
  outline: none;
  font-size: 13px;
  font-family: inherit;
  padding: 0 3px;
  background: var(--cell-bg);
  color: var(--text);
  box-shadow: var(--shadow);
}
#clip-sink { position: fixed; left: -9999px; top: 0; width: 10px; height: 10px; opacity: 0; }

.chart-box {
  position: absolute;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.14);
  z-index: 1;
  overflow: hidden;
}
.chart-box canvas { display: block; }
.chart-box .chart-del {
  position: absolute;
  top: 2px; right: 2px;
  width: 20px; height: 20px;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  display: none;
}
.chart-box:hover .chart-del { display: block; }
.chart-box .chart-del:hover { background: var(--bg-3); color: var(--danger); }

/* ======= chat panel ======= */
#chat {
  width: 340px;
  min-width: 260px;
  flex: none;
  border-left: 1px solid var(--line);
  background: var(--chat-bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}
#chat-resizer {
  position: absolute;
  left: -3px;
  top: 0;
  bottom: 0;
  width: 7px;
  cursor: col-resize;
  z-index: 6;
}
#chat-resizer:hover, #chat-resizer.dragging { background: var(--green); opacity: 0.5; }
#chat.hidden { display: none !important; }
.chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.chat-title { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13.5px; color: var(--green); }
[data-theme="dark"] .chat-title { color: #7fd7a8; }
#model-select {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  font-size: 11.5px;
  height: 26px;
}
.chat-x { background: none; border: none; color: var(--text-2); font-size: 18px; padding: 0 6px; border-radius: 4px; }
.chat-x:hover { background: var(--bg-3); }

#chat-messages { flex: 1; overflow-y: auto; padding: 12px 12px 6px; scroll-behavior: smooth; }
.chat-welcome { font-size: 13px; line-height: 1.45; margin-bottom: 10px; }
.chat-welcome p { margin: 0 0 8px; }
#chat-suggestions { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.sugg {
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--line-2);
  color: var(--text);
  border-radius: 14px;
  font-size: 12.5px;
  padding: 7px 12px;
}
.sugg:hover { border-color: var(--green); color: var(--green); }
[data-theme="dark"] .sugg:hover { color: #7fd7a8; }

.msg { margin-bottom: 10px; display: flex; flex-direction: column; }
.msg .bubble {
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 13px;
  line-height: 1.45;
  max-width: 95%;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user { align-items: flex-end; }
.msg.user .bubble { background: var(--bubble-user); border-bottom-right-radius: 3px; }
.msg.ai { align-items: flex-start; }
.msg.ai .bubble { background: var(--bubble-ai); border-bottom-left-radius: 3px; }
.msg .meta { font-size: 10.5px; color: var(--text-2); margin-top: 3px; padding: 0 3px; display: flex; gap: 8px; align-items: center; }
.msg .meta button { background: none; border: none; color: var(--accent-link); font-size: 10.5px; padding: 0; text-decoration: underline; }
.ops-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--green-soft);
  color: var(--green-darker);
  border-radius: 10px;
  font-size: 11px;
  padding: 2px 9px;
  margin-top: 5px;
  width: fit-content;
}
[data-theme="dark"] .ops-chip { color: #9fe6c2; }
.ops-chip.err { background: rgba(197, 15, 31, 0.12); color: var(--danger); }
.typing { display: inline-block; }
.typing::after { content: "…"; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }

.chat-compose { border-top: 1px solid var(--line); padding: 8px 10px 9px; flex: none; background: var(--chat-bg); }
.chat-hint { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); margin-bottom: 8px; flex-wrap: wrap; }
.compose-row { display: flex; gap: 6px; align-items: flex-end; }
#chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  line-height: 1.4;
  max-height: 120px;
}
#chat-input:focus { outline: none; border-color: var(--green); }
#btn-chat-send { border-radius: 8px; padding: 8px 12px; height: 36px; }
#btn-chat-stop { border-radius: 8px; height: 36px; }
.chat-status-row { display: flex; justify-content: space-between; margin-top: 5px; min-height: 14px; }

/* ======= bottom bar ======= */
#bottombar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  height: 30px;
  flex: none;
  padding: 0 10px 0 4px;
  gap: 10px;
}
.sheettabs-wrap { display: flex; align-items: center; min-width: 0; overflow: hidden; }
#btn-sheet-add {
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 17px;
  padding: 0 10px;
  height: 100%;
}
#btn-sheet-add:hover { color: var(--green); }
#sheettabs { display: flex; align-items: stretch; height: 30px; overflow-x: auto; scrollbar-width: none; }
.sheettab {
  background: none;
  border: none;
  border-right: 1px solid var(--line);
  color: var(--text-2);
  font-size: 12.5px;
  padding: 0 14px;
  white-space: nowrap;
  position: relative;
}
.sheettab:hover { background: var(--bg-3); }
.sheettab.active {
  background: var(--bg);
  color: var(--green);
  font-weight: 600;
}
.sheettab.active::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 2px;
  background: var(--green);
}
#statusagg { color: var(--text-2); white-space: nowrap; display: flex; gap: 14px; }

/* ======= cell markers ======= */
.note-dot {
  position: absolute;
  top: 0; right: 0;
  width: 0; height: 0;
  border-style: solid;
  border-width: 0 7px 7px 0;
  border-color: transparent #C00000 transparent transparent;
  pointer-events: none;
}
.fbtn {
  position: absolute;
  right: 2px; top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  line-height: 15px;
  text-align: center;
  font-size: 9px;
  color: var(--text-2);
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 3px;
  cursor: pointer;
  user-select: none;
}
.fbtn:hover { border-color: var(--green); color: var(--green); }
.fbtn.on { color: #fff; background: var(--green); border-color: var(--green); }
.chart-box.movable { cursor: move; }
.obj-resize {
  position: absolute;
  right: 0; bottom: 0;
  width: 13px; height: 13px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 55%, var(--line-2) 55%);
}
.obj-resize:hover { background: linear-gradient(135deg, transparent 55%, var(--green) 55%); }
.image-box img { width: 100%; height: 100%; display: block; object-fit: fill; }

/* ======= filter panel ======= */
#filter-panel {
  position: fixed;
  z-index: 60;
  width: 236px;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 9px;
  font-size: 12.5px;
}
.fp-sort { display: flex; gap: 6px; margin-bottom: 7px; }
.fp-sort button { flex: 1; font-size: 12px; padding: 4px 6px; }
#fp-search {
  width: 100%;
  border: 1px solid var(--line-2);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  padding: 5px 8px;
  font-size: 12.5px;
}
#fp-search:focus { outline: none; border-color: var(--green); }
.fp-all { display: flex; gap: 6px; align-items: center; padding: 6px 4px 2px; font-weight: 600; }
#fp-list {
  max-height: 190px;
  overflow-y: auto;
  margin: 4px 0 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 3px;
}
#fp-list label { display: flex; gap: 6px; align-items: center; padding: 2.5px 5px; border-radius: 3px; }
#fp-list label:hover { background: var(--bg-2); }
#fp-list .fp-count { margin-left: auto; color: var(--text-2); font-size: 11px; }
.fp-actions { display: flex; gap: 6px; align-items: center; }
.fp-actions button { font-size: 12px; padding: 5px 9px; }
.fp-sp { flex: 1; }

/* ======= find & replace ======= */
#findbar {
  position: absolute;
  top: 8px; right: 18px;
  z-index: 40;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 9px;
  width: 320px;
}
.fb-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.fb-row:last-child { margin-bottom: 0; }
.fb-row input[type="text"] {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line-2);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  padding: 5px 8px;
  font-size: 13px;
}
.fb-row input[type="text"]:focus { outline: none; border-color: var(--green); }
.fb-row button.ghost { padding: 4px 9px; font-size: 12px; }
.fb-x { background: none; border: none; color: var(--text-2); font-size: 17px; padding: 0 5px; cursor: pointer; border-radius: 4px; }
.fb-x:hover { background: var(--bg-3); }
.fb-opts { gap: 14px; font-size: 12px; color: var(--text-2); }
.fb-opts label { display: flex; gap: 4px; align-items: center; }
#fb-count { min-width: 52px; text-align: right; }

/* ======= note editor ======= */
#note-pop {
  position: fixed;
  z-index: 60;
  width: 250px;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-top: 3px solid #C00000;
  border-radius: 7px;
  box-shadow: var(--shadow);
  padding: 9px;
}
#note-text {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line-2);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
  margin: 5px 0 8px;
}
#note-text:focus { outline: none; border-color: var(--green); }
.np-actions { display: flex; gap: 6px; align-items: center; }
.np-actions button { font-size: 12px; padding: 5px 10px; }

/* ======= context menu ======= */
.ctx-menu {
  position: fixed;
  z-index: 50;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 4px;
  min-width: 180px;
}
.ctx-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 4px;
}
.ctx-menu button:hover { background: var(--green-soft-2); }
[data-theme="dark"] .ctx-menu button:hover { background: var(--green-soft); }
.ctx-menu .ctx-sep { height: 1px; background: var(--line); margin: 4px 6px; }

/* ======= overlays ======= */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(16, 124, 65, 0.18);
  border: 3px dashed var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
}
.drop-overlay span {
  background: var(--bg);
  border-radius: 8px;
  padding: 14px 26px;
  font-size: 16px;
  font-weight: 600;
  box-shadow: var(--shadow);
}
.busy { position: fixed; inset: 0; z-index: 110; background: rgba(0, 0, 0, 0.25); display: flex; align-items: center; justify-content: center; }
.busy[hidden], .drop-overlay[hidden] { display: none; }
.busy-box {
  background: var(--bg);
  border-radius: 8px;
  padding: 18px 26px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  font-size: 14px;
}
.spinner {
  width: 20px; height: 20px;
  border: 3px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.toasts { position: fixed; bottom: 42px; left: 50%; transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--text);
  color: var(--bg);
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
  max-width: 480px;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ======= responsive ======= */
@media (max-width: 900px) {
  #chat { position: fixed; right: 0; top: 44px; bottom: 0; z-index: 40; box-shadow: var(--shadow); width: min(340px, 92vw); }
  .rgroup-label { display: none; }
}
@media (max-width: 600px) {
  .apptitle { display: none; }
  .doc-name { width: 12ch; }
}
