:root {
  --brand: #eb9826;
  --brand-dark: #c97a12;
  --brand-soft: rgba(235, 152, 38, 0.14);
  --bg: #f4f6fa;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #ea580c;
  --info: #0284c7;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overscroll-behavior-y: contain;
}

.hidden { display: none !important; }
.flex-1 { flex: 1; }
.text-center { text-align: center; }
.text-muted { color: var(--muted); font-size: 13px; margin: 0; }
.stack-sm { display: flex; flex-direction: column; gap: 10px; }
.stack-md { display: flex; flex-direction: column; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Views */
.view { display: none; min-height: 100dvh; }
.view.active { display: flex; flex-direction: column; }

/* Toast */
.toast-container {
  position: fixed;
  top: calc(14px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  background: #0f172a;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.25);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: fadeSlideDown 0.22s ease;
}
.toast.positive { background: var(--success); }
.toast.negative { background: var(--danger); }
.toast.warning { background: var(--warning); }

@keyframes fadeSlideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Login */
.login-hero {
  position: relative;
  padding: calc(44px + var(--safe-top)) 24px 40px;
  background: linear-gradient(145deg, #0f172a 0%, #1e293b 65%, var(--brand-dark) 100%);
  color: #fff;
  border-bottom-left-radius: 28px;
  border-bottom-right-radius: 28px;
  text-align: center;
}
.brand-badge {
  width: 72px;
  height: 72px;
  margin: 0 auto 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.12);
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
}
.brand-badge img { width: 100%; height: 100%; object-fit: contain; border-radius: 12px; }
.login-hero h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.login-subtitle { margin: 6px 0 0; opacity: 0.85; font-size: 13px; }

.login-card {
  margin: -22px 16px 24px;
  background: var(--surface);
  border-radius: 20px;
  padding: 22px 18px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  border: 1px solid var(--border);
}

.login-footer-actions {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.server-pill {
  font-size: 11px;
  color: var(--muted);
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 999px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Inputs & Buttons */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 700; color: #334155; }

.input-icon {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 12px;
  height: 46px;
  transition: border-color 0.15s;
}
.input-icon:focus-within { border-color: var(--brand); background: #fff; }
.input-icon .material-icons-round { color: var(--muted); font-size: 20px; }
.input-icon input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
}

.input-plain {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  background: #f8fafc;
  color: var(--text);
  outline: none;
}
.input-plain:focus { border-color: var(--brand); background: #fff; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 12px; border-radius: 10px; }
.btn-icon-only { width: 46px; height: 46px; padding: 0; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-outline { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--brand-dark); }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn-inline {
  background: transparent;
  border: none;
  color: var(--muted);
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 4px;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #0f172a;
  color: #fff;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.18);
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-logo { width: 34px; height: 34px; border-radius: 10px; object-fit: contain; background: rgba(255,255,255,0.1); padding: 3px; }
.topbar-title { font-weight: 800; font-size: 15px; line-height: 1.1; }
.topbar-subtitle { font-size: 11px; opacity: 0.78; }
.topbar-actions { display: flex; gap: 8px; }

/* Main & Bottom Nav */
.main-content {
  flex: 1;
  padding: 12px 14px calc(82px + var(--safe-bottom));
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 60;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 4px calc(6px + var(--safe-bottom));
  box-shadow: 0 -4px 18px rgba(15, 23, 42, 0.06);
}
.nav-item {
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  font-size: 11px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.nav-item .material-icons-round { font-size: 22px; }
.nav-item.active { color: var(--brand-dark); }

/* Segmented Tabs & Filters */
.seg-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: #e2e8f0;
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 12px;
}
.seg-btn {
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 9px;
  font-weight: 700;
  font-size: 12px;
  color: #475569;
  font-family: inherit;
  cursor: pointer;
}
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 2px 6px rgba(15,23,42,0.08); }

.search-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }

.filter-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 6px;
}
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: #475569;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
}
.chip.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); }

/* Cards */
.cards-list { display: flex; flex-direction: column; gap: 12px; }

.order-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}
.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f1f5f9;
}
.guia-code { font-weight: 800; font-size: 15px; color: var(--text); }
.guia-sub { font-size: 11px; color: var(--muted); }

