:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #f8f6f2;
  --line: #e6e0d6;
  --text: #1d1a17;
  --muted: #6f675d;
  --accent: #a8590f;
  --accent-soft: #f6e7d5;
  --ok: #1f7a4d;
  --ok-soft: #dff1e6;
  --bad: #b3261e;
  --bad-soft: #fbe2df;
  --warn: #8a5a00;
  --warn-soft: #fbefcf;
  --na: #55606e;
  --na-soft: #e6eaf0;
  --meter-bg: #0f0d0c;
  --meter-grid: #2a2522;
  --meter-text: #f3ede6;
  --trace: #ff5a36;
  --strike: #ffc24a;
  --extra: #5fb4ff;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 4px 16px rgba(40, 30, 20, .05);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210; --surface: #1d1a17; --surface-2: #24201c; --line: #342f2a;
    --text: #f1ece5; --muted: #a59b8f; --accent: #e08a3a; --accent-soft: #3a2a1a;
    --ok: #59c58c; --ok-soft: #173325; --bad: #ff7b70; --bad-soft: #3b1c1a;
    --warn: #e7b44c; --warn-soft: #3a2f16; --na: #a7b2c0; --na-soft: #262c34;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

#app { max-width: 760px; margin: 0 auto; padding-bottom: 48px; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.titles { flex: 1; min-width: 0; }
.title { font-size: 19px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 6px; }
main { padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; border: 0; background: transparent; display: grid; place-items: center;
  cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

.section-label { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 8px 4px -4px; display: flex; justify-content: space-between; align-items: center; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 16px; }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card .hint { color: var(--muted); font-size: 13.5px; line-height: 1.45; margin: 0; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 15px;
  text-decoration: none; color: var(--text);
}
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 14px 4px; border-bottom: 1px solid var(--line); cursor: pointer; text-decoration: none; color: inherit;
}
.list-item:last-child { border-bottom: 0; }
.list-item .chev { color: var(--muted); }
.avatar { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; flex: none; }
.avatar svg { width: 22px; height: 22px; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.na { background: var(--na-soft); color: var(--na); border-color: transparent; }
.chip.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* Passos da fase 1 */
.step { display: flex; gap: 14px; align-items: flex-start; }
.step-num { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: var(--surface-2); border: 1px solid var(--line); flex: none; }
.step-num.done { background: var(--ok); border-color: var(--ok); color: #fff; }

.rec-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.rec-tile {
  border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: var(--surface-2); cursor: pointer; text-align: left;
  display: flex; flex-direction: column; gap: 8px;
}
.rec-tile:hover { border-color: var(--accent); }
.rec-tile .big { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.dots { display: flex; gap: 6px; flex-wrap: wrap; }
.dot { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--bg); color: var(--muted); }
.dot.on { background: var(--ok-soft); color: var(--ok); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.kpi { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.kpi .k { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .v small { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 2px; }

/* Ecrã de medição — painel escuro tipo sonómetro */
.meter { background: var(--meter-bg); color: var(--meter-text); border-radius: 20px; padding: 14px 14px 10px; display: flex; flex-direction: column; gap: 10px; }
.meter-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.meter-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.meter-tag { background: #221e1b; color: #d9d0c6; border-radius: 8px; padding: 4px 8px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.meter-tag b { color: #fff; }
.meter-value { font-size: 52px; line-height: .95; font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: -.03em; text-align: right; }
.meter-value small { display: block; font-size: 12px; font-weight: 600; color: #a49a90; letter-spacing: 0; }
.meter canvas { width: 100%; height: 220px; display: block; cursor: crosshair; }
.transport { display: flex; justify-content: center; gap: 18px; padding: 4px 0 6px; }
.tbtn { width: 58px; height: 58px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer; background: #2a2522; color: #fff; }
.tbtn svg { width: 24px; height: 24px; }
.tbtn.rec { background: #3a1512; color: #ff6b5b; }
.tbtn:disabled { opacity: .35; cursor: not-allowed; }
.tbtn.active { background: var(--trace); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11.5px; color: #b9afa5; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

.drop {
  border: 1.5px dashed var(--line); border-radius: 14px; padding: 18px; text-align: center; color: var(--muted); cursor: pointer; background: var(--surface-2);
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.drop b { color: var(--text); }

/* Formulários */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 12px; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper input { width: 64px; text-align: center; }
.choice { display: flex; gap: 6px; flex-wrap: wrap; }
.choice button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 7px 12px; font-size: 13.5px; cursor: pointer; }
.choice button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
details.adv summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--accent); list-style: none; }
details.adv summary::-webkit-details-marker { display: none; }
details.adv[open] summary { margin-bottom: 12px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }

/* Tabelas */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px 6px; border-bottom: 1px solid var(--line); }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }

.verdict { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-radius: 12px; font-weight: 700; }
.verdict.ok { background: var(--ok-soft); color: var(--ok); }
.verdict.bad { background: var(--bad-soft); color: var(--bad); }
.verdict.na { background: var(--na-soft); color: var(--na); }
.period-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.period { border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); }
.calc-line { display: flex; justify-content: space-between; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.calc-line span:first-child { color: var(--muted); }

.warnbox { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 13.5px; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .5; }

.spectrum { display: flex; align-items: flex-end; gap: 2px; height: 90px; }
.spectrum div { flex: 1; background: var(--accent); opacity: .55; border-radius: 2px 2px 0 0; min-height: 1px; }
.spectrum div.tonal { opacity: 1; background: var(--bad); }
.spectrum-x { display: flex; gap: 2px; font-size: 9px; color: var(--muted); }
.spectrum-x span { flex: 1; text-align: center; overflow: hidden; }

/* Bottom sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(10, 8, 6, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; background: var(--surface); border-radius: 22px 22px 0 0; padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 4px; }
.sheet h2 { margin: 0; font-size: 19px; }
@media (min-width: 700px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 22px; } }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #1d1a17; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 60; max-width: 90vw; }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.test-banner { display: flex; gap: 10px; align-items: center; background: var(--accent-soft); color: var(--accent); border-radius: 12px; padding: 10px 12px; font-size: 13px; font-weight: 600; }
.test-banner svg { width: 18px; height: 18px; flex: none; }

/* Relatório */
.report { background: #fff; color: #111; padding: 28px; border-radius: 6px; font-size: 13.5px; line-height: 1.5; }
.report h1 { font-size: 22px; margin: 0 0 4px; }
.report h2 { font-size: 16px; margin: 24px 0 8px; border-bottom: 2px solid #a8590f; padding-bottom: 4px; }
.report h3 { font-size: 14px; margin: 16px 0 6px; }
.report table { font-size: 12.5px; }
.report th { color: #555; }
.report td, .report th { border-color: #ddd; }
.report .meta { color: #555; }
@media print {
  .topbar, .no-print { display: none !important; }
  body, #app, main { background: #fff; padding: 0; margin: 0; max-width: none; }
  .report { padding: 0; }
}

/* ajustes */
.field input, .field select { width: 100%; min-width: 0; }
.grid2 > *, .grid3 > * { min-width: 0; }
.btn svg { flex: none; }
#bulkLog .row { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: start; }
#bulkLog .row .muted { grid-column: 2; }
#bulkLog .row .mono { word-break: break-all; }
.assign-row { display: grid; grid-template-columns: 1fr minmax(150px, 46%); gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.assign-row select { min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 8px; width: 100%; min-width: 0; }
@media (max-width: 480px) { .assign-row { grid-template-columns: 1fr; } }
.seg { display: inline-flex; background: #221e1b; border-radius: 10px; padding: 2px; }
.seg button { border: 0; background: transparent; color: #b9afa5; font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: #3a332e; color: #fff; }
.meter-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.edit-bar { background: #2a2118; color: var(--strike); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.edit-bar .btn { min-height: 30px; }
tr.est td { color: var(--muted); font-style: italic; }

/* v3: interruptores, listas de seleção, toques desativados */
.toggle { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; flex: none; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle span { width: 44px; height: 26px; border-radius: 13px; background: var(--line); position: relative; transition: background .15s; }
.toggle span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.toggle input:checked + span { background: var(--ok); }
.toggle input:checked + span::after { transform: translateX(18px); }
.toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); cursor: pointer; font-size: 14px; }
.check-row input[type=checkbox]:not(.toggle input) { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.inactive { opacity: .5; }
.list-item.inactive .avatar { background: var(--surface-2); color: var(--muted); }

/* origem do registo: medir / carregar */
.source-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.source-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 16px 10px; min-height: 108px;
  border: 1.5px solid var(--line); border-radius: 14px; background: var(--surface-2); color: var(--text); text-decoration: none; cursor: pointer; font: inherit; text-align: center; }
.source-btn:hover { border-color: var(--accent); }
.source-btn svg { width: 28px; height: 28px; color: var(--accent); }
.source-btn b { font-size: 15px; }
.source-btn span { font-size: 12px; color: var(--muted); }
.list-item .icon-btn { width: 34px; height: 34px; color: var(--muted); }
.list-item .icon-btn:hover { color: var(--accent); }
.meter-value { white-space: nowrap; }

/* volume de audição */
.vol { display: flex; align-items: center; gap: 10px; padding: 2px 4px 0; }
.vol-ic { color: #b9afa5; display: grid; place-items: center; }
.vol-ic svg { width: 20px; height: 20px; }
.vol input[type=range] { flex: 1; min-width: 0; accent-color: var(--trace); height: 28px; }
.vol-val { color: #fff; font-size: 13px; font-weight: 600; min-width: 52px; text-align: right; }
.vol-auto { border: 1px solid #3a332e; background: #221e1b; color: #d9d0c6; border-radius: 8px; padding: 5px 10px; font-size: 12px; font-weight: 700; cursor: pointer; }
.vol-auto.on { background: var(--trace); border-color: var(--trace); color: #fff; }
.vol-note { font-size: 11px; color: #8d847a; text-align: center; margin-top: -4px; }

/* ecrã de saída */
.quit-screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; padding: 24px; color: var(--muted); }
.quit-screen svg { width: 48px; height: 48px; color: var(--accent); }
.quit-screen h2 { color: var(--text); margin: 8px 0 0; }
#quit svg { color: var(--bad); }

/* versão iPhone */
.meter .field input, .meter .field select { background: #2a2522; color: #f3ece4; border-color: #3a332e; -webkit-text-fill-color: #f3ece4; opacity: 1; }
.meter .field input:disabled { color: #cfc6bb; -webkit-text-fill-color: #cfc6bb; }
a.test-banner { color: var(--accent); }
