:root {
  --bg: #0d0f12;
  --panel: #161a20;
  --panel-2: #1d222b;
  --border: #2a313c;
  --text: #e6e9ee;
  --muted: #8a93a2;
  --accent: #f59e0b;
  --accent-2: #38bdf8;
  --danger: #ef4444;
}

* { box-sizing: border-box; }

/* Garante que o atributo `hidden` sempre esconda (evita overlay do modal
   capturar cliques quando .modal define display:flex). */
[hidden] { display: none !important; }

.stage.dragover::after {
  content: "Solte a imagem aqui";
  position: absolute; inset: 12px;
  border: 3px dashed var(--accent); border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; color: var(--accent);
  background: rgba(245,158,11,.08); pointer-events: none; z-index: 5;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}

body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; white-space: nowrap; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-size: 16px; font-weight: 700; }
.brand-sub { display: flex; align-items: baseline; gap: 6px; font-size: 11px; font-weight: 400; }
.brand small { color: var(--muted); font-weight: 400; }
.brand-ver { color: var(--accent); font-weight: 600; }
.logo { font-size: 22px; }

.brand-link { text-decoration: none; color: inherit; }
.brand-link:hover { color: var(--accent); }

.toolbar { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.spacer { flex: 1; }
/* divisor vertical entre grupos de botões */
.tb-divider { width: 1px; height: 24px; background: var(--border); margin: 0 4px; flex: none; }

/* Barra do projeto (editor) */
.project-bar { display: flex; align-items: center; gap: 8px; flex: none; min-width: 0; }
.proj-name {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 7px 10px; font-size: 14px; font-weight: 600;
  width: 180px; min-width: 90px;
}
.proj-name:focus { outline: none; border-color: var(--accent); }
.save-status { font-size: 12px; white-space: nowrap; }

/* Barra de menus (estilo desktop) */
.menubar { display: flex; align-items: stretch; gap: 2px; flex: none; }
.menu { position: relative; display: flex; }
.menu-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; color: var(--text); border: 1px solid transparent;
  border-radius: 8px; padding: 7px 12px; cursor: pointer; font-size: 13px;
  font-family: inherit; white-space: nowrap; user-select: none;
}
.menu-btn:hover { background: var(--panel-2); }
.menu.open > .menu-btn { background: var(--panel-2); border-color: var(--border); }
.menu.disabled > .menu-btn { color: var(--muted); opacity: .5; cursor: default; }
.menu.disabled > .menu-btn:hover { background: transparent; }

.menu-pop {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 80;
  min-width: 230px; margin: 0; padding: 6px; list-style: none;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0,0,0,.5); display: none;
}
.menu.open > .menu-pop { display: block; animation: dlg-in .1s ease-out; }

.menu-item {
  display: flex; align-items: center; gap: 10px; position: relative;
  padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; white-space: nowrap;
}
.menu-item:hover { background: var(--panel-2); }
.menu-item.muted, .menu-item.disabled { color: var(--muted); cursor: default; }
.menu-item.muted:hover, .menu-item.disabled:hover { background: transparent; }
.mi-ico { width: 18px; text-align: center; flex: none; }
.mi-lbl { flex: 1; }
.mi-key { color: var(--muted); font-size: 12px; margin-left: 22px; letter-spacing: 1px; }
.mi-arrow { color: var(--muted); margin-left: 16px; }
.menu-sep { height: 1px; background: var(--border); margin: 6px 4px; padding: 0; }

/* submenu (Abrir recente) */
.menu-item.has-sub > .submenu { top: -7px; left: calc(100% + 5px); }
.menu-item.has-sub:hover > .submenu { display: block; }

