/* =====================================================================
   ROUTIX - Sistema de diseño
   Base: oscuro con tinte violeta, acento verde lima, Manrope, botones en píldora
   ===================================================================== */

@font-face {
  font-family: "Manrope"; font-style: normal; font-weight: 200 800; font-display: swap;
  src: url("../fonts/manrope-latin-ext-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Manrope"; font-style: normal; font-weight: 200 800; font-display: swap;
  src: url("../fonts/manrope-latin-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #170e16;
  --bg-side: #120a11;
  --card: #211822;
  --card-2: #2a202c;
  --line: #33283a;
  --line-soft: #2a2030;
  --text: #f5f0f5;
  --muted: #a594a3;
  --faint: #6f5f6d;

  --lime: #a8f53b;
  --lime-hi: #c3ff6b;
  --lime-ink: #191018;
  --lime-soft: rgba(168, 245, 59, .14);
  --pale: #f0fde7;

  --ok: #a8f53b;
  --warn: #ffc857;
  --bad: #ff6b6b;
  --bad-soft: rgba(255, 107, 107, .14);
  --warn-soft: rgba(255, 200, 87, .14);

  --r-sm: 10px; --r-md: 14px; --r-lg: 20px; --r-pill: 999px;
  --side-w: 76px;
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 500 14px/1.5 var(--font); -webkit-font-smoothing: antialiased;
  min-height: 100dvh; overscroll-behavior-y: none;
}
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
h2 { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
h3 { font-size: 14px; font-weight: 700; }
a { color: var(--lime); text-decoration: none; }
a:hover { color: var(--lime-hi); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { display: block; max-width: 100%; }
:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.first-cap::first-letter { text-transform: uppercase; }

/* ---------- Iconos ---------- */
.ico { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico.sm { width: 16px; height: 16px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--r-pill);
  padding: 11px 22px; font-weight: 700; font-size: 14px; line-height: 1.2;
  background: var(--lime); color: var(--lime-ink);
  transition: background .15s var(--ease), transform .1s var(--ease), border-color .15s, opacity .15s;
  white-space: nowrap; user-select: none; -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--lime-hi); }
.btn:active { transform: scale(.98); }
.btn[disabled], .btn.loading { opacity: .55; pointer-events: none; }
.btn.secondary { background: var(--card-2); color: var(--text); border-color: var(--line); }
.btn.secondary:hover { background: #342838; }
.btn.ghost { background: transparent; color: var(--muted); padding: 9px 14px; }
.btn.ghost:hover { color: var(--text); background: var(--card-2); }
.btn.danger { background: var(--bad-soft); color: var(--bad); border-color: rgba(255,107,107,.3); }
.btn.danger:hover { background: rgba(255,107,107,.24); }
.btn.sm { padding: 7px 14px; font-size: 13px; }
.btn.lg { padding: 15px 28px; font-size: 16px; }
.btn.block { width: 100%; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; color: var(--muted);
  display: inline-grid; place-items: center; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--card-2); color: var(--text); }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .02em; }
.input, select.input, textarea.input {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 12px 14px; color: var(--text); transition: border-color .15s, box-shadow .15s;
  min-height: 46px; appearance: none; -webkit-appearance: none;
}
select.input {
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a594a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
textarea.input { min-height: 84px; resize: vertical; }
.input::placeholder { color: var(--faint); }
.input:focus { outline: none; border-color: var(--lime); box-shadow: 0 0 0 3px var(--lime-soft); }
.input[aria-invalid="true"] { border-color: var(--bad); }
.hint { font-size: 12px; color: var(--faint); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-error { background: var(--bad-soft); color: #ffb4b4; border: 1px solid rgba(255,107,107,.3); border-radius: var(--r-md); padding: 10px 14px; font-size: 13px; }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.check input { width: 20px; height: 20px; accent-color: var(--lime); }
input[type="range"] { accent-color: var(--lime); width: 100%; height: 34px; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 48px; }
.pw-wrap .icon-btn { position: absolute; right: 3px; top: 3px; }

/* ---------- Estructura ---------- */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100dvh; }
.side {
  position: sticky; top: 0; height: 100dvh; background: var(--bg-side); border-right: 1px solid var(--line-soft);
  display: flex; flex-direction: column; align-items: center; padding: 18px 0; gap: 6px; z-index: 30;
}
.side .brand { width: 44px; height: 44px; margin-bottom: 14px; }
.side .brand img { width: 100%; height: 100%; object-fit: contain; }
.side nav { display: flex; flex-direction: column; gap: 6px; flex: 1; align-items: center; }
.nav-link {
  position: relative; width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  color: var(--muted); transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--card-2); color: var(--text); }
.nav-link.active { background: var(--lime); color: var(--lime-ink); }
.nav-link .tip {
  position: absolute; left: 58px; background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  padding: 5px 10px; border-radius: 8px; font-size: 12px; font-weight: 700; white-space: nowrap;
  opacity: 0; pointer-events: none; transform: translateX(-4px); transition: all .15s; z-index: 50;
}
.nav-link:hover .tip { opacity: 1; transform: none; }
.side-foot { display: flex; flex-direction: column; gap: 6px; align-items: center; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 14px 28px; border-bottom: 1px solid var(--line-soft);
  background: var(--bg); position: sticky; top: 0; z-index: 20;
}
.topbar .title { font-weight: 700; font-size: 15px; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.sync-pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 700; background: var(--warn-soft); color: var(--warn);
}
.sync-pill.off { background: var(--bad-soft); color: var(--bad); }
.sync-pill i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--lime-soft); color: var(--lime);
  display: grid; place-items: center; font-weight: 800; font-size: 14px; border: 0;
}
.page { padding: 28px; max-width: 1480px; width: 100%; margin: 0 auto; animation: fade .25s var(--ease); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Tarjetas ---------- */
.card { background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r-lg); padding: 22px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.grid { display: grid; gap: 18px; }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-main { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 18px; }

.kpi .label { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.kpi .value { font-size: 28px; font-weight: 800; letter-spacing: -.02em; margin-top: 6px; line-height: 1.1; }
.kpi .value small { font-size: 14px; font-weight: 700; color: var(--muted); margin-left: 4px; }
.kpi .sub { margin-top: 6px; font-size: 12px; color: var(--muted); }

/* ---------- Chips y alertas ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--r-pill); font-size: 12px; font-weight: 700; background: var(--card-2); color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--lime-soft); color: var(--lime); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.neutral { background: var(--card-2); color: var(--text); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 700; color: var(--muted); padding: 0 14px 12px 0; white-space: nowrap; }
td { padding: 14px 14px 14px 0; border-top: 1px solid var(--line-soft); vertical-align: middle; }
th:last-child, td:last-child { padding-right: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: rgba(255,255,255,.02); }
.cell-main { font-weight: 700; }
.cell-sub { font-size: 12px; color: var(--muted); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 18px; }
.toolbar .field { min-width: 150px; }
.toolbar .grow { flex: 1; min-width: 200px; }
.search { position: relative; }
.search .ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search .input { padding-left: 42px; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 7px 14px; border-radius: var(--r-pill); font-weight: 700; font-size: 13px; }
.seg button.on { background: var(--lime); color: var(--lime-ink); }

/* ---------- Gráficos ---------- */
.hbar { display: grid; grid-template-columns: 96px 1fr 64px; gap: 12px; align-items: center; padding: 9px 0; }
.hbar .name { font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 14px; border-radius: var(--r-pill); background: var(--pale); overflow: hidden; position: relative; }
.hbar .fill { position: absolute; inset: 0 auto 0 0; background: var(--lime); border-radius: var(--r-pill); transition: width .5s var(--ease); }
.hbar .fill.over { background: var(--warn); }
.hbar .val { text-align: right; font-weight: 700; font-size: 13px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 14px; font-size: 12px; color: var(--muted); font-weight: 600; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: var(--lime); }
.legend i.pale { background: var(--pale); }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 220px; padding-top: 10px; border-bottom: 1px solid var(--line); position: relative; }
.bars .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; min-width: 0; }
.bars .bar { width: 100%; max-width: 26px; border-radius: 8px 8px 3px 3px; background: var(--lime); min-height: 3px; transition: height .5s var(--ease); }
.bars .col:nth-child(even) .bar { background: var(--pale); }
.bars .col:hover .bar { filter: brightness(1.12); }
.bar-labels { display: flex; gap: 8px; margin-top: 8px; }
.bar-labels span { flex: 1; text-align: center; font-size: 11px; color: var(--faint); font-weight: 600; overflow: hidden; }
.chart-empty { height: 220px; display: grid; place-items: center; color: var(--faint); }

.timeline { display: flex; flex-direction: column; }
.tl-item { display: grid; grid-template-columns: 14px 1fr; gap: 14px; padding-bottom: 18px; position: relative; }
.tl-item::before { content: ""; position: absolute; left: 6px; top: 16px; bottom: 0; width: 2px; background: var(--line); }
.tl-item:last-child::before { display: none; }
.tl-dot { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--card); background: var(--muted); margin-top: 3px; z-index: 1; }
.tl-dot.bad { background: var(--bad); } .tl-dot.warn { background: var(--warn); } .tl-dot.ok { background: var(--lime); }

