/* Painel do gestor. Estilo "framed sheet": moldura verde-acinzentada (do verde do app) com a página numa folha branca.
   Grade: barra lateral 232 + folha; dentro da folha, 24 de respiro e um único espaçamento de 16 entre blocos.
   Visão geral: 1fr + 384 + 16 = largura útil da folha. */
:root {
  --ground: #f1f5f2;
  --surface: #ffffff;
  --raised: #f5f7f6;
  --active: #e3e9e5;
  --border: #e6eae7;
  --rule: #eff2f0;
  --control: #ccd3cf;
  --text: #111814;
  --muted: #56605a;
  --faint: #66706a;
  --accent: #16a34a;
  --primary: #111814;
  --primary-ink: #ffffff;
  --positive: #15803d; --negative: #c4242a; --warning: #92400e;
  --pill-positive-bg: #dcfae5; --pill-positive-ink: #04250e;
  --pill-negative-bg: #ffedea; --pill-negative-ink: #831c1e;
  --pill-warning-bg: #fffbeb; --pill-warning-ink: #92400e;
  --pill-neutral-bg: #eef1ef; --pill-neutral-ink: #3d4440;
  --chart-1: #16a34a; --chart-2: #86c79c; --chart-3: #b08a2e; --chart-muted: #cdd5d0;
  --chart-mark: var(--text); --chart-span: 0.06;
  --grid: var(--rule); --axis-ink: var(--muted); --ink: var(--text);

  /* Fonte do sistema: SF Pro no Mac e no iPhone; Inter nos outros (o mais perto da SF fora da Apple) */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "IBM Plex Mono", monospace;
  --fs-title: 28px; --fs-section: 16px; --fs-kpi: 24px; --fs-lead: 32px; --fs-body: 14px; --fs-small: 12px;

  --sidebar-width: 232px;
  --top: 48px;
  --pad: 24px;
  --gap: 16px;
  --card-pad: 20px;
  --radius-sheet: 16px;
  /* Cantos e controles no padrão do macOS */
  --radius-card: 12px;
  --radius-control: 8px;
  --control-height: 34px;
  --hairline: 0 0 0 0.5px rgba(17, 24, 20, 0.12);
  --lift: 0 1px 2px rgba(17, 24, 20, 0.06), 0 0 0 0.5px rgba(17, 24, 20, 0.10);
  --focus-ring: 0 0 0 3px rgba(22, 163, 74, 0.32);
  --row-height: 48px;
  --nav-row: 32px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --t-press: 120ms; --t-hover: 150ms; --t-ui: 200ms;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--text); font: var(--fs-body)/20px var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4, p, figure, ul, ol, dl, dd { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, svg { display: block; }
img { max-width: 100%; }
/* Prevent unsized SVG icons from stretching in flex containers */
button svg, a svg, .nav-item svg { flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.num, table, .kpi-value { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.boot { display: grid; place-items: center; min-height: 100svh; color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- moldura em L e folha ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); grid-template-rows: var(--top) 1fr; min-height: 100svh; }
.sidebar { grid-row: 1 / 3; position: sticky; top: 0; height: 100svh; display: flex; flex-direction: column; gap: 2px; padding: 12px; overflow: auto; }
.brand { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 8px; font-weight: 600; font-size: 15px; }
.brand-mark { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 6px; background: var(--text); flex: none; }
.brand-mark svg { width: 15px; height: 15px; fill: var(--accent); }
.org-switch { display: flex; align-items: center; gap: 10px; width: 100%; margin: 10px 0 8px; padding: 8px; border: 1px solid transparent; box-shadow: var(--lift); border-radius: var(--radius-card); background: var(--surface); text-align: left; cursor: pointer; transition: border-color var(--t-hover); }
.org-switch:hover { border-color: var(--control); }
.org-switch .org-text { display: grid; min-width: 0; flex: 1; }
.org-switch b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.org-switch small { color: var(--muted); font-size: var(--fs-small); }
.org-switch svg { width: 14px; height: 14px; color: var(--muted); flex: none; }
.group-label { margin: 18px 8px 6px; font-size: var(--fs-small); color: var(--faint); }
.nav-item { display: flex; align-items: center; gap: 10px; height: var(--nav-row); padding: 0 8px; border-radius: 8px; color: var(--muted); transition: background-color var(--t-hover), color var(--t-hover); }
.nav-item svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover { background: var(--raised); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--active); color: var(--text); }
.nav-item .count { margin-left: auto; font-size: var(--fs-small); color: var(--pill-negative-ink); background: var(--pill-negative-bg); padding: 0 7px; border-radius: 999px; line-height: 20px; }
.sidebar .bottom { margin-top: auto; display: grid; gap: 8px; }
.plan-box { padding: 12px; border-radius: var(--radius-card); background: var(--surface); border: 0; box-shadow: var(--lift); display: grid; gap: 8px; }
.plan-box .plan-line { display: flex; justify-content: space-between; font-size: var(--fs-small); color: var(--muted); }
.plan-box b { color: var(--text); font-weight: 600; font-size: var(--fs-body); }
.track { height: 6px; border-radius: 999px; background: var(--active); overflow: hidden; }
.track i { display: block; height: 100%; background: var(--text); border-radius: 999px; }
.lang-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 8px; font-size: var(--fs-small); color: var(--muted); }
.lang-select { width: auto; min-width: 0; padding-block: 4px; font-size: var(--fs-small); }
.user-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.user-row .who { display: grid; min-width: 0; flex: 1; }
.user-row .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row .who small { color: var(--muted); font-size: var(--fs-small); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar { display: flex; align-items: center; gap: 12px; padding: 0 16px 0 0; }
.search-btn { display: flex; align-items: center; gap: 8px; width: min(548px, 100%); height: 32px; margin: 0 auto; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--faint); cursor: pointer; transition: border-color var(--t-hover); }
.search-btn:hover { border-color: var(--control); }
.search-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.search-btn kbd { margin-left: auto; font: inherit; font-size: var(--fs-small); padding: 0 6px; border-radius: 4px; background: var(--raised); color: var(--muted); }
.demo-flag { font-size: var(--fs-small); padding: 4px 10px; border-radius: 999px; background: var(--pill-warning-bg); color: var(--pill-warning-ink); white-space: nowrap; }
.menu-toggle { display: none; }
.theme-toggle { margin-left: auto; }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle + .bell { margin-left: 0; }

.sheet { grid-column: 2; margin: 0 8px 8px 0; padding: var(--pad); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sheet); min-width: 0; }