/* Avisos do modo online/público */
.online-notice {
  background: rgba(245,158,11,.10); border: 1px solid #5a4520; color: #f3d9a8;
  border-radius: 10px; padding: 10px 14px; margin: 0 0 18px; font-size: 13px; line-height: 1.5;
}
.online-notice a, .online-hint a { color: var(--accent); }
.online-hint {
  background: rgba(245,158,11,.10); border: 1px solid #5a4520; color: #f3d9a8;
  border-radius: 8px; padding: 8px 12px; margin: 0 0 14px; font-size: 13px;
}

/* Página Sobre */
.about { max-width: 820px; margin: 0 auto; padding: 28px 20px 60px; width: 100%; }
.about-title { font-size: 24px; margin: 6px 0 14px; }
.about-ver { color: var(--accent); font-size: 16px; font-weight: 600; }
.about-lead { color: var(--text); font-size: 15px; line-height: 1.6; margin: 0 0 18px; }
.about-links { display: flex; flex-direction: column; gap: 6px; margin: 0 0 22px; }
.about-row { display: flex; gap: 10px; align-items: baseline; }
.about-k { color: var(--muted); min-width: 70px; flex: none; }
.about-row a { color: var(--accent); text-decoration: none; }
.about-row a:hover { text-decoration: underline; }
.about-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; margin: 0 0 18px; }
.about-card h2 { margin: 0 0 10px; font-size: 17px; }
.about-card p { line-height: 1.6; margin: 0 0 10px; }
.about-card ul { margin: 0 0 10px; padding-left: 20px; line-height: 1.6; }
.about-card li { margin: 4px 0; }
.about-card code { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; font-size: 12px; }
.about-card--warn { border-color: #5a4520; background: rgba(245,158,11,.06); }

/* Em telas estreitas, mostra só os ícones dos botões da toolbar para não estourar */
@media (max-width: 1180px) {
  .toolbar .btn .btn-txt { display: none; }
  .toolbar .btn { padding: 7px 9px; }
}
@media (max-width: 920px) {
  .brand-sub { display: none; }
  .proj-name { width: 130px; }
}

/* Página de projetos */
.projects-page { overflow: auto; }
.projects { max-width: 1000px; margin: 0 auto; padding: 28px 20px 60px; width: 100%; }
.projects-title { font-size: 20px; margin: 6px 0 20px; }
.project-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px;
}
.project-card {
  display: flex; align-items: stretch; gap: 0;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
}
.project-card:hover { border-color: var(--accent); }
.pc-main { flex: 1; min-width: 0; padding: 16px; text-decoration: none; color: var(--text); display: flex; flex-direction: column; gap: 6px; }
.pc-name { font-size: 16px; font-weight: 700; word-break: break-word; }
.pc-meta { font-size: 12px; color: var(--muted); }
.pc-del { border: none; border-left: 1px solid var(--border); border-radius: 0; padding: 0 14px; }
.empty-projects { color: var(--muted); padding: 40px 4px; font-size: 15px; }
.empty-projects strong { color: var(--accent); }
.project-error { color: #ffb4b4; list-style: none; }

/* ---------- Plano de corte ---------- */
.cut-layout { flex: 1; display: flex; min-height: 0; }
.cut-config { width: 340px; flex: none; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto; }
.cfg-label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); }
.cfg-label select, .cfg-label input { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 7px 8px; font-size: 13px; }

