:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1f2630;
  --muted: #6b7584;
  --accent: #0e8a7e;
  --accent-ink: #ffffff;
  --accent-soft: #d8f1ee;
  --danger: #c92a2a;
  --danger-soft: #ffe3e3;
  --shadow: 0 6px 24px rgba(20, 30, 45, .12), 0 1px 3px rgba(20, 30, 45, .08);
  --radius: 10px;
  --topbar-h: 56px;
  --panel-w: 300px;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #14171c;
  --surface: #1c2027;
  --surface-2: #242a33;
  --border: #323a46;
  --text: #e5e8ec;
  --muted: #98a2b0;
  --accent: #34d1bf;
  --accent-ink: #0b1f1c;
  --accent-soft: #173a36;
  --danger: #ff8787;
  --danger-soft: #3d1f22;
  --shadow: 0 8px 28px rgba(0, 0, 0, .45), 0 1px 3px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
#app { height: 100%; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
h2 { font-size: 15px; margin: 0; }
h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); margin: 6px 0 0; }
[hidden] { display: none !important; }

.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 12px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; cursor: pointer;
  white-space: nowrap; user-select: none;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .map-name:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.btn:disabled { opacity: .38; cursor: default; background: transparent; }
.btn.icon { width: 36px; padding: 0; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.danger.solid { background: var(--danger); color: #fff; }
.btn.block { width: 100%; }
.btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.btn.outline { border-color: var(--border); background: var(--surface); }

/* ---------- barra superior ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 4px;
  padding: 0 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 20;
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none;
}
.topbar::-webkit-scrollbar { display: none; }
.brand { color: var(--accent); display: flex; padding: 0 2px; }
.brand .ic { width: 24px; height: 24px; }
.map-name {
  min-width: 120px; width: 220px; height: 36px;
  border: 1px solid transparent; border-radius: 8px; background: transparent;
  padding: 0 8px; font-weight: 600; font-size: 15px; text-overflow: ellipsis;
}
.map-name:hover { border-color: var(--border); }
.save-status { font-size: 12px; color: var(--muted); min-width: 64px; }
.tb-group { display: flex; align-items: center; gap: 2px; padding: 0 6px; border-left: 1px solid var(--border); }
.spacer { flex: 1; min-width: 8px; }
.zoom-label { min-width: 58px; padding: 0 6px; font-variant-numeric: tabular-nums; font-size: 13px; }

.menu-wrap { position: static; }
.menu {
  position: fixed; z-index: 60; min-width: 230px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px;
}
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 0; background: none; padding: 9px 10px; border-radius: 6px; cursor: pointer; text-align: left;
}
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); outline: none; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

/* ---------- área de trabalho ---------- */
.topbar { flex: none; }
.workspace { position: relative; display: flex; flex: 1; min-height: 0; }
.canvas-wrap { position: relative; flex: 1; min-width: 0; overflow: hidden; background: var(--bg); }
#canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none;
  cursor: grab; user-select: none; -webkit-user-select: none;
  background-image: radial-gradient(circle, color-mix(in srgb, var(--muted) 28%, transparent) 1px, transparent 1.2px);
  background-size: 24px 24px;
}
#canvas.panning { cursor: grabbing; }
#canvas .node { cursor: pointer; }
#canvas .node .ico { cursor: pointer; }
#canvas .node .ico:hover path { stroke-width: 2.2; }
#canvas .toggle { cursor: pointer; }
#canvas .toggle.open { opacity: 0; transition: opacity .15s; }
#canvas .node:hover .toggle.open, #canvas .node.selected .toggle.open { opacity: 1; }
#canvas.dragging, #canvas.dragging .node { cursor: grabbing; }
.drop-hint {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  padding: 6px 12px; border-radius: 99px; font-size: 13px; pointer-events: none;
}

.editor {
  position: absolute; z-index: 5; resize: none; overflow: hidden;
  border: 2px solid var(--accent); border-radius: 8px;
  background: var(--surface); color: var(--text);
  padding: 4px 6px; text-align: center; line-height: 1.3;
  box-shadow: var(--shadow); outline: none;
}

/* ---------- gaveta de mapas ---------- */
.drawer {
  position: absolute; z-index: 30; left: 0; top: 0; bottom: 0; width: min(340px, 88vw);
  background: var(--surface); border-right: 1px solid var(--border); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  transform: translateX(-105%); transition: transform .2s ease;
}
.drawer.open { transform: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 16px; }
.drawer-actions { display: flex; gap: 8px; padding: 4px 16px 10px; }
.drawer-actions .btn { flex: 1; }
.drawer-actions .btn:not(.primary) { border-color: var(--border); }
.search { display: flex; align-items: center; gap: 8px; margin: 0 16px 8px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.search .ic { width: 16px; height: 16px; color: var(--muted); }
.search input { flex: 1; border: 0; background: transparent; height: 34px; outline: none; }
.map-list { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
.map-item { display: flex; align-items: center; gap: 4px; border-radius: 8px; padding: 2px 2px 2px 0; }
.map-item.active { background: var(--accent-soft); }
.map-item:hover:not(.active) { background: var(--surface-2); }
.map-open { flex: 1; min-width: 0; text-align: left; border: 0; background: none; cursor: pointer; padding: 8px 8px; border-radius: 8px; }
.map-open strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.map-open span { font-size: 12px; color: var(--muted); }
.map-item .btn.icon { width: 30px; height: 30px; opacity: .65; }
.map-item .btn.icon:hover { opacity: 1; }
.map-item .btn .ic { width: 17px; height: 17px; }
.drawer-foot { padding: 10px 16px 14px; border-top: 1px solid var(--border); }
.drawer-foot .btn { border-color: var(--border); }
.drawer-foot p { margin: 8px 0 0; }

.scrim { position: absolute; inset: 0; z-index: 25; background: rgba(10, 14, 20, .28); }

/* ---------- painel de estilo ---------- */
.inspector {
  width: var(--panel-w); flex: none;
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.inspector.closed { display: none; }
.insp-empty { padding: 4px 16px; color: var(--text); }
.insp-body { overflow-y: auto; padding: 0 16px 20px; }
.insp-body section { padding: 12px 0; border-bottom: 1px solid var(--border); }
.insp-body section:last-child { border-bottom: 0; }
.row { display: flex; gap: 6px; align-items: center; }
.row input, .row select { flex: 1; min-width: 0; }
input[type="url"], input[type="text"], select, textarea {
  height: 36px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); padding: 0 10px;
}
textarea { height: auto; padding: 8px 10px; width: 100%; resize: vertical; min-height: 80px; }
.shape-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.shape-grid .btn { height: 44px; padding: 0; border: 1px solid var(--border); flex-direction: column; gap: 2px; font-size: 10px; }
.shape-grid .btn svg { width: 34px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.color-row { display: grid; grid-template-columns: 1fr; gap: 6px; margin-bottom: 10px; }
.color-row > span { font-size: 12px; color: var(--muted); }
.swatches { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.swatch {
  width: 24px; height: 24px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .15); cursor: pointer; padding: 0;
  position: relative;
}
.swatch[aria-pressed="true"]::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--accent); }
.swatch.auto {
  background: linear-gradient(135deg, var(--surface) 45%, var(--danger) 46%, var(--danger) 54%, var(--surface) 55%);
}
.swatch.custom { overflow: hidden; background: conic-gradient(#f03e3e, #fab005, #40c057, #15aabf, #4c6ef5, #be4bdb, #f03e3e); }
.swatch.custom input { opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }
.segmented { display: flex; flex-wrap: wrap; gap: 4px; }
.btn.seg { border: 1px solid var(--border); height: 32px; padding: 0 10px; font-size: 13px; }
.row .btn.seg { width: 36px; padding: 0; }
.insp-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.insp-actions .btn { justify-content: flex-start; border-color: var(--border); }

/* ---------- diálogos ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 14, 20, .45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--surface); color: var(--text); border-radius: 14px; box-shadow: var(--shadow);
  width: min(460px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column;
}
.modal.wide { width: min(940px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 8px; }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 6px 18px 12px; overflow-y: auto; }
.modal-body p { margin: 0 0 10px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; flex-wrap: wrap; }
.modal-foot .btn:not(.primary):not(.solid) { border-color: var(--border); }
.modal-body input[type="text"] { width: 100%; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; cursor: pointer; }

.export-grid { display: grid; grid-template-columns: 280px 1fr; gap: 18px; }
.export-preview {
  background: var(--surface-2); border-radius: 10px; min-height: 360px; padding: 16px;
  display: flex; flex-wrap: wrap; gap: 12px; align-content: flex-start; justify-content: center; overflow: auto; max-height: 62vh;
}
.export-preview.single { align-content: center; }
.page-thumb { background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .18); position: relative; flex: none; }
.page-thumb svg { width: 100%; height: 100%; display: block; }
.page-thumb .pg-num { position: absolute; right: 4px; bottom: 2px; font-size: 10px; color: #888; }
.png-thumb { max-width: 100%; max-height: 56vh; box-shadow: 0 2px 10px rgba(0, 0, 0, .18); background-image: linear-gradient(45deg, #ddd 25%, transparent 25%, transparent 75%, #ddd 75%), linear-gradient(45deg, #ddd 25%, transparent 25%, transparent 75%, #ddd 75%); background-size: 16px 16px; background-position: 0 0, 8px 8px; }
.export-info { font-size: 12px; color: var(--muted); margin-top: 10px; }
.export-info.warn { color: #b35c00; }
[data-theme="dark"] .export-info.warn { color: #ffc078; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.tabs .btn { flex: 1; height: 32px; }
.tabs .btn[aria-selected="true"] { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

.backup-list { list-style: none; padding: 0; margin: 0; }
.backup-list li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.backup-list li > div { flex: 1; min-width: 0; }
.backup-list strong { display: block; }
.backup-list .btn { height: 32px; padding: 0 10px; border-color: var(--border); }
.backup-list .btn.icon { width: 32px; padding: 0; }

.kbd-table { width: 100%; border-collapse: collapse; }
.kbd-table td { padding: 6px 4px; border-bottom: 1px solid var(--border); }
kbd { font: 12px/1 var(--font); background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 3px 6px; white-space: nowrap; }

.toasts { position: fixed; z-index: 200; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #253041; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; animation: toastIn .18s ease; max-width: 90vw; }
.toast.error { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

.print-area { display: none; }

/* ---------- responsivo ---------- */
@media (max-width: 1100px) {
  .inspector {
    position: absolute; right: 0; top: 0; bottom: 0; z-index: 22; box-shadow: var(--shadow);
  }
  .map-name { width: 160px; }
}
@media (max-width: 900px) {
  .save-status, .brand, #btnZoomReset { display: none; }
  .map-name { width: 120px; min-width: 90px; }
  .tb-group { padding: 0 3px; }
  .topbar .btn.primary .lbl { display: none; }
  .topbar .btn.primary { width: 36px; padding: 0; }
}
@media (max-width: 760px) {
  :root { --panel-w: min(320px, 92vw); }
  .export-grid { grid-template-columns: 1fr; }
  .export-preview { min-height: 220px; }
}
@media (pointer: coarse) {
  .btn { height: 40px; }
  .btn.icon { width: 40px; }
  .swatch { width: 30px; height: 30px; }
}

/* ---------- impressão (Salvar como PDF) ---------- */
@media print {
  html, body { height: auto; overflow: visible; background: #fff; }
  #app, #modalRoot, #toasts { display: none !important; }
  .print-area { display: block; }
  .print-page { overflow: hidden; page-break-after: always; break-after: page; }
  .print-page:last-child { page-break-after: auto; break-after: auto; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
