:root {
  --primary:#111111;
  --secondary:#2ecc71;
  --bg:#f5f7fa;
  --card:#ffffff;
  --text:#1f2933;
  --muted:#697586;
  --line:#dde3ea;
  --warning:#f1c40f;
  --info:#3498db;
  --success:#2ecc71;
  --danger:#e74c3c;
  --shadow:0 12px 30px rgba(17, 17, 17, .09);
  --header-height:82px;
  --bottom-nav-height:72px;
}

* { box-sizing:border-box; }
html {
  min-height:100%;
  -webkit-text-size-adjust:100%;
}

body {
  margin:0;
  font-family:Inter, Arial, sans-serif;
  background:var(--bg);
  color:var(--text);
  min-height:100%;
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
  overscroll-behavior-y:none;
}

a { color:inherit; text-decoration:none; }

button, input, textarea {
  font:inherit;
}

button {
  min-height:48px;
  border:0;
  border-radius:8px;
  cursor:pointer;
  transition:.2s ease;
  touch-action:manipulation;
  -webkit-tap-highlight-color:transparent;
}

button:disabled {
  cursor:not-allowed;
  opacity:.55;
}

input, textarea {
  width:100%;
  border:1px solid var(--line);
  border-radius:8px;
  min-height:48px;
  padding:12px 14px;
  background:#fff;
  outline:none;
  font-size:16px;
}

textarea { resize:vertical; min-height:92px; }

input:focus, textarea:focus {
  border-color:var(--info);
  box-shadow:0 0 0 3px rgba(52, 152, 219, .13);
}

.guide-prefix-control {
  display:flex;
  align-items:center;
  width:100%;
  min-height:48px;
  border:1px solid var(--line);
  border-radius:8px;
  background:#fff;
  overflow:hidden;
  transition:.2s ease;
}

.guide-prefix-control:focus-within {
  border-color:var(--info);
  box-shadow:0 0 0 3px rgba(52, 152, 219, .13);
}

.guide-prefix-control span {
  align-self:stretch;
  display:flex;
  align-items:center;
  padding:0 12px 0 14px;
  background:#f0f4f8;
  color:#0d1b3d;
  font-weight:800;
  border-right:1px solid var(--line);
}

.guide-prefix-control input {
  min-height:46px;
  border:0;
  border-radius:0;
  box-shadow:none;
}

.guide-prefix-control input:focus {
  border:0;
  box-shadow:none;
}

.app-shell {
  min-height:100vh;
  padding:20px 20px calc(86px + env(safe-area-inset-bottom));
}

.container {
  width:min(1180px, 100%);
  margin:0 auto;
}

.topbar {
  position:sticky;
  top:0;
  z-index:25;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  min-height:var(--header-height);
  margin:0 -20px 20px;
  padding:14px 20px;
  background:rgba(245, 247, 250, .94);
  border-bottom:1px solid rgba(221, 227, 234, .72);
  backdrop-filter:blur(14px);
  -webkit-backdrop-filter:blur(14px);
}

.brand {
  display:flex;
  align-items:center;
  gap:12px;
}

.brand img {
  width:54px;
  height:54px;
  object-fit:contain;
}

.brand-title {
  margin:0;
  font-size:22px;
  line-height:1.1;
}

.brand-subtitle {
  margin:4px 0 0;
  color:var(--muted);
  font-size:13px;
}

.card {
  background:var(--card);
  border:1px solid rgba(221, 227, 234, .9);
  border-radius:8px;
  box-shadow:var(--shadow);
}

.admin-menu {
  display:grid;
  grid-template-columns:repeat(4, minmax(0, 1fr));
  gap:12px;
  margin:0 0 18px;
}

.admin-menu a {
  min-height:86px;
  display:flex;
  flex-direction:column;
  justify-content:center;
  gap:6px;
  padding:16px;
  border:1px solid rgba(221, 227, 234, .95);
  border-radius:8px;
  background:#fff;
  color:var(--text);
  box-shadow:0 10px 24px rgba(17, 17, 17, .06);
  transition:.2s ease;
}

.admin-menu a:hover {
  transform:translateY(-2px);
  border-color:rgba(52, 152, 219, .42);
  box-shadow:0 14px 30px rgba(17, 17, 17, .1);
}

.admin-menu a.active {
  background:#0d1b3d;
  border-color:#0d1b3d;
  color:#fff;
}

.admin-menu span {
  font-size:17px;
  font-weight:800;
}

