:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-subtle: #fafafa;
  --ink: #202329;
  --muted: #68707d;
  --line: #e3e6ea;
  --line-strong: #d2d7dc;
  --brand: #d64f78;
  --brand-dark: #a92f57;
  --brand-soft: #fff0f4;
  --green: #15805f;
  --green-soft: #e8f7f1;
  --yellow: #a26208;
  --yellow-soft: #fff5dd;
  --red: #be3d45;
  --red-soft: #fff0f1;
  --blue: #2668a6;
  --blue-soft: #edf5fc;
  --shadow: 0 18px 60px rgba(26, 31, 38, 0.08);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; overflow-x: hidden; color: var(--ink); background: var(--bg); font-size: 14px; letter-spacing: 0; }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(214, 79, 120, 0.2); outline-offset: 1px; }
.hidden, [hidden] { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: #24272c; color: #fff; padding: 22px 14px 18px; display: flex; flex-direction: column; z-index: 20; }
.brand-lockup { height: 68px; display: flex; align-items: center; gap: 12px; padding: 0 8px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand-lockup img { width: 108px; height: 52px; object-fit: contain; background: #fff; border-radius: 4px; padding: 3px; }
.brand-lockup span { font-weight: 700; font-size: 15px; }
.nav-list { display: grid; gap: 4px; padding-top: 22px; }
.nav-item { width: 100%; min-height: 44px; display: flex; align-items: center; gap: 11px; color: #c9ced6; background: transparent; border: 0; border-radius: 6px; padding: 0 12px; text-align: left; }
.nav-item svg { width: 19px; height: 19px; flex: 0 0 auto; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: #383b42; box-shadow: inset 3px 0 var(--brand); }
.nav-item b { margin-left: auto; min-width: 22px; height: 20px; display: inline-grid; place-items: center; border-radius: 10px; background: var(--red); color: #fff; font-size: 11px; }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 8px 0; border-top: 1px solid rgba(255,255,255,.1); color: #b8bec7; }
.sidebar-footer form { margin: 0; }
.sidebar-footer .icon-button { color: #c9ced6; border-color: rgba(255,255,255,.14); }

.main-content { min-width: 0; padding: 0 28px 40px; }
.topbar { min-height: 90px; display: flex; align-items: center; gap: 16px; justify-content: space-between; border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0; font-size: 24px; line-height: 1.2; }
.topbar p { margin: 5px 0 0; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.date-control, .search-box { background: var(--surface); border: 1px solid var(--line-strong); border-radius: 6px; display: flex; align-items: center; gap: 8px; padding: 0 10px; min-height: 40px; }
.date-control svg, .search-box svg { width: 17px; color: var(--muted); }
.date-control input, .search-box input { border: 0; outline: 0; background: transparent; min-height: 38px; color: var(--ink); }
.icon-button { width: 40px; height: 40px; display: inline-grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--ink); padding: 0; flex: 0 0 auto; }
.icon-button:hover { background: var(--surface-subtle); border-color: #bec4ca; }
.icon-button svg { width: 18px; height: 18px; }
.icon-button.loading svg { animation: spin 1s linear infinite; }
.mobile-only { display: none; }

.view { display: none; padding-top: 24px; }
.view.active { display: block; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric { min-height: 118px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 17px 18px; display: flex; flex-direction: column; justify-content: space-between; }
.metric-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); }
.metric-head svg { width: 19px; height: 19px; }
.metric strong { font-size: 28px; line-height: 1; font-variant-numeric: tabular-nums; }
.metric small { color: var(--muted); }
.metric[data-tone="green"] .metric-head svg { color: var(--green); }
.metric[data-tone="pink"] .metric-head svg { color: var(--brand); }
.metric[data-tone="yellow"] .metric-head svg { color: var(--yellow); }
.metric[data-tone="blue"] .metric-head svg { color: var(--blue); }

.content-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, .9fr); gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; min-width: 0; }
.panel-header { min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 0; font-size: 16px; }
.panel-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.text-button { border: 0; background: transparent; color: var(--brand-dark); font-weight: 700; padding: 8px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th { height: 42px; padding: 0 14px; text-align: left; font-size: 11px; color: var(--muted); text-transform: uppercase; font-weight: 700; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { height: 54px; padding: 8px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfcfd; }
.cell-title { font-weight: 700; }
.cell-subtitle { color: var(--muted); font-size: 12px; margin-top: 3px; }
.money { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 12px; font-weight: 700; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status.ok { color: var(--green); }
.status.ok::before { background: var(--green); }
.status.warn { color: var(--yellow); }
.status.warn::before { background: var(--yellow); }
.status.error { color: var(--red); }
.status.error::before { background: var(--red); }
.status.info { color: var(--blue); }
.status.info::before { background: var(--blue); }
.row-action { width: 34px; height: 34px; }
.empty-state { min-height: 180px; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }

.driver-list { display: grid; }
.driver-row { min-height: 69px; display: grid; grid-template-columns: 36px minmax(0,1fr) auto; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.driver-row:last-child { border-bottom: 0; }
.driver-avatar { width: 34px; height: 34px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-dark); font-weight: 800; border-radius: 50%; }
.driver-meta strong { display: block; }
.driver-meta span, .driver-value span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.driver-value { text-align: right; font-variant-numeric: tabular-nums; }

.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); padding: 3px; margin-bottom: 14px; }
.segmented button { min-height: 34px; border: 0; background: transparent; border-radius: 4px; color: var(--muted); padding: 0 15px; font-weight: 700; }
.segmented button.active { color: var(--ink); background: #eef0f2; }
.toolbar { display: grid; grid-template-columns: minmax(260px, 1fr) 220px 190px; gap: 10px; margin-bottom: 14px; }
.toolbar select { min-height: 42px; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 6px; color: var(--ink); padding: 0 10px; }
.search-box { min-height: 42px; }
.search-box input { width: 100%; }
.table-panel { overflow-x: auto; overflow-y: hidden; }
.pagination { height: 58px; display: flex; align-items: center; justify-content: flex-end; gap: 9px; padding: 0 14px; border-top: 1px solid var(--line); color: var(--muted); }
.pagination > span:first-child { margin-right: auto; }
.pagination .icon-button { width: 34px; height: 34px; }

.notice { border: 1px solid #ead6a9; background: var(--yellow-soft); color: #6e4a12; border-radius: 7px; min-height: 66px; padding: 13px 16px; display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.notice svg { width: 22px; flex: 0 0 auto; }
.notice strong, .notice span { display: block; }
.notice span { margin-top: 3px; color: #85652f; }
.issue-list { display: grid; gap: 8px; }
.issue { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--yellow); border-radius: 6px; min-height: 84px; padding: 14px 16px; display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: 14px; }
.issue[data-kind="event"], .issue[data-kind="message"] { border-left-color: var(--red); }
.issue-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 6px; background: var(--yellow-soft); color: var(--yellow); }
.issue[data-kind="event"] .issue-icon, .issue[data-kind="message"] .issue-icon { background: var(--red-soft); color: var(--red); }
.issue-icon svg { width: 19px; }
.issue h3 { margin: 0; font-size: 14px; }
.issue p { margin: 5px 0 0; color: var(--muted); overflow-wrap: anywhere; }
.issue-side { text-align: right; color: var(--muted); font-size: 12px; }
.issue-side strong { display: block; color: var(--ink); font-size: 14px; margin-bottom: 4px; }

.health-grid { display: grid; grid-template-columns: repeat(4, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.health-card { min-height: 128px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 16px; }
.health-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.health-card-head svg { width: 20px; color: var(--muted); }
.health-state { font-size: 18px; font-weight: 800; }
.health-detail { color: var(--muted); margin-top: 6px; font-size: 12px; }
.whatsapp-panel { max-width: 820px; }
.whatsapp-action { padding: 18px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.connection-line { display: flex; align-items: center; gap: 10px; }
.connection-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 4px var(--red-soft); }
.connection-dot.open { background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 6px; padding: 0 16px; font-weight: 800; border: 1px solid transparent; }
.button svg { width: 17px; height: 17px; }
.button-primary { background: var(--brand); color: #fff; }
.button-primary:hover { background: var(--brand-dark); }
.button-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.button-secondary:hover { background: var(--surface-subtle); }

.drawer-backdrop, .modal-backdrop { position: fixed; inset: 0; background: rgba(20, 23, 27, .36); z-index: 40; }
.detail-drawer { position: fixed; inset: 0 0 0 auto; width: min(560px, 100%); background: var(--surface); box-shadow: var(--shadow); z-index: 50; transform: translateX(102%); transition: transform .22s ease; display: flex; flex-direction: column; }
.detail-drawer.open { transform: translateX(0); }
.drawer-header, .modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px; border-bottom: 1px solid var(--line); }
.drawer-header h2, .modal-header h2 { margin: 4px 0 0; font-size: 20px; }
.modal-header p { margin: 5px 0 0; color: var(--muted); }
.eyebrow { display: block; color: var(--brand-dark); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.drawer-content { overflow: auto; padding: 18px 20px 32px; }
.detail-summary { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 22px; }
.detail-field { min-height: 66px; padding: 12px; border-bottom: 1px solid var(--line); }
.detail-field:nth-child(odd) { border-right: 1px solid var(--line); }
.detail-field:nth-last-child(-n+2) { border-bottom: 0; }
.detail-field span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; margin-bottom: 5px; }
.detail-field strong { overflow-wrap: anywhere; }
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ""; position: absolute; top: 8px; bottom: 8px; left: 6px; width: 1px; background: var(--line-strong); }
.timeline-item { position: relative; padding: 0 0 18px; }
.timeline-item::before { content: ""; position: absolute; top: 5px; left: -22px; width: 9px; height: 9px; border-radius: 50%; background: var(--green); border: 3px solid var(--green-soft); }
.timeline-item.error::before { background: var(--red); border-color: var(--red-soft); }
.timeline-item strong { display: block; }
.timeline-item span { display: block; color: var(--muted); margin-top: 4px; font-size: 12px; }
.invoice-link { margin-top: 15px; }

.modal-backdrop { display: grid; place-items: center; padding: 16px; }
.modal { width: min(460px, 100%); background: var(--surface); border-radius: 7px; box-shadow: var(--shadow); }
.qr-content { min-height: 280px; padding: 22px; display: grid; place-items: center; text-align: center; }
.qr-content img { width: min(290px, 100%); aspect-ratio: 1; object-fit: contain; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 80; max-width: min(380px, calc(100vw - 32px)); background: #24272c; color: #fff; border-radius: 6px; padding: 13px 16px; box-shadow: var(--shadow); }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #f3f4f6; }
.login-shell { width: min(880px, 100%); min-height: 520px; display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); }
.login-brand { background: #292b30; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 42px; color: #fff; }
.login-brand img { width: min(330px, 100%); background: #fff; border-radius: 6px; }
.login-brand p { margin: 24px 0 0; color: #d0d3d8; font-size: 15px; }
.login-panel { padding: 54px 46px; align-self: center; }
.login-copy h1 { margin: 8px 0 10px; font-size: 30px; }
.login-copy p { margin: 0 0 28px; color: var(--muted); line-height: 1.55; }
.login-form { display: grid; gap: 8px; }
.login-form label { font-weight: 700; margin-top: 8px; }
.login-form input { height: 44px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 12px; }
.login-form .button { margin-top: 14px; height: 44px; }
.alert { border-radius: 6px; padding: 11px 13px; margin-bottom: 16px; }
.alert-error { background: var(--red-soft); border: 1px solid #f2c9cc; color: var(--red); }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1120px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
  .content-grid { grid-template-columns: 1fr; }
  .health-grid { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
}

@media (max-width: 800px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; transform: translateX(-102%); width: 242px; transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .main-content { padding: 0 14px 28px; }
  .mobile-only { display: inline-grid; }
  .topbar { min-height: 76px; justify-content: flex-start; }
  .topbar h1 { font-size: 19px; }
  .topbar p { display: none; }
  .topbar-actions { margin-left: auto; }
  .date-control { padding: 0 7px; }
  .date-control svg { display: none; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric { min-height: 105px; padding: 14px; }
  .metric strong { font-size: 24px; }
  .toolbar { grid-template-columns: 1fr; }
  .health-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .panel-header { align-items: flex-start; }
  .issue { grid-template-columns: 36px minmax(0,1fr); }
  .issue-side { grid-column: 2; text-align: left; }
  .drawer-backdrop.visible { display: block; }
  .login-shell { grid-template-columns: 1fr; max-width: 500px; }
  .login-brand { min-height: 190px; padding: 28px; }
  .login-brand img { width: 250px; }
  .login-brand p { margin-top: 14px; }
  .login-panel { padding: 34px 28px 40px; }
}

@media (max-width: 520px) {
  .date-control input { width: 123px; }
  .metric-grid, .health-grid { grid-template-columns: 1fr; }
  .metric { min-height: 92px; }
  .whatsapp-action { align-items: stretch; flex-direction: column; }
  .panel-header .button span { display: none; }
  .detail-summary { grid-template-columns: 1fr; }
  .detail-field, .detail-field:nth-child(odd), .detail-field:nth-last-child(-n+2) { border-right: 0; border-bottom: 1px solid var(--line); }
  .detail-field:last-child { border-bottom: 0; }
}