.status-pill {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  background: #f1f5f9;
  color: #475569;
  white-space: nowrap;
}
.st-ENTREGADO, .st-VERIFICADO, .st-COMPLETADA { background: #dcfce7; color: #15803d; }
.st-EN_RUTA, .st-EN_CAMINO, .st-EN\ RUTA { background: #e0f2fe; color: #0369a1; }
.st-NOVEDAD, .st-CANCELADO, .st-DEVOLUCION, .st-ANULADO { background: #fee2e2; color: #b91c1c; }
.st-REPROGRAMADO { background: #fef3c7; color: #b45309; }
.st-EN_BODEGA, .st-EN\ BODEGA { background: #f3e8ff; color: #7e22ce; }

.card-mid { padding: 10px 0; display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
.card-row { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; }
.card-row .material-icons-round { font-size: 17px; color: var(--brand-dark); margin-top: 1px; }
.recaudo-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 800;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 8px;
}

.card-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid #f1f5f9;
}
.card-action-btn {
  border: 1px solid var(--border);
  background: #f8fafc;
  color: var(--text);
  border-radius: 10px;
  padding: 7px 4px;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  font-family: inherit;
}
.card-action-btn .material-icons-round { font-size: 17px; }
.card-action-btn.wa { color: #15803d; border-color: #bbf7d0; background: #f0fdf4; }
.card-action-btn.primary { color: var(--brand-dark); border-color: #fde68a; background: #fffbeb; }

/* Empty State */
.empty-state {
  text-align: center;
  padding: 42px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
  color: var(--muted);
}
.empty-state .material-icons-round { font-size: 46px; opacity: 0.45; margin-bottom: 8px; }

.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.section-header-row h2 { margin: 0; font-size: 18px; font-weight: 800; }
.badge-muted { background: #e2e8f0; color: #475569; padding: 4px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }

/* Fullsheet */
.fullsheet {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: var(--bg);
  display: none;
  flex-direction: column;
}
#sheet-guia-detail.fullsheet { z-index: 140; }
.fullsheet.active { display: flex; }
.sheet-header {
  background: #0f172a;
  color: #fff;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sheet-title-wrap { flex: 1; min-width: 0; }
.sheet-title { font-weight: 800; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-subtitle { font-size: 11px; opacity: 0.78; }
.sheet-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; max-width: 680px; width: 100%; margin: 0 auto; }

.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.detail-card-title { font-size: 12px; font-weight: 800; text-transform: uppercase; color: var(--brand-dark); letter-spacing: 0.03em; }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.kv span:first-child { color: var(--muted); }
.kv strong { text-align: right; }

.evidence-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.evidence-thumb {
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 1;
  background: #f1f5f9;
  position: relative;
  cursor: pointer;
}
.evidence-thumb img { width: 100%; height: 100%; object-fit: cover; }
.evidence-thumb span {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 6px;
  text-align: center;
}

.timeline { display: flex; flex-direction: column; gap: 10px; border-left: 2px solid var(--border); padding-left: 12px; margin-left: 4px; }
.tl-item { position: relative; font-size: 12px; }
.tl-item::before {
  content: '';
  position: absolute;
  left: -17px;
  top: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
}
.tl-date { font-size: 11px; color: var(--muted); }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop.active { display: flex; }
.bottom-modal {
  display: none;
  width: 100%;
  max-width: 540px;
  max-height: 90dvh;
  background: var(--surface);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  padding: 10px 16px calc(20px + var(--safe-bottom));
  overflow-y: auto;
}
.bottom-modal.active { display: block; animation: slideUp 0.2s ease; }
@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-handle { width: 42px; height: 4px; border-radius: 99px; background: #cbd5e1; margin: 0 auto 10px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-header h3 { margin: 0; font-size: 16px; font-weight: 800; }
.modal-header .icon-btn { background: #f1f5f9; color: var(--text); }

.camera-box {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.camera-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.photo-preview { max-height: 190px; border-radius: 10px; object-fit: contain; }
.full-evidence-img { max-width: 100%; max-height: 70dvh; border-radius: 12px; }

.firma-canvas {
  width: 100%;
  height: 200px;
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  background: #fff;
  touch-action: none;
}

.info-banner {
  background: var(--brand-soft);
  color: var(--brand-dark);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.qr-reader-box {
  width: 100%;
  min-height: 240px;
  border-radius: 12px;
  overflow: hidden;
  background: #0f172a;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.stat-val { font-size: 20px; font-weight: 800; color: var(--brand-dark); }
.stat-lbl { font-size: 11px; color: var(--muted); font-weight: 600; margin-top: 2px; }
