:root {
  --bg: #fafaf8;
  --surface: #ffffff;
  --ink: #1c1c1a;
  --muted: #6b6b66;
  --line: #e4e3de;
  --accent: #1f4e79;
  --accent-ink: #ffffff;
  --accent-soft: #e6edf4;
  --danger: #b3261e;
  --desk: #e6e5e0;
  --grid-line: rgba(31, 78, 121, 0.07);
  --scrim: rgba(20, 20, 18, 0.38);
  --shadow: 0 1px 2px rgba(28, 28, 26, 0.08), 0 8px 28px rgba(28, 28, 26, 0.12);
  --page-shadow: 0 0 0 1px rgba(28, 28, 26, 0.08), 0 1px 3px rgba(28, 28, 26, 0.12);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141414;
    --surface: #1e1e1d;
    --ink: #f0efea;
    --muted: #9a9a94;
    --line: #30302d;
    --accent: #5b9bd5;
    --accent-ink: #0d1520;
    --accent-soft: #1d2a37;
    --danger: #f2b8b5;
    --desk: #0b0b0b;
    --grid-line: rgba(91, 155, 213, 0.07);
    --scrim: rgba(0, 0, 0, 0.55);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 28px rgba(0, 0, 0, 0.5);
    --page-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ic { width: 24px; height: 24px; display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#app { height: 100%; }
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* Buttons */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 44px;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.danger { color: #3a0b08; } }
.btn:disabled { opacity: .45; }
.ib {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border: 0; background: transparent; border-radius: 22px; cursor: pointer;
}
.ib:active { background: var(--accent-soft); }
.ib:disabled { opacity: .35; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 8px 4px; cursor: pointer; }

/* Home */
.home {
  overflow-y: auto;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: -1px -1px;
}
.home-inner {
  width: 100%; max-width: 520px; margin: 0 auto;
  min-height: 100%;
  padding: calc(40px + var(--safe-t)) 20px calc(24px + var(--safe-b));
  display: flex; flex-direction: column;
}
.home-head { display: flex; align-items: center; gap: 14px; margin-bottom: 32px; }
.home-logo { width: 64px; height: 64px; flex: none; }
.home-head h1 { font-size: 24px; line-height: 1.15; margin: 0; font-weight: 650; letter-spacing: -.01em; }
.home-sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.home-spacer { flex: 1 0 0; }
.dev-by { margin: 20px auto 0; padding: 14px 24px 12px; display: flex; flex-direction: column; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 14px; background: none; color: var(--muted); font: inherit; font-size: 12px; letter-spacing: .02em; cursor: pointer; }
/* A small arrow after "Developed by" hints that it opens something */
.dev-by > span::after { content: ""; display: inline-block; width: 5px; height: 5px; margin: 0 0 1px 7px; border-top: 1.5px solid currentColor; border-right: 1.5px solid currentColor; transform: rotate(45deg); vertical-align: middle; }
.dev-by:active { background: var(--accent-soft); }
.dev-by img { display: block; width: 220px; height: auto; }
.dev-by + .titleblock { margin-top: 12px; padding-top: 0; }
.about-card { padding: 16px 18px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--bg); }
.about-card .lbl { margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.about-card .logo { display: block; width: 100%; max-width: 300px; height: auto; margin-bottom: 12px; }
.about-card p { margin: 0 0 12px; color: var(--ink); }
.about-card .mail { display: block; margin: 0 0 14px; font-size: 18px; font-weight: 650; color: var(--accent); text-decoration: none; word-break: break-all; }
.about-card .btn { width: 100%; display: flex; align-items: center; justify-content: center; text-decoration: none; box-sizing: border-box; }
.about-card .muted { color: var(--muted); font-size: 13px; margin: 0; }

.home-actions { display: grid; gap: 12px; }
.action {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  padding: 18px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  cursor: pointer;
}
.action:active { transform: scale(.99); }
.action.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.action-ic {
  width: 44px; height: 44px; flex: none; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.action.primary .action-ic { background: rgba(255,255,255,.14); color: var(--accent-ink); }
.action-text { display: flex; flex-direction: column; gap: 2px; }
.action-text strong { font-size: 17px; font-weight: 650; }
.action-text span { font-size: 14px; opacity: .8; }

.home-note {
  margin-top: 20px; padding: 14px 16px;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 0 10px 10px 0;
  font-size: 14px; color: var(--muted);
}
.home-note b { color: var(--ink); }
.install-card {
  margin-top: 20px; padding: 16px;
  border: 1px dashed var(--accent);
  border-radius: 14px;
  background: var(--surface);
}
.install-card p { margin: 0 0 12px; font-size: 14px; color: var(--muted); }
.install-card p strong { color: var(--ink); font-size: 15px; }
.install-card .install-manual { margin: 10px 0 0; }
.install-card .install-manual:first-child { margin: 0; }

.titleblock {
  margin-top: auto;
  padding-top: 32px;
  display: grid; grid-template-columns: 1fr auto;
  font-size: 13px;
}
.titleblock > div {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 8px 12px;
  color: var(--ink);
}
.titleblock > div + div { border-left: 0; text-align: right; }
.titleblock span { display: block; font-size: 11px; color: var(--muted); }
.titleblock b { font-weight: 600; font-variant-numeric: tabular-nums; }
.home-credits { margin: 10px 2px 0; font-size: 11px; line-height: 1.5; color: var(--muted); }
.home-credits a { color: inherit; }

/* Document screen */
.topbar {
  flex: none;
  display: flex; align-items: center; gap: 2px;
  padding: calc(6px + var(--safe-t)) 8px 6px 4px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.doc-title { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0 6px; }
#docTitle { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#pagesInfo { flex: 1; min-width: 0; }
#btnAddFiles { display: inline-flex; align-items: center; gap: 4px; }
#btnAddFiles .ic { width: 18px; height: 18px; stroke-width: 2; }
#docMeta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-save { margin-left: 6px; min-height: 38px; padding: 6px 16px; }

.views { flex: 1; position: relative; min-height: 0; }

/* Open files as tabs (shown when two or more are open) */
.doc-tabs {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; overflow-x: auto; scrollbar-width: none;
  background: var(--bg); border-bottom: 1px solid var(--line); z-index: 4;
}
.doc-tabs::-webkit-scrollbar { display: none; }
.dtab {
  flex: none; display: flex; align-items: center; max-width: 52%; min-width: 0; height: 32px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--muted);
}
.dtab.on { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--accent-soft); color: var(--ink); }
.dtab-name {
  flex: 1; min-width: 0; height: 100%; display: flex; align-items: center; gap: 6px; padding: 0 12px;
  border: 0; background: none; color: inherit; font: inherit; font-size: 13px; cursor: pointer;
}
.dtab-name span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dtab.on .dtab-name { padding-right: 0; font-weight: 600; }
.dtab-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.dtab-x { flex: none; width: 32px; height: 100%; display: grid; place-items: center; padding: 0; border: 0; background: none; color: inherit; cursor: pointer; }
.dtab-x .ic { width: 16px; height: 16px; }
.dtab-add {
  flex: none; width: 32px; height: 32px; display: grid; place-items: center; padding: 0;
  border: 1px dashed var(--line); border-radius: 9px; background: none; color: var(--muted); cursor: pointer;
}
.dtab-add .ic { width: 18px; height: 18px; }
.doc.immersive .doc-tabs, .doc.mode-markup .doc-tabs { display: none !important; }

.viewer {
  position: absolute; inset: 0;
  overflow: auto;
  background: var(--desk);
  touch-action: pan-x pan-y;
  overscroll-behavior: contain;
  outline: none;
}
.vwrap { position: relative; transform-origin: 0 0; }
.vpage {
  position: absolute;
  background: #fff;
  box-shadow: var(--page-shadow);
  overflow: hidden;
}
.vpage canvas { position: absolute; left: 0; top: 0; display: block; }
.vpage canvas.base { width: 100%; height: 100%; }
.vpage .ov { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.ov-blurs .blur {
  position: absolute;
  backdrop-filter: blur(var(--blur, 6px)); -webkit-backdrop-filter: blur(var(--blur, 6px));
  background: rgba(255, 255, 255, .12);
}
.viewer.markup .ov-blurs .blur { outline: 1.5px dashed rgba(31, 78, 121, .7); outline-offset: -1px; }
.ov-pins .pin {
  pointer-events: auto;
  position: absolute; width: 28px; height: 28px; margin: 0; padding: 0; border: 0;
  transform: translate(-6px, -100%);
  border-radius: 8px 8px 8px 2px; color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  cursor: pointer;
}
.ov-pins .pin .ic { width: 15px; height: 15px; stroke-width: 2.4; }
.ov-pins .pin-area { pointer-events: auto; position: absolute; border: 0; padding: 0; margin: 0; background: transparent; cursor: pointer; }

/* Selectable text (from the PDF, or recognised) */
.tl-wrap { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.viewer.markup { touch-action: none; }
.viewer.markup .tl-wrap { pointer-events: none; user-select: none; -webkit-user-select: none; }
.textLayer {
  position: absolute; inset: 0; overflow: clip; opacity: 1; line-height: 1;
  text-align: initial; letter-spacing: normal; word-spacing: normal;
  -webkit-text-size-adjust: none; text-size-adjust: none; forced-color-adjust: none;
  transform-origin: 0 0; caret-color: CanvasText; z-index: 0;
  --min-font-size: 1;
  --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size));
  --min-font-size-inv: calc(1 / var(--min-font-size));
}
.textLayer :is(span, br) { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%; user-select: text; -webkit-user-select: text; }
.textLayer > :not(.markedContent), .textLayer .markedContent span:not(.markedContent) {
  z-index: 1; --font-height: 0; font-size: calc(var(--text-scale-factor) * var(--font-height));
  --scale-x: 1; --rotate: 0deg;
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv));
}
.textLayer .markedContent { display: contents; }
.textLayer ::selection, .ocr-layer ::selection { background: rgba(31, 78, 121, .3); color: transparent; }
.textLayer br::selection { background: transparent; }
.textLayer .endOfContent { display: block; position: absolute; inset: 100% 0 0; z-index: 0; cursor: default; user-select: none; }
.textLayer.selecting .endOfContent { top: 0; }
.textLayer[data-main-rotation="90"] { transform: rotate(90deg) translateY(-100%); }
.textLayer[data-main-rotation="180"] { transform: rotate(180deg) translate(-100%, -100%); }
.textLayer[data-main-rotation="270"] { transform: rotate(270deg) translateX(-100%); }
.ocr-layer span { position: absolute; color: transparent; white-space: pre; transform-origin: 0 0; line-height: 1; font-family: sans-serif; cursor: text; user-select: text; -webkit-user-select: text; }

/* Selection in Mark up */
.sel-ui { position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none; z-index: 4; }
.selbox { position: absolute; border: 1.5px dashed var(--accent); border-radius: 3px; }
.sel-ui .handle { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border: 2px solid var(--accent); background: #fff; border-radius: 4px; box-sizing: border-box; }
.floatbar {
  position: absolute; transform: translateX(-50%);
  display: flex; pointer-events: auto;
  border-radius: 10px; background: #2b2b29; color: #f4f3ef;
  box-shadow: 0 8px 28px rgba(28, 28, 26, .28);
  white-space: nowrap;
}
.floatbar button { display: flex; align-items: center; gap: 6px; height: 42px; padding: 0 12px; border: 0; background: none; color: inherit; font-size: 14px; cursor: pointer; }
.floatbar button .ic { width: 18px; height: 18px; }
.floatbar button.danger { color: #f2b8b5; }
.composer {
  position: absolute; z-index: 5; box-sizing: border-box;
  padding: 12px 14px; border-radius: 14px; background: var(--surface);
  box-shadow: var(--shadow);
}
.composer textarea { min-height: 64px; resize: none; display: block; }
.composer-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.composer-row .meta { flex: 1; font-size: 12px; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-row .btn { min-height: 38px; padding: 6px 14px; }
.link-btn { border: 0 !important; background: none !important; color: var(--accent) !important; }
.draw-hint {
  position: absolute; left: 12px; right: 12px; top: 12px; z-index: 6;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 12px;
  background: #2b2b29; color: #f4f3ef; font-size: 14px;
  box-shadow: var(--shadow);
}
.draw-hint span { flex: 1; }
.draw-hint button { border: 0; background: none; color: #9cc6ee; font-weight: 700; padding: 6px 2px; cursor: pointer; }

/* Mark up bars */
.markbar { gap: 6px; padding-left: 8px; }
.done-btn { min-height: 38px; padding: 6px 14px 6px 10px; display: flex; align-items: center; gap: 6px; flex: none; }
.done-btn .ic { width: 20px; height: 20px; stroke-width: 2; }
.layer-chip {
  flex: 1; min-width: 0; height: 34px;
  display: flex; align-items: center; gap: 6px;
  padding: 0 10px 0 12px; border: 0; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 13px; cursor: pointer;
}
.layer-chip .chip-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.layer-chip b { font-weight: 650; }
.layer-chip .ic { width: 16px; height: 16px; flex: none; }
.layer-chip.note { background: none; color: var(--muted); padding-left: 6px; cursor: default; }
.layer-chip .chip-note { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.optbar {
  flex: none; min-height: 56px; box-sizing: border-box;
  align-items: center; gap: 8px; padding: 6px 12px;
  background: var(--surface); border-top: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
.optbar::-webkit-scrollbar { display: none; }
.optbar .grow { flex: 1; }
.optbar .seg { flex: none; }
.optbar .seg button { flex: none; min-height: 36px; padding: 4px 12px; }
.optbar .seg.tight button { padding: 4px 9px; }
.optbar .swatches.small { gap: 6px; }
.optbar .swatches.small .sw { width: 22px; height: 22px; }
.optbar .chip-btn.tight { padding: 0 10px; }
.markup-mode .toasts { bottom: calc(132px + var(--safe-b)); }
.opt-note { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.35; }
.toolbar { background: var(--surface); }
.toolbar .tab { color: var(--ink); }
.toolbar .tool-pill { width: 48px; height: 28px; border-radius: 14px; display: grid; place-items: center; }
.toolbar .tool-pill .ic { width: 22px; height: 22px; }
.toolbar .tab.active { color: var(--accent); font-weight: 600; }
.toolbar .tab.active .tool-pill { background: var(--accent-soft); }
.style-btn {
  flex: none; width: 60px; height: 38px; display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer;
}
.style-btn .dot { width: 16px; height: 16px; border-radius: 8px; }
.style-btn .bar { width: 16px; border-radius: 2px; background: var(--ink); }
.chip-btn {
  flex: none; height: 38px; display: flex; align-items: center; gap: 6px;
  padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip-btn .ic { width: 18px; height: 18px; }
.chip-btn.toggle.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chip-btn .fill-box { width: 14px; height: 14px; border: 1.5px solid currentColor; border-radius: 3px; box-sizing: border-box; }
.chip-btn.on .fill-box { background: currentColor; opacity: .5; }
.chip-btn.grow-btn { flex: 1; min-width: 0; }
.ell { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stepper { flex: none; display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; height: 38px; font-size: 14px; }
.stepper button { width: 38px; height: 100%; border: 0; background: var(--bg); font-size: 18px; cursor: pointer; }
.stepper span { padding: 0 10px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.swatches { display: flex; gap: 12px; flex-wrap: wrap; }
.swatches.small { gap: 7px; flex: none; }
.sw { width: 28px; height: 28px; border-radius: 50%; border: 0; padding: 0; background: var(--c); cursor: pointer; flex: none; }
.swatches.small .sw { width: 24px; height: 24px; }
.sw.big { width: 34px; height: 34px; }
.sw.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--c); }

/* Popover above the bars */
.pop-scrim { position: absolute; inset: 0; z-index: 19; }
.pop {
  position: absolute; left: 12px; right: 12px; bottom: calc(128px + var(--safe-b)); z-index: 20;
  max-width: 520px; margin: 0 auto; box-sizing: border-box;
  padding: 14px 16px 6px; border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow);
  animation: rise .18s ease-out;
}
.pop-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.pop .swatches { margin-bottom: 14px; }
.thick-row { display: flex; gap: 8px; }
.thick { flex: 1; height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 13px; cursor: pointer; }
.thick span { width: 36px; border-radius: 3px; background: var(--ink); }
.thick.on { border: 1.5px solid var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.pop-note { margin: 6px 0 6px; font-size: 12px; color: var(--muted); }
.pop-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 44px; border: 0; background: none; padding: 0; font-size: 15px; text-align: left; cursor: pointer; }

/* Shapes */
.group-label { margin: 14px 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.group-label:first-child { margin-top: 2px; }
.shape-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.shape-tile { height: 76px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); font-size: 12px; cursor: pointer; text-align: center; }
.shape-tile .ic { width: 28px; height: 28px; }
.shape-tile.on { border: 1.5px solid var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Comments */
.comments-chip {
  position: absolute; left: 12px; bottom: 12px; z-index: 3;
  height: 40px; display: flex; align-items: center; gap: 8px;
  padding: 0 16px 0 12px; border: 0; border-radius: 20px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.comments-chip .ic { width: 20px; height: 20px; color: var(--accent); }
.head-switch { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 6px; border: 0; background: none; font-size: 13px; color: var(--muted); cursor: pointer; }
.comment-list { list-style: none; margin: 0; padding: 0; }
.comment-row { display: flex; gap: 12px; width: 100%; padding: 12px 18px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.comment-row:active { background: var(--accent-soft); }
.ctype { width: 32px; height: 32px; flex: none; border-radius: 8px; display: grid; place-items: center; color: #fff; }
.ctype .ic { width: 18px; height: 18px; stroke-width: 2; }
.ctext { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ctext small { font-size: 12px; color: var(--muted); }
.ctext > span { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble { position: absolute; box-sizing: border-box; padding: 14px 16px 10px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); animation: fade .15s ease-out; }
.bubble-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.bubble-meta .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.bubble-text { margin: 8px 0 10px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 40vh; overflow: auto; }
.bubble-actions { display: flex; justify-content: flex-end; gap: 6px; }

/* Layers sheet */
.layers-body { padding-bottom: 12px; }
.switch-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 8px 18px; border: 0; background: none; text-align: left; cursor: pointer; font-size: 15px; }
.switch-row small { display: block; font-size: 13px; color: var(--muted); }
.switch-row .grow { flex: 1; }
.comments-row { border-bottom: 1px solid var(--line); }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 10px 8px 0 18px; font-size: 13px; font-weight: 600; color: var(--muted); }
.sec-head .link { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; padding: 8px 8px; }
.sec-head .link .ic { width: 18px; height: 18px; stroke-width: 2; }
.sec-sub { display: flex; align-items: center; justify-content: space-between; padding: 2px 14px 4px 18px; }
.sec-empty { margin: 4px 18px 8px; font-size: 13px; color: var(--muted); }
.my-layer { display: flex; align-items: center; padding-right: 6px; }
.my-layer-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 0 0 18px; border: 0; background: none; text-align: left; font-size: 15px; cursor: pointer; }
.my-layer-main .name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.my-layer.off .name { color: var(--muted); }
.my-layer .tag { flex: none; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }
.my-layers { border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.layer-search { padding: 6px 14px 4px; }
.search-box { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--muted); }
.search-box .ic { width: 18px; height: 18px; flex: none; }
.search-box input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 15px; color: var(--ink); }

/* Menus */
.menu { position: absolute; padding: 6px 0; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); animation: fade .12s ease-out; max-height: 70vh; overflow-y: auto; }
.menu-item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 0 16px; border: 0; background: none; text-align: left; font-size: 15px; cursor: pointer; }
.menu-item span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-item .ic { width: 22px; height: 22px; flex: none; }
.menu-item.danger { color: var(--danger); }
.menu-item:active { background: var(--accent-soft); }
.menu-div { height: 1px; background: var(--line); margin: 6px 0; }

/* Tools */
.tool-row { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 64px; padding: 6px 12px 6px 18px; border: 0; background: none; text-align: left; cursor: pointer; }
.tool-row:active { background: var(--accent-soft); }
.tool-ic { width: 40px; height: 40px; flex: none; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.tool-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tool-text b { font-weight: 600; }
.tool-text small { font-size: 13px; color: var(--muted); }
.tool-row > .ic { color: var(--muted); width: 20px; height: 20px; }
.note.tools-foot { margin: 6px 18px 0; padding-top: 12px; border-top: 1px solid var(--line); }
.radio-card { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; padding: 10px 12px; margin-bottom: 8px; border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer; }
.radio-card.on { border-color: var(--accent); background: var(--accent-soft); }
.radio-card > input, .radio-line > input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.radio-card b { font-weight: 600; }
.radio-card small { display: block; font-size: 13px; color: var(--muted); }
.radio-card.on small { color: var(--ink); opacity: .75; }
.radio-line { display: flex; gap: 12px; align-items: flex-start; flex: 1 1 100%; cursor: pointer; }
.card-extra { flex: 1 1 100%; margin-left: 32px; display: none; }
.radio-card.on .card-extra { display: block; }
.card-extra .input { background: var(--surface); }
.file-list { list-style: none; margin: 0; padding: 0; }
.file-list li { display: flex; align-items: center; gap: 10px; min-height: 34px; font-size: 13px; }
.file-list li .ic { width: 18px; height: 18px; color: var(--muted); flex: none; }
.file-list li span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-list li small { color: var(--muted); font-variant-numeric: tabular-nums; }
.lang-row { display: flex; align-items: center; gap: 12px; min-height: 52px; border-bottom: 1px solid var(--line); }
.lang-row label { flex: 1; display: flex; align-items: center; gap: 12px; cursor: pointer; }
.lang-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.lang-row small { color: var(--muted); font-size: 13px; }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.btn.small .ic { width: 16px; height: 16px; }
.btn.outline { border-color: var(--accent); color: var(--accent); background: none; }
.btn.danger-outline { border-color: var(--danger); color: var(--danger); background: none; }
.danger-text { color: var(--danger) !important; }
.pw-wrap { position: relative; display: block; }
.pw-wrap .input { padding-right: 48px; }
.pw-wrap .ib { position: absolute; right: 1px; top: 1px; color: var(--muted); }
.form-error { margin: 0 0 12px; font-size: 14px; color: var(--danger); }
.foot-row { display: flex; gap: 10px; flex: 1; }
.foot-row .btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; }
.foot-row .btn .ic { width: 20px; height: 20px; }
.save-notes { margin: 4px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--muted); }
.save-notes li { margin-bottom: 4px; }

/* Watermark */
.wm-body { margin: -14px -18px 0; }
.wm-preview { height: 180px; display: grid; place-items: center; background: var(--desk); }
.wm-page { position: relative; background: #fff; box-shadow: var(--page-shadow); overflow: hidden; }
.wm-page canvas, .wm-page svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.wm-controls { padding: 14px 18px 0; }
.wm-controls > div[data-type] { margin-bottom: 12px; }
.wm-controls > div[data-src] { margin-bottom: 6px; }
.wm-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; border-bottom: 1px solid var(--line); }
.wm-row.last { border-bottom: 0; }
.wm-row > span { flex: none; }
.wm-row input[type=range] { flex: 1; max-width: 190px; accent-color: var(--accent); }
.wm-row .op-val { width: 40px; text-align: right; font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; }
.wm-img-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 46px; }
.wm-img-row img { width: 40px; height: 40px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.wm-img-row img.wide { width: 112px; padding: 4px 6px; box-sizing: border-box; }
.wm-img-row img.dark { background: #1c1c1a; border-color: #1c1c1a; }
.seg.small button { min-height: 34px; padding: 4px 10px; font-size: 13px; flex: none; }
.sheet.full { height: calc(100% - 64px - var(--safe-t)); }
.vpage .spin { position: absolute; left: 50%; top: 50%; margin: -12px 0 0 -12px; }
.page-badge {
  position: absolute; right: 12px; top: 12px; z-index: 3;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 13px; font-variant-numeric: tabular-nums; font-weight: 600;
  opacity: 0; transition: opacity .25s;
  pointer-events: none;
}
.page-badge.show { opacity: 1; }

.doc.immersive .topbar, .doc.immersive .tabbar, .doc.immersive .optbar { display: none !important; }

/* Which bars show in which mode */
.doc .markbar, .doc .optbar, .doc .toolbar { display: none; }
.doc.mode-markup .viewbar, .doc.mode-markup #tabbar, .doc.mode-markup #selbar { display: none !important; }
.doc.mode-markup .markbar, .doc.mode-markup .optbar { display: flex; }
.doc.mode-markup .toolbar { display: flex; }
.doc.mode-markup .comments-chip { display: none; }
.doc.tab-pages .comments-chip, .doc.tab-pages .page-badge { display: none; }

.pages-view { position: absolute; inset: 0; overflow-y: auto; background: var(--bg); overscroll-behavior: contain; }
.pages-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 2px;
  padding: 4px 6px 4px 16px;
  background: var(--bg);
  font-size: 13px; color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 14px 10px;
  padding: 14px 12px calc(24px + var(--safe-b));
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; touch-action: pan-y; }
.tile .thumb {
  position: relative;
  width: 100%; aspect-ratio: 1 / 1.25;
  display: grid; place-items: center;
}
.tile .thumb canvas, .tile .thumb .ph {
  max-width: 100%; max-height: 100%;
  background: #fff; box-shadow: var(--page-shadow);
  display: block;
}
.tile .thumb .ph { width: 70%; height: 90%; }
.tile .cap { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px; }
.tile .cap i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tile .check {
  position: absolute; right: 2px; top: 2px;
  width: 24px; height: 24px; border-radius: 12px;
  border: 2px solid rgba(255,255,255,.95);
  background: rgba(28,28,26,.25);
  display: grid; place-items: center;
  color: #fff;
}
.tile .check .ic { width: 16px; height: 16px; stroke-width: 3; opacity: 0; }
.tile.sel .thumb::after {
  content: ""; position: absolute; inset: -4px; border: 2.5px solid var(--accent); border-radius: 6px; pointer-events: none;
}
.tile.sel .check { background: var(--accent); border-color: var(--accent); }
.tile.sel .check .ic { opacity: 1; }
.tile.sel .cap { color: var(--accent); font-weight: 600; }
.tile.dragging { opacity: .25; }
.drop-mark { position: absolute; width: 3px; border-radius: 2px; background: var(--accent); pointer-events: none; z-index: 3; }
.drag-ghost {
  position: fixed; z-index: 50; pointer-events: none;
  width: 92px; transform: translate(-50%, -60%) rotate(-3deg);
  box-shadow: var(--shadow); background: #fff;
}
.drag-ghost canvas { width: 100%; display: block; }
.drag-ghost b {
  position: absolute; right: -8px; top: -8px; min-width: 24px; height: 24px; padding: 0 6px;
  border-radius: 12px; background: var(--accent); color: var(--accent-ink);
  font-size: 13px; display: grid; place-items: center;
}

.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); padding: 24px; background: var(--bg); }
.empty p { margin: 4px 0; }
.empty strong { color: var(--ink); }

.tabbar {
  flex: none;
  display: flex;
  padding: 4px 4px calc(4px + var(--safe-b));
  background: var(--bg);
  border-top: 1px solid var(--line);
  z-index: 5;
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 0; background: none;
  padding: 6px 2px 4px;
  font-size: 12px; color: var(--muted);
  border-radius: 10px;
  cursor: pointer;
  min-height: 52px;
}
.tab.active { color: var(--accent); font-weight: 600; }
.tab.active .ic { stroke-width: 2.2; }
.tab:active { background: var(--accent-soft); }
.tab.danger { color: var(--danger); }
.tab:disabled { opacity: .35; }
.selbar .tab { color: var(--ink); }
.selbar .tab.danger { color: var(--danger); }

/* Sheets and dialogs */
.overlay { position: fixed; inset: 0; z-index: 30; }
.overlay .scrim { position: absolute; inset: 0; background: var(--scrim); animation: fade .18s ease-out; }
.overlay.clear .scrim { background: transparent; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 88%;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  padding-bottom: var(--safe-b);
  animation: rise .22s cubic-bezier(.2,.8,.2,1);
  max-width: 640px; margin: 0 auto;
}
.sheet.tall { height: 58%; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 18px; border-bottom: 1px solid var(--line); }
.sheet-head::before { content: ""; position: absolute; left: 50%; top: 6px; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--line); }
.sheet-head h2 { flex: 1; margin: 8px 0 0; font-size: 17px; font-weight: 650; }
.sheet-body { overflow-y: auto; padding: 14px 18px 18px; overscroll-behavior: contain; }
.sheet-foot { display: flex; gap: 10px; padding: 12px 18px 14px; border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1; }
@keyframes rise { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet, .overlay .scrim, .dialog { animation: none; } }

.dialog {
  position: absolute; left: 50%; top: 50%;
  width: min(360px, calc(100% - 40px));
  transform: translate(-50%, -50%);
  background: var(--surface);
  border-radius: 18px;
  padding: 22px 20px 14px;
  box-shadow: var(--shadow);
  animation: fade .15s ease-out;
}
.dialog h2 { margin: 0 0 8px; font-size: 18px; font-weight: 650; }
.dialog p { margin: 0 0 12px; color: var(--muted); }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dialog .actions .btn { min-width: 88px; }

.field { display: block; margin-bottom: 16px; }
.field > span:first-child { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.namefield { display: flex; align-items: center; gap: 6px; }
.namefield .input { flex: 1; }
.namefield em { font-style: normal; color: var(--muted); }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--bg); padding: 10px 4px; font-size: 14px; cursor: pointer; min-height: 42px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.check-row { display: flex; gap: 12px; align-items: flex-start; padding: 6px 0 14px; cursor: pointer; }
.check-row input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.check-row small { display: block; color: var(--muted); font-size: 13px; }
.note { font-size: 13px; color: var(--muted); margin: 0 0 14px; }
.warn { font-size: 14px; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); margin: 0 0 14px; }

/* Layers */
.layer-tools { display: flex; gap: 8px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.layer-tools .input { min-height: 40px; padding: 8px 12px; font-size: 15px; }
.layer-tools .btn { min-height: 40px; padding: 6px 10px; font-size: 14px; white-space: nowrap; }
.layer-list { list-style: none; margin: 0; padding: 4px 0 12px; }
.layer-row { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px 0 calc(14px + var(--depth, 0) * 18px); cursor: pointer; }
.layer-row:active { background: var(--accent-soft); }
.layer-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-row.off .name { color: var(--muted); }
.layer-row.head { min-height: 40px; }
.layer-row.head .name { font-weight: 650; font-size: 14px; }
.layer-row.file { background: var(--bg); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.layer-row .count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.layer-summary { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.switch { width: 40px; height: 24px; border-radius: 12px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 9px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(16px); }
.switch.mixed { background: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.switch.mixed::after { transform: translateX(8px); }
.layer-empty { padding: 24px 18px; color: var(--muted); text-align: center; }

/* Crop */
.crop-screen { position: fixed; inset: 0; z-index: 40; background: #0e0e0e; display: flex; flex-direction: column; color: #f0efea; }
.crop-top { display: flex; align-items: center; gap: 8px; padding: calc(6px + var(--safe-t)) 8px 6px 4px; }
.crop-top h2 { flex: 1; margin: 0; font-size: 17px; font-weight: 600; }
.crop-stage { flex: 1; position: relative; min-height: 0; touch-action: none; overflow: hidden; }
.crop-paper { position: absolute; background: #fff; }
.crop-paper canvas { width: 100%; height: 100%; display: block; }
.crop-box { position: absolute; box-shadow: 0 0 0 9999px rgba(0,0,0,.6); outline: 1.5px solid #fff; }
.crop-clip { position: absolute; }
.crop-box .h { position: absolute; width: 36px; height: 36px; }
.crop-box .h::after { content: ""; position: absolute; left: 10px; top: 10px; width: 16px; height: 16px; border: 3px solid #fff; }
.crop-box .h.tl { left: -18px; top: -18px; } .crop-box .h.tl::after { border-right: 0; border-bottom: 0; }
.crop-box .h.tr { right: -18px; top: -18px; } .crop-box .h.tr::after { border-left: 0; border-bottom: 0; }
.crop-box .h.bl { left: -18px; bottom: -18px; } .crop-box .h.bl::after { border-right: 0; border-top: 0; }
.crop-box .h.br { right: -18px; bottom: -18px; } .crop-box .h.br::after { border-left: 0; border-top: 0; }
.crop-box .e { position: absolute; }
.crop-box .e.t, .crop-box .e.b { left: 18px; right: 18px; height: 28px; }
.crop-box .e.t { top: -14px; } .crop-box .e.b { bottom: -14px; }
.crop-box .e.l, .crop-box .e.r { top: 18px; bottom: 18px; width: 28px; }
.crop-box .e.l { left: -14px; } .crop-box .e.r { right: -14px; }
.crop-foot { padding: 10px 16px calc(12px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; }
.crop-foot .seg { border-color: #3a3a37; }
.crop-foot .seg button { background: #1d1d1c; color: #f0efea; }
.crop-foot .seg button + button { border-color: #3a3a37; }
.crop-foot .seg button.on { background: #5b9bd5; color: #0d1520; }
.crop-foot .row { display: flex; gap: 10px; }
.crop-foot .row .btn { flex: 1; }
.crop-foot .btn { background: #1d1d1c; color: #f0efea; border-color: #3a3a37; }
.crop-foot .btn.primary { background: #5b9bd5; border-color: #5b9bd5; color: #0d1520; }

/* Scanner (built-in, used in Chrome) */
.scanner .crop-top h2 { text-align: left; }
.scan-stage { display: flex; }
.scan-start { margin: auto; padding: 24px; max-width: 360px; display: flex; flex-direction: column; align-items: stretch; gap: 12px; text-align: center; }
.scan-start p { margin: 0 0 8px; color: #b9b8b2; line-height: 1.5; }
.scan-start p b { color: #f0efea; }
.scan-big { align-self: center; width: 84px; height: 84px; border-radius: 22px; display: grid; place-items: center; background: #1d1d1c; color: #5b9bd5; margin-bottom: 6px; }
.scan-big .ic { width: 44px; height: 44px; stroke-width: 1.6; }
.scan-start .btn { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; background: #1d1d1c; color: #f0efea; border-color: #3a3a37; }
.scan-start .btn.primary { background: #5b9bd5; border-color: #5b9bd5; color: #0d1520; }
.scan-ready { margin-top: 14px; padding-top: 16px; border-top: 1px solid #2a2a28; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: #b9b8b2; }
.scan-ready .btn { min-height: 44px; padding: 8px 22px; }
.scan-edit { position: absolute; inset: 0; }
.scan-edit canvas[data-canvas] { position: absolute; }
.scan-edit svg { position: absolute; left: 0; top: 0; touch-action: none; }
.scan-edit polygon { fill: rgba(91, 155, 213, .16); stroke: #5b9bd5; stroke-width: 2.5; stroke-linejoin: round; }
.scan-edit circle { fill: rgba(14, 14, 14, .35); stroke: #fff; stroke-width: 3; }
.scan-edit circle.on { fill: rgba(91, 155, 213, .45); }
.scan-loupe { position: absolute; width: 120px; height: 120px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 4px 18px rgba(0,0,0,.6); pointer-events: none; }
.scan-hint { margin: 0; font-size: 13px; color: #b9b8b2; text-align: center; }
.scanner .crop-foot .row .btn { padding: 10px 8px; white-space: nowrap; }

/* Toasts and busy */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(76px + var(--safe-b)); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 14px;
  max-width: 520px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #2b2b29; color: #f4f3ef;
  box-shadow: var(--shadow);
  font-size: 14px;
  animation: rise .2s ease-out;
}
.toast button { border: 0; background: none; color: #9cc6ee; font-weight: 700; padding: 4px 2px; cursor: pointer; white-space: nowrap; }
.busy { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; background: var(--scrim); }
.busy > div { background: var(--surface); border-radius: 16px; padding: 22px 26px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow); max-width: 80%; }
.spin { width: 24px; height: 24px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Architecture blocks ---------- */
.sheet.shapes-sheet { height: 84%; }
.shapes-sheet .sheet-body { padding-top: 12px; }
.shape-tabs { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 12px; }
.shape-tabs button { justify-content: center; }
.shapes-foot:empty { display: none; }
.sheet-foot:has(.shapes-foot:empty) { display: none; }
.shapes-foot { flex: 1; min-width: 0; }
.block-foot { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.block-foot .ic { width: 18px; height: 18px; flex: none; }
.block-foot .grow { flex: 1; min-width: 0; }
.block-foot b { color: var(--ink); font-weight: 600; }
.block-foot .link { flex: none; font-size: 14px; }
.block-search { height: 44px; display: flex; align-items: center; gap: 8px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--muted); }
.block-search .ic { width: 18px; height: 18px; flex: none; }
.block-search input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; outline: none; font: inherit; font-size: 15px; color: var(--ink); }
.block-search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.block-cats { display: flex; gap: 8px; margin: 12px -18px 4px; padding: 0 18px 6px; overflow-x: auto; scrollbar-width: none; }
.block-cats::-webkit-scrollbar { display: none; }
.block-cat { flex: none; height: 34px; display: inline-flex; align-items: center; gap: 6px; padding: 0 14px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); color: var(--ink); font: inherit; font-size: 14px; white-space: nowrap; cursor: pointer; }
.block-cat .ic { width: 16px; height: 16px; }
.block-cat.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.block-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 8px; }
.block-tile { min-height: 124px; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 3px; padding: 8px 4px 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--ink); font: inherit; cursor: pointer; text-align: center; }
.block-tile:active { background: var(--accent-soft); border-color: var(--accent); }
.block-tile svg { flex: none; margin-bottom: 2px; }
.block-tile b { font-size: 13px; font-weight: 600; line-height: 1.2; }
.block-tile small { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.block-empty { margin: 24px 0; text-align: center; color: var(--muted); font-size: 14px; }

.scale-body .found-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 4px; border-radius: 12px; background: #f1f6ee; border: 1px solid #cfe0c7; color: var(--ink); }
.scale-body .found-card > .ic { flex: none; width: 36px; height: 36px; padding: 8px; box-sizing: border-box; border-radius: 18px; background: #fff; color: #2e7d32; }
.scale-body .found-card b { display: block; font-weight: 650; }
.scale-body .found-card small { color: var(--muted); font-size: 13px; }
.scale-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.scale-chip { height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); font: inherit; font-size: 15px; font-variant-numeric: tabular-nums; cursor: pointer; }
.scale-chip.on { border: 1.5px solid var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.measure-card { width: 100%; margin-top: 16px; align-items: center; flex-wrap: nowrap; background: var(--surface); color: var(--ink); font: inherit; text-align: left; }
.measure-card > .ic:first-child { flex: none; width: 36px; height: 36px; padding: 8px; box-sizing: border-box; border-radius: 18px; background: var(--accent-soft); color: var(--accent); }
.measure-card > span { flex: 1; min-width: 0; }
.measure-card > .ic:last-child { flex: none; width: 18px; height: 18px; color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .scale-body .found-card { background: #1f2a1c; border-color: #35502d; }
  .scale-body .found-card > .ic { background: #2a3a26; color: #8fd18a; }
}

.sel-ui .selbox { transform-origin: 50% 50%; }
.sel-ui .handle { border-radius: 7px; }
.sel-ui .handle.rot { width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 15px; display: grid; place-items: center; color: var(--accent); }
.sel-ui .handle.rot .ic { width: 16px; height: 16px; }
.dim-pill { position: absolute; transform: translateX(-50%); padding: 3px 10px; border-radius: 12px; background: var(--accent); color: #fff; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.floatbar.labels { padding: 0 4px; }
.floatbar.labels button { flex-direction: column; justify-content: center; gap: 1px; height: 48px; padding: 0 10px; font-size: 12px; }
.chip-btn .fill-box.white { background: #fff; }
.chip-btn.on .fill-box.white { background: #fff; opacity: 1; }

.measure-ui { position: absolute; left: 0; top: 0; width: 0; height: 0; z-index: 5; }
.measure-line { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; pointer-events: none; }
.measure-line line { stroke: #d84315; stroke-width: 2; }
.m-mark { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 22px; touch-action: none; cursor: grab; }
.m-mark::before { content: ""; position: absolute; inset: 7px; border: 2px solid #d84315; border-radius: 50%; background: rgba(255,255,255,.35); }
.m-mark::after { content: ""; position: absolute; left: 10px; top: 10px; width: 24px; height: 24px; background: linear-gradient(#d84315, #d84315) center / 2px 100% no-repeat, linear-gradient(#d84315, #d84315) center / 100% 2px no-repeat; }
.measure-banner { position: absolute; left: 12px; right: 12px; top: 12px; z-index: 6; display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px; background: #2b2b29; color: #f4f3ef; font-size: 14px; line-height: 1.35; box-shadow: 0 6px 20px rgba(0,0,0,.2); pointer-events: none; }
.measure-banner .ic { width: 18px; height: 18px; flex: none; }
.measure-panel { position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; padding: 14px 18px calc(10px + var(--safe-b)); background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -8px 28px rgba(0,0,0,.08); }
.measure-panel label { display: block; font-size: 15px; font-weight: 650; }
.measure-panel .m-row { display: flex; gap: 10px; margin-top: 10px; }
.measure-panel .m-input { flex: 1; min-width: 0; height: 50px; display: flex; align-items: center; padding: 0 14px; border: 1.5px solid var(--accent); border-radius: 12px; background: var(--surface); }
.measure-panel input { flex: 1; min-width: 0; border: 0; outline: none; background: none; font: inherit; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); }
.measure-panel em { font-style: normal; color: var(--muted); }
.measure-panel .m-row .btn { flex: none; height: 50px; padding: 0 20px; }
.measure-panel .m-note { margin: 8px 0 0; min-height: 18px; font-size: 13px; color: var(--muted); }
.measure-panel [data-cancel] { margin-top: 2px; padding-left: 0; }
.doc.measuring .optbar, .doc.measuring .toolbar, .doc.measuring .markbar { display: none !important; }

/* Thickness slider and eraser size */
.pop-label.thick-head { display: flex; align-items: baseline; justify-content: space-between; }
.thick-val { font-weight: 600; color: var(--ink); font-size: 13px; font-variant-numeric: tabular-nums; }
.thick-slider { display: flex; flex-direction: column; gap: 2px; margin-bottom: 4px; }
.thick-preview { width: 100%; height: 34px; display: block; }
.thick-slider input[type=range], .eraser-size input[type=range] { width: 100%; height: 32px; margin: 0; accent-color: var(--accent); }
.eraser-size { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding-left: 4px; }
.eraser-size .ring { flex: none; box-sizing: border-box; border: 2px solid var(--accent); border-radius: 50%; background: var(--accent-soft); }
.eraser-size input { flex: 1; min-width: 0; }

/* Choice dialog */
.dialog .actions.choices .btn { min-width: 0; flex: 1; }

/* My blocks */
.block-tile { position: relative; }
.block-tile.action { justify-content: center; border-style: dashed; color: var(--accent); }
.block-tile.action .act-ic { width: 40px; height: 40px; border-radius: 20px; display: grid; place-items: center; background: var(--accent-soft); margin-bottom: 4px; }
.block-tile.action .act-ic .ic { width: 22px; height: 22px; }
.block-tile.action small { color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px; }
.tile-more { position: absolute; right: 2px; top: 2px; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 18px; color: var(--muted); }
.tile-more .ic { width: 18px; height: 18px; }
.pick-banner { pointer-events: auto; }
.pick-banner .btn { margin-left: auto; flex: none; background: transparent; color: #f4f3ef; border-color: rgba(255,255,255,.35); }