/* ---------- título e filtros ---------- */
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.title-row h1 { font-size: var(--fs-title); line-height: 34px; font-weight: 700; letter-spacing: -0.02em; }
.title-row .sub { margin-top: 4px; color: var(--muted); font-size: 15px; }
.title-row .sub b { color: var(--text); font-weight: 500; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumbs { display: flex; align-items: center; gap: 8px; font-size: var(--fs-section); }
.crumbs a { color: var(--muted); font-weight: 600; }
.crumbs a:hover { color: var(--text); }
.crumbs h1 { font-size: var(--fs-section); line-height: 24px; font-weight: 600; }
.crumbs .chip { font-size: var(--fs-small); color: var(--muted); background: var(--raised); padding: 2px 8px; border-radius: 6px; font-weight: 400; white-space: nowrap; }
.filters { display: flex; align-items: center; gap: 8px; margin-bottom: var(--gap); flex-wrap: wrap; }
.filters .spacer { flex: 1; }
.stamp { color: var(--faint); font-size: var(--fs-small); }

/* ---------- painéis ---------- */
.overview { display: grid; grid-template-columns: minmax(0, 1fr) 384px; gap: var(--gap); align-items: start; }
.stack { display: grid; gap: var(--gap); align-content: start; min-width: 0; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); align-items: start; }
.pair.stretch { align-items: stretch; }
.rank { display: flex; flex-direction: column; }
.rank-total { margin-top: auto; padding-top: 12px; display: flex; justify-content: space-between; color: var(--muted); border-top: 1px solid var(--rule); }
.rank-total b { color: var(--text); font-weight: 500; }
.panel { background: var(--surface); border: 0; box-shadow: var(--lift); border-radius: var(--radius-card); padding: var(--card-pad); min-width: 0; }
.panel > header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel h2 { font-size: var(--fs-section); line-height: 22px; font-weight: 600; }
.panel .meta { color: var(--faint); font-size: var(--fs-small); }
.rail-head { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 8px; }
.rail-head h2 { font-size: var(--fs-section); font-weight: 600; }
.rail-block + .rail-block { margin-top: 8px; }
.card-link { display: inline-flex; align-items: center; gap: 2px; padding: 0; border: 0; background: none; color: var(--text); font-weight: 500; cursor: pointer; text-underline-offset: 3px; white-space: nowrap; }
.card-link:hover { text-decoration: underline; }
.chart { position: relative; min-width: 0; }

/* KPIs: uma faixa dividida */
.kpis { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); border: 0; box-shadow: var(--lift); background: var(--surface); border-radius: var(--radius-card); }
.kpi { padding: 16px var(--card-pad); min-width: 0; }
.kpi + .kpi { border-left: 1px solid var(--border); }
.kpi-label { color: var(--muted); }
.kpi-value { margin-top: 6px; font-size: var(--fs-kpi); line-height: 30px; font-weight: 500; letter-spacing: -0.01em; }
.kpi-value small { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 2px; }
.kpi-value.lead { font-size: var(--fs-lead); line-height: 38px; }
.delta { margin-top: 4px; font-size: var(--fs-small); color: var(--muted); }
.delta .good { color: var(--positive); } .delta .bad { color: var(--negative); }

/* listas */
.rows { display: grid; }
.row { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 0; }
.row + .row { border-top: 1px solid var(--rule); }
.row .grow { flex: 1; min-width: 0; display: grid; }
.row .grow b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .grow small { color: var(--muted); font-size: var(--fs-small); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.row:hover b { text-decoration: underline; text-underline-offset: 3px; }
.view-all { display: flex; justify-content: center; align-items: center; width: 100%; height: 30px; margin-top: 8px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); font-weight: 500; cursor: pointer; transition: background-color var(--t-hover); }
.view-all:hover { background: var(--raised); }

/* pessoas: inicial e um tom pálido próprio */
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: var(--fs-small); font-weight: 600; color: #1d2a22; background: hsl(var(--h, 140) 45% 88%); }
.avatar.lg { width: 36px; height: 36px; font-size: 14px; }
.avatar.xl { width: 56px; height: 56px; font-size: 20px; }
img.avatar { object-fit: cover; background: var(--active); }
img.avatar.org-logo { border-radius: 8px; object-fit: contain; background: var(--surface); box-shadow: inset 0 0 0 1px var(--border); }

/* sino */
.bell { position: relative; margin-left: auto; }
.bell-n { position: absolute; top: 2px; right: 2px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: var(--negative); color: #fff; font-size: 10px; font-weight: 600; line-height: 16px; text-align: center; }
.notif-dialog .dialog-box { width: min(480px, calc(100vw - 32px)); max-height: min(640px, calc(100svh - 64px)); overflow: auto; }
.notif { align-items: flex-start; padding: 10px 0; text-decoration: none; color: inherit; }
.notif .grow small { color: var(--muted); }
.notif.unread b::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--accent); vertical-align: 1px; }

