:root {
  --bg: #f5f6f8; --panel: #ffffff; --text: #111827; --muted: #6b7280; --line: #e5e7eb; --soft: #f3f4f6;
  --accent: #d6300c; --accent-ink: #ffffff; --pos: #047857; --neg: #b91c1c; --warn: #b45309;
  --side: #111827; --side-text: #e5e7eb; --side-muted: #9ca3af;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 3px rgba(0,0,0,.06);
  --s-excelente: #6d28d9; --s-muito-boa: #047857; --s-boa: #16a34a; --s-normal: #ca8a04; --s-fraca: #ea580c; --s-evitar: #b91c1c;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17; --panel: #131a25; --text: #e5e7eb; --muted: #94a3b8; --line: #243042; --soft: #1a2330;
    --accent: #f0522f; --pos: #34d399; --neg: #f87171; --warn: #fbbf24; --side: #070a10;
    --shadow: none;
    --s-excelente: #a78bfa; --s-muito-boa: #34d399; --s-boa: #4ade80; --s-normal: #facc15; --s-fraca: #fb923c; --s-evitar: #f87171;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg);
  display: grid; grid-template-columns: 220px 1fr; min-height: 100vh;
}
a { color: inherit; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }

/* Sidebar */
.sidebar { background: var(--side); color: var(--side-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px; }
.brand { display: flex; gap: 10px; align-items: center; text-decoration: none; padding: 0 6px; }
.brand span { display: flex; flex-direction: column; line-height: 1.2; }
.brand small { color: var(--side-muted); font-size: 11px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a { text-decoration: none; padding: 8px 10px; border-radius: 8px; color: var(--side-text); }
#nav a:hover { background: rgba(255,255,255,.06); }
#nav a.active { background: rgba(255,255,255,.12); font-weight: 600; }
.quick { margin-top: auto; display: grid; gap: 8px; }
.sidebar .btn { background: transparent; color: var(--side-text); border-color: #374151; }
.sidebar .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* Main */
main { padding: 24px 28px 60px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.stack { display: grid; gap: 16px; }
@media (max-width: 1000px) { .g2, .g3 { grid-template-columns: 1fr; } }
@media (max-width: 760px) { body { grid-template-columns: 1fr; } .sidebar { position: static; height: auto; } main { padding: 16px; } }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; margin-bottom: 16px; }
@media (max-width: 1000px) { .kpis { grid-template-columns: repeat(2, minmax(0,1fr)); } }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.01em; }
.kpi .foot { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.hero { border-color: var(--accent); }

/* Buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--neg); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
form .sec { margin-bottom: 16px; }
.fields { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
@media (max-width: 1000px) { .fields { grid-template-columns: repeat(2, minmax(0,1fr)); } }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.span2 { grid-column: span 2; } .field.full { grid-column: 1 / -1; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; }
.field .hint { font-size: 11px; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.checks label { display: inline-flex; gap: 6px; align-items: center; padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; user-select: none; }
.checks input { width: auto; margin: 0; }
.checks label:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.form-foot { display: flex; gap: 8px; justify-content: flex-end; position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input[type=search] { flex: 1 1 220px; width: auto; }
.filters select { width: auto; }
.filters label { display: inline-flex; align-items: center; gap: 6px; }
.filters label input { width: auto; }

/* Tables & lists */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: var(--soft); }
tr:last-child td { border-bottom: 0; }
.thumb { width: 34px; height: 47px; object-fit: cover; border-radius: 3px; background: var(--soft); display: block; }
.thumb.empty { border: 1px dashed var(--line); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list a { text-decoration: none; }
.empty-state { color: var(--muted); padding: 20px 0; text-align: center; }

/* Badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--soft); border: 1px solid var(--line); white-space: nowrap; }
.badge.accent { background: color-mix(in srgb, var(--accent) 12%, transparent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--accent); }
.score { display: inline-flex; align-items: center; justify-content: center; min-width: 36px; padding: 1px 7px; border-radius: 6px; font-weight: 700; font-size: 12px; color: #fff; font-variant-numeric: tabular-nums; }
.score.none { background: var(--soft); color: var(--muted); border: 1px solid var(--line); font-weight: 500; }
.score.excelente { background: var(--s-excelente); } .score.muito-boa { background: var(--s-muito-boa); } .score.boa { background: var(--s-boa); }
.score.normal { background: var(--s-normal); } .score.fraca { background: var(--s-fraca); } .score.evitar { background: var(--s-evitar); }
@media (prefers-color-scheme: dark) { .score:not(.none) { color: #0b0f17; } }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }

/* Detail */
.detail { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .detail { grid-template-columns: 1fr; } }
.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.photos img, .photo-ph { width: 100%; aspect-ratio: 63/88; object-fit: cover; border-radius: 8px; background: var(--soft); border: 1px solid var(--line); }
.photo-ph { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; border-style: dashed; }
.photos img { cursor: zoom-in; }
dl.info { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; }
.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: 170px 1fr 48px; gap: 10px; align-items: center; font-size: 13px; }
.bar .track { height: 8px; background: var(--soft); border-radius: 4px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 4px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); }
.chart .line { stroke: var(--accent); stroke-width: 2.25; fill: none; }
.chart .ref { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1.25; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .dot { fill: var(--accent); }

/* Photo uploader */
.photo-field { display: flex; flex-direction: column; gap: 6px; }
.photo-field .preview { width: 100%; max-width: 160px; aspect-ratio: 63/88; border-radius: 8px; border: 1px dashed var(--line); background: var(--soft) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; cursor: pointer; }
.photo-field input[type=file] { display: none; }

/* Boosters */
.boosters { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.booster { border: 1px solid var(--line); border-radius: 8px; padding: 8px; min-height: 64px; font-size: 12px; background: var(--panel); text-align: left; font: inherit; color: inherit; }
.booster .n { font-weight: 700; font-size: 11px; color: var(--muted); }
.booster.open { background: var(--soft); }
.booster.hit { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.booster.next { border-style: dashed; cursor: pointer; }
.booster.open { cursor: pointer; }
.booster .r { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* Location tree */
.tree { list-style: none; padding-left: 0; margin: 0; }
.tree ul { list-style: none; padding-left: 18px; margin: 4px 0; border-left: 1px solid var(--line); }
.tree li { padding: 2px 0; }
.tree .node { font-weight: 600; }
.tree mark { background: color-mix(in srgb, var(--accent) 25%, transparent); color: inherit; border-radius: 3px; }

/* Score editor */
.score-editor { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
@media (max-width: 1000px) { .score-editor { grid-template-columns: repeat(2, minmax(0,1fr)); } }
.score-total { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.score-total .score { font-size: 16px; padding: 4px 10px; }

/* Modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 12px; padding: 20px; width: min(560px, 100%); border: 1px solid var(--line); }
.modal.wide { width: min(900px, 100%); }
.modal h2 { font-size: 17px; }
.modal .fields { grid-template-columns: repeat(2, minmax(0,1fr)); }
.modal .form-foot { position: static; background: none; padding-bottom: 0; }
.modal img.zoom { width: 100%; border-radius: 8px; }
#toast { position: fixed; bottom: 20px; right: 20px; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; z-index: 60; max-width: 360px; }
#toast.show { opacity: 1; transform: none; }
#toast.err { background: var(--neg); color: #fff; }
.notice { border: 1px solid var(--line); border-left: 3px solid var(--warn); padding: 10px 12px; border-radius: 8px; background: var(--panel); margin-bottom: 16px; }
.split { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.split h2 { margin: 0; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.pcard { text-decoration: none; display: flex; flex-direction: column; gap: 8px; }
.pcard:hover { border-color: var(--muted); }
.pcard .row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.progress { height: 6px; background: var(--soft); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }

/* Login */
body.logged-out { grid-template-columns: 1fr; }
body.logged-out .sidebar { display: none; }
.login { max-width: 360px; margin: 10vh auto 0; text-align: center; }
.login form { text-align: left; margin-top: 16px; }
.login h1 { margin-top: 8px; }

/* Scanner */
.scan-drop { display: flex; align-items: center; justify-content: center; min-height: 220px; border: 2px dashed var(--line); border-radius: 12px; cursor: pointer;
  background: var(--soft) center/contain no-repeat; text-align: center; padding: 16px; font-weight: 600; }
.scan-drop:hover { border-color: var(--accent); }
.scan-drop input { display: none; }
.scan-drop.has-img span { background: var(--panel); padding: 4px 10px; border-radius: 8px; border: 1px solid var(--line); }
.scan-drop.disabled { opacity: .5; cursor: not-allowed; }
.reading { margin-top: 12px; }
.cands { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-top: 16px; }
.cand { display: grid; grid-template-columns: 90px 1fr; gap: 12px; align-items: start; }
.cand img, .cand .photo-ph { width: 90px; aspect-ratio: 63/88; object-fit: cover; border-radius: 6px; cursor: zoom-in; }
.cand-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cand-body .row { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; }
.cand-body .btn { margin-top: 6px; align-self: flex-start; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Celular: menu compacto em uma faixa rolável no topo */
@media (max-width: 760px) {
  body { grid-template-columns: minmax(0, 1fr); }
  main { min-width: 0; }
  .sidebar { padding: 10px 10px 8px; gap: 8px; z-index: 20; position: sticky; top: 0; min-width: 0; }
  .brand small { display: none; }
  #nav { flex-direction: row; overflow-x: auto; gap: 4px; scrollbar-width: none; }
  #nav::-webkit-scrollbar { display: none; }
  #nav a { white-space: nowrap; padding: 6px 10px; font-size: 13px; }
  .quick { margin-top: 0; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .quick .btn { padding: 6px 4px; font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .kpi .value { font-size: 18px; }
  .fields, .modal .fields { grid-template-columns: 1fr 1fr; }
  #cat-form .fields { grid-template-columns: 1fr 1fr !important; }
}
