:root {
  --ink: #14161c;
  --ink-2: #3a3f4b;
  --muted: #687082;
  --line: #e3e6ec;
  --bg: #f6f7f9;
  --card: #ffffff;
  --brand: #e3123b;
  --brand-ink: #ffffff;
  --yellow: #ffc233;
  --green: #5fa832;
  --ok: #17794a;
  --ok-bg: #e5f5ec;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --bad: #b4232f;
  --bad-bg: #fdeaec;
  --info: #1f5fbf;
  --info-bg: #e8f0fd;
  --muted-bg: #eef0f3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 22, 28, 0.05), 0 2px 10px rgba(20, 22, 28, 0.04);
  --font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg); }
a { color: var(--info); text-underline-offset: 3px; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.015em; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; margin-top: 1em; }
p { margin: 0 0 0.8em; }
code, .mono { font-family: var(--mono); font-size: 0.9em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .container { padding: 0 24px; } }
.narrow { max-width: 680px; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }
.mt { margin-top: 16px; }
.row { display: flex; align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.gap { gap: 10px; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack > .btn { align-self: flex-start; }
.section { padding: 48px 0; }
.section.alt { background: #fff; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.75rem; font-weight: 700; color: var(--brand); margin-bottom: 6px; }

/* Brand */
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; color: var(--ink); text-decoration: none; letter-spacing: -0.02em; font-size: 1.05rem; }
.logo { width: 28px; height: 28px; flex: none; }

/* Buttons and forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; line-height: 1.2; }
.btn:hover { border-color: #c9ced8; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #2a2e38; }
.btn-sm { padding: 5px 10px; font-size: 0.85rem; border-radius: 7px; }
.btn-lg { padding: 12px 20px; font-size: 1rem; }
.btn-danger-ghost { color: var(--bad); }
.btn-whatsapp { background: #1fa855; color: #fff; border-color: #1fa855; }
.link-btn { background: none; border: 0; padding: 0; color: var(--info); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link-btn.danger { color: var(--bad); }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.88rem; }
input, select, textarea { font: inherit; font-weight: 400; padding: 8px 10px; border: 1px solid #cfd4dc; border-radius: 8px; background: #fff; color: var(--ink); width: 100%; min-width: 0; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--info); outline-offset: 0; border-color: var(--info); }
input[type='checkbox'], input[type='radio'] { width: auto; }
label.check { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.8rem; }
.hint.suggest { color: var(--warn); font-weight: 600; }
.field-error { color: var(--bad); font-size: 0.85rem; margin: -6px 0 0; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-weight: 600; font-size: 0.88rem; margin-bottom: 6px; }
.choice label.check { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.narrow-form { max-width: 720px; }
.inline-label { flex-direction: row; align-items: center; gap: 10px; }
.inline-label .mono { min-width: 60px; }

/* Cards, tables */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-bad { border-color: #f1b8bf; background: #fffafa; }
.card-info { border-color: #c4d7f6; }
.card.empty { text-align: center; padding: 40px 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + .card, .card + .grid-2 { margin-top: 16px; }
.grid-2.tight { gap: 12px; grid-template-columns: 1fr 1fr; }
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table td.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.kv { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.kv th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 12px 6px 0; vertical-align: top; white-space: nowrap; width: 1%; }
.kv td { padding: 6px 0; word-break: break-word; }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 16px; }
.kv-grid span { display: block; color: var(--muted); font-size: 0.8rem; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 7px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }

/* Badges, status */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; vertical-align: 1px; }
.tone-ok { background: var(--ok-bg); color: var(--ok); }
.tone-warn { background: var(--warn-bg); color: var(--warn); }
.tone-bad { background: var(--bad-bg); color: var(--bad); }
.tone-info { background: var(--info-bg); color: var(--info); }
.tone-muted { background: var(--muted-bg); color: var(--ink-2); }
.chan { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 20px; padding: 0 5px; border-radius: 5px; font-size: 0.68rem; font-weight: 800; letter-spacing: 0.03em; vertical-align: 2px; }
.chan-edi { background: #1d2230; color: var(--yellow); }
.chan-email { background: var(--info-bg); color: var(--info); }
.chan-checkin { background: var(--ok-bg); color: var(--ok); }
.count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--yellow); color: #3b2a00; font-size: 0.72rem; font-weight: 700; text-align: center; }
.count-bad { background: var(--brand); color: #fff; }
.conf { font-size: 0.75rem; color: var(--ok); font-weight: 600; }
.conf-low { color: var(--warn); }
.evidence { color: var(--muted); font-size: 0.8rem; margin-top: 2px; word-break: break-word; }
.ok-dot { color: var(--ok); font-size: 0.7rem; }
.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.checks li:last-child { border-bottom: 0; }
.check-icon { flex: none; width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 800; }
.check-pass .check-icon { background: var(--ok-bg); color: var(--ok); }
.check-warn .check-icon { background: var(--warn-bg); color: var(--warn); }
.check-fail .check-icon { background: var(--bad-bg); color: var(--bad); }
.check-skip .check-icon { background: var(--muted-bg); color: var(--muted); }
.flash { padding: 10px 14px; border-radius: 10px; margin: 0 0 16px; border: 1px solid transparent; }
.flash-success { background: var(--ok-bg); border-color: #bfe5cf; }
.flash-error { background: var(--bad-bg); border-color: #f3c1c7; }
.flash-warn { background: var(--warn-bg); border-color: #f2dca3; }
.flash input { width: auto; min-width: 280px; margin: 0 6px; }
pre.source { background: #f3f4f7; border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-family: var(--mono); font-size: 0.8rem; white-space: pre-wrap; word-break: break-all; max-height: 420px; overflow: auto; margin: 0 0 10px; }

/* Public site */
.site-header { background: #fff; border-bottom: 1px solid var(--line); }
.nav { display: flex; justify-content: space-between; align-items: center; height: 60px; }
.nav-links { display: flex; align-items: center; gap: 16px; }
.nav-links > a:not(.btn) { color: var(--ink); text-decoration: none; font-weight: 600; }
.public main { min-height: 60vh; }
.public .container > .flash { margin-top: 16px; }
.hero { padding: 56px 0 40px; background: radial-gradient(1000px 400px at 85% 0%, #fff4d6 0%, transparent 60%), radial-gradient(800px 300px at 0% 100%, #fde8ec 0%, transparent 60%); }
.hero-inner { display: grid; grid-template-columns: 1fr; gap: 32px; align-items: center; }
@media (min-width: 960px) { .hero-inner { grid-template-columns: 1.1fr 0.9fr; } }
.hero h1 { font-size: clamp(2rem, 4.2vw, 3rem); letter-spacing: -0.03em; }
.lead { font-size: 1.1rem; color: var(--ink-2); max-width: 620px; }
.hero-cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 20px 0 10px; }
.hero-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 12px 40px rgba(20, 22, 28, 0.08); padding: 20px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.flow-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.flow-row code { background: #f3f4f7; padding: 3px 7px; border-radius: 6px; font-size: 0.8rem; overflow-wrap: anywhere; }
.flow-arrow { color: var(--muted); font-size: 0.8rem; padding-left: 4px; }
.steps { padding-left: 20px; margin: 0; }
.steps li { margin-bottom: 8px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 24px; }
.stats strong { display: block; font-size: 2rem; letter-spacing: -0.03em; }
.stats span { color: var(--muted); }
.site-footer { border-top: 1px solid var(--line); background: #fff; padding: 20px 0; }
.footer-inner { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.auth { max-width: 460px; padding-top: 40px; padding-bottom: 40px; }

/* App shell */
.app-header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 58px; background: #fff; border-bottom: 1px solid var(--line); }
.app-nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.app-nav a { padding: 7px 11px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-weight: 600; white-space: nowrap; font-size: 0.92rem; }
.app-nav a:hover { background: var(--bg); }
.app-nav a.active { background: var(--ink); color: #fff; }
.app-user { display: flex; align-items: center; gap: 12px; white-space: nowrap; font-size: 0.88rem; }
.ws-name { font-weight: 600; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.demo-bar { background: #1d2230; color: #e8eaf0; font-size: 0.82rem; padding: 7px 20px; }
.app-main { max-width: 1240px; margin: 0 auto; padding: 24px 20px 64px; }
@media (max-width: 860px) {
  .app-header { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 8px 12px; }
  .app-nav { order: 3; flex-basis: 100%; }
  .app-user { margin-left: auto; }
  .ws-name { max-width: 150px; }
  .app-main { padding: 16px 16px 48px; }
  .demo-bar { padding: 7px 16px; }
}
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { margin-bottom: 4px; }
.page-head p { margin: 0; }
.crumbs { font-size: 0.85rem; margin-bottom: 4px !important; }
.crumbs a { color: var(--muted); }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { padding: 5px 12px; border-radius: 999px; text-decoration: none; color: var(--ink-2); font-weight: 600; font-size: 0.85rem; border: 1px solid var(--line); background: #fff; }
.tabs a.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* Dashboard */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.kpi strong { font-size: 1.7rem; letter-spacing: -0.02em; }
.kpi-sub { font-size: 0.8rem; color: var(--muted); }
.kpi-warn { border-color: #f2dca3; background: #fffcf3; }

/* Inbox presets */
.presets { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px; }
.preset { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.preset p { margin: 4px 0 0; }

/* Orders */
.progress { display: flex; list-style: none; margin: 0; padding: 0; gap: 4px; overflow-x: auto; }
.progress li { flex: 1; min-width: 92px; font-size: 0.76rem; font-weight: 600; color: var(--muted); padding-top: 10px; border-top: 4px solid var(--line); }
.progress li.done { border-top-color: var(--green); color: var(--ink-2); }
.progress li.current { color: var(--ink); }
.timeline { list-style: none; margin: 0; padding: 0 0 0 16px; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 16px 12px; }
.timeline li::before { content: ''; position: absolute; left: -23px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid var(--green); }
.linkbox { display: flex; flex-direction: column; gap: 10px; }

/* Mapping studio */
.steps-head { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.steps-head span { padding: 6px 12px; border-radius: 999px; background: #fff; border: 1px solid var(--line); font-weight: 600; font-size: 0.85rem; color: var(--muted); }
.steps-head span.current { border-color: var(--ink); color: var(--ink); }
.steps-head span.done { background: var(--ok-bg); border-color: #bfe5cf; color: var(--ok); }
.samples { list-style: none; padding: 0; margin: 0; }
.samples li { border-bottom: 1px solid var(--line); padding: 8px 0; }
.samples summary { cursor: pointer; }
.samples pre { margin-top: 8px; }
.versions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.versions a { padding: 4px 10px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--ink); font-weight: 600; font-size: 0.85rem; }
.versions a.active { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.mapping-meta { font-size: 0.88rem; margin-bottom: 10px; }
.notes { background: #fbfaf5; border: 1px solid #efe7cc; border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; }
.notes h3 { margin-top: 0; }
.notes ul { margin: 0; padding-left: 18px; font-size: 0.88rem; }
.codes { display: flex; flex-wrap: wrap; gap: 6px; }
.code { background: var(--muted-bg); border-radius: 6px; padding: 2px 8px; font-size: 0.82rem; }
.unmapped { background: var(--warn-bg); border: 1px solid #f2dca3; border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.unmapped h3 { margin: 0; }
.json-edit summary { cursor: pointer; font-weight: 600; margin: 8px 0; }
.tests td { font-size: 0.85rem; }
.approve { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: 16px; padding: 14px; border-radius: 10px; background: #f3faf6; border: 1px solid #bfe5cf; flex-wrap: wrap; }
.approve p { margin: 2px 0 0; }
.drafting { display: flex; gap: 14px; align-items: center; padding: 18px; background: var(--info-bg); border-radius: 10px; }
.drafting p { margin: 2px 0 0; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #b9cdf1; border-top-color: var(--info); animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* Driver check-in */
.checkin { background: #f1f2f5; }
.checkin-main { max-width: 480px; margin: 0 auto; padding: 16px; }
.checkin-head { display: flex; align-items: center; gap: 10px; margin: 8px 0 14px; }
.checkin-head .logo { width: 34px; height: 34px; }
.checkin h1 { font-size: 1.5rem; margin: 0; }
.route { font-size: 1.05rem; font-weight: 600; margin: 4px 0; }
.status-pick label { flex-direction: row; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 12px; padding: 14px; font-size: 1rem; cursor: pointer; }
.status-pick label:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); background: #fafbfc; }
.status-pick input { width: 20px; height: 20px; flex: none; }
.status-pick small { display: block; color: var(--muted); font-weight: 400; font-size: 0.82rem; }
.big-check { font-size: 3rem; color: var(--ok); margin: 0; }
