/* app.css — the application around the document.
   Everything in here disappears when the document prints. */

:root {
  --bg: #eceef1;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --line: #dfe3e8;
  --text: #1f2933;
  --dim: #7b8794;
  --faint: #9aa5b1;
  --brand: #2f6b4f;
  --brand-ink: #ffffff;
  --danger: #c0392b;
  --warn: #b7791f;
  --good: #2f855a;
  --sel: #3d5a80;
  --radius: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --ui: 'Segoe UI', Inter, system-ui, -apple-system, sans-serif;
  --mono: 'Cascadia Code', Consolas, 'SF Mono', monospace;
}

body.dark {
  --bg: #14171c;
  --panel: #1c2027;
  --panel-2: #21262e;
  --line: #2e343d;
  --text: #e4e8ee;
  --dim: #98a2b0;
  --faint: #6d7684;
  --brand: #4f9d78;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

/* ─────────── toolbar ─────────── */

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 46px;
  padding: 0 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 30;
}

.tb-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 6px;
  border-right: 1px solid var(--line);
}
.tb-group:last-child { border-right: 0; }
.tb-spacer { flex: 1; }

.tb {
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: background .12s, border-color .12s;
}
.tb:hover:not(:disabled) { background: var(--panel-2); border-color: var(--line); }
.tb:active:not(:disabled) { transform: translateY(1px); }
.tb:disabled { opacity: .3; cursor: default; }
.tb.primary { background: var(--brand); color: var(--brand-ink); }
.tb.primary:hover { filter: brightness(1.08); background: var(--brand); border-color: transparent; }
.tb.on { background: var(--panel-2); border-color: var(--line); box-shadow: inset 0 0 0 1px var(--brand); }

.zoom {
  min-width: 44px;
  text-align: center;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.doc-num { display: flex; align-items: center; gap: 8px; }
.dn-num { font-weight: 700; font-variant-numeric: tabular-nums; }
.dn-title { color: var(--dim); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dn-rev { color: var(--faint); font-size: 11px; }

.pill {
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: var(--panel-2);
  color: var(--dim);
  border: 1px solid var(--line);
}
.pill.sent { background: #e6f0fb; color: #24558c; border-color: #c5daf3; }
.pill.accepted { background: #e6f5ec; color: #26654a; border-color: #c3e5d2; }
.pill.rejected { background: #fbeaea; color: #9b2c2c; border-color: #f0cccc; }
.pill.expired { background: #f3f0e6; color: #856404; border-color: #e6ddc2; }
body.dark .pill.sent { background: #1c3350; color: #a8cbf2; border-color: #2b4a70; }
body.dark .pill.accepted { background: #1a3b2c; color: #8fdcb4; border-color: #27573f; }
body.dark .pill.rejected { background: #431f1f; color: #f0a9a9; border-color: #5e2c2c; }

/* ─────────── shell ─────────── */

.shell {
  display: grid;
  grid-template-columns: 244px 1fr 292px;
  height: calc(100% - 46px - 26px);
}

.panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  min-height: 0;
}
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); }

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  flex: 0 0 auto;
}
.tab {
  flex: 1;
  padding: 8px 4px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); border-bottom-color: var(--brand); background: var(--panel); }

.panel-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.panel-body { padding: 10px; }

.panel-group {
  margin: 14px 0 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--faint);
}
.panel-group:first-child { margin-top: 2px; }

.panel-note {
  margin: 12px 2px 4px;
  color: var(--faint);
  font-size: 11.5px;
  line-height: 1.5;
}
.panel-actions { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }

/* ─────────── blocks palette ─────────── */

.blocks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.block {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  cursor: grab;
  text-align: left;
  transition: border-color .12s, transform .08s, background .12s;
}
.block:hover { border-color: var(--brand); background: var(--panel); }
.block:active { cursor: grabbing; transform: scale(.97); }
.block-icon {
  width: 20px;
  flex: 0 0 20px;
  text-align: center;
  font-size: 14px;
  color: var(--brand);
}
.block-label { font-size: 11.5px; line-height: 1.25; }

/* ─────────── outline ─────────── */

.outline { display: flex; flex-direction: column; gap: 2px; }
.out-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
}
.out-item:hover { background: var(--panel-2); }
.out-item.sel { background: var(--panel-2); border-color: var(--brand); }
.out-item.over { border-top: 2px solid var(--brand); }
.out-icon { width: 16px; text-align: center; color: var(--brand); }
.out-label { flex: 1; font-weight: 600; font-size: 12px; }
.out-type { color: var(--faint); font-size: 11px; }

/* ─────────── catalog / clients / library ─────────── */

.cat-list, .lib-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }

.cat-item, .lib-item {
  position: relative;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  cursor: pointer;
}
.cat-item:hover, .lib-item:hover { border-color: var(--brand); background: var(--panel); }
.cat-item { cursor: grab; }
.cat-item:active { cursor: grabbing; }

.cat-main, .lib-main { display: flex; align-items: baseline; gap: 8px; }
.cat-name, .lib-title { flex: 1; font-weight: 600; font-size: 12px; }
.cat-rate, .lib-total { font-variant-numeric: tabular-nums; font-size: 12px; }
.cat-sub, .lib-sub {
  display: flex;
  gap: 8px;
  margin-top: 2px;
  color: var(--faint);
  font-size: 11px;
}
.cat-cost { color: var(--warn); }
.lib-num { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 12px; }
.cat-tools, .lib-item > .icon-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  display: none;
  gap: 2px;
}
.cat-item:hover .cat-tools, .lib-item:hover > .icon-btn { display: flex; }

