*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --orange: #f97316; --orange-dark: #c2410c;
  --green: #16a34a;  --red: #dc2626;
  --gray-100: #f3f4f6; --gray-200: #e5e7eb; --gray-400: #9ca3af;
  --gray-600: #4b5563; --gray-700: #374151;
}
body { font-family: system-ui,-apple-system,sans-serif; background:#f9fafb; }
.hidden { display: none !important; }
.err  { color: var(--red);   font-size:.875rem; text-align:center; margin-top:.5rem; }
.ok   { color: var(--green); font-size:.875rem; text-align:center; margin-top:.5rem; }
.empty { color:var(--gray-400); font-size:.875rem; }

/* ── Topbar ── */
.topbar {
  background: var(--orange); color:#fff;
  padding:.9rem 1.25rem; display:flex; align-items:center; gap:.75rem; flex-shrink:0;
}
.admin-topbar { background: var(--orange-dark); }
.topbar-logo  { font-size:1.6rem; }
.topbar-name  { flex:1; font-weight:700; font-size:1.1rem; }
.btn-logout {
  background:rgba(255,255,255,.25); border:none; color:#fff;
  padding:.4rem .9rem; border-radius:.6rem; font-size:.85rem; cursor:pointer;
}

/* ── Login ── */
#view-login {
  min-height:100dvh; display:flex; align-items:center; justify-content:center;
  background:#fff7ed; padding:1rem;
}
.login-card {
  background:#fff; border-radius:1.25rem; padding:2rem 1.75rem;
  width:100%; max-width:380px; box-shadow:0 4px 24px rgba(0,0,0,.1);
  display:flex; flex-direction:column; gap:.75rem;
}
.login-logo { font-size:3rem; text-align:center; }
.login-card h1 { text-align:center; font-size:1.5rem; color:var(--orange-dark); }
.login-sub { text-align:center; color:var(--gray-400); font-size:.875rem; }
.login-card form { display:flex; flex-direction:column; gap:.5rem; }
.login-card label { font-size:.85rem; font-weight:600; color:var(--gray-700); }
.login-card input, .name-form input {
  padding:.75rem 1rem; border:1.5px solid var(--gray-200);
  border-radius:.75rem; font-size:1rem; outline:none;
}
.login-card input:focus, .name-form input:focus { border-color:var(--orange); }
.btn-primary {
  padding:.85rem; background:var(--orange); color:#fff;
  border:none; border-radius:.75rem; font-size:1rem; font-weight:700;
  cursor:pointer; width:100%;
}
.btn-primary:hover:not(:disabled) { background:#ea6c10; }
.btn-primary:disabled { opacity:.6; cursor:default; }

/* ── Driver ── */
#view-driver { min-height:100dvh; background:#fff7ed; display:flex; flex-direction:column; }
.driver-main {
  flex:1; display:flex; flex-direction:column; align-items:center;
  justify-content:center; gap:1.5rem; padding:2rem 1.25rem;
}
.welcome-card {
  background:#fff; border-radius:1.25rem; padding:1.75rem 2rem;
  text-align:center; box-shadow:0 4px 20px rgba(0,0,0,.07); width:100%; max-width:340px;
}
.welcome-label { font-size:1.5rem; font-weight:800; color:var(--orange-dark); }
.welcome-sub   { color:var(--gray-400); font-size:.9rem; margin-top:.4rem; }
.name-form {
  display:flex; flex-direction:column; gap:.6rem; width:100%; max-width:340px;
}
.btn-start, .btn-stop {
  padding:1rem; border:none; border-radius:1rem; font-size:1.1rem;
  font-weight:700; cursor:pointer; width:100%; transition:background .2s;
}
.btn-start { background:var(--green); color:#fff; }
.btn-start:hover:not(:disabled) { background:#15803d; }
.btn-stop  { background:var(--red);   color:#fff; }
.btn-stop:hover:not(:disabled)  { background:#b91c1c; }
.btn-start:disabled, .btn-stop:disabled { opacity:.6; cursor:default; }

.km-card {
  background:#fff; border-radius:1.5rem; padding:2rem 2rem 1.5rem;
  text-align:center; box-shadow:0 4px 24px rgba(0,0,0,.08); width:100%; max-width:340px;
}
.km-driver { font-weight:700; color:var(--gray-700); font-size:1.05rem; margin-bottom:.75rem; }
.km-label  { color:var(--gray-400); font-size:.9rem; }
.km-value  { font-size:3.75rem; font-weight:800; color:var(--orange-dark); line-height:1.1; }
.km-unit   { font-size:1.4rem; font-weight:500; color:var(--gray-400); }
.km-time   { color:var(--gray-600); font-size:.875rem; margin-top:.3rem; }
.km-status { margin-top:.5rem; font-size:.78rem; color:var(--green); font-weight:600; }

.summary-card {
  background:#fff; border-radius:1.5rem; padding:2rem;
  text-align:center; box-shadow:0 4px 24px rgba(0,0,0,.08);
  width:100%; max-width:340px; display:flex; flex-direction:column; gap:1rem;
}
.summary-name { font-size:1.2rem; font-weight:700; color:var(--gray-700); }
.summary-row  { display:flex; align-items:center; gap:.75rem; justify-content:center; }
.summary-icon { font-size:1.5rem; }
.summary-val  { font-size:1.1rem; font-weight:600; color:var(--orange-dark); }
.summary-thanks { color:var(--gray-400); font-size:.875rem; }
.driver-hint { font-size:.8rem; color:var(--gray-400); text-align:center; line-height:1.5; max-width:300px; }
.ios-warn {
  background:#fef3c7; border:1.5px solid #fbbf24; border-radius:.75rem;
  padding:.75rem 1rem; font-size:.85rem; color:#92400e;
  text-align:center; max-width:340px; line-height:1.4;
}

/* ── Admin ── */
#view-admin { height:100dvh; display:flex; flex-direction:column; }
.admin-tabs {
  display:flex; background:#fff; border-bottom:2px solid var(--gray-200); flex-shrink:0;
}
.admin-tabs button {
  flex:1; padding:.7rem; background:none; border:none;
  font-size:.95rem; cursor:pointer; color:var(--gray-600); font-weight:600;
  border-bottom:3px solid transparent;
}
.admin-tabs button.active { color:var(--orange-dark); border-bottom-color:var(--orange); }
.admin-content { flex:1; overflow:hidden; display:flex; flex-direction:column; }

/* live panel */
.live-panel { padding:1.25rem; overflow-y:auto; height:100%; }
.live-header {
  display:flex; align-items:center; gap:.6rem; margin-bottom:1rem;
}
.live-header h2 { font-size:1.05rem; color:var(--gray-700); }
.live-dot {
  width:10px; height:10px; background:var(--gray-400);
  border-radius:50%; transition:background .3s;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }
.live-grid {
  display:grid; grid-template-columns:repeat(auto-fill,minmax(240px,1fr)); gap:1rem;
}
.live-card {
  background:#fff; border-radius:1rem; padding:1rem 1.1rem;
  box-shadow:0 2px 10px rgba(0,0,0,.06); display:flex; flex-direction:column; gap:.4rem;
}
.live-card-top   { display:flex; justify-content:space-between; align-items:center; }
.live-store      { background:var(--orange); color:#fff; font-size:.75rem; font-weight:700; padding:.2rem .6rem; border-radius:.4rem; }
.live-km         { font-weight:800; font-size:1.1rem; color:var(--orange-dark); }
.live-name       { font-weight:700; color:var(--gray-700); font-size:.95rem; }
.live-card-bottom{ display:flex; justify-content:space-between; font-size:.78rem; color:var(--gray-400); }
.poll-note       { font-size:.75rem; color:var(--gray-400); margin-top:1rem; text-align:center; }
.live-dot        { background:var(--gray-400); }   /* gris cuando sin activos */
.live-dot.dot-active { background:var(--green); animation:pulse 2s infinite; }

/* history panel */
.history-panel { padding:1.25rem; overflow-y:auto; height:100%; display:flex; flex-direction:column; gap:1rem; }
.history-filters {
  display:flex; flex-wrap:wrap; gap:.5rem; align-items:center;
  background:#fff; padding:.75rem; border-radius:.75rem;
  box-shadow:0 1px 6px rgba(0,0,0,.05);
}
.history-filters select,
.history-filters input[type="date"],
.history-filters input[type="text"] {
  padding:.45rem .7rem; border:1.5px solid var(--gray-200);
  border-radius:.6rem; font-size:.875rem; flex:1; min-width:130px; outline:none;
}
.history-filters select:focus,
.history-filters input:focus { border-color:var(--orange); }
.history-summary {
  display:flex; gap:1.5rem; padding:.5rem 0;
  font-size:.875rem; font-weight:600; color:var(--gray-600);
}
.history-table-scroll { overflow-x:auto; border-radius:.75rem; box-shadow:0 2px 10px rgba(0,0,0,.06); }
.history-table {
  width:100%; border-collapse:collapse; background:#fff; font-size:.875rem;
}
.history-table thead { background:var(--gray-100); }
.history-table th {
  text-align:left; padding:.65rem .9rem;
  font-size:.78rem; font-weight:700; color:var(--gray-600);
  text-transform:uppercase; letter-spacing:.04em; white-space:nowrap;
}
.history-table td { padding:.65rem .9rem; border-top:1px solid var(--gray-200); vertical-align:middle; }
.history-table tbody tr:hover { background:var(--gray-100); }
.store-tag {
  background:var(--orange); color:#fff; font-size:.72rem; font-weight:700;
  padding:.15rem .55rem; border-radius:.35rem; white-space:nowrap;
}
.td-km { font-weight:700; color:var(--orange-dark); }

/* map panel */
.map-panel { display:flex; height:100%; }
.map-sidebar {
  width:260px; flex-shrink:0; overflow-y:auto; padding:1rem;
  background:#fff; border-right:1px solid var(--gray-200);
  display:flex; flex-direction:column; gap:.6rem;
}
.map-sidebar h2 { font-size:1rem; color:var(--gray-700); }
.map-sidebar select {
  padding:.5rem .75rem; border:1.5px solid var(--gray-200);
  border-radius:.6rem; font-size:.9rem; width:100%;
}
.btn-search {
  padding:.6rem; background:var(--orange); color:#fff;
  border:none; border-radius:.6rem; font-weight:700; cursor:pointer; font-size:.9rem;
}
.btn-search:disabled { opacity:.6; }
.map-container { flex:1; }
#map-routes    { height:100%; width:100%; }
.route-chip {
  background:var(--gray-100); border-radius:.6rem; padding:.6rem .75rem;
  display:flex; flex-direction:column; gap:.1rem; font-size:.875rem;
}
.route-chip strong { color:var(--gray-700); }
.route-chip span   { font-weight:700; color:var(--orange-dark); }
.route-chip small  { color:var(--gray-400); }
.route-store-tag {
  font-size:.75rem; background:var(--orange); color:#fff;
  padding:.1rem .4rem; border-radius:.3rem; align-self:flex-start;
}

/* QR panel */
.qr-panel { padding:1.5rem; overflow-y:auto; height:100%; }
.qr-intro { color:var(--gray-600); font-size:.9rem; margin-bottom:1.5rem; line-height:1.5; }
.qr-grid  { display:flex; gap:1.5rem; flex-wrap:wrap; }
.qr-card  {
  background:#fff; border-radius:1rem; padding:1.5rem;
  box-shadow:0 2px 12px rgba(0,0,0,.07);
  display:flex; flex-direction:column; align-items:center; gap:.75rem; width:240px;
}
.qr-card h3   { font-size:1.1rem; color:var(--orange-dark); font-weight:700; }
.qr-img       { width:180px; height:180px; }
.qr-url       { font-size:.72rem; color:var(--gray-400); word-break:break-all; text-align:center; }
.btn-print    {
  padding:.5rem 1rem; background:var(--orange); color:#fff;
  border:none; border-radius:.6rem; font-size:.85rem; font-weight:700; cursor:pointer;
}
.qr-fallback  { font-size:.75rem; word-break:break-all; }

@media (max-width:640px) {
  .map-panel    { flex-direction:column; }
  .map-sidebar  { width:100%; max-height:160px; }
  .map-container{ flex:1; min-height:0; }
  #map-routes   { height:100%; }
  .qr-grid      { justify-content:center; }
  .live-grid    { grid-template-columns:1fr; }
  .history-filters { flex-direction:column; }
  .history-filters select,
  .history-filters input { min-width:0; width:100%; }
}