.proj-tree { display: flex; flex-direction: column; gap: 4px; }
.proj-node { border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); overflow: hidden; }
.proj-row { display: flex; align-items: center; gap: 4px; padding: 6px 8px; }
.proj-toggle { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 12px; width: 18px; }
.proj-check { display: flex; align-items: center; gap: 8px; flex: 1; cursor: pointer; }
.proj-name-t { font-weight: 600; }
.proj-check .muted { margin-left: auto; font-size: 11px; }
.piece-sublist { list-style: none; margin: 0; padding: 2px 8px 8px 28px; display: flex; flex-direction: column; gap: 2px; }
.piece-check { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.piece-check:hover { background: var(--bg); }
.piece-check.disabled { opacity: .5; cursor: not-allowed; }

.cut-preview { flex: 1; min-width: 0; background: #555; overflow: auto; padding: 18px; }
.report { background: #fff; color: #111; max-width: 900px; margin: 0 auto; padding: 24px; border-radius: 8px; }
.report-empty { color: #666; padding: 40px; text-align: center; }
.report .rep-title { font-size: 20px; margin: 0 0 10px; }
.report .rep-head { border-bottom: 2px solid #222; padding-bottom: 10px; margin-bottom: 14px; }
.report .rep-summary { display: flex; gap: 30px; flex-wrap: wrap; font-size: 12px; }
.report .rep-stats div, .report .rep-panels div { display: flex; gap: 8px; margin: 2px 0; }
.report .rep-stats span, .report .rep-panels span { color: #555; min-width: 170px; display: inline-block; }
.report .rep-stats b i { font-style: normal; color: #888; font-weight: 400; }
.report .x { color: #888; }
.report .rep-warn { background: #fff4e5; border: 1px solid #f0c98a; padding: 8px 10px; border-radius: 6px; font-size: 12px; margin-bottom: 12px; color: #7a5b1e; }
.report .sheet-block { display: flex; gap: 16px; margin-bottom: 22px; border-top: 1px solid #ddd; padding-top: 12px; }
.report .sheet-side { width: 230px; flex: none; font-size: 12px; }
.report table { border-collapse: collapse; width: 100%; margin-bottom: 12px; }
.report .sheet-info th { text-align: left; color: #555; font-weight: 500; padding: 3px 6px; }
.report .sheet-info td { text-align: right; padding: 3px 6px; }
.report .sheet-pieces th { background: #eee; text-align: left; padding: 4px 6px; }
.report .sheet-pieces td { padding: 3px 6px; border-bottom: 1px solid #eee; }
.report .ta-r { text-align: right; }
.report .sheet-diagram { flex: 1; min-width: 0; }
.report .sheet-cap { font-size: 12px; color: #555; margin-bottom: 6px; }
.report .svg-sheet { width: 100%; height: auto; max-height: 70vh; }
.report small { color: #999; }

/* ---------- Drag & drop na lista de peças (editor) ---------- */
.piece-item { transition: background .12s, border-color .12s; }
.piece-item.dragging { opacity: .5; }
.piece-item.drop-before { box-shadow: 0 -2px 0 0 var(--accent); }
.piece-item.drop-after { box-shadow: 0 2px 0 0 var(--accent); }
.piece-handle { cursor: grab; color: var(--muted); margin-right: 2px; user-select: none; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; font-size: 13px;
  user-select: none; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.danger { border-color: #5a2a2a; color: #ffb4b4; }
.btn.danger:hover { background: #3a1f1f; }
.btn.full { width: 100%; justify-content: center; margin-top: 10px; }
.btn-sm { padding: 3px 8px; font-size: 11px; }
.panel h2 .btn-sm { margin-left: auto; }
.panel h2 .btn-sm ~ .btn-sm { margin-left: 0; }
.btn.active { background: var(--accent); color: #1a1205; font-weight: 600; border-color: var(--accent); }

.tools { display: flex; gap: 4px; background: var(--panel-2); padding: 4px; border-radius: 10px; border: 1px solid var(--border); }
.tool {
  background: transparent; color: var(--muted); border: none;
  padding: 6px 10px; border-radius: 7px; cursor: pointer; font-size: 13px;
}
.tool:hover { color: var(--text); }
.tool.active { background: var(--accent); color: #1a1205; font-weight: 600; }

/* Layout */
.layout { flex: 1; display: flex; min-height: 0; }

.stage { position: relative; flex: 1; min-width: 0; background: #0a0c0f; overflow: hidden; }
#editor { display: block; width: 100%; height: 100%; }

.empty-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none; color: var(--muted); text-align: left;
}
.empty-hint > div { background: rgba(22,26,32,.7); border: 1px solid var(--border); padding: 22px 26px; border-radius: 12px; max-width: 420px; }
.empty-hint p { margin: 8px 0; }
.empty-hint strong { color: var(--accent); }

.crop-bar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; align-items: center;
  background: rgba(13,15,18,.94); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 8px; z-index: 6;
}
.crop-dims { color: var(--muted); font-size: 12px; padding: 0 6px; }
.crop-bar .btn { padding: 5px 10px; }
#btnCropApply { border-color: #3a6b2a; color: #bdf5a6; }
#btnCropApply:hover { background: #1f2e16; }

.status {
  position: absolute; left: 10px; bottom: 10px;
  background: rgba(13,15,18,.8); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 6px; color: var(--muted); font-size: 12px;
  pointer-events: none;
}

/* Sidebar */
.sidebar {
  width: 320px; flex: none; background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden;
}
.panel { padding: 14px; border-bottom: 1px solid var(--border); }
.panel.grow { flex: 1; min-height: 120px; overflow-y: auto; }
.panel h2 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.badge { background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; font-size: 12px; color: var(--text); }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 11px; margin: 8px 0 0; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; min-width: 0; }
.field-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); min-width: 0; }
.field-grid .col2 { grid-column: span 2; }
.field-grid input { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 6px 8px; font-size: 13px; width: 100%; min-width: 0; }
.field-grid input[type="color"] { padding: 2px; height: 32px; }
.manual-toggle { display: flex; flex-direction: row !important; align-items: center; gap: 6px; }

.scale-row { margin-bottom: 10px; }

.layer-row { display: flex; align-items: center; gap: 6px; margin-top: 12px; }
.layer-row span { font-size: 11px; color: var(--muted); margin-right: 2px; }
.layer-row .btn { flex: 1; justify-content: center; padding: 6px 4px; }

/* Lista de peças */
.piece-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.piece-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; background: var(--panel-2);
}
.piece-item:hover { border-color: var(--accent-2); }
.piece-item.selected { border-color: var(--accent); background: #251d10; }
.piece-swatch { width: 14px; height: 14px; border-radius: 3px; flex: none; border: 1px solid rgba(255,255,255,.3); }
.piece-name { font-weight: 600; }
.piece-dims { margin-left: auto; color: var(--muted); font-size: 12px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-box { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; width: min(1500px, 96vw); height: min(92vh, 1000px); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-actions { display: flex; gap: 8px; }
.modal-body { flex: 1; overflow: auto; background: #0a0c0f; display: flex; align-items: flex-start; justify-content: center; padding: 12px; }
#schematic { background: #111317; max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: 8px; }

/* Diálogos customizados (uiAlert / uiConfirm / uiPrompt) */
.modal.dialog { z-index: 100; }
.dialog-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  width: min(440px, 94vw); max-height: 90vh; overflow: auto;
  padding: 20px; box-shadow: 0 18px 50px rgba(0,0,0,.5);
  animation: dlg-in .12s ease-out;
}
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.dialog-title { margin: 0 0 8px; font-size: 16px; font-weight: 700; }
.dialog-msg { margin: 0; color: var(--text); font-size: 14px; line-height: 1.5; white-space: pre-line; }
.dialog-msg a { color: var(--accent); text-decoration: none; }
.dialog-msg a:hover { text-decoration: underline; }
.dlg-row { display: flex; gap: 10px; align-items: baseline; white-space: normal; margin-top: 4px; }
.dlg-k { color: var(--muted); min-width: 60px; flex: none; }
.dialog-input { width: 100%; margin-top: 14px; min-width: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dialog-actions .btn { padding: 8px 16px; }
.dialog-ok { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.dialog-ok:hover { background: rgba(245,158,11,.12); }
.dialog-ok.danger { border-color: #5a2a2a; color: #ffb4b4; }
.dialog-ok.danger:hover { background: #3a1f1f; }
