:root {
  --bg: #1b1d21; --panel: #24272d; --line: #363a42; --text: #e8e9ec; --muted: #9aa0aa;
  --accent: #d9913a; --accent-2: #f0b46a; --danger: #e05d5d; --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
body { display: flex; flex-direction: column; overflow: hidden; }

/* Cabeçalho */
.top { position: relative; display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { white-space: nowrap; font-size: 17px; }
.brand span { color: var(--accent); }
.project-name { flex: 1; min-width: 0; background: transparent; border: 1px solid transparent;
  border-radius: 8px; padding: 6px 8px; }
.project-name:focus { border-color: var(--line); outline: none; background: var(--bg); }
.top-actions { display: flex; gap: 6px; }
.menu { position: absolute; right: 10px; top: 100%; z-index: 20; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px; display: flex; flex-direction: column; min-width: 220px; box-shadow: 0 8px 30px #0008; }
.menu button { background: none; border: 0; text-align: left; padding: 10px 12px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--line); }

.btn { background: var(--line); border: 0; border-radius: 8px; padding: 8px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--accent); color: #1b1208; font-weight: 600; }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.icon { width: 38px; padding: 8px 0; }
.btn.active { outline: 2px solid var(--accent-2); }

/* Layout: lado a lado no tablet/paisagem, empilhado no celular em pé */
.layout { flex: 1; display: flex; min-height: 0; }
.viewport { position: relative; flex: 1; min-width: 0; }
#view3d { width: 100%; height: 100%; display: block; touch-action: none; }
.panel { width: 380px; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
@media (orientation: portrait), (max-width: 760px) {
  .layout { flex-direction: column; }
  .viewport { flex: 0 0 48vh; }
  .panel { width: auto; flex: 1; border-left: 0; border-top: 1px solid var(--line); }
  .brand { display: none; }
}

.view-tools { position: absolute; left: 8px; top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: #000a; border: 1px solid #fff2; border-radius: 99px; padding: 4px 10px; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px; }
.photo-strip { position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; gap: 8px; overflow-x: auto; padding: 6px;
  background: #000a; border-radius: 10px; z-index: 2; }
.photo-strip .ph { position: relative; flex: none; }
.photo-strip img { height: 84px; border-radius: 6px; display: block; cursor: pointer; border: 2px solid transparent; }
.photo-strip .ph.on img { border-color: var(--accent); }
.photo-strip .del { position: absolute; top: 2px; right: 2px; background: #000c; color: #fff; border: 0; border-radius: 50%;
  width: 22px; height: 22px; font-size: 12px; cursor: pointer; }
.photo-strip .empty { color: var(--muted); font-size: 13px; padding: 8px; }
.chip.active { background: var(--accent); color: #1b1208; }
.ar-hint { position: absolute; left: 8px; right: 8px; bottom: 8px; margin: 0; background: #000b; padding: 8px 10px;
  border-radius: 8px; font-size: 13px; color: var(--accent-2); }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; background: none; border: 0; padding: 12px 0; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { padding: 12px; overflow-y: auto; flex: 1; }
.help { color: var(--muted); margin: 0 0 12px; }
.help.small { font-size: 13px; }
h3 { font-size: 14px; margin: 18px 0 8px; color: var(--muted); font-weight: 600; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.row { flex-direction: row; align-items: center; justify-content: space-between; margin-top: 10px; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
input[type=number], input[type=text], select { background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px; width: 100%; color: var(--text); }
input[type=color] { width: 48px; height: 32px; border: 1px solid var(--line); border-radius: 6px; background: none; padding: 2px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.btn.wide { width: 100%; padding: 12px; margin-bottom: 6px; }
.span2 { grid-column: span 2; }
.pair { display: flex; gap: 6px; }
#btnClearScan { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

.add-row { display: flex; gap: 8px; margin-bottom: 12px; }
.item-list, .measure-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.item-list li { display: flex; align-items: center; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.item-list li.selected { border-color: var(--accent); background: #d9913a18; }
.item-list .sw { width: 14px; height: 14px; border-radius: 3px; flex: none; border: 1px solid #fff3; }
.item-list .dims { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.measure-list li { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
.measure-list b { margin-right: auto; }
.measure-list button { font-size: 12px; padding: 4px 8px; }

.editor { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.editor h4 { margin: 6px 0 0; font-size: 13px; color: var(--accent-2); }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.swatch { width: 28px; height: 28px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; }
.swatch.on { border-color: var(--accent-2); }
.nudge { display: flex; gap: 6px; flex-wrap: wrap; }
.nudge .btn { font-size: 13px; padding: 6px 10px; }

table.parts { width: 100%; border-collapse: collapse; font-size: 13px; }
table.parts th, table.parts td { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: left; }
table.parts td.n { text-align: right; font-variant-numeric: tabular-nums; }
.parts-group { margin: 14px 0 6px; color: var(--accent-2); font-weight: 600; }

/* Modo AR (por cima da câmera) */
.ar-overlay { position: fixed; inset: 0; display: flex; flex-direction: column; justify-content: space-between;
  pointer-events: none; padding: max(10px, env(safe-area-inset-top)) 10px max(14px, env(safe-area-inset-bottom)); }
.ar-overlay[hidden] { display: none; }
.ar-overlay .btn, .ar-overlay button { pointer-events: auto; }
.ar-top { display: flex; gap: 8px; align-items: flex-start; margin-top: 34px; }
.ar-status { flex: 1; background: #000b; padding: 8px 12px; border-radius: 8px; font-size: 14px; }
.ar-measure { align-self: center; background: #000c; color: #fff; font-size: 28px; font-weight: 700; padding: 6px 16px; border-radius: 10px; }
.ar-bottom { display: flex; flex-direction: column; gap: 8px; }
.ar-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.ar-overlay .btn { background: #000b; color: #fff; padding: 12px 14px; font-size: 15px; }
.ar-overlay .btn.active { background: var(--accent); color: #1b1208; }
.ar-overlay select { pointer-events: auto; background: #000b; color: #fff; border: 1px solid #fff3; border-radius: 8px; padding: 10px; max-width: 60vw; }
.ar-overlay .btn.rec { background: #c0392b; color: #fff; }
.ar-flash { position: fixed; inset: 0; background: #fff; opacity: .7; pointer-events: none; }
.ar-overlay .btn.primary { background: var(--accent); color: #1b1208; }
.ar-labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.ar-labels div { position: absolute; transform: translate(-50%, -50%); background: #000c; color: #fff; font: 700 14px system-ui;
  padding: 3px 8px; border-radius: 6px; white-space: nowrap; }
.ar-labels div.sel { background: var(--accent); color: #1b1208; }
.ar-cross { position: fixed; left: 50%; top: 50%; width: 26px; height: 26px; margin: -13px 0 0 -13px; pointer-events: none;
  background: linear-gradient(#fff, #fff) center/2px 100% no-repeat, linear-gradient(#fff, #fff) center/100% 2px no-repeat;
  filter: drop-shadow(0 0 2px #000); opacity: .85; }
.ar-ctx-info { pointer-events: none; background: #000b; color: #fff; padding: 8px 10px; border-radius: 8px; font-size: 13px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #000d; color: #fff; padding: 10px 16px;
  border-radius: 8px; z-index: 50; max-width: 90vw; text-align: center; }