/* cadastro e logo */
textarea.input { height: auto; min-height: 84px; padding: 8px 10px; resize: vertical; font: inherit; }
fieldset.field { border: 0; padding: 0; margin: 0; }
fieldset.field legend { font-weight: 500; margin-bottom: 8px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 32px; font-weight: 400 !important; }
.tpl-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 12px; padding: 4px 0 0 24px; }
.logo-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.logo-preview { width: 72px; height: 72px; border-radius: 12px; object-fit: contain; background: var(--raised); box-shadow: inset 0 0 0 1px var(--border); display: grid; place-items: center; color: var(--muted); font-size: var(--fs-small); }
.person { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.person span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- tabelas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { height: 36px; padding: 0 12px; text-align: left; font-weight: 400; font-size: var(--fs-small); color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
th button:focus-visible { outline: 2px solid var(--accent); }
td { padding: 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--raised); }
tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
th.n, td.n { text-align: right; }
td .sub { display: block; font-size: var(--fs-small); color: var(--muted); }
td b { font-weight: 500; }
.ident { max-width: 420px; }
.ident b, .ident .sub { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phone-line { display: none !important; }

.pill { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: var(--fs-small); font-weight: 500; background: var(--pill-neutral-bg); color: var(--pill-neutral-ink); white-space: nowrap; flex: none; }
.pill.pos { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.pill.neg { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.pill.warn { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }
.dash { color: var(--faint); }

/* ---------- controles ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: var(--control-height); padding: 0 12px; border-radius: var(--radius-control); border: 1px solid var(--control); background: var(--surface); font-weight: 500; cursor: pointer; white-space: nowrap; transition: background-color var(--t-hover), transform var(--t-press) var(--ease-out), opacity var(--t-hover); }
.btn:hover { background: var(--raised); }
.btn:active { filter: brightness(0.92); }
.btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.primary:hover { opacity: 0.88; }
.btn.danger { color: var(--negative); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--raised); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; transform: none; }
.icon-btn { width: var(--control-height); padding: 0; }
.icon-btn svg { fill: none; stroke: currentColor; stroke-width: 1.5; width: 18px; height: 18px; flex: none; }
.input, select.input { height: var(--control-height); padding: 0 10px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); min-width: 0; }
.input::placeholder { color: var(--faint); }
.input:focus, select.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.search { position: relative; width: min(300px, 100%); }
.search .input { width: 100%; padding-left: 32px; }
.search svg { position: absolute; left: 10px; top: 10px; width: 14px; height: 14px; fill: none; stroke: var(--faint); stroke-width: 1.5; pointer-events: none; }
.field { display: grid; gap: 8px; }
.field label, .field .label { font-weight: 500; }
.field .hint { color: var(--muted); font-size: var(--fs-small); }
.field .input { height: 40px; border-color: var(--border); border-radius: 10px; }
.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--border); margin-bottom: 22px; overflow-x: auto; scrollbar-width: none; }
.tabs button { position: relative; flex: none; padding: 10px 0; border: 0; background: none; color: var(--muted); cursor: pointer; transition: color var(--t-hover); }
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); }
.tabs button[aria-selected="true"]::after { content: ""; position: absolute; left: -4px; right: -4px; bottom: -1px; height: 2px; background: var(--text); }
.tabs .n { color: var(--faint); margin-left: 4px; }
.segmented { display: inline-flex; padding: 2px; border-radius: 9px; background: rgba(118, 128, 122, 0.14); }
.segmented button { height: 30px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; transition: background-color var(--t-hover), color var(--t-hover); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(17, 24, 20, 0.14), 0 0 0 0.5px rgba(17, 24, 20, 0.08); font-weight: 500; }

.empty { display: grid; place-items: center; gap: 8px; min-height: 96px; padding: 16px; border: 0; background: var(--raised); border-radius: var(--radius-card); color: var(--muted); text-align: center; }
.error-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: var(--radius-control); background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.skeleton { background: var(--raised); border-radius: 4px; }
.notice { padding: 10px 14px; border-radius: var(--radius-card); background: var(--pill-warning-bg); border: 0; color: var(--pill-warning-ink); font-size: 13px; }
.notice.error { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.ai-status { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-small); padding: 4px 10px; border-radius: 999px; }
.ai-status.ok { background: var(--pill-positive-bg, #d1fae5); color: var(--pill-positive-ink, #065f46); }
.ai-status svg { width: 13px; height: 13px; }
.field-label { display: flex; flex-direction: column; gap: 5px; font-size: var(--fs-small); color: var(--muted); }
.field-label .input { margin-top: 2px; }
.ai-report { display: flex; flex-direction: column; gap: 0; }
.ai-report-header { display: flex; align-items: center; gap: 8px; padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--border); font-weight: 600; }
.ai-report-header svg { width: 16px; height: 16px; color: var(--accent); flex-shrink: 0; }
.ai-report-body { line-height: 1.65; color: var(--text); }
.ai-report-body .report-title { display: block; font-size: 15px; font-weight: 700; color: var(--text); margin: 0 0 16px; }
.ai-report-body h2 { font-size: var(--fs-section); font-weight: 700; margin: 22px 0 6px; color: var(--text); border-top: 1px solid var(--rule); padding-top: 16px; }
.ai-report-body h2:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.ai-report-body h3 { font-size: 14px; font-weight: 600; margin: 14px 0 4px; }
.ai-report-body ul, .ai-report-body ol { margin: 6px 0 10px 18px; display: flex; flex-direction: column; gap: 4px; }
.ai-report-body ul li { list-style: disc; }
.ai-report-body ol { list-style: decimal; }
.ai-report-body ol li { list-style: decimal; }
.ai-report-body p { margin: 6px 0; }
.ai-report-body strong { font-weight: 600; }
.ai-report-body em { font-style: italic; }

/* ---------- visão geral ---------- */
.legend { display: flex; gap: 14px; color: var(--muted); font-size: var(--fs-small); }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
.map { height: 320px; border-radius: var(--radius-control); overflow: hidden; background: var(--raised); z-index: 0; }
.map.tall { height: calc(100svh - 230px); min-height: 420px; }
.map-split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--gap); align-items: start; }
.map-list { max-height: calc(100svh - 230px); min-height: 420px; overflow: auto; }
.map-list .row { cursor: pointer; padding-right: 4px; }
.map-list .row[aria-selected="true"] { background: var(--active); border-radius: 6px; }
.leaflet-container { font: inherit; }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; line-height: 18px; }
.leaflet-popup-content b { font-weight: 600; }
.leaflet-popup-content a { color: var(--text); text-decoration: underline; }

/* ---------- detalhe ---------- */
.kv { display: grid; grid-template-columns: minmax(120px, 36%) 1fr; }
.kv dt, .kv dd { padding: 9px 0; border-bottom: 1px solid var(--rule); }
.kv dt { color: var(--muted); }
.kv dd { font-weight: 500; }
.kv > :nth-last-child(-n + 2) { border-bottom: 0; }
.check-section + .check-section { margin-top: 18px; }
.check-section h3 { font-size: var(--fs-body); font-weight: 600; margin-bottom: 4px; }
.check-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; min-height: 44px; padding: 8px 0; }
.check-row + .check-row { border-top: 1px solid var(--rule); }
.check-row small { display: block; color: var(--pill-negative-ink); font-size: 13px; margin-top: 2px; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--gap); }
.photo { display: grid; gap: 8px; padding: 0; border: 0; background: none; text-align: left; cursor: zoom-in; }
.photo-frame { position: relative; aspect-ratio: 4 / 3; border-radius: 8px; overflow: hidden; background: var(--raised); }
.photo-frame img { width: 100%; height: 100%; object-fit: cover; transition: transform 300ms var(--ease-out); }
.photo:hover .photo-frame img { transform: scale(1.03); }
.photo-frame .pill { position: absolute; left: 8px; top: 8px; }
.photo .cap { display: grid; gap: 2px; }
.photo .cap b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo .cap small { color: var(--muted); font-size: var(--fs-small); }

