:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e4e7ec;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e8efff;
  --success: #15803d;
  --success-soft: #e7f6ec;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --sidebar: 232px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1f252e;
    --border: #2a313c;
    --text: #e6e8eb;
    --muted: #8b949e;
    --accent: #4c8dff;
    --accent-hover: #6aa0ff;
    --accent-soft: #1a2a47;
    --success: #4ade80;
    --success-soft: #12301f;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
.app { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.2rem; padding: 4px 10px 20px; color: var(--text); }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 20px; height: 20px; flex: none; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 14px; }
.user-chip { padding: 0 10px 10px; }
.user-chip strong { display: block; font-size: .9rem; }

.main { margin-left: var(--sidebar); padding: 28px 32px 48px; max-width: calc(1180px + var(--sidebar)); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; }

.topbar, .bottom-nav { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 16px 16px 96px; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 10; padding: 10px 16px;
    background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .topbar .brand { padding: 0; font-size: 1.05rem; }
  .bottom-nav {
    display: flex; position: fixed; inset: auto 0 0 0; z-index: 10;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: .7rem; color: var(--muted); padding: 4px 0; border-radius: 8px;
  }
  .bottom-nav a.active { color: var(--accent); }
  .bottom-nav a:hover { text-decoration: none; }
  .bottom-nav svg { width: 22px; height: 22px; }
  h1 { font-size: 1.3rem; }
}

/* ---------- Components ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }

.grid { display: grid; gap: 16px; }
.grid > .card + .card { margin-top: 0; }
.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 16px; }
@media (max-width: 640px) { .stats { gap: 10px; } .stat .value { font-size: 1.5rem; } }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.8rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.two-col { grid-template-columns: 3fr 2fr; }
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }

.trend { display: inline-flex; align-items: center; gap: 2px; font-weight: 600; font-size: .85rem; border-radius: 999px; padding: 1px 8px; }
.trend.up { color: var(--success); background: var(--success-soft); }
.trend.down { color: var(--danger); background: var(--danger-soft); }
.trend.flat { color: var(--muted); background: var(--surface-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-lg { height: 48px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-sm { height: 32px; padding: 0 12px; font-size: .85rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Forms */
.form { display: grid; gap: 14px; }
.form-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
label { display: block; font-weight: 500; font-size: .9rem; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date],
select, textarea {
  width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.file-input {
  display: block; width: 100%; padding: 18px 12px; border: 1.5px dashed var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text); font: inherit; cursor: pointer;
}
.file-input::file-selector-button {
  margin-right: 12px; height: 34px; padding: 0 14px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin: 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.check-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px;
  max-height: 340px; overflow: auto; padding: 10px; border: 1px solid var(--border); border-radius: 10px;
}
.check-list .check { padding: 6px 8px; border-radius: 8px; font-weight: 400; }
.check-list .check:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-icon { width: 36px; padding: 0; }
.inline-form { display: inline; margin: 0; }
.form > .card + .card { margin-top: 0; }

/* Seletor de opções (1 mês / 3 meses, Hoje / Ontem) */
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented a, .segmented button {
  height: 36px; padding: 0 14px; display: inline-flex; align-items: center; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap;
}
.segmented a:hover, .segmented button:hover { color: var(--text); text-decoration: none; }
.segmented .active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

/* Lançamento de visitas */
.date-pick { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.date-pick input { max-width: 220px; }
.pick-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.pick-tools input { flex: 1 1 220px; }
.pick-list { max-height: min(55vh, 460px); }
.pick-list .check { align-items: flex-start; padding: 10px 8px; }
.pick-list .check input { margin-top: 2px; flex: none; }
.pick-list .check:has(input:checked) { background: var(--accent-soft); }
.sticky-actions {
  position: sticky; bottom: 0; z-index: 5; display: flex; gap: 8px; flex-wrap: wrap;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); background: var(--bg);
}
@media (max-width: 860px) {
  .sticky-actions { bottom: calc(58px + env(safe-area-inset-bottom)); padding-bottom: 10px; }
  .sticky-actions .btn-primary { flex: 1; }
}
.filters { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; margin-bottom: 16px; }
.filters label { font-size: .8rem; color: var(--muted); margin-bottom: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.right, th.right { text-align: right; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }
.badge.off { background: var(--danger-soft); color: var(--danger); }

.demo-banner {
  margin-bottom: 16px; padding: 8px 14px; border-radius: 10px; font-size: .85rem;
  background: #fff4d6; color: #7a5300; border: 1px solid #f3dc9a;
}
.demo-banner code { font-weight: 600; }
@media (prefers-color-scheme: dark) {
  .demo-banner { background: #3a2e0d; color: #f5cf6b; border-color: #5a4714; }
}

/* Clientes sem visita */
.stat-link { color: var(--text); }
.stat-link:hover { text-decoration: none; border-color: var(--accent); }
.stat-link .small { color: var(--muted); margin-top: 2px; }
.stat-link.alert { border-color: var(--danger); }
.stat-link.alert .value, .stat-link.alert .small { color: var(--danger); }
.overdue-banner {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px; padding: 12px 16px; border-radius: var(--radius);
  background: var(--danger-soft); color: var(--danger); font-size: .92rem;
}
.overdue-banner:hover { text-decoration: none; filter: brightness(.98); }
.overdue-banner span { font-weight: 600; white-space: nowrap; }
.company-card.is-overdue { border-color: var(--danger); }

/* Segurança */
.code-input { font-size: 1.4rem; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; height: 52px; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 18px; }
.qr-box { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.qr { background: #fff; padding: 6px; border-radius: 10px; border: 1px solid var(--border); line-height: 0; }
.qr svg { width: 180px; height: 180px; }
.secret { display: inline-block; margin-top: 6px; font-size: .95rem; letter-spacing: .05em; word-break: break-all; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.codes code { padding: 10px; border-radius: 8px; background: var(--surface-2); text-align: center; font-size: 1.05rem; letter-spacing: .08em; }
code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

/* Flash */
.flashes { display: grid; gap: 8px; margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.flash.success { background: var(--success-soft); border-color: transparent; color: var(--success); }
.flash.error { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.flash.info { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

/* Company list (vendedor) */
.company-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.company-card { display: flex; flex-direction: column; gap: 12px; }
.company-card .top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.company-card h3 a { color: var(--text); }
.company-card .meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

/* Dialog */
dialog {
  border: 1px solid var(--border); border-radius: 16px; padding: 22px; width: min(460px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
@media (max-width: 600px) {
  dialog { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 16px 16px 0 0; padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
}

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 12px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.pagination { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 16px; }
.chart-box { position: relative; height: 300px; }

/* Login */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: min(400px, 100%); padding: 28px; }
.auth .brand { justify-content: center; padding: 0 0 6px; font-size: 1.5rem; }

/* Mobile table → cards */
@media (max-width: 640px) {
  .stack-table thead { display: none; }
  .stack-table tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--border); }
  .stack-table td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 3px 0; }
  .stack-table td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; flex: none; }
  .stack-table td.right { text-align: right; }
  .stack-table td > * { text-align: right; }
  .table-wrap { margin: 0; padding: 0; }
}

/* Print */
.print-only { display: none; }
@media print {
  .sidebar, .topbar, .bottom-nav, .no-print, .flashes { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .main { margin: 0; padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; }
  th { color: #333; }
  tr { break-inside: avoid; }
}
