:root {
  --ink: #1d2420;
  --ink-2: #4b554f;
  --ink-3: #7c857f;
  --paper: #f4f1ea;
  --card: #ffffff;
  --line: #e2ddd2;
  --brand: #1f2a24;
  --accent: #e8a317;
  --accent-ink: #3a2a00;
  --ok: #2f7d4f;
  --ok-bg: #e3f2e8;
  --warn: #9a6400;
  --warn-bg: #fdf0d4;
  --bad: #b3261e;
  --bad-bg: #fbe3e1;
  --info: #2b5c8a;
  --info-bg: #e2edf7;
  --mute-bg: #ece9e2;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--info); }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 1.6rem 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
.muted { color: var(--ink-3); }
.small { font-size: .87rem; }
.mono, .plate { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* ---------- topo */
.top {
  background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 20;
  padding: .55rem 1rem; display: flex; align-items: center; gap: 1rem;
  padding-top: calc(.55rem + env(safe-area-inset-top));
}
.top .logo { color: #fff; text-decoration: none; font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.top .logo span.dot { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-grid; place-items: center; color: var(--accent-ink); font-size: .8rem; }
.top nav { display: flex; gap: .2rem; margin-left: 1rem; }
.top nav a { color: #d6dcd8; text-decoration: none; padding: .4rem .7rem; border-radius: 8px; font-size: .95rem; }
.top nav a.on, .top nav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.top .who { margin-left: auto; display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.top .who a { color: #fff; text-decoration: none; }
.badge-count { background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 0 .45rem; font-size: .75rem; font-weight: 700; margin-left: .2rem; }

/* ---------- navegação inferior (telemóvel) */
.bottom {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: #fff; border-top: 1px solid var(--line);
  display: none; justify-content: space-around; align-items: flex-end;
  padding: .3rem .3rem calc(.3rem + env(safe-area-inset-bottom));
}
.bottom a { flex: 1; text-align: center; color: var(--ink-2); text-decoration: none; font-size: .72rem; padding: .25rem 0; }
.bottom a svg { width: 24px; height: 24px; display: block; margin: 0 auto 2px; }
.bottom a.on { color: var(--brand); font-weight: 600; }
.bottom a.scan { position: relative; top: -14px; }
.bottom a.scan .ring { width: 58px; height: 58px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; margin: 0 auto 2px; box-shadow: 0 4px 12px rgba(0,0,0,.18); color: var(--accent-ink); }
.bottom a.scan svg { width: 28px; height: 28px; margin: 0; }

@media (max-width: 760px) {
  .top nav, .top .who .name { display: none; }
  .bottom { display: flex; }
}
@media (min-width: 761px) { body { padding-bottom: 2rem; } }

main { max-width: 1080px; margin: 0 auto; padding: 1rem; }

/* ---------- mensagens */
.flash { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: .7rem; font-size: .95rem; }
.flash.ok { background: var(--ok-bg); color: #184d2e; }
.flash.erro { background: var(--bad-bg); color: #7a1610; }
.flash.aviso { background: var(--warn-bg); color: #6b4500; }

/* ---------- cartões e grelhas */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card + .card { margin-top: .8rem; }
.grid { display: grid; gap: .8rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .8rem; text-decoration: none; color: inherit; border-left: 5px solid var(--line); }
.stat b { display: block; font-size: 1.7rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: .85rem; color: var(--ink-2); }
.stat.s-disponivel { border-left-color: var(--ok); }
.stat.s-em_uso, .stat.s-reservada { border-left-color: var(--info); }
.stat.s-avariada { border-left-color: var(--bad); }
.stat.s-oficina { border-left-color: var(--warn); }
.stat.s-inativa { border-left-color: var(--ink-3); }

.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

/* ---------- listas */
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.list a.item, .list .item { display: flex; gap: .8rem; align-items: center; padding: .75rem 1rem; color: inherit; text-decoration: none; }
.list a.item:hover { background: #faf8f3; }
.item .main { flex: 1; min-width: 0; }
.item .main .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .main .s { font-size: .85rem; color: var(--ink-3); }
.empty { padding: 1.4rem; text-align: center; color: var(--ink-3); }

.plate { text-decoration: none; color: var(--ink);
  display: inline-block; background: #fff; border: 2px solid var(--ink); border-radius: 5px;
  padding: .05rem .45rem .05rem .9rem; font-weight: 700; letter-spacing: .04em; position: relative; white-space: nowrap; font-size: .95rem;
}
.plate::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: .55rem; background: #1c4fa8; border-radius: 2px 0 0 2px; }
.plate.big { font-size: 1.6rem; border-width: 3px; padding: .1rem .7rem .1rem 1.4rem; }
.plate.big::before { width: .9rem; }

/* ---------- etiquetas de estado */
.tag { display: inline-block; padding: .12rem .55rem; border-radius: 99px; font-size: .8rem; font-weight: 600; white-space: nowrap; background: var(--mute-bg); color: var(--ink-2); }
.tag.disponivel, .tag.resolvida { background: var(--ok-bg); color: var(--ok); }
.tag.em_uso, .tag.reservada, .tag.em_analise { background: var(--info-bg); color: var(--info); }
.tag.avariada, .tag.imobilizada, .tag.alta, .tag.aberta { background: var(--bad-bg); color: var(--bad); }
.tag.oficina, .tag.em_reparacao, .tag.aguarda_pecas, .tag.media { background: var(--warn-bg); color: var(--warn); }
.tag.pendente { background: var(--warn-bg); color: var(--warn); }
.tag.ativo { background: var(--ok-bg); color: var(--ok); }
.tag.bloqueado { background: var(--bad-bg); color: var(--bad); }

/* ---------- formulários */
label { display: block; font-weight: 600; font-size: .9rem; margin: .8rem 0 .25rem; }
label.check { display: flex; gap: .5rem; align-items: center; font-weight: 400; margin: .35rem 0; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=tel], input[type=date], input[type=search], select, textarea {
  width: 100%; font: inherit; padding: .65rem .75rem; border: 1px solid #cfc9bc; border-radius: 10px; background: #fff; color: var(--ink);
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(232,163,23,.35); border-color: var(--accent); }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 .8rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; font: inherit; font-weight: 600;
  padding: .65rem 1.05rem; border-radius: 10px; border: 1px solid transparent; cursor: pointer; text-decoration: none;
  background: var(--brand); color: #fff; min-height: 44px;
}
.btn:hover { filter: brightness(1.12); }
.btn.accent { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: #fff; color: var(--ink); border-color: #cfc9bc; }
.btn.danger { background: var(--bad); }
.btn.small { padding: .35rem .7rem; min-height: 34px; font-size: .88rem; }
.btn.block { width: 100%; }
.btn svg { width: 20px; height: 20px; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }

.chips { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .8rem; }
.chips a { padding: .35rem .75rem; border-radius: 99px; background: #fff; border: 1px solid var(--line); color: var(--ink-2); text-decoration: none; font-size: .88rem; }
.chips a.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- anexos / captura */
.capture { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-top: .3rem; }
.capture .cap { display: flex; flex-direction: column; align-items: center; gap: .25rem; padding: .8rem .3rem; border: 1px dashed #bdb6a6; border-radius: 10px; background: #fbfaf6; cursor: pointer; font-size: .85rem; font-weight: 600; color: var(--ink-2); text-align: center; }
.capture .cap svg { width: 28px; height: 28px; }
.capture .cap.rec { border-color: var(--bad); color: var(--bad); background: var(--bad-bg); }
.capture input[type=file] { display: none; }
.pending { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }
.pending .pf { position: relative; width: 88px; height: 88px; border-radius: 8px; background: var(--mute-bg); overflow: hidden; display: grid; place-items: center; font-size: .72rem; text-align: center; padding: .2rem; color: var(--ink-2); }
.pending .pf img, .pending .pf video { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.pending .pf button { position: absolute; top: 3px; right: 3px; z-index: 2; border: 0; background: rgba(0,0,0,.6); color: #fff; width: 24px; height: 24px; border-radius: 50%; cursor: pointer; line-height: 1; }
.progress { height: 8px; background: var(--mute-bg); border-radius: 99px; overflow: hidden; margin-top: .8rem; display: none; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .4rem; margin-top: .6rem; }
.gallery a img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; background: var(--mute-bg); }
.media-block { margin-top: .6rem; }
.media-block video { width: 100%; max-height: 420px; border-radius: 8px; background: #000; }
.media-block audio { width: 100%; }

/* ---------- linha temporal da avaria */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline > li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; margin-bottom: .6rem; }
.timeline > li.system { background: #faf8f3; border-style: dashed; }
.timeline .meta { font-size: .82rem; color: var(--ink-3); margin-bottom: .3rem; }
.timeline .txt { white-space: pre-wrap; }

table.tbl { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; font-size: .93rem; }
.tbl th, .tbl td { padding: .6rem .7rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { background: #faf8f3; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); }

details.box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .2rem 1rem; margin-bottom: .6rem; }
details.box summary { cursor: pointer; padding: .7rem 0; font-weight: 600; }
details.box[open] { padding-bottom: 1rem; }

/* ---------- autenticação */
.auth { max-width: 420px; margin: 6vh auto 2rem; }
.auth .brand { text-align: center; margin-bottom: 1.2rem; }
.auth .brand .dot { width: 54px; height: 54px; border-radius: 14px; background: var(--brand); color: var(--accent); display: inline-grid; place-items: center; font-weight: 800; font-size: 1.3rem; }

/* ---------- leitor */
.scanner { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 3/4; max-height: 70vh; margin: 0 auto; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; inset: 18% 12%; border: 3px solid var(--accent); border-radius: 16px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); }
.scanner .hint { position: absolute; bottom: .8rem; left: 0; right: 0; text-align: center; color: #fff; font-size: .9rem; text-shadow: 0 1px 3px #000; }

/* ---------- etiquetas para imprimir */
.labels { display: grid; grid-template-columns: repeat(auto-fill, 62mm); gap: 4mm; }
.label { width: 62mm; border: 1px solid #000; border-radius: 3mm; padding: 3mm; text-align: center; background: #fff; break-inside: avoid; }
.label img { width: 44mm; height: 44mm; display: block; margin: 0 auto 2mm; }
.label .plate { font-size: 14pt; }
.label .lt { font-size: 8pt; margin-top: 1.5mm; color: #333; }
@media print {
  .top, .bottom, .noprint, .flash { display: none !important; }
  body { background: #fff; padding: 0; }
  main { max-width: none; padding: 0; }
}