/* visualizador de foto */
dialog { padding: 0; border: 0; border-radius: 14px; color: var(--text); background: var(--surface); box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28); max-width: calc(100vw - 32px); }
dialog::backdrop { background: rgba(10, 16, 12, 0.55); }
.viewer { width: min(1180px, calc(100vw - 32px)); }
.viewer-body { display: grid; grid-template-columns: minmax(0, 1fr) 340px; max-height: calc(100svh - 64px); }
.viewer-img { background: #0b0f0c; display: grid; place-items: center; min-height: 360px; position: relative; }
.viewer-img img { max-height: calc(100svh - 64px); width: 100%; object-fit: contain; }
.viewer-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, 0.92); cursor: pointer; display: grid; place-items: center; }
.viewer-nav svg { width: 18px; height: 18px; fill: none; stroke: #111; stroke-width: 2; }
.viewer-nav.prev { left: 12px; } .viewer-nav.next { right: 12px; }
.viewer-side { padding: 20px; overflow: auto; display: grid; gap: 14px; align-content: start; }
.viewer-side header { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.viewer-side h2 { font-size: var(--fs-section); font-weight: 600; }
.hash { display: flex; gap: 8px; align-items: start; }
.hash code { font-family: var(--mono); font-size: 12px; line-height: 18px; word-break: break-all; color: var(--muted); }
.dialog-box { width: min(440px, calc(100vw - 32px)); padding: 20px; display: grid; gap: 14px; }
.dialog-box h2 { font-size: var(--fs-section); font-weight: 600; }
.dialog-box .actions { justify-content: flex-end; }

/* paleta de comandos */
.palette { width: min(600px, calc(100vw - 32px)); margin-top: 12vh; }
.palette input { width: 100%; height: 52px; padding: 0 18px; border: 0; border-bottom: 1px solid var(--border); font-size: 16px; background: transparent; }
.palette input:focus { outline: none; }
.palette ul { max-height: 360px; overflow: auto; padding: 6px; }
.palette li button { display: flex; width: 100%; align-items: center; gap: 10px; min-height: 40px; padding: 6px 12px; border: 0; border-radius: 6px; background: none; text-align: left; cursor: pointer; }
.palette li button[aria-selected="true"] { background: var(--active); }
.palette li small { margin-left: auto; color: var(--muted); font-size: var(--fs-small); white-space: nowrap; }
.palette .group { padding: 8px 12px 4px; font-size: var(--fs-small); color: var(--faint); }

/* ---------- autenticidade ---------- */
.drop { display: grid; place-items: center; gap: 10px; min-height: 220px; padding: 24px; border: 1px dashed var(--control); border-radius: var(--radius-card); text-align: center; color: var(--muted); cursor: pointer; transition: background-color var(--t-hover), border-color var(--t-hover); }
.drop:hover, .drop.over { background: var(--raised); border-color: var(--text); }
.drop b { color: var(--text); font-weight: 500; font-size: 15px; }
.drop svg { width: 28px; height: 28px; fill: none; stroke: var(--muted); stroke-width: 1.5; }
.result { display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 12px 0; }
.result + .result { border-top: 1px solid var(--rule); }
.result .thumb { width: 96px; aspect-ratio: 4 / 3; border-radius: 6px; object-fit: cover; background: var(--raised); }
.result .thumb.none { display: grid; place-items: center; color: var(--faint); font-size: var(--fs-small); }

/* ---------- configurações ---------- */
.settings { max-width: 1152px; }
.set-row { display: grid; grid-template-columns: minmax(0, 400px) minmax(0, 1fr); gap: 32px; padding: 32px 0; }
.set-row + .set-row { border-top: 1px solid var(--border); }
.set-row:first-child { padding-top: 8px; }
.set-label { padding-top: 8px; display: grid; gap: 4px; align-content: start; }
.set-label h2 { font-size: var(--fs-section); font-weight: 500; }
.set-label p { color: var(--muted); }
.set-panel { background: var(--raised); border-radius: 16px; padding: 16px; display: grid; gap: 16px; }
.set-panel .actions { justify-content: flex-end; }
.danger-zone .set-label h2 { color: var(--negative); }

/* toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; }
.toast { padding: 10px 16px; border-radius: 999px; background: var(--text); color: var(--primary-ink); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); animation: toast-in 220ms var(--ease-out); }
.toast.bad { background: var(--negative); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* login */
.login { min-height: 100svh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); background: var(--ground); }
.login-side { padding: 48px; display: grid; align-content: space-between; gap: 32px; }
.login-card { align-self: center; justify-self: center; width: min(400px, 100%); display: grid; gap: 16px; }
.login-card h1 { font-size: var(--fs-title); line-height: 34px; font-weight: 700; letter-spacing: -0.02em; }
.login-card .btn { height: 44px; }
.login-shot { margin: 8px 8px 8px 0; border-radius: var(--radius-sheet); overflow: hidden; position: relative; background: #0b0f0c; }
.login-shot img { width: 100%; height: 100%; object-fit: cover; opacity: 0.9; }
.login-stamp { position: absolute; left: 24px; bottom: 24px; padding: 14px 16px; border-radius: 12px; background: rgba(2, 6, 16, 0.8); color: #f8fafc; font-size: 13px; line-height: 19px; font-variant-numeric: tabular-nums; }
.login-stamp b { color: #4ade80; font-weight: 600; }

/* ── Login video ── */
.login-video { position:absolute; inset:0; width:100%; height:100%; object-fit:cover; }

.error { color: var(--negative); }


/* ---------- rotinas ---------- */
.week { display: inline-flex; gap: 4px; }
.day { display: grid; justify-items: center; gap: 2px; }
.day i, .legend .lg { display: block; width: 18px; height: 18px; border-radius: 4px; background: var(--raised); }
.legend .lg { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.day small { font-size: 11px; line-height: 12px; color: var(--faint); }
.k-done i, .lg.k-done { background: var(--accent); }
.k-late i, .lg.k-late { background: var(--pill-negative-bg); box-shadow: inset 0 0 0 1.5px var(--negative); }
.k-pending i, .lg.k-pending { background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--control); }
.k-off i, .lg.k-off { background: var(--raised); }
.people { display: inline-flex; margin-bottom: 2px; }
.people .avatar { width: 24px; height: 24px; font-size: 11px; box-shadow: 0 0 0 2px var(--surface); }
.people .avatar + .avatar { margin-left: -6px; }
.presets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--gap); }
.preset { display: grid; gap: 6px; align-content: start; min-height: 132px; padding: 16px; text-align: left; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface); cursor: pointer; transition: border-color var(--t-hover), background-color var(--t-hover); }
.preset:hover:not([disabled]) { border-color: var(--text); }
.preset[disabled] { opacity: 0.6; cursor: not-allowed; }
.preset b { font-weight: 600; font-size: 15px; }
.preset span { color: var(--muted); }
.preset small { margin-top: auto; color: var(--faint); font-size: var(--fs-small); }
.preset.blank { background: var(--raised); }

.builder { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: var(--gap); align-items: start; }
.preview-col { position: sticky; top: 16px; }
.preview { border: 1px solid var(--border); border-radius: 16px; background: var(--ground); padding: 16px; display: grid; gap: 12px; min-height: 520px; grid-template-rows: auto auto 1fr auto; }
.pv-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.pv-top b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-top span { color: var(--muted); font-size: var(--fs-small); white-space: nowrap; }
.pv-body { background: var(--surface); border-radius: 12px; padding: 20px 16px; display: grid; gap: 12px; align-content: start; }
.pv-section { font-size: var(--fs-small); color: var(--positive); font-weight: 600; }
.pv-q { font-size: 20px; line-height: 26px; font-weight: 600; letter-spacing: -0.01em; }
.pv-q small { font-size: 14px; font-weight: 400; color: var(--muted); }
.pv-help { color: var(--muted); font-size: 15px; line-height: 22px; }
.pv-choices { display: grid; gap: 8px; }
.pv-choices.two { grid-template-columns: 1fr 1fr; }
.pv-choices button { min-height: 52px; border: 1.5px solid var(--control); border-radius: 12px; background: var(--surface); font-weight: 600; font-size: 15px; cursor: pointer; transition: background-color var(--t-hover), border-color var(--t-hover); }
.pv-choices button[aria-pressed="true"] { border-color: var(--accent); background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.pv-choices button.problem[aria-pressed="true"] { border-color: var(--negative); background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.pv-input { min-height: 52px; padding: 14px; border: 1.5px solid var(--control); border-radius: 12px; color: var(--faint); font-size: 15px; }
.pv-input.tall { min-height: 96px; }
.pv-input span { color: var(--muted); }
.pv-camera { display: grid; place-items: center; min-height: 140px; border-radius: 12px; background: #0b1220; color: #fff; font-weight: 600; }
.pv-photo { font-size: 14px; color: var(--pill-negative-ink); }
.pv-photo.optional { color: var(--muted); }
.pv-photo span { text-decoration: underline; color: var(--text); }
.pv-review { display: grid; gap: 6px; }
.pv-review p { display: flex; gap: 8px; }
.pv-review span { width: 18px; color: var(--faint); }
.pv-review span.ok { color: var(--positive); font-weight: 600; }
.pv-foot { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }
.pv-foot .btn { height: 44px; }

.items { display: grid; gap: 10px; }
.item-card { display: grid; gap: 10px; padding: 14px; border: 0; box-shadow: var(--lift); border-radius: var(--radius-card); background: var(--surface); transition: box-shadow var(--t-hover); }
.item-card:focus-within { box-shadow: var(--lift), var(--focus-ring); }
.item-card.is-title { background: var(--raised); }
.item-head { display: flex; align-items: center; gap: 6px; }
.item-head select.input { width: auto; }
.item-head .spacer { flex: 1; }
.item-n { width: 24px; color: var(--faint); font-weight: 500; }
.item-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.item-foot .hint { font-size: var(--fs-small); }
.mini-check { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.mini-check input, .toggle-row input, .person-pick input { width: 16px; height: 16px; accent-color: var(--text); }
.input.area { height: auto; padding: 8px 10px; line-height: 20px; resize: vertical; font: inherit; }
.field .input.area { padding: 10px 12px; }
.stack > .segmented, .item-card > .segmented { justify-self: start; }
.add-types { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented.wrap { flex-wrap: wrap; }
.pair-inputs { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 8px; }
.item-card.is-title .item-head .input { flex: 1; }
/* prévia do PDF no editor de modelos */
.tpl-doc { --text: #111814; --muted: #56605a; --border: #e6eae7; --rule: #eff2f0; --raised: #f5f7f6; --pill-positive-bg: #dcfae5; --pill-positive-ink: #04250e; --pill-negative-bg: #ffedea; --pill-negative-ink: #831c1e; color: var(--text); border: 1px solid var(--border); border-radius: 12px; background: #fff; padding: 18px; display: grid; gap: 8px; font-size: 12px; box-shadow: 0 6px 20px rgba(17, 24, 20, 0.06); }
.tpl-doc .doc-head { display: grid; gap: 2px; padding-bottom: 8px; border-bottom: 3px solid #16a34a; }
.tpl-doc .doc-kind { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.tpl-doc .doc-head b { font-size: 15px; }
.tpl-doc .doc-head small, .tpl-doc .muted { color: var(--muted); }
.tpl-doc h4 { margin: 8px 0 0; font-size: 12px; font-weight: 600; border-left: 3px solid #16a34a; padding-left: 6px; }
.tpl-doc .doc-fields { width: 100%; border-collapse: collapse; }
.tpl-doc .doc-fields th { width: 45%; text-align: left; font-weight: 600; color: var(--muted); background: var(--raised); padding: 4px 6px; }
.tpl-doc .doc-fields td { padding: 4px 6px; border-bottom: 1px solid var(--rule); }
.tpl-doc .doc-check { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--rule); }
.tpl-doc .doc-check .pill { font-size: 10px; padding: 1px 6px; }
.tpl-doc .doc-text { border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; color: var(--muted); }
.tpl-doc .doc-signs { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 18px; }
.tpl-doc .doc-signs span { flex: 1; min-width: 110px; border-top: 1px solid var(--text); padding-top: 3px; text-align: center; color: var(--muted); font-size: 10px; }
.tpl-doc .doc-photo { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; display: grid; }
.tpl-doc .doc-img { height: 90px; background: #0b1220; color: rgba(255,255,255,0.55); display: grid; place-items: center; font-size: 11px; }
.tpl-doc .doc-photo .doc-check { padding: 4px 8px; }
.toggle-row { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.toggle-row span { display: grid; }
.toggle-row b { font-weight: 500; }
.toggle-row small { color: var(--muted); font-size: 13px; }
.day-picks { display: flex; flex-wrap: wrap; gap: 6px; }
.day-picks button { width: 52px; height: 36px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); cursor: pointer; transition: background-color var(--t-hover); }
.day-picks button[aria-pressed="true"] { background: var(--text); color: var(--primary-ink); border-color: var(--text); }
.people-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; margin-top: 4px; }
.person-pick { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-control); cursor: pointer; }
.person-pick:has(input:checked) { border-color: var(--text); background: var(--raised); }

.answer-section { font-size: var(--fs-body); font-weight: 600; margin: 16px 0 2px; color: var(--positive); }
.answer-section:first-child { margin-top: 0; }
.answer { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; align-items: center; padding: 10px 0; }
.answer + .answer { border-top: 1px solid var(--rule); }
.answer-q small { display: block; color: var(--pill-negative-ink); font-size: 13px; margin-top: 2px; }
.answer-a { justify-self: end; text-align: right; }
.answer-a b { font-weight: 500; }
.answer-shots { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }
.shot { width: 96px; aspect-ratio: 4 / 3; padding: 0; border: 0; border-radius: 6px; overflow: hidden; background: var(--raised); cursor: zoom-in; }
.shot img { width: 100%; height: 100%; object-fit: cover; }

@media (max-width: 1240px) { .presets { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1100px) { .builder { grid-template-columns: minmax(0, 1fr); } .preview-col { position: static; } }
@media (max-width: 760px) {
  .presets { grid-template-columns: minmax(0, 1fr); }
  .item-head { flex-wrap: wrap; }
  .item-head select.input { flex: 1 1 70%; min-width: 0; order: -1; }
  .item-head .item-n { display: none; }
  .item-card { min-width: 0; }
  .crumbs { flex-wrap: wrap; row-gap: 2px; }
  .crumbs .chip { display: none; }
  .add-types .btn { flex: 1 1 45%; }
}

/* ---------- tablet e celular ---------- */
@media (max-width: 1240px) {
  .overview { grid-template-columns: minmax(0, 1fr); }
  .rail { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
  .rail-block + .rail-block { margin-top: 0; }
}
@media (max-width: 1100px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: var(--top) 1fr; }
  .sidebar { position: fixed; inset: 0; width: min(320px, 86vw); height: 100%; z-index: 30; background: var(--ground); transform: translateX(-100%); transition: transform var(--t-ui) var(--ease-out); box-shadow: 0 0 0 100vmax rgba(10, 16, 12, 0); }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(10, 16, 12, 0.4); }
  .topbar { padding: 0 12px; }
  .menu-toggle { display: inline-flex; }
  .sheet { grid-column: 1; margin: 0 8px 8px; }
  .map-split { grid-template-columns: minmax(0, 1fr); }
  .map-list { max-height: none; min-height: 0; }
  .viewer-body { grid-template-columns: minmax(0, 1fr); overflow: auto; }
  .login { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  /* no celular a foto vira uma faixa acima do formulário */
  .login-shot { order: -1; height: 34svh; min-height: 200px; margin: 8px 8px 0; }
  .login-stamp { left: 12px; right: 12px; bottom: 12px; padding: 10px 12px; font-size: 11px; line-height: 16px; }
}
@media (max-width: 760px) {
  :root { --pad: 16px; }
  .sheet { margin: 0; border-radius: 0; border-width: 1px 0 0; }
  .search-btn span, .search-btn kbd { display: none; }
  .search-btn { width: 36px; height: 36px; margin: 0 0 0 auto; justify-content: center; padding: 0; }
  .kpis { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi + .kpi { border-left: 0; }
  .kpi:nth-child(n + 3) { border-top: 1px solid var(--border); }
  .kpi:nth-child(2n) { border-left: 1px solid var(--border); }
  .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .pair, .rail { grid-template-columns: minmax(0, 1fr); }
  .set-row { grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 24px 0; }
  .title-row h1 { font-size: 22px; }
  .filters .search { width: 100%; }
  .filters select.input { flex: 1; }
  /* a tabela vira lista de duas linhas */
  .tasks-table thead { display: none; }
  .tasks-table, .tasks-table tbody, .tasks-table tr, .tasks-table td { display: block; }
  .tasks-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--rule); }
  .tasks-table td { padding: 0; border: 0; }
  .tasks-table td.c-name { grid-column: 1; }
  .tasks-table td.c-nok { grid-column: 2; grid-row: 1; align-self: start; }
  .tasks-table td.c-tpl, .tasks-table td.c-tech, .tasks-table td.c-date, .tasks-table td.c-photos { display: none; }
  .tasks-table .phone-line { display: block !important; margin-top: 2px; white-space: normal; }
  .ident { max-width: none; }
  .result { grid-template-columns: 72px minmax(0, 1fr); }
  .result .thumb { width: 72px; }
  .result > :last-child { grid-column: 1 / -1; }
  .login-side { padding: 24px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0.01ms !important; animation: none !important; } }

/* assinaturas feitas no celular */
.signs { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.sign { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.sign-box { width: 100%; height: 64px; display: flex; align-items: center; justify-content: center; border-bottom: 1px solid var(--text); margin-bottom: 6px; background: #fff; border-radius: 6px 6px 0 0; }
.sign-box img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sign span { color: var(--muted); font-size: 13px; }
.sign small { color: var(--faint); font-size: 11px; }
.print-only { display: none; }
@media print {
  body { background: #fff; }
  /* Cabeçalho da empresa e marca d'água: só no PDF, a logo do menu não sai na impressão */
  .print-only { display: flex; }
  .print-head { align-items: center; gap: 12px; padding-bottom: 12px; margin-bottom: 16px; border-bottom: 1px solid #d9dfdb; position: relative; z-index: 1; }
  .print-head img { height: 40px; max-width: 160px; object-fit: contain; }
  .print-head strong { display: block; font-size: 15px; }
  .print-head span { font-size: 11px; color: #5b665f; }
  /* fixed repete em todas as páginas; por cima dos cartões (que são brancos), mas tão apagada que o texto segue legível */
  .print-watermark { position: fixed; inset: 0; flex-direction: column; align-items: center; justify-content: center; gap: 18px; opacity: 0.05; mix-blend-mode: multiply; pointer-events: none; z-index: 10; transform: rotate(-24deg); }
  .print-watermark img { width: 40%; max-width: 300px; filter: grayscale(1); }
  .print-watermark span { max-width: 70%; font-size: 34px; line-height: 1.25; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: #000; text-align: center; }

  .sidebar, .topbar, .tabs, .no-print, .toasts { display: none !important; }
  .app { display: block; }
  .sheet { border: 0; margin: 0; padding: 0; }
  .photo { break-inside: avoid; }
}

/* ---------- tema escuro ("black") ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  /* No escuro a sombra some: fica só a linha fina clara em volta */
  --lift: 0 0 0 0.5px rgba(255, 255, 255, 0.12);
  --hairline: 0 0 0 0.5px rgba(255, 255, 255, 0.12);
  --ground: #0a0d0b;
  --surface: #121614;
  --raised: #1a1f1c;
  --active: #242b27;
  --border: #262d29;
  --rule: #1d2320;
  --control: #3b443f;
  --text: #edf2ee;
  --muted: #9ba69f;
  --faint: #808b84;
  --accent: #22c55e;
  --primary: #edf2ee;
  --primary-ink: #0a0d0b;
  --positive: #4ade80; --negative: #f87171; --warning: #fbbf24;
  --pill-positive-bg: #12301d; --pill-positive-ink: #86efac;
  --pill-negative-bg: #3a1618; --pill-negative-ink: #fca5a5;
  --pill-warning-bg: #33260b; --pill-warning-ink: #fcd34d;
  --pill-neutral-bg: #222825; --pill-neutral-ink: #c5ccc8;
  --chart-1: #22c55e; --chart-2: #2e7d4a; --chart-3: #d4a72c; --chart-muted: #3b443f; --chart-span: 0.12;
}
:root[data-theme="dark"] .avatar { color: #e6efe9; background: hsl(var(--h, 140) 28% 24%); }
:root[data-theme="dark"] img.avatar { background: var(--active); }
:root[data-theme="dark"] .brand-mark { background: #16241c; }
:root[data-theme="dark"] .track i { background: var(--accent); }
:root[data-theme="dark"] .viewer-nav { background: rgba(26, 31, 28, 0.92); color: var(--text); }
/* mapa: ruas do OpenStreetMap escurecidas para não estourar a vista */
:root[data-theme="dark"] .leaflet-tile { filter: invert(1) hue-rotate(180deg) brightness(0.85) contrast(0.9) saturate(0.4); }
:root[data-theme="dark"] .leaflet-container { background: #1a1f1c; }

/* ---------- menu recolhido no computador: coluna só com os ícones ---------- */
@media (min-width: 1101px) {
  .menu-toggle { display: inline-flex; }
  .app.collapsed { --sidebar-width: 68px; }
  .app.collapsed .sidebar { padding: 12px 10px; align-items: center; }
  .app.collapsed .brand { padding: 0; gap: 0; font-size: 0; }
  .app.collapsed .org-switch { width: 44px; padding: 6px; justify-content: center; }
  .app.collapsed .org-switch .org-text, .app.collapsed .org-switch > svg,
  .app.collapsed .group-label, .app.collapsed .plan-box, .app.collapsed .lang-row, .app.collapsed .user-row .who, .app.collapsed #logout { display: none; }
  .app.collapsed nav { display: grid; gap: 2px; }
  .app.collapsed nav[aria-label="Organização"] { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
  .app.collapsed .nav-item { position: relative; width: 44px; height: 40px; padding: 0; justify-content: center; }
  .app.collapsed .nav-item svg { width: 18px; height: 18px; }
  .app.collapsed .nav-item span:not(.count) { display: none; }
  .app.collapsed .nav-item .count { position: absolute; top: 1px; right: -2px; font-size: 10px; line-height: 16px; padding: 0 5px; }
  .app.collapsed .user-row { padding: 6px 0; justify-content: center; }
}

/* ─── Routes — operation cards ─── */
.routes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}

/* Card base */
.route-card {
  background: var(--surface);
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow var(--t-hover), border-color var(--t-hover), transform var(--t-hover);
  cursor: default;
}
.route-card:hover {
  box-shadow: 0 4px 16px rgba(17,24,20,.07), 0 0 0 1px var(--control);
  border-color: var(--control);
  transform: translateY(-1px);
}

/* Status accent bar at top */
.route-card-accent {
  height: 3px;
  width: 100%;
  flex: none;
}
.route-card-accent.pending  { background: var(--control); }
.route-card-accent.active   { background: #2563eb; }
.route-card-accent.completed { background: var(--accent); }
.route-card-accent.canceled { background: var(--negative); }

/* Card body */
.route-card-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 12px; flex: 1; }

/* Head row: status chip + delete */
.route-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rc-status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 6px;
}
.rc-status::before { content: ''; display: block; width: 6px; height: 6px; border-radius: 50%; flex: none; }
.rc-status.pending  { background: var(--raised); color: var(--muted); }
.rc-status.pending::before  { background: var(--control); }
.rc-status.active   { background: #eff6ff; color: #1d4ed8; }
.rc-status.active::before   { background: #2563eb; }
.rc-status.completed { background: var(--pill-positive-bg); color: var(--positive); }
.rc-status.completed::before { background: var(--accent); }
.rc-status.canceled { background: var(--pill-negative-bg); color: var(--negative); }
.rc-status.canceled::before { background: var(--negative); }

/* Name */
.route-name {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--text);
}

/* Divider */
.route-card-divider { height: 1px; background: var(--border); margin: 0 -18px; }

/* Assignee row */
.route-tech {
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; color: var(--text);
}
.tech-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: var(--primary-ink);
  font-size: 11px; font-weight: 700;
  display: grid; place-items: center; flex: none;
  letter-spacing: 0.01em;
  object-fit: cover; /* when img */
}
.tech-avatar.unassigned {
  background: var(--raised); color: var(--muted);
  border: 1.5px dashed var(--control);
  font-size: 14px;
}
.route-tech-name { font-weight: 500; }
.route-tech-label { font-size: 11px; color: var(--muted); display: block; margin-top: 1px; }

/* Stop segments */
.route-stops-row {
  display: flex; align-items: center; gap: 6px;
}
.stop-segments {
  display: flex; align-items: center; gap: 3px; flex: 1;
}
.stop-seg {
  height: 6px; flex: 1; border-radius: 3px; min-width: 0;
  transition: background var(--t-ui);
}
.stop-seg.arrived   { background: var(--accent); }
.stop-seg.skipped   { background: var(--control); }
.stop-seg.pending   { background: var(--raised); border: 1px solid var(--control); }
.stop-seg-count { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Footer row */
.route-card-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding-top: 2px;
}
.route-date { font-size: 11px; color: var(--muted); }

/* View button */
.route-view-btn {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600;
  color: var(--primary); text-decoration: none;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: background var(--t-hover), border-color var(--t-hover);
  background: transparent;
}
.route-view-btn:hover { background: var(--raised); border-color: var(--control); }
.route-view-btn svg { width: 12px; height: 12px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Map section */
.rmap-section { background: var(--surface); border-radius: var(--radius-card); border: 1px solid var(--border); margin-bottom: 24px; overflow: hidden; }
.rmap-toggle-btn { display: flex; width: 100%; align-items: center; gap: 8px; padding: 14px 16px; background: none; border: none; cursor: pointer; font-size: 14px; font-weight: 600; color: inherit; text-align: left; }
.rmap-toggle-btn svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.rmap-toggle-btn:hover { background: var(--raised); }
.rmap-filters { display: flex; gap: 8px; align-items: center; padding: 12px 16px; flex-wrap: wrap; border-top: 1px solid var(--border); }
.rmap-legend { margin-left: auto; display: flex; gap: 10px; font-size: 12px; color: var(--muted); }
.rmap-route-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 10px 16px; border-top: 1px solid var(--border); }
.rmap-route-legend:empty { display: none; }
.rmap-leg-item { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.rmap-leg-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.rmap-leg-name { font-weight: 600; }
.rmap-leg-tech { color: var(--muted); }
.rmap-leg-tech::before { content: '·'; margin-right: 4px; }
.rmap-leg-count { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: auto; padding-left: 8px; }

/* Route info (compat) */
.route-info { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.back-link svg { width: 14px; height: 14px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ─── Route detail page ─── */

/* Meta header row */
.rd-meta-row {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  gap: 16px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
  margin-bottom: 20px;
}
.rd-meta-tech {
  display: flex; align-items: center; gap: 12px;
  grid-column: 1;
}
.rd-tech-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--primary); color: var(--primary-ink);
  font-size: 14px; font-weight: 700;
  display: grid; place-items: center; flex: none;
  object-fit: cover;
}
.rd-tech-avatar.unassigned { background: var(--raised); color: var(--muted); border: 2px dashed var(--control); }
.rd-tech-name { font-size: 15px; font-weight: 600; display: block; }
.rd-tech-label { font-size: 11px; color: var(--muted); display: block; margin-top: 2px; }

.rd-meta-stats {
  display: flex; align-items: center; gap: 24px;
  grid-column: 2;
}
.rd-stat { display: flex; flex-direction: column; gap: 2px; }
.rd-stat-val { font-size: 18px; font-weight: 700; line-height: 1; }
.rd-stat-label { font-size: 11px; color: var(--muted); }

.rd-meta-progress {
  grid-column: 1 / -1;
}
.rd-progress-bar {
  height: 6px; background: var(--raised); border-radius: 3px; overflow: hidden;
}
.rd-progress-fill {
  height: 100%; background: var(--accent); border-radius: 3px;
  transition: width 0.5s var(--ease-out);
}

/* Route detail map */
.rd-map {
  height: 320px;
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 20px;
}

/* Stop list */
.rd-stops-list { display: grid; gap: 10px; }

/* Stop card */
.rd-stop-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--control);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  transition: border-color var(--t-hover);
}
.rd-stop-card.arrived { border-left-color: var(--accent); }
.rd-stop-card.skipped { border-left-color: var(--control); opacity: 0.7; }
.rd-stop-card.pending { border-left-color: #f59e0b; }

.rd-stop-head {
  display: flex; align-items: flex-start; gap: 12px;
}
.rd-stop-num {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--raised); border: 1px solid var(--border);
  font-size: 11px; font-weight: 700; color: var(--muted);
  display: grid; place-items: center; flex: none; margin-top: 1px;
}
.rd-stop-card.arrived .rd-stop-num { background: var(--pill-positive-bg); color: var(--positive); border-color: transparent; }
.rd-stop-card.pending .rd-stop-num { background: #fffbeb; color: #92400e; border-color: transparent; }

.rd-stop-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.rd-stop-addr { font-size: 14px; font-weight: 500; line-height: 1.4; }
.rd-stop-instr { font-size: 12px; color: var(--muted); }

.rd-stop-status {
  font-size: 11px; font-weight: 600; letter-spacing: 0.03em;
  padding: 3px 8px; border-radius: 6px; white-space: nowrap; flex: none;
}
.rd-stop-status.arrived  { background: var(--pill-positive-bg); color: var(--positive); }
.rd-stop-status.skipped  { background: var(--pill-neutral-bg); color: var(--muted); }
.rd-stop-status.pending  { background: #fffbeb; color: #92400e; }

.rd-stop-obs {
  font-size: 13px; color: var(--muted);
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--rule);
  line-height: 1.5;
}

.rd-stop-photos {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-top: 10px;
}
.rd-stop-photos img {
  width: 88px; height: 66px;
  object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border);
}

/* ── Drag-to-reorder stops ───────────────────────────────────── */
.rd-stops-list.sortable .rd-stop-card { cursor: grab; }
.rd-stop-drag-handle {
  color: var(--muted); flex: none; cursor: grab; padding: 2px 4px;
  opacity: 0.5; transition: opacity 160ms;
}
.rd-stops-list.sortable .rd-stop-card:hover .rd-stop-drag-handle { opacity: 1; }
.rd-stop-card.drag-over {
  border-style: dashed; background: var(--raised);
}
.rd-stop-card.dragging { opacity: 0.35; }

/* ── Member cards ────────────────────────────────────────────── */
.member-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.member-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
  transition: box-shadow var(--t-hover);
}
.member-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,.08); }
.member-card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px;
  cursor: pointer;
  user-select: none;
}
.member-card-head .avatar.xl { flex: none; }
.member-card-meta { flex: 1; min-width: 0; }
.member-card-name {
  font-size: 14px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.member-card-sub {
  font-size: 12px; color: var(--muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.member-card-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.member-card-chevron {
  color: var(--muted); flex: none; transition: transform 200ms;
}
.member-card.open .member-card-chevron { transform: rotate(180deg); }
.member-card-body {
  display: none; padding: 0 16px 16px;
  border-top: 1px solid var(--rule);
}
.member-card.open .member-card-body { display: block; }
.member-card-detail {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px;
  margin-top: 12px;
}
.member-card-field { display: flex; flex-direction: column; gap: 2px; }
.member-card-field-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.member-card-field-value { font-size: 13px; color: var(--text); }
.member-card-addr { grid-column: 1 / -1; }
.member-card-actions { display: flex; gap: 8px; margin-top: 14px; justify-content: flex-end; }

@media (max-width: 760px) {
  .routes-grid { grid-template-columns: minmax(0, 1fr); }
  .rmap-legend { margin-left: 0; }
  .rd-meta-row { grid-template-columns: 1fr; }
  .rd-meta-stats { flex-wrap: wrap; gap: 16px; }
  .rd-meta-progress { grid-column: 1; }
  .member-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ── Formulário de rota — modal moderno ──────────────────────── */
.rf-backdrop {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(0,0,0,.38);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: rf-fade-in 160ms ease;
}
@keyframes rf-fade-in { from { opacity: 0 } to { opacity: 1 } }

.rf-modal {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,.22);
  width: min(620px, 100%);
  max-height: calc(100dvh - 32px);
  display: flex; flex-direction: column;
  animation: rf-slide-up 200ms var(--ease-out, cubic-bezier(.2,.8,.4,1));
}
@keyframes rf-slide-up { from { transform: translateY(20px); opacity: 0 } to { transform: none; opacity: 1 } }

.rf-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 0;
  flex: none;
}
.rf-modal-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.rf-modal-close {
  width: 32px; height: 32px; border-radius: 50%;
  border: none; background: var(--raised); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 18px; line-height: 1;
  transition: background 120ms;
}
.rf-modal-close:hover { background: var(--active); }

.rf-modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
  display: flex; flex-direction: column; gap: 16px;
}

.rf-field { display: flex; flex-direction: column; gap: 6px; }
.rf-field label { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .3px; text-transform: uppercase; }
.rf-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.rf-stops-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}
.rf-stops-header span { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }

.rf-stop-row {
  display: grid;
  grid-template-columns: 28px 1fr 140px 32px;
  gap: 8px; align-items: center;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  transition: box-shadow 120ms;
}
.rf-stop-row:focus-within { box-shadow: 0 0 0 2px var(--accent); border-color: var(--accent); }
.rf-stop-num {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: var(--primary-ink);
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex: none;
}
.rf-stop-row .input {
  background: transparent; border-color: transparent;
  padding: 0 4px; height: 32px;
}
.rf-stop-row .input:focus { border-color: transparent; box-shadow: none; background: var(--surface); border-radius: 6px; }
.rf-stop-remove {
  width: 28px; height: 28px; border-radius: 6px;
  border: none; background: none; cursor: pointer;
  color: var(--muted); font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: background 120ms, color 120ms;
}
.rf-stop-remove:hover { background: var(--pill-negative-bg); color: var(--negative); }

.rf-add-stop {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 1.5px dashed var(--control); border-radius: 10px;
  background: none; cursor: pointer; color: var(--muted);
  padding: 10px; font-size: 13px; font-weight: 500;
  transition: border-color 120ms, color 120ms, background 120ms;
  width: 100%;
}
.rf-add-stop:hover { border-color: var(--accent); color: var(--accent); background: #f0fdf4; }

.rf-modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--rule);
  flex: none;
}
.rf-modal-foot .btn { height: 40px; padding: 0 20px; border-radius: 10px; font-size: 14px; }

.btn-primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn-primary:hover { opacity: .88; }

@media (max-width: 560px) {
  .rf-row { grid-template-columns: 1fr; }
  .rf-stop-row { grid-template-columns: 28px 1fr 32px; }
  .rf-stop-row .input[data-field="instr"] { display: none; }
}