/* ---------- Estados vacíos / carga ---------- */
.empty { text-align: center; padding: 44px 16px; color: var(--muted); }
.empty .ico { width: 36px; height: 36px; margin: 0 auto 12px; color: var(--faint); }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.skeleton { background: linear-gradient(90deg, var(--card) 0%, var(--card-2) 50%, var(--card) 100%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: var(--r-md); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Modal, toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(8, 4, 8, .72); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 16px; z-index: 100; animation: fadeo .15s; }
@keyframes fadeo { from { opacity: 0; } }
.modal { background: var(--card); border: 1px solid var(--line); border-radius: 24px; width: min(560px, 100%); max-height: min(90dvh, 820px); display: flex; flex-direction: column; animation: pop .22s var(--ease); }
.modal.sm { width: min(420px, 100%); }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 22px 24px 8px; }
.modal-body { padding: 12px 24px 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal-foot { padding: 16px 24px 22px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 200; max-width: min(380px, calc(100vw - 40px)); }
.toast { background: var(--card-2); border: 1px solid var(--line); border-left: 4px solid var(--lime); border-radius: var(--r-md); padding: 12px 16px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: pop .22s var(--ease); }
.toast.error { border-left-color: var(--bad); }
.toast.warn { border-left-color: var(--warn); }

/* ---------- Autenticación ---------- */
.auth { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-art { background: var(--bg-side); border-right: 1px solid var(--line-soft); display: flex; flex-direction: column; justify-content: center; align-items: flex-start; padding: 64px; gap: 22px; position: relative; overflow: hidden; }
.auth-art img { width: 120px; }
.auth-art h2 { font-size: 34px; line-height: 1.15; letter-spacing: -.02em; max-width: 14ch; }
.auth-art p { color: var(--muted); max-width: 38ch; font-size: 15px; }
.auth-art::after { content: ""; position: absolute; width: 520px; height: 520px; right: -200px; bottom: -220px; border-radius: 50%; background: radial-gradient(circle, var(--lime-soft), transparent 65%); }
.auth-panel { display: grid; place-items: center; padding: 28px; }
.auth-box { width: min(420px, 100%); display: flex; flex-direction: column; gap: 22px; }
.auth-box .mobile-logo { display: none; width: 76px; }
.auth-box form { display: flex; flex-direction: column; gap: 16px; }
.auth-foot { text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Vista del conductor ---------- */
.drv { max-width: 560px; margin: 0 auto; padding: 20px 18px 110px; }
.drv .hero { background: var(--card); border: 1px solid var(--line-soft); border-radius: 26px; padding: 24px; display: flex; flex-direction: column; gap: 18px; }
.drv .hero.active { border-color: rgba(168,245,59,.4); background: linear-gradient(160deg, #2a2a1f 0%, var(--card) 60%); }
.big-num { font-size: 40px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.kv { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.kv .k { font-size: 12px; color: var(--muted); font-weight: 700; }
.kv .v { font-weight: 800; font-size: 17px; margin-top: 2px; }
.bottom-nav { display: none; }
.level { display: flex; flex-direction: column; gap: 6px; }
.level-top { display: flex; justify-content: space-between; align-items: baseline; }
.level-top b { font-size: 26px; font-weight: 800; }
.level-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); font-weight: 700; }
.photo-drop { border: 1.5px dashed var(--line); border-radius: var(--r-md); padding: 16px; display: flex; align-items: center; gap: 14px; cursor: pointer; color: var(--muted); font-weight: 600; }
.photo-drop:hover { border-color: var(--lime); color: var(--text); }
.photo-drop img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; }
.list-item { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 14px 0; border-top: 1px solid var(--line-soft); }
.list-item:first-child { border-top: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-main { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 244px; align-items: stretch; padding: 18px 14px; transform: translateX(-100%); transition: transform .25s var(--ease); box-shadow: 20px 0 60px rgba(0,0,0,.5); }
  .side.open { transform: none; }
  .side .brand { width: 56px; height: 56px; margin-left: 4px; }
  .side nav, .side-foot { align-items: stretch; }
  .nav-link { width: 100%; height: 46px; justify-content: flex-start; padding: 0 14px; gap: 14px; display: flex; align-items: center; }
  .nav-link .tip { position: static; opacity: 1; transform: none; background: none; border: 0; padding: 0; font-size: 14px; color: inherit; }
  .scrim { position: fixed; inset: 0; background: rgba(8,4,8,.6); z-index: 25; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 10px 16px; }
  .page { padding: 20px 16px 40px; }
  .page-head h1, h1 { font-size: 22px; }
  .cols-3, .cols-2 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-art { display: none; }
  .auth-box .mobile-logo { display: block; }
  .toasts { left: 16px; right: 16px; bottom: 84px; max-width: none; }
  .card { padding: 18px; border-radius: 18px; }
  .table-wrap { margin: 0 -18px; padding: 0 18px; }
}
@media (max-width: 560px) {
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .value { font-size: 22px; }
  .modal { border-radius: 22px 22px 0 0; align-self: end; width: 100%; max-height: 92dvh; }
  .overlay { padding: 0; place-items: end center; }
  .hbar { grid-template-columns: 78px 1fr 52px; }
}
.is-driver .bottom-nav {
  display: grid; grid-template-columns: repeat(3, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: rgba(18,10,17,.94); backdrop-filter: blur(12px); border-top: 1px solid var(--line-soft);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}
.bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 4px; border-radius: 14px; color: var(--muted); font-size: 11px; font-weight: 700; }
.bottom-nav a.active { color: var(--lime-ink); background: var(--lime); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media print { .side, .topbar, .actions, .toolbar, .bottom-nav, .toasts { display: none !important; } body { background: #fff; color: #000; } .card { border: 1px solid #ccc; background: #fff; } }