.empty { color: var(--faint); font-size: 12px; padding: 16px 4px; text-align: center; }

/* ─────────── inspector ─────────── */

.insp-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  margin-bottom: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.insp-icon { font-size: 18px; color: var(--brand); }
.insp-title { font-weight: 700; }
.insp-sub { color: var(--faint); font-size: 11px; }
.insp-sub code { font-family: var(--mono); color: var(--brand); }
.insp-head .icon-btn { margin-left: auto; }

.form { display: flex; flex-direction: column; gap: 9px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.f { display: flex; flex-direction: column; gap: 3px; }
.f-label { font-size: 11px; font-weight: 600; color: var(--dim); }
.f-hint { font-size: 10.5px; color: var(--faint); }

.field {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font: inherit;
}
.field:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
select.field { cursor: pointer; }

.check { display: flex; align-items: center; gap: 7px; font-size: 12px; cursor: pointer; }
.check input { accent-color: var(--brand); }

.seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button {
  flex: 1;
  padding: 5px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  font-size: 12px;
}
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }

.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch {
  width: 26px;
  height: 26px;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
}
.swatch.on { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--brand); }

.col-list { display: flex; flex-direction: column; gap: 3px; }
.col-row {
  display: grid;
  grid-template-columns: 46px 1fr auto auto;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  font-size: 11.5px;
}
.col-row.internal { border-style: dashed; opacity: .82; }
.col-key {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--brand);
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-flags { display: flex; gap: 3px; }
.flag {
  min-width: 15px;
  padding: 0 3px;
  border-radius: 3px;
  background: var(--line);
  color: var(--dim);
  font-size: 9.5px;
  font-weight: 700;
  text-align: center;
  line-height: 15px;
}
.flag.money { background: #d8ecdf; color: #1f6444; }
.flag.fx { background: #e0e7f5; color: #2f4d80; }
.flag.lock { background: transparent; }
.flag.role { background: #f2e3cd; color: #8a5a12; }
.col-tools { display: flex; gap: 1px; }
.col-formula {
  grid-column: 1 / -1;
  width: 100%;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
  font-family: var(--mono);
  font-size: 10.5px;
}

.icon-btn {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}
.icon-btn:hover:not(:disabled) { background: var(--line); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger); color: #fff; }
.icon-btn:disabled { opacity: .25; cursor: default; }

.btn {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn.small { padding: 4px 9px; font-size: 11.5px; }
.btn.ghost { background: transparent; }

/* ─────────── canvas ─────────── */

.canvas {
  --zoom: 1;
  overflow: auto;
  padding: 26px 0 60px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  position: relative;
}
.canvas > .page {
  zoom: var(--zoom);   /* zoom, not transform: it reflows, so scrollbars stay honest */
}

.drop-line {
  height: 3px;
  margin: 2px 0;
  border-radius: 2px;
  background: var(--brand);
  box-shadow: 0 0 0 3px rgba(47, 107, 79, .18);
}
body.dragging .el { cursor: grabbing; }
body.dragging .cell { pointer-events: none; }

/* ─────────── status bar ─────────── */

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 26px;
  padding: 0 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  color: var(--dim);
  font-size: 11.5px;
}
.status .sep { color: var(--faint); }
.st-total b { color: var(--text); font-variant-numeric: tabular-nums; }
.st-margin.good { color: var(--good); }
.st-margin.bad { color: var(--danger); }
.st-save { color: var(--faint); }
.st-save.dirty { color: var(--warn); }
.st-save.saving { color: var(--warn); }
.st-save.saved { color: var(--good); }
.st-save.offline { color: var(--danger); }
.st-save.saved::before { content: '✓ '; }
.st-save.saving::before { content: '⟳ '; }
.st-save.offline::before { content: '⚠ '; }

.share-dialog .share-url-row { display: flex; gap: 8px; margin-top: 8px; }
.share-dialog .share-url-row .field { flex: 1; font-family: monospace; font-size: 12px; }

/* attachments */
.attach-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.attach-list { display: flex; flex-direction: column; gap: 6px; }
.attach-empty { color: var(--faint); font-size: 12px; padding: 4px 0; }
.attach-item { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border: 1px solid var(--line, #e5e7eb); border-radius: 6px; }
.attach-thumb { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; }
.attach-ico { width: 28px; text-align: center; }
.attach-name { flex: 1; background: none; border: 0; text-align: left; cursor: pointer; color: var(--accent, #3d5a80); text-decoration: underline; font-size: 13px; }
.attach-size { color: var(--faint); font-size: 11px; }
.attach-x { background: none; border: 0; cursor: pointer; color: var(--faint); }
.attach-x:hover { color: var(--danger, #c0392b); }

/* ─────────── menu ─────────── */

.menu {
  position: fixed;
  z-index: 200;
  min-width: 216px;
  max-height: 78vh;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.menu-header {
  padding: 6px 8px 4px;
  color: var(--faint);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.menu-sep { height: 1px; margin: 4px 6px; background: var(--line); }
.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-size: 12.5px;
}
.menu-item:hover:not(:disabled) { background: var(--panel-2); }
.menu-item:disabled { opacity: .35; cursor: default; }
.menu-item.danger:hover { background: var(--danger); color: #fff; }
.menu-icon { width: 16px; flex: 0 0 16px; text-align: center; color: var(--brand); font-size: 12px; }
.menu-item.danger:hover .menu-icon, .menu-item.danger:hover .menu-hint { color: #fff; }
.menu-label { flex: 1; }
.menu-hint { color: var(--faint); font-size: 10.5px; }
.menu-check { width: 12px; color: var(--brand); }

/* ─────────── dialog ─────────── */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  background: rgba(16, 24, 40, .45);
  opacity: 0;
  transition: opacity .16s;
}
.backdrop.in { opacity: 1; }
.dialog {
  max-width: calc(100vw - 32px);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 24px 64px rgba(0, 0, 0, .3);
  transform: translateY(6px);
  transition: transform .16s;
}
.backdrop.in .dialog { transform: none; }
.dialog-head {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.dialog-head h3 { flex: 1; margin: 0; font-size: 14px; }
.dialog-body { padding: 14px; overflow-y: auto; }
.dialog-text { margin: 0 0 10px; color: var(--dim); white-space: pre-wrap; line-height: 1.6; }
.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}

/* ─────────── help ─────────── */

.help p { margin: 0 0 10px; color: var(--dim); line-height: 1.6; }
.help code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--brand);
  font-family: var(--mono);
  font-size: 11.5px;
}
.help-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.help-table td { padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.help-table td:first-child { width: 46%; }
.help-table td:last-child { color: var(--dim); font-size: 12px; }
.help-note { font-size: 12px; line-height: 1.65; }

/* ─────────── toasts ─────────── */

.toasts {
  position: fixed;
  bottom: 38px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}
.toast {
  padding: 7px 14px;
  border-radius: 999px;
  background: #1f2933;
  color: #fff;
  font-size: 12.5px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
}
.toast.in { opacity: 1; transform: none; }
.toast.warn { background: var(--warn); }
.toast.bad { background: var(--danger); }
