/* ============================================================
   ControlTransporte — Sistema de diseño
   ============================================================ */
:root {
  /* Color */
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafd;
  --border: #e6ebf2;
  --border-strong: #d4dde9;
  --text: #10203a;
  --muted: #5c6b80;
  --faint: #93a1b5;

  --primary: #2563eb;
  --primary-600: #1d4fd8;
  --primary-soft: #eaf1fe;
  --navy: #0e1f33;
  --navy-2: #14293f;
  --accent: #f59e0b;
  --accent-soft: #fef3e0;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --success: #16a34a;
  --success-soft: #e8f7ee;
  --warning: #d97706;
  --warning-soft: #fdf3e3;
  --info: #0e7490;
  --info-soft: #e6f6fa;

  /* Forma */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-md: 0 1px 3px rgba(15, 23, 42, .07), 0 8px 24px -12px rgba(15, 23, 42, .18);
  --shadow-lg: 0 24px 64px -16px rgba(10, 20, 40, .35);

  --side-w: 248px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; font-weight: 750; letter-spacing: -.02em; }
h2 { font-size: 1.1rem;  font-weight: 700; letter-spacing: -.01em; }
h3 { font-size: .98rem;  font-weight: 700; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
svg.ico { width: 19px; height: 19px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ============================================================
   Estructura: sidebar (escritorio) + contenido + nav inferior (móvil)
   ============================================================ */
.layout { min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 60;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-2) 100%);
  color: #c6d3e2;
  display: flex; flex-direction: column;
  padding: 18px 14px 14px;
}
.side-brand {
  display: flex; align-items: center; gap: 10px;
  color: #fff; font-weight: 750; font-size: 1.02rem; letter-spacing: -.01em;
  padding: 2px 8px 0;
}
.side-brand img { width: 34px; height: 34px; border-radius: 9px; box-shadow: var(--shadow-sm); }
.side-company {
  margin: 14px 8px 6px; padding: 10px 12px;
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .08);
  border-radius: var(--r-sm); font-size: .78rem; color: #9fb2c8;
}
.side-company b { display: block; color: #e8eff7; font-size: .84rem; margin-bottom: 2px; }

.side-nav { display: flex; flex-direction: column; gap: 3px; margin-top: 14px; flex: 1; }
.side-nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9.5px 12px; border-radius: 9px;
  color: #aebdd0; font-weight: 550; font-size: .92rem; text-decoration: none;
  transition: background .15s, color .15s;
  position: relative;
}
.side-nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.side-nav a.active { background: rgba(255, 255, 255, .1); color: #fff; }
.side-nav a.active::before {
  content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3.5px;
  background: var(--accent); border-radius: 0 4px 4px 0;
}

.side-user {
  margin-top: 12px; padding: 12px 10px 4px;
  border-top: 1px solid rgba(255, 255, 255, .09);
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--primary), #6d9bff);
  color: #fff; font-weight: 700; font-size: .82rem;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: .02em;
}
.side-user .who { flex: 1; min-width: 0; }
.side-user .who b { display: block; color: #fff; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user .who span { font-size: .75rem; color: #8ba0b8; }
.icon-btn {
  background: transparent; border: none; color: #9fb2c8; cursor: pointer;
  padding: 8px; border-radius: 8px; display: flex; align-items: center;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }

/* Contenido */
.content { margin-left: var(--side-w); min-height: 100vh; }
.page { max-width: 1180px; margin: 0 auto; padding: 30px 34px 70px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-sub { margin: 4px 0 0; color: var(--muted); font-size: .92rem; }

/* Barra superior y nav inferior (solo móvil) */
.mobile-top {
  display: none;
  position: sticky; top: 0; z-index: 55;
  background: var(--navy); color: #fff;
  padding: 10px 14px;
  align-items: center; gap: 10px;
}
.mobile-top img { width: 28px; height: 28px; border-radius: 7px; }
.mobile-top .m-brand { font-weight: 700; font-size: .98rem; flex: 1; }
.mobile-top .m-user { font-size: .75rem; color: #b9c8da; text-align: right; line-height: 1.3; }
.mobile-top .m-user b { display: block; color: #fff; font-size: .82rem; }

.bottom-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(15, 23, 42, .06);
  padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; color: var(--faint); text-decoration: none;
  font-size: .62rem; font-weight: 600; letter-spacing: .01em;
  border-radius: 8px;
}
.bottom-nav a svg.ico { width: 21px; height: 21px; }
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a:hover { text-decoration: none; }

@media (max-width: 999px) {
  .sidebar { display: none; }
  .content { margin-left: 0; }
  .mobile-top { display: flex; }
  .bottom-nav { display: flex; }
  .page { padding: 18px 14px 90px; }
  .page-head { margin-bottom: 16px; }
  h1 { font-size: 1.3rem; }
}

/* ============================================================
   Tarjetas
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}
.card > h2:first-child, .card > h3:first-child { margin-bottom: 14px; }

/* Tarjetas de estadística */
.stats-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin-bottom: 18px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
  display: flex; align-items: center; gap: 14px;
}
.stat .s-ico {
  width: 42px; height: 42px; border-radius: 11px; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.stat .s-ico svg.ico { width: 21px; height: 21px; }
.stat .num { font-size: 1.55rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: .8rem; font-weight: 550; }
.tint-blue   { background: var(--primary-soft); color: var(--primary); }
.tint-amber  { background: var(--accent-soft);  color: var(--warning); }
.tint-green  { background: var(--success-soft); color: var(--success); }
.tint-cyan   { background: var(--info-soft);    color: var(--info); }
.tint-red    { background: var(--danger-soft);  color: var(--danger); }

/* ============================================================
   Tablas
   ============================================================ */
.table-wrap { overflow-x: auto; }
.card.table-wrap, .card.table-card { padding: 0; overflow: hidden; }
.card.table-card .table-wrap { border-radius: 0; }
.card.table-card .t-head { padding: 16px 20px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
table { border-collapse: collapse; width: 100%; font-size: .875rem; }
th {
  text-align: left; background: var(--surface-2); color: var(--muted);
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr, table tr { transition: background .12s; }
tr:hover td { background: #f7fafd; }
td .actions { display: flex; gap: 6px; flex-wrap: wrap; }
td.empty-cell, td .empty-cell { text-align: center; }
.empty-row td { text-align: center; padding: 34px 16px; color: var(--faint); font-size: .9rem; }

/* ============================================================
   Formularios
   ============================================================ */
label {
  display: block; font-size: .72rem; font-weight: 700; color: var(--muted);
  margin: 12px 0 5px; text-transform: uppercase; letter-spacing: .05em;
}
input, select, textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  font: inherit; font-size: .9rem; background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}
input[type="file"] { padding: 8px; background: var(--surface-2); border-style: dashed; cursor: pointer; }
input[type="date"] { min-height: 38.5px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 0 18px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 9px; margin-top: 14px; }
.check input { width: 17px; height: 17px; flex: none; accent-color: var(--primary); cursor: pointer; }
.check label { margin: 0; text-transform: none; font-size: .89rem; font-weight: 550; letter-spacing: 0; color: var(--text); cursor: pointer; }
.hint { color: var(--muted); font-size: .8rem; margin-top: 4px; }

/* ============================================================
   Botones
   ============================================================ */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--primary); color: #fff;
  border: 1px solid transparent; border-radius: var(--r-sm);
  padding: 0 16px; height: 38px;
  font: inherit; font-size: .875rem; font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
}
button:hover, .btn:hover { background: var(--primary-600); text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button:focus-visible, .btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(37, 99, 235, .3); }
.btn-sm { height: 30px; padding: 0 11px; font-size: .78rem; border-radius: 7px; gap: 5px; }
.btn-sm svg.ico { width: 15px; height: 15px; }
.btn-outline {
  background: var(--surface); color: var(--text); border-color: var(--border-strong);
}
.btn-outline:hover { background: var(--surface-2); border-color: var(--faint); }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-danger.btn-outline, .btn-outline-danger {
  background: var(--surface); color: var(--danger); border-color: #f3c1c1;
}
.btn-outline-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-success { background: var(--success); }
.btn-success:hover { background: #15803d; }
.btn-warn { background: var(--accent); color: #442c05; }
.btn-warn:hover { background: #e18f06; }
button:disabled { opacity: .55; cursor: not-allowed; }

/* Barra de herramientas / filtros */
.toolbar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  margin-bottom: 16px;
}
.toolbar > div { min-width: 150px; }
.toolbar label { margin-top: 0; }
.toolbar .spacer { flex: 1; min-width: 0 !important; }
.filters-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  padding: 14px 18px 16px; margin-bottom: 16px;
  display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end;
}
.filters-card > div { min-width: 150px; }
.filters-card label { margin-top: 0; }
.filters-card .spacer { flex: 1; min-width: 0; }

/* ============================================================
   Chips de estado
   ============================================================ */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: .74rem; font-weight: 650; white-space: nowrap; line-height: 1.5;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.no-dot::before, .chip.sandach-1::before, .chip.sandach-2::before, .chip.sandach-3::before { display: none; }
.chip.pendiente  { background: #eef1f6; color: #4b5a70; }
.chip.asignado   { background: var(--primary-soft); color: var(--primary-600); }
.chip.aceptado   { background: #ece9fd; color: #5b47c9; }
.chip.en_carga   { background: var(--warning-soft); color: var(--warning); }
.chip.en_ruta    { background: var(--info-soft); color: var(--info); }
.chip.entregado  { background: var(--success-soft); color: var(--success); }
.chip.completado { background: #d7f2e1; color: #0d6832; }
.chip.rechazado, .chip.cancelado { background: var(--danger-soft); color: var(--danger); }
.chip.ok  { background: var(--success-soft); color: var(--success); }
.chip.off { background: var(--danger-soft); color: var(--danger); }
.chip.sandach-1 { background: #1a1a1a; color: #fff; }
.chip.sandach-2 { background: #fbbf24; color: #4a3203; }
.chip.sandach-3 { background: #16a34a; color: #fff; }

/* ============================================================
   Modal
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 20, 38, .5);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 4vh 14px 24px; overflow-y: auto;
  animation: fadeIn .18s ease;
}
.modal {
  background: var(--surface); border-radius: var(--r-lg);
  width: 100%; max-width: 700px;
  padding: 24px 26px;
  box-shadow: var(--shadow-lg);
  animation: popIn .22s cubic-bezier(.2, .9, .3, 1.2);
}
.modal h2 { margin-bottom: 4px; }
.modal .modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--border);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }

/* ============================================================
   Toasts
   ============================================================ */
#toast-container {
  position: fixed; bottom: 18px; right: 18px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(92vw, 360px);
}
@media (max-width: 999px) {
  #toast-container { bottom: calc(74px + env(safe-area-inset-bottom)); right: 12px; left: 12px; max-width: none; }
}
.toast {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-left: 4px solid var(--primary);
  padding: 11px 15px; border-radius: 10px;
  box-shadow: var(--shadow-md);
  font-size: .87rem; font-weight: 550;
  animation: slideIn .22s ease;
}
.toast.error   { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
.toast.warn    { border-left-color: var(--accent); }
@keyframes slideIn { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ============================================================
   Login y pantalla de bloqueo
   ============================================================ */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1100px 600px at 15% -10%, #24466e 0%, transparent 55%),
              radial-gradient(900px 500px at 110% 110%, #1c3a5e 0%, transparent 55%),
              linear-gradient(160deg, #0c1a2c 0%, #12283f 100%);
  padding: 24px 14px;
}
.login-card {
  background: var(--surface); border-radius: 20px;
  padding: 38px 34px 32px;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-card .logo { display: flex; justify-content: center; margin-bottom: 14px; }
.login-card .logo img { width: 62px; height: 62px; border-radius: 16px; box-shadow: var(--shadow-md); }
.login-card h1 { text-align: center; font-size: 1.35rem; }
.login-card .sub { text-align: center; color: var(--muted); font-size: .85rem; margin: 6px 0 18px; }
.login-card button { width: 100%; height: 42px; margin-top: 20px; font-size: .92rem; }
.login-err { color: var(--danger); font-size: .84rem; margin-top: 12px; text-align: center; font-weight: 550; }
.login-foot { text-align: center; color: var(--faint); font-size: .72rem; margin-top: 18px; }

.blocked-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #1b1d22, #2a2d34); padding: 16px;
}
.blocked-card {
  background: var(--surface); border-radius: 20px; padding: 38px 34px;
  max-width: 480px; text-align: center; box-shadow: var(--shadow-lg);
}
.blocked-card .icon {
  width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 18px;
  background: var(--danger-soft); color: var(--danger);
  display: flex; align-items: center; justify-content: center; font-size: 1.7rem;
}
.blocked-card h1 { font-size: 1.3rem; margin-bottom: 8px; }
.blocked-card p { color: var(--muted); }
.blocked-card button { margin-top: 14px; }

/* ============================================================
   Vista del conductor
   ============================================================ */
.push-banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: linear-gradient(120deg, #fff8ec, #fef3e0);
  border: 1px solid #f5dcae; border-radius: var(--r-md);
  padding: 13px 16px; margin-bottom: 16px;
}
.push-banner .pb-text { flex: 1; min-width: 200px; font-size: .86rem; color: #6b4d10; }
.push-banner .pb-text b { display: block; color: #4a3203; font-size: .9rem; }

.trip-card { padding: 0; overflow: hidden; }
.trip-head { padding: 18px 20px 14px; display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.trip-card .route { font-size: 1.12rem; font-weight: 750; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.trip-card .route .arr { color: var(--faint); font-weight: 400; }
.trip-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; }
.trip-meta span { color: var(--muted); font-size: .83rem; display: inline-flex; align-items: center; gap: 6px; }
.trip-meta svg.ico { width: 15px; height: 15px; color: var(--faint); }

.sandach-banner {
  padding: 9px 14px; font-weight: 700; text-align: center;
  font-size: .84rem; letter-spacing: .03em;
}
.sandach-banner.c1 { background: #161616; color: #fff; }
.sandach-banner.c2 { background: #fbbf24; color: #4a3203; }
.sandach-banner.c3 { background: #16a34a; color: #fff; }

/* Stepper del viaje */
.trip-steps { padding: 8px 20px 20px; }
.step { display: flex; gap: 14px; position: relative; padding: 10px 0 14px; }
.step:not(:last-child)::before {
  content: ""; position: absolute; left: 14px; top: 44px; bottom: -4px; width: 2px;
  background: var(--border); border-radius: 2px;
}
.step.done:not(:last-child)::before { background: #b3e0c3; }
.step-dot {
  width: 29px; height: 29px; border-radius: 50%; flex: none; margin-top: 3px;
  background: var(--surface); border: 2px solid var(--border-strong);
  color: var(--muted); font-size: .8rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; z-index: 1;
}
.step.done .step-dot { background: var(--success); border-color: var(--success); color: #fff; }
.step-body { flex: 1; min-width: 0; }
.step-title { font-weight: 700; font-size: .92rem; padding-top: 6px; }
.step.done .step-title { color: var(--success); }
.step-content { margin-top: 4px; }
.step-done-note { color: var(--muted); font-size: .84rem; margin-top: 2px; }
.step .sig-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.accept-box {
  padding: 14px 20px 20px; display: flex; gap: 10px; flex-wrap: wrap;
  border-top: 1px dashed var(--border);
}
.accept-box .btn-success, .accept-box .btn-outline-danger { flex: 1; min-width: 140px; height: 44px; }

.sig-pad {
  border: 2px dashed var(--border-strong); border-radius: var(--r-sm);
  background: #fcfdff; touch-action: none; width: 100%; display: block;
}

/* ============================================================
   Varios
   ============================================================ */
.import-result {
  font-size: .84rem; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 12px 14px; margin-top: 12px; max-height: 220px; overflow-y: auto;
}
.import-result .err { color: var(--danger); margin-top: 2px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--faint); }
.empty-state .e-ico {
  width: 52px; height: 52px; margin: 0 auto 12px; border-radius: 14px;
  background: var(--surface-2); color: var(--faint);
  display: flex; align-items: center; justify-content: center;
}
.empty-state .e-ico svg.ico { width: 24px; height: 24px; }
.empty-state p { margin: 0; font-size: .9rem; }

.lic-note { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .toolbar, .filters-card { flex-direction: column; align-items: stretch; }
  .toolbar > div, .filters-card > div { min-width: 0; }
  .toolbar button, .filters-card button { width: 100%; }
  .page-head { flex-direction: column; align-items: stretch; }
  .modal { padding: 20px 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  td, th { padding: 9px 10px; }
}