.admin-menu strong {
  font-size:12px;
  line-height:1.35;
  color:var(--muted);
}

.admin-menu a.active strong {
  color:rgba(255, 255, 255, .75);
}

.login-page {
  min-height:100vh;
  min-height:100dvh;
  display:grid;
  place-items:center;
  padding:calc(20px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
}

.login-card {
  width:min(420px, 100%);
  padding:28px;
}

.login-logo {
  width:118px;
  display:block;
  margin:0 auto 14px;
}

.recaptcha-wrap {
  display:flex;
  justify-content:center;
  margin:0 0 16px;
  min-height:78px;
}

.field { margin-bottom:14px; }

.field label {
  display:block;
  margin-bottom:6px;
  color:var(--muted);
  font-size:13px;
}

.row {
  display:flex;
  gap:12px;
  align-items:center;
}

.btn {
  display:inline-flex;
  justify-content:center;
  align-items:center;
  gap:8px;
  min-height:48px;
  padding:10px 14px;
  font-weight:700;
  line-height:1.1;
}

.btn-primary { background:var(--primary); color:#fff; }
.btn-secondary { background:var(--secondary); color:#fff; }
.btn-soft { background:#edf2f7; color:var(--text); }
.btn-danger { background:var(--danger); color:#fff; }
.btn-icon { min-width:48px; min-height:48px; padding:0 10px; }

.btn:hover { transform:translateY(-1px); }
.btn:active { transform:translateY(0) scale(.99); }

.status {
  min-height:22px;
  margin:10px 0;
  color:var(--muted);
  text-align:center;
}

.panel-status-row {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:12px;
}

.panel-status-row .status {
  flex:1;
  margin:0;
  text-align:left;
}

.dashboard {
  display:grid;
  grid-template-columns:repeat(4, minmax(0, 1fr));
  gap:12px;
  margin-bottom:16px;
}

.metric {
  padding:16px;
  color:#fff;
  border-radius:8px;
  box-shadow:var(--shadow);
  min-height:96px;
}

.metric strong {
  display:block;
  margin-top:6px;
  font-size:28px;
}

.filters {
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  align-items:center;
  justify-content:space-between;
  margin-bottom:16px;
}

.filter-actions {
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

.filter-actions .btn {
  min-width:104px;
}

.filter-actions .active {
  background:var(--primary);
  color:#fff;
}

.table-wrap { overflow-x:auto; }

.data-table {
  width:100%;
  border-collapse:collapse;
  background:#fff;
  border-radius:8px;
  overflow:hidden;
}

.data-table th, .data-table td {
  padding:12px 10px;
  border-bottom:1px solid var(--line);
  text-align:left;
  vertical-align:middle;
}

.data-table th {
  background:var(--primary);
  color:#fff;
  font-size:13px;
}

.badge {
  display:inline-flex;
  align-items:center;
  min-height:28px;
  border-radius:999px;
  padding:4px 10px;
  color:#fff;
  font-weight:700;
  font-size:12px;
}

.estado-pendiente { background:var(--warning); }
.estado-en-ruta { background:var(--info); }
.estado-entregado { background:var(--success); }

.actions {
  display:flex;
  flex-wrap:wrap;
  gap:6px;
  min-width:270px;
}

.mobile-list { display:none; }

.shipment-card {
  padding:16px;
  margin-bottom:12px;
  border-left:4px solid var(--primary);
}

.shipment-card h3 {
  margin:0 0 8px;
  font-size:18px;
}

.shipment-card p {
  margin:4px 0;
  color:var(--muted);
}

.shipment-card .actions {
  display:grid;
  grid-template-columns:repeat(6, minmax(0, 1fr));
  gap:8px;
  min-width:0;
}

.shipment-card .actions .btn {
  width:100%;
}

.bottom-nav {
  position:fixed;
  left:0;
  right:0;
  bottom:0;
  display:none;
  grid-template-columns:repeat(4, 1fr);
  min-height:calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
  padding-bottom:env(safe-area-inset-bottom);
  background:rgba(255, 255, 255, .96);
  border-top:1px solid var(--line);
  box-shadow:0 -10px 30px rgba(17, 17, 17, .08);
  backdrop-filter:blur(14px);
  -webkit-backdrop-filter:blur(14px);
  z-index:50;
}

.bottom-nav a {
  min-height:var(--bottom-nav-height);
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:4px;
  color:var(--muted);
  font-size:12px;
  -webkit-tap-highlight-color:transparent;
}

.bottom-nav a span {
  font-size:20px;
  line-height:1;
}

.bottom-nav a.active {
  color:var(--primary);
  font-weight:700;
}

.install-app {
  position:fixed;
  left:16px;
  right:16px;
  bottom:calc(var(--bottom-nav-height) + 14px + env(safe-area-inset-bottom));
  z-index:55;
  display:none;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  max-width:420px;
  margin:0 auto;
  padding:12px;
  background:#111;
  color:#fff;
  border-radius:8px;
  box-shadow:0 16px 34px rgba(17, 17, 17, .24);
}

.install-app.visible {
  display:flex;
}

.install-app p {
  margin:0;
  font-size:13px;
  line-height:1.3;
}

.install-app button {
  flex:0 0 auto;
  background:var(--secondary);
  color:#fff;
  padding:0 14px;
  font-weight:900;
}

.standalone .install-app {
  display:none !important;
}

.modal {
  position:fixed;
  inset:0;
  display:none;
  align-items:center;
  justify-content:center;
  padding:calc(18px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
  background:rgba(17, 17, 17, .54);
  z-index:60;
}

.modal.open { display:flex; }

.modal-card {
  width:min(480px, 100%);
  padding:20px;
  max-height:calc(100dvh - 36px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow:auto;
}

.guide-actions {
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  justify-content:center;
  margin:16px 0;
}

.guide-label {
  width:10cm;
  min-height:15cm;
  margin:20px auto;
  background:#fff;
  color:#111;
  border:1.5px solid #111;
  overflow:hidden;
}

.guide-header {
  display:grid;
  grid-template-columns:64px 1fr;
  gap:10px;
  align-items:center;
  padding:10px;
  border-bottom:1px solid #111;
}

.guide-header img {
  width:58px;
  height:58px;
  object-fit:contain;
}

.guide-header h2 {
  margin:0;
  font-size:20px;
  letter-spacing:0;
}

.guide-header p { margin:2px 0; font-size:11px; }

.guide-section {
  padding:10px;
  border-bottom:1px solid #111;
}

.guide-label-title {
  font-size:10px;
  font-weight:800;
  color:#333;
  margin-bottom:4px;
}

.guide-address {
  font-size:20px;
  font-weight:900;
  line-height:1.16;
  white-space:pre-line;
  word-break:break-word;
}

.guide-grid {
  display:grid;
  grid-template-columns:1fr 140px;
  gap:10px;
  align-items:center;
}

.guide-small {
  font-size:12px;
  line-height:1.35;
}

.signature {
  padding-top:20px;
  text-align:center;
  font-size:11px;
}

.signature-line {
  border-top:1px solid #111;
  width:80%;
  margin:0 auto 6px;
}

.tracking-card {
  width:min(680px, 100%);
  margin:0 auto;
  padding:22px;
}

.tracking-state {
  font-size:26px;
  font-weight:900;
  text-align:center;
  margin:12px 0;
}

.progress {
  display:grid;
  grid-template-columns:repeat(3, 1fr);
  gap:8px;
  margin:18px 0;
}

.progress span {
  min-height:8px;
  border-radius:999px;
  background:#d8dee6;
}

.progress .done { background:var(--secondary); }

.pod-photo {
  max-width:100%;
  border-radius:8px;
  border:1px solid var(--line);
}

.pod-time {
  min-height:48px;
  display:flex;
  align-items:center;
  padding:12px 14px;
  border:1px solid var(--line);
  border-radius:8px;
  background:#f8fafc;
  color:var(--muted);
  font-weight:700;
}

.pod-preview {
  display:none;
  width:100%;
  max-height:260px;
  margin:0 0 14px;
  object-fit:cover;
  border:1px solid var(--line);
  border-radius:8px;
}

.reports-dashboard {
  grid-template-columns:repeat(4, minmax(0, 1fr));
}

.reports-dashboard .metric strong {
  font-size:24px;
}

.reports-grid {
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:16px;
  margin-bottom:16px;
}

.report-card {
  padding:20px;
}

.report-head {
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:14px;
  margin-bottom:16px;
}

.report-head h2 {
  margin:0;
  font-size:20px;
}

.report-head p {
  margin:4px 0 0;
  color:var(--muted);
  font-size:13px;
}

.bar-chart {
  display:grid;
  gap:14px;
}

.bar-row {
  display:grid;
  gap:8px;
}

.bar-label {
  display:flex;
  justify-content:space-between;
  gap:12px;
  color:var(--muted);
  font-weight:800;
}

.bar-label strong {
  color:var(--text);
}

.bar-track {
  height:12px;
  overflow:hidden;
  border-radius:999px;
  background:#edf2f7;
}

.bar-track span {
  display:block;
  height:100%;
  min-width:4px;
  border-radius:999px;
}

.mini-chart {
  min-height:210px;
  display:grid;
  grid-template-columns:repeat(7, minmax(0, 1fr));
  gap:10px;
  align-items:end;
}

.mini-bar {
  height:190px;
  display:grid;
  grid-template-rows:1fr auto auto;
  align-items:end;
  justify-items:center;
  gap:6px;
}

.mini-fill {
  width:100%;
  border-radius:8px 8px 3px 3px;
  background:linear-gradient(180deg, #2ecc71, #16a085);
  min-height:8px;
}

.mini-bar strong {
  font-size:13px;
}

.mini-bar span {
  color:var(--muted);
  font-size:11px;
  font-weight:800;
  text-transform:capitalize;
}

.summary-list {
  display:grid;
  grid-template-columns:repeat(3, minmax(0, 1fr));
  gap:12px;
}

.summary-list div {
  padding:14px;
  border:1px solid var(--line);
  border-radius:8px;
  background:#fff;
}

.summary-list span {
  display:block;
  color:var(--muted);
  font-size:12px;
  font-weight:800;
  margin-bottom:6px;
}

.summary-list strong {
  font-size:20px;
}

.visits-list strong {
  font-size:16px;
}

.select-control {
  width:100%;
  min-height:48px;
  border:1px solid var(--line);
  border-radius:8px;
  padding:0 12px;
  background:#fff;
  color:var(--text);
  font:inherit;
}

.courier-layout {
  display:grid;
  grid-template-columns:380px 1fr;
  gap:16px;
  margin-bottom:16px;
}

.courier-summary {
  grid-template-columns:repeat(3, minmax(0, 1fr));
}

.courier-delivered {
  display:grid;
  gap:10px;
}

.courier-delivery-row {
  display:flex;
  justify-content:space-between;
  gap:12px;
  padding:12px;
  border:1px solid var(--line);
  border-radius:8px;
  background:#fff;
}

.courier-delivery-row span {
  display:block;
  margin-top:4px;
  color:var(--muted);
  font-size:13px;
}

.scanner-card {
  margin-bottom:16px;
}

.scanner-grid {
  display:grid;
  grid-template-columns:minmax(260px, 360px) 1fr;
  gap:16px;
  align-items:start;
}

.scanner-actions {
  display:grid;
  grid-template-columns:repeat(3, minmax(0, 1fr));
  gap:8px;
}

.scanner-view {
  min-height:260px;
  overflow:hidden;
  border:1px solid var(--line);
  border-radius:8px;
  background:#111;
}

#barcodeReader {
  width:100%;
  min-height:260px;
}

#barcodeReader video {
  width:100% !important;
  min-height:260px;
  object-fit:cover;
}

.courier-dashboard {
  grid-template-columns:repeat(3, minmax(0, 1fr));
}

.courier-route-list {
  display:grid !important;
  gap:12px;
}

.courier-bottom {
  grid-template-columns:repeat(3, 1fr);
}

@media (max-width:768px) {
  body {
    background:linear-gradient(180deg, #ffffff 0, var(--bg) 190px);
  }

  .app-shell {
    padding:0 14px calc(var(--bottom-nav-height) + 18px + env(safe-area-inset-bottom));
  }

  .container {
    width:100%;
  }

  .admin-menu {
    grid-template-columns:repeat(2, minmax(0, 1fr));
    gap:10px;
    margin-bottom:14px;
  }

  .admin-menu a {
    min-height:74px;
    padding:12px;
  }

  .admin-menu span {
    font-size:15px;
  }

  .admin-menu strong {
    font-size:11px;
  }

  .topbar {
    align-items:center;
    min-height:72px;
    margin:0 -14px 14px;
    padding:calc(10px + env(safe-area-inset-top)) 14px 10px;
    border-bottom-color:rgba(221, 227, 234, .82);
  }

  .topbar .btn[data-logout] {
    min-width:48px;
    width:48px;
    padding:0;
    overflow:hidden;
    color:transparent;
    position:relative;
  }

  .topbar .btn[data-logout]::after {
    content:"Salir";
    color:var(--text);
    position:absolute;
    inset:0;
    display:grid;
    place-items:center;
    font-size:12px;
  }

  .brand {
    min-width:0;
  }

  .brand img {
    width:44px;
    height:44px;
  }

  .brand-title {
    font-size:18px;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
    max-width:calc(100vw - 126px);
  }

  .brand-subtitle {
    font-size:12px;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
    max-width:calc(100vw - 126px);
  }

  .dashboard { grid-template-columns:repeat(2, minmax(0, 1fr)); }
  .reports-dashboard { grid-template-columns:repeat(2, minmax(0, 1fr)); }
  .reports-grid { grid-template-columns:1fr; }
  .courier-layout { grid-template-columns:1fr; }
  .scanner-grid { grid-template-columns:1fr; }
  .scanner-actions { grid-template-columns:1fr; }
  .scanner-view { min-height:220px; }
  #barcodeReader { min-height:220px; }
  #barcodeReader video { min-height:220px; }
  .courier-dashboard { grid-template-columns:repeat(3, minmax(0, 1fr)); }
  .courier-summary { grid-template-columns:1fr; }
  .courier-delivery-row { display:block; }
  .report-card { padding:16px; }
  .report-head { align-items:stretch; }
  .report-head .btn { min-width:112px; }
  .summary-list { grid-template-columns:1fr; }
  .table-wrap { display:none; }
  .mobile-list { display:block; }
  .bottom-nav { display:grid; }

  .card {
    border-radius:8px;
    box-shadow:0 8px 24px rgba(17, 17, 17, .07);
  }

  .metric {
    min-height:84px;
    padding:14px;
  }

  .metric strong {
    font-size:25px;
  }

  .actions button {
    min-height:48px;
    min-width:48px;
    padding:0 8px;
    font-size:18px;
  }

  .filters {
    position:sticky;
    top:72px;
    z-index:20;
    align-items:stretch;
    margin:0 -14px 14px;
    padding:10px 14px;
    background:rgba(245, 247, 250, .94);
    border-bottom:1px solid rgba(221, 227, 234, .72);
    backdrop-filter:blur(14px);
    -webkit-backdrop-filter:blur(14px);
  }

  .filters input { min-height:48px; }

  .filter-actions {
    display:grid;
    grid-template-columns:repeat(4, minmax(0, 1fr));
    width:100%;
    gap:6px;
  }

  .filter-actions .btn {
    min-width:0;
    padding:0 8px;
    font-size:12px;
    white-space:nowrap;
  }

  .status {
    margin:8px 0 12px;
    font-size:13px;
  }

  .panel-status-row {
    align-items:stretch;
  }

  .panel-status-row .btn {
    min-width:112px;
  }

  .shipment-card {
    position:relative;
    margin-bottom:12px;
    padding:16px;
  }

  .shipment-card h3 {
    font-size:19px;
    letter-spacing:0;
  }

  .shipment-card p {
    font-size:14px;
  }

  .guide-label {
    width:calc(100vw - 24px);
    min-height:auto;
  }

  .guide-grid { grid-template-columns:1fr; }

  .guide-actions .btn,
  form .row .btn {
    flex:1 1 100%;
  }

  .login-card,
  .tracking-card {
    border-radius:8px;
    width:100%;
  }

  .tracking-card {
    min-height:calc(100dvh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    display:flex;
    flex-direction:column;
    justify-content:center;
  }
}

@media (display-mode: standalone) {
  body {
    user-select:none;
  }

  input,
  textarea {
    user-select:text;
  }
}

@media (max-width:420px) {
  .dashboard {
    grid-template-columns:repeat(2, minmax(0, 1fr));
    gap:8px;
  }

  .metric {
    min-height:78px;
    padding:12px;
  }

  .metric span {
    font-size:12px;
  }

  .metric strong {
    font-size:22px;
  }

  .login-card { padding:22px; }
  .guide-address { font-size:17px; }

  .shipment-card .actions {
    grid-template-columns:repeat(3, minmax(0, 1fr));
  }

  .bottom-nav a {
    font-size:11px;
  }

  .bottom-nav a span {
    font-size:19px;
  }
}

@media (min-width:769px) {
  .table-wrap {
    display:block;
  }

  .mobile-list {
    display:none !important;
  }
}

@media print {
  body { background:#fff; }
  .no-print, .topbar, .bottom-nav, .guide-actions { display:none !important; }
  .app-shell { padding:0; }
  .guide-label { margin:0 auto; box-shadow:none; }
}
