:root {
  --bg: #f2f3f7;
  --panel: #ffffff;
  --border: #e0e2ea;
  --text: #1d1f27;
  --muted: #6b7280;
  --accent: #3b6fb8;
  --accent-2: #e8f0fa;
  --danger: #dc2626;
}
[data-theme="dark"] {
  --bg: #12141c;
  --panel: #1a1d28;
  --border: #2a2e3d;
  --text: #e6e8f0;
  --muted: #9aa1b5;
  --accent: #7aa5dd;
  --accent-2: #232a40;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text); background: var(--bg);
  display: flex; flex-direction: column; overflow: hidden;
}
#topbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: .4px; margin-right: 4px; }
.brand .tag { color: var(--accent); font-weight: 500; font-size: .8em; }
.sep { width: 1px; height: 24px; background: var(--border); margin: 0 6px; }
button {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
button:hover { border-color: var(--accent); }
button.active { background: var(--accent-2); border-color: var(--accent); color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.tool-toggle.active { background: var(--accent); color: #fff; }
.tabs { display: flex; gap: 2px; background: var(--accent-2); border-radius: 9px; padding: 3px; }
.tab { border: none; background: transparent; color: var(--muted); padding: 6px 12px; }
.tab.active { background: var(--panel); color: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.toolbar { display: flex; gap: 4px; }
.menu-wrap { position: relative; }
.dropdown {
  position: absolute; top: 110%; left: 0; background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.18);
  display: flex; flex-direction: column; min-width: 210px; padding: 4px; z-index: 50;
}
.dropdown button {
  border: none; background: none; text-align: left; padding: 8px 10px; border-radius: 7px; font-size: 13.5px;
}
.dropdown button:hover { background: var(--accent-2); }
.zoom { display: flex; gap: 4px; align-items: center; }
.zoom input { width: 62px; padding: 5px 6px; border-radius: 7px; border: 1px solid var(--border); background: var(--bg); color: var(--text); text-align: right; }
.pct { font-size: 12px; color: var(--muted); }
#app { display: flex; flex: 1; min-height: 0; }
#sidebar {
  width: 220px; min-width: 220px; background: var(--panel);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto;
}
.sidebar-search { padding: 10px; border-bottom: 1px solid var(--border); }
.sidebar-search input { width: 100%; padding: 7px 9px; border-radius: 7px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
#search-results { font-size: 12px; color: var(--muted); margin-top: 6px; max-height: 120px; overflow-y: auto; }
#search-results .hit { cursor: pointer; padding: 2px 4px; border-radius: 4px; }
#search-results .hit:hover { background: var(--accent-2); }
.thumbs { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.thumb { cursor: pointer; border: 2px solid transparent; border-radius: 6px; position: relative; }
.thumb.active { border-color: var(--accent); }
.thumb canvas { width: 100%; height: auto; border-radius: 4px; background: #fff; display: block; }
.thumb .num { position: absolute; top: 3px; right: 4px; font-size: 10px; background: rgba(0,0,0,.5); color: #fff; padding: 1px 5px; border-radius: 8px; }
.annot-panel { padding: 10px; border-top: 1px solid var(--border); }
.annot-panel h4 { margin: 0 0 6px; font-size: 13px; }
.annot-panel li { font-size: 12px; padding: 4px 2px; display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.annot-panel .del { font-size: 11px; color: var(--danger); border: none; background: none; padding: 0 4px; }
#stage { flex: 1; overflow: auto; position: relative; }
#canvas-wrap { position: relative; min-height: 100%; padding: 24px; display: flex; justify-content: center; align-items: flex-start; }
#pageholder { max-width: 100%; }
#page-canvas { display: block; background: #fff; box-shadow: 0 2px 14px rgba(0,0,0,.14); }
#overlay { position: absolute; inset: 0; pointer-events: none; }
#overlay > * { pointer-events: auto; }
#empty-state { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--muted); }
#empty-state p { margin: 0; text-align: center; }
#empty-state .tiny { font-size: 12px; max-width: 520px; }
#statusbar { display: flex; justify-content: space-between; padding: 6px 14px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); background: var(--panel); }
.hidden { display: none !important; }
#cmp-wrap { display: flex; gap: 16px; padding: 24px; align-items: flex-start; }
.cmp-side { flex: 1; min-width: 0; }
.cmp-side canvas { max-width: 100%; box-shadow: 0 2px 14px rgba(0,0,0,.14); background: #fff; }
/* seleção de bloco */
.sel-box { position: absolute; outline: 2px solid #4a7fd6; background: rgba(74,127,214,.07); touch-action: none; }
.handle { position: absolute; width: 10px; height: 10px; background: #fff; border: 2px solid #4a7fd6; border-radius: 50%; margin: -5px; }
.hand-move { cursor: move; }
.sel-toolbar {
  position: absolute; background: #fff; border: 1px solid var(--border); border-radius: 9px;
  box-shadow: 0 4px 14px rgba(0,0,0,.2); display: flex; gap: 2px; padding: 3px; z-index: 30;
}
.sel-toolbar button { font-size: 12px; padding: 4px 8px; border: none; background: none; }
.sel-toolbar button:hover { background: var(--accent-2); }
.sel-toolbar button.on { color: var(--accent); }
/* bloqueio de imagem */
.img-hint { position: absolute; border: 1.5px dashed rgba(74,127,214,.85); cursor: move; background: rgba(74,127,214,.04); }
.editable {
  position: absolute; outline: 2px solid var(--accent); outline-offset: 2px;
  background: rgba(255,255,255,.85); white-space: pre-wrap; overflow: hidden; cursor: text;
}
.editable:focus { outline-color: #f59e0b; }
.block-hint { position: absolute; border: 1.5px dashed var(--accent); border-radius: 3px; cursor: pointer; opacity: .3; }
.block-hint:hover { opacity: .95; }
.editable-bar {
  position: absolute; background: var(--accent); color: #fff; font-size: 12px; padding: 4px 10px;
  border-radius: 6px; cursor: pointer; white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
#modal { position: fixed; inset: 0; background: rgba(10,12,20,.45); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-card { background: var(--panel); border-radius: 14px; padding: 20px; min-width: 320px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.modal-card h3 { margin: 0 0 10px; }
.modal-card input { width: 100%; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); margin: 6px 0; }
.modal-card .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.bgc-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.bgc { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; }
.bgc.on { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(74,127,214,.35); }

button svg.ic, .tool-btn svg.ic, .sel-toolbar svg.ic { vertical-align: -3px; }
button { display: inline-flex; align-items: center; gap: 5px; }
.dropdown button { gap: 8px; }
#btn-menu { font-size: 0; }
#btn-menu svg.ic { margin: 2px; }
.tool-btn { padding: 7px 8px; }

/* camada de texto selecionável */
.text-layer { position: absolute; inset: 0; pointer-events: auto; user-select: text; z-index: 5; opacity: 0; }
.text-layer.active { opacity: 1; }
.text-layer .tx { position: absolute; white-space: pre; user-select: text; color: transparent; cursor: text; }
.text-layer .tx::selection { background: rgba(255, 200, 60, .75); color: transparent; }
/* menu flutuante de marcação */
.mark-pop {
  position: absolute; z-index: 40; background: #16181f; color: #e8eaf0;
  border-radius: 12px; padding: 8px 10px; box-shadow: 0 8px 26px rgba(0,0,0,.45);
  display: flex; flex-direction: column; gap: 8px; pointer-events: auto;
}
.mark-actions { display: flex; gap: 4px; }
.mark-actions button {
  background: none; border: none; color: #cdd3e0; padding: 7px; border-radius: 8px; cursor: pointer;
}
.mark-actions button:hover { background: #262a36; color: #fff; }
.mark-colors { display: flex; gap: 6px; align-items: center; }
.mark-colors .mc {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0;
}
.mark-colors .mc.on { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,.25); }
/* sidebar de propriedades */
#props-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 260px; background: var(--panel);
  border-left: 1px solid var(--border); z-index: 30; overflow-y: auto; padding: 14px;
}
#props-panel h4 { margin: 2px 0 10px; font-size: 14px; }
#props-panel .group { border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 10px; }
#props-panel label { font-size: 12px; color: var(--muted); display: block; margin: 6px 0 3px; }
#props-panel .swatches { display: flex; gap: 6px; flex-wrap: wrap; }
#props-panel .sw {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer;
}
#props-panel .sw.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(90,140,220,.3); }
#props-panel input[type=range] { width: 100%; }
#props-panel select { width: 100%; padding: 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }

.hover-outline {
  position: absolute; border: 1.5px solid rgba(74,127,214,.85); border-radius: 3px;
  pointer-events: none; z-index: 20; box-shadow: 0 0 0 1px rgba(255,255,255,.5);
}
.handle.h-rot {
  position: absolute; width: 12px; height: 12px; border-radius: 50%;
  background: #fff; border: 2px solid #4a7fd6; display: flex; align-items: center; justify-content: center;
  font-size: 9px; color: #4a7fd6; line-height: 1;
}
.handle.h-rot::after { content: "↻"; }
.tb-label {
  font-size: 11.5px; color: var(--muted); padding: 3px 8px; white-space: nowrap;
  border-right: 1px solid var(--border); margin-right: 2px;
}
.sel-toolbar button { font-size: 12px; padding: 4px 7px; border: none; background: none; border-radius: 6px; }
.sel-toolbar button:hover { background: var(--accent-2); }
.sel-toolbar button.on { color: var(--accent); }

.modal-card { position: relative; }
.modal-x {
  position: absolute; top: 10px; right: 10px; border: none; background: none;
  color: var(--muted); padding: 6px; border-radius: 8px; cursor: pointer; line-height: 0;
}
.modal-x:hover { background: var(--accent-2); color: var(--text); }

.sig-tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.sig-tab { border: none; background: var(--accent-2); color: var(--muted); padding: 7px 14px; border-radius: 8px; }
.sig-tab.on { background: var(--accent); color: #fff; }

.doc-tabs { display: flex; gap: 2px; max-width: 40vw; overflow-x: auto; }
.doc-tab {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px;
  padding: 5px 8px; cursor: pointer; white-space: nowrap;
}
.doc-tab.active { background: var(--accent-2); color: var(--accent); }
.doc-tab .dt-x { border: none; background: none; color: var(--muted); padding: 0 2px; font-size: 13px; cursor: pointer; }
.doc-tab .dt-x:hover { color: #dc2626; }
.doc-tab .dot { width: 6px; height: 6px; border-radius: 50%; background: #f59e0b; display: none; }
.doc-tab.dirty .dot { display: inline-block; }
