:root {
  --brand: #571251;
  --brand-2: #e45518;
  --bg: #f4f1f4;
  --card: #ffffff;
  --text: #1f1a1f;
  --muted: #6b616a;
  --line: #e2dbe1;
  --pendente: #8a8a8a;   --pendente-bg: #f6f6f6;
  --parcial: #b7791f;    --parcial-bg: #fff6dc;
  --disponivel: #1d5fd1; --disponivel-bg: #e3edfd;
  --nao: #c0392b;        --nao-bg: #fde6e2;
  --entregue: #2e8540;   --entregue-bg: #e2f3e5;
  --faturado: #7b3fc4;   --faturado-bg: #efe6fb;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; }

/* Login */
.login { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; background: var(--brand); color: #fff; }
.login-logo { width: min(320px, 80vw); height: auto; }
.login h1 { font-size: 1.1rem; font-weight: 500; letter-spacing: .04em; margin: 18px 0 24px; opacity: .9; }
.login form { width: min(360px, 100%); display: grid; gap: 14px; background: #fff; color: var(--text); padding: 20px; border-radius: 14px; }
label { display: grid; gap: 6px; font-size: .9rem; color: var(--muted); }
input, select, textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text); font-size: 1rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); border-color: transparent; }
.error { color: var(--nao); margin: 0; min-height: 1em; font-size: .9rem; }

.btn { border: 1px solid var(--line); background: #fff; color: var(--text); padding: 11px 14px; border-radius: 10px; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: none; border: 0; font-size: 1.4rem; color: inherit; padding: 6px 10px; cursor: pointer; }

/* Topo */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; background: var(--brand); color: #fff; padding: 8px 8px 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
.top-logo { height: 30px; width: auto; }
.top-title { flex: 1; font-weight: 600; letter-spacing: .03em; opacity: .9; }
.toolbar { position: sticky; top: 46px; z-index: 4; background: var(--bg); padding: 10px 16px 8px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.round-info { font-size: .82rem; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--brand-2); transition: width .3s; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 11px; font-size: .85rem; cursor: pointer; white-space: nowrap; }
.chip b { font-weight: 700; margin-left: 4px; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }

/* Lista */
.list { padding: 4px 16px 80px; }
.group-head { position: sticky; top: 196px; z-index: 2; margin: 14px -16px 6px; padding: 6px 16px; background: var(--bg); font-size: .78rem; font-weight: 700; color: var(--brand); text-transform: uppercase; letter-spacing: .08em; }
.card { background: var(--card); border-radius: 12px; border: 1px solid var(--line); border-left: 6px solid var(--c, var(--pendente)); margin-bottom: 8px; padding: 10px 12px; }
.card.s-pendente { --c: var(--pendente); }
.card.s-parcial { --c: var(--parcial); background: var(--parcial-bg); }
.card.s-disponivel { --c: var(--disponivel); background: var(--disponivel-bg); }
.card.s-nao_localizado { --c: var(--nao); background: var(--nao-bg); }
.card.s-entregue { --c: var(--entregue); background: var(--entregue-bg); }
.card.s-faturado { --c: var(--faturado); background: var(--faturado-bg); }
.card-top { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.pos { flex: none; min-width: 52px; text-align: center; font-weight: 800; font-size: 1.25rem; background: var(--brand); color: #fff; border-radius: 8px; padding: 4px 6px; }
.pos.none { background: var(--line); color: var(--muted); font-size: .8rem; padding: 8px 6px; }
.who { flex: 1; min-width: 0; }
.ticket-no { font-weight: 800; font-size: 1.05rem; }
.ticket-no small { font-weight: 500; color: var(--muted); font-size: .75rem; margin-left: 4px; }
.cliente { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { flex: none; font-size: .75rem; font-weight: 700; padding: 4px 8px; border-radius: 999px; color: #fff; background: var(--c, var(--pendente)); }
.meta { font-size: .78rem; color: var(--muted); margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.pieces { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.piece { width: 40px; height: 40px; border-radius: 9px; border: 2px solid var(--disponivel); background: #fff; color: var(--disponivel); font-weight: 700; cursor: pointer; }
.piece.on { background: var(--disponivel); color: #fff; }
.piece:disabled { opacity: .45; cursor: default; }
.piece-all { height: 40px; padding: 0 10px; border-radius: 9px; border: 1px dashed var(--disponivel); background: none; color: var(--disponivel); font-weight: 600; cursor: pointer; }
.count { font-weight: 700; color: var(--muted); margin-left: 4px; }
.mark { font-size: .82rem; margin-top: 8px; }
.mark em { color: var(--muted); }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.actions .btn { padding: 10px 6px; font-size: .85rem; }
.btn.nao { border-color: var(--nao); color: var(--nao); }
.btn.ent { background: var(--entregue); border-color: var(--entregue); color: #fff; }
.btn.fat { background: var(--faturado); border-color: var(--faturado); color: #fff; }
.actions .wide { grid-column: span 3; }
.links { display: flex; gap: 14px; margin-top: 8px; font-size: .82rem; }
.links a { color: var(--brand); cursor: pointer; text-decoration: underline; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* Diálogos */
dialog.sheet { border: 0; border-radius: 16px 16px 0 0; padding: 16px; width: 100%; max-width: 560px; margin: auto auto 0; max-height: 85dvh; overflow: auto; }
dialog.sheet.tall { min-height: 60dvh; }
dialog::backdrop { background: rgba(20, 0, 20, .45); }
@media (min-width: 600px) { dialog.sheet { border-radius: 16px; margin: auto; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.sheet form, #upload-form { display: grid; gap: 12px; }
.row-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.menu-items { display: grid; gap: 8px; }
.menu-items .btn { text-align: left; }
.user-row { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.user-row .u { flex: 1; min-width: 0; }
.user-row small { color: var(--muted); display: block; }
.user-row.off { opacity: .5; }
.user-row .btn { padding: 6px 9px; font-size: .8rem; }
.user-form { margin-top: 16px; }
.user-form h3 { margin: 0; font-size: 1rem; }
.log-row { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.log-row small { color: var(--muted); display: block; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem; z-index: 20; max-width: calc(100% - 32px); }
