:root {
    --bg: #f7f7f5;
    --surface: #ffffff;
    --text: #171717;
    --muted: #757575;
    --line: #e8e8e5;
    --soft: #f0f0ed;
    --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.brand { font-size: 12px; font-weight: 800; letter-spacing: .18em; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 220px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--surface); border-right: 1px solid var(--line); padding: 28px 20px; display: flex; flex-direction: column; gap: 34px; }
.side-title { font-size: 22px; font-weight: 650; margin-top: 8px; }
.nav { display: grid; gap: 4px; }
.nav button { border: 0; background: transparent; text-align: left; padding: 10px 12px; border-radius: 9px; color: #595959; }
.nav button:hover, .nav button.active { background: var(--soft); color: var(--text); }
.sidebar-bottom { margin-top: auto; display: grid; gap: 10px; overflow: hidden; }
.sidebar-bottom small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-button { border: 0; padding: 0; background: transparent; text-align: left; color: var(--muted); }

.main { min-width: 0; padding: 32px; }
.topbar { display: flex; justify-content: space-between; gap: 20px; align-items: end; margin: 0 auto 26px; max-width: 1300px; }
h1 { margin: 0; font-size: 26px; letter-spacing: -.03em; }
h2 { margin: 0; font-size: 15px; }
h3 { margin: 0; }
.topbar p { margin: 6px 0 0; }
.period-label { display: grid; gap: 6px; font-size: 11px; color: var(--muted); }
select, input { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 9px; padding: 10px 12px; outline: none; }
select:focus, input:focus { border-color: #a9a9a4; box-shadow: 0 0 0 3px #00000008; }

.view { display: none; max-width: 1300px; margin: 0 auto; }
.view.active { display: block; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; margin-bottom: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: grid; gap: 7px; }
.kpi > span, .kpi > small { color: var(--muted); }
.kpi strong { font-size: 29px; letter-spacing: -.04em; }
.grid-2 { display: grid; grid-template-columns: 1.35fr .65fr; gap: 12px; margin-bottom: 12px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.chart-box { min-height: 250px; display: grid; align-items: center; }
.line-chart { width: 100%; height: 220px; overflow: visible; }
.axis-line { stroke: #e5e5e1; stroke-width: 1; }
.chart-line { fill: none; stroke: #222; stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-dot { fill: #222; }
.chart-legend { text-align: center; font-size: 11px; color: var(--muted); margin-top: 4px; }
.bar-list { display: grid; gap: 14px; }
.bar-item { display: grid; gap: 7px; }
.bar-top { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
.bar-track { height: 5px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: #222; border-radius: inherit; }
.metric-list { display: grid; }
.metric-row { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.metric-row:last-child { border-bottom: 0; }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar input { min-width: min(460px, 100%); }
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 9px; padding: 10px 14px; }
.btn:hover { background: var(--soft); }
.btn.primary { background: #171717; color: white; border-color: #171717; }
.btn.small { padding: 7px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.table-panel { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-size: 11px; color: var(--muted); font-weight: 600; background: #fbfbfa; }
td { font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable:hover { background: #fafaf8; cursor: pointer; }
.status { display: inline-flex; padding: 4px 7px; border-radius: 99px; font-size: 11px; background: var(--soft); }
.status-enviado { background: #e9f4eb; color: #285d31; }
.status-abandono, .status-abandonou { background: #f7ece8; color: #7a3d2d; }
.status-iniciado { background: #f3f0e5; color: #6f5d25; }
.pagination { padding: 13px 16px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12px; }
.pagination > div { display: flex; gap: 6px; }
.empty { margin: 30px 0; text-align: center; }

.drawer-backdrop { position: fixed; inset: 0; background: #0004; z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(560px, 94vw); background: var(--surface); border-left: 1px solid var(--line); z-index: 21; padding: 24px; transform: translateX(102%); transition: transform .2s ease; overflow-y: auto; }
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.icon-btn { border: 0; background: var(--soft); width: 34px; height: 34px; border-radius: 50%; font-size: 22px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.detail-grid > div { background: var(--surface); padding: 13px; min-width: 0; overflow-wrap: anywhere; }
.detail-grid small { display: block; color: var(--muted); margin-bottom: 6px; }
.section-title { font-size: 14px; margin: 28px 0 16px; }
.timeline { position: relative; display: grid; gap: 0; }
.timeline-item { display: grid; grid-template-columns: 20px 1fr; gap: 10px; position: relative; padding-bottom: 20px; }
.timeline-item::before { content: ''; position: absolute; left: 5px; top: 12px; bottom: -2px; width: 1px; background: var(--line); }
.timeline-item:last-child::before { display: none; }
.timeline-dot { width: 11px; height: 11px; border: 2px solid #222; background: white; border-radius: 50%; margin-top: 4px; z-index: 1; }
.timeline-head { display: flex; justify-content: space-between; gap: 12px; }
.timeline-head time { color: var(--muted); font-size: 11px; white-space: nowrap; }
.timeline-item p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; background: #171717; color: white; border-radius: 9px; padding: 11px 14px; max-width: 360px; box-shadow: 0 10px 30px #0002; }

.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.auth-card h1 { margin-top: 10px; }
.auth-card > p { margin: 8px 0 24px; }
.stack { display: grid; gap: 15px; }
.stack label { display: grid; gap: 7px; font-size: 12px; color: #565656; }
.form-error { margin: 0; color: #a22929; font-size: 12px; }
code { font-family: ui-monospace, monospace; font-size: .9em; }

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 18px; gap: 16px; }
    .nav { display: flex; overflow-x: auto; }
    .nav button { white-space: nowrap; }
    .sidebar-bottom { display: flex; justify-content: space-between; }
    .main { padding: 20px 14px; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
    .topbar { align-items: flex-start; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .kpi { padding: 16px; }
    .kpi strong { font-size: 23px; }
    .toolbar { flex-direction: column; }
    .toolbar input { min-width: 0; width: 100%; }
    .detail-grid { grid-template-columns: 1fr; }
    .timeline-head { display: grid; gap: 3px; }
}
