* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #1a365d;
  --primary-light: #2c5282;
  --accent: #e53e3e;
  --accent-orange: #dd6b20;
  --success: #276749;
  --warning: #d69e2e;
  --bg: #f7fafc;
  --card-bg: #ffffff;
  --text: #2d3748;
  --text-light: #718096;
  --border: #e2e8f0;
  --sidebar-w: 240px;
}
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
button { cursor: pointer; }

/* Login */
#login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #1a365d 0%, #2b6cb0 100%); }
.login-card { background: white; border-radius: 16px; padding: 40px; width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { color: var(--primary); font-size: 22px; margin-top: 12px; }
.login-logo p { color: var(--text-light); font-size: 13px; }
.login-logo .icon { font-size: 48px; color: var(--primary); }
.login-logo .icon .ti { font-size: 52px; }
.login-logo-img { width: 80px; height: 80px; object-fit: contain; display: block; margin: 0 auto 6px; }
.login-brand { font-size: 24px; font-weight: 700; margin: 4px 0 2px; letter-spacing: -0.5px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 14px; transition: border-color 0.2s; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--primary-light); }
.form-group textarea { min-height: 80px; resize: vertical; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 20px; border: none; border-radius: 8px; font-size: 14px; font-weight: 600; transition: all 0.2s; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-danger { background: var(--accent); color: white; }
.btn-danger:hover { background: #c53030; }
.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.otp-input { letter-spacing: 10px; font-size: 24px; font-weight: 700; text-align: center; }
.otp-box { background: #f0f4ff; border: 2px dashed #4a90e2; border-radius: 12px; padding: 20px; text-align: center; }
.otp-box small { color: var(--text-light); font-size: 12px; }

/* Layout */
#app { display: none; }
.sidebar { position: fixed; top: 0; left: 0; width: var(--sidebar-w); height: 100vh; background: var(--primary); color: white; overflow-y: auto; z-index: 100; }
.sidebar-header { padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,0.1); display: flex; align-items: center; gap: 10px; }
.sidebar-header h2 { font-size: 15px; font-weight: 700; margin: 0; }
.sidebar-header p { font-size: 11px; opacity: 0.7; margin-top: 2px; }
.sidebar-logo-img { width: 44px; height: 44px; object-fit: contain; flex-shrink: 0; filter: drop-shadow(0 1px 3px rgba(0,0,0,0.4)); }
.sidebar-brand { font-size: 15px; font-weight: 700; margin: 0; }
.sidebar-user { padding: 12px 20px; background: rgba(255,255,255,0.08); border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-user .user-name { font-size: 13px; font-weight: 600; }
.sidebar-user .user-role { font-size: 11px; opacity: 0.6; }
.sidebar-user .user-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 700; text-transform: uppercase; background: rgba(255,255,255,0.2); margin-top: 4px; }
nav ul { list-style: none; padding: 8px 0; }
nav ul li a { display: flex; align-items: center; gap: 10px; padding: 10px 20px; font-size: 13px; color: rgba(255,255,255,0.8); transition: all 0.2s; }
nav ul li a:hover, nav ul li a.active { background: rgba(255,255,255,0.12); color: white; }
nav ul li a .icon { font-size: 16px; width: 20px; text-align: center; }
.nav-section { padding: 8px 20px 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; color: rgba(255,255,255,0.4); letter-spacing: 1px; margin-top: 4px; }
.nav-logout { padding: 12px 20px; border-top: 1px solid rgba(255,255,255,0.1); margin-top: auto; }
.nav-logout button { background: rgba(255,255,255,0.1); color: white; border: none; padding: 8px 16px; border-radius: 6px; font-size: 13px; width: 100%; }

.main-content { margin-left: var(--sidebar-w); min-height: 100vh; }
.page-header { background: white; padding: 16px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10; }
.page-header h1 { font-size: 20px; font-weight: 700; color: var(--primary); }
.page-body { padding: 24px; }

/* Cards */
.card { background: white; border-radius: 12px; border: 1px solid var(--border); padding: 20px; margin-bottom: 16px; }
.card-title { font-size: 14px; font-weight: 700; color: var(--primary); margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: white; border-radius: 12px; padding: 20px; border: 1px solid var(--border); }
.stat-card .stat-num { font-size: 32px; font-weight: 800; color: var(--primary); }
.stat-card .stat-label { font-size: 12px; color: var(--text-light); margin-top: 4px; }
.stat-card.danger .stat-num { color: var(--accent); }
.stat-card.warning .stat-num { color: var(--warning); }
.stat-card.success .stat-num { color: var(--success); }

/* Table */
.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
thead th { background: #f8fafc; padding: 10px 14px; font-size: 12px; font-weight: 700; text-align: left; color: var(--text-light); border-bottom: 1px solid var(--border); text-transform: uppercase; letter-spacing: 0.5px; }
tbody td { padding: 10px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-success { background: #c6f6d5; color: #276749; }
.badge-danger { background: #fed7d7; color: #c53030; }
.badge-warning { background: #fef3c7; color: #d69e2e; }
.badge-info { background: #bee3f8; color: #2b6cb0; }
.badge-gray { background: #e2e8f0; color: #4a5568; }
.badge-purple { background: #e9d8fd; color: #553c9a; }
.badge-blue-soft { background: #bee3f8; color: #1a365d; font-weight:700; }
.badge-inactive { background: #e2e8f0; color: #718096; border: 1px dashed #a0aec0; font-size: 11px; }

/* Filas inactivas */
tr.row-inactive td { opacity: 0.55; }
tr.row-inactive { background: repeating-linear-gradient(
  135deg,
  transparent,
  transparent 6px,
  rgba(0,0,0,0.02) 6px,
  rgba(0,0,0,0.02) 12px
); }

/* Campos de vehículo bloqueados para trasladistas */
.vf-locked {
  background: #f7fafc !important;
  color: #4a5568 !important;
  border-color: #e2e8f0 !important;
  cursor: not-allowed !important;
  user-select: none;
}
.vf-locked:focus { outline: none; box-shadow: none; border-color: #e2e8f0 !important; }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: white; border-radius: 16px; padding: 28px; width: 90%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal-lg { max-width: 780px; }
.modal-xl { max-width: 1000px; }
.modal-wide { max-width: 680px; }

/* Photo batch capture grid */
.ph-slot { -webkit-tap-highlight-color: transparent; transition: transform 0.1s, box-shadow 0.1s; }
.ph-slot:active { transform: scale(0.96); }
.ph-slot.has-pic { box-shadow: 0 2px 8px rgba(56,161,105,0.25); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-header h3 { font-size: 18px; font-weight: 700; color: var(--primary); }
.modal-close { background: none; border: none; font-size: 22px; color: var(--text-light); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row.three { grid-template-columns: 1fr 1fr 1fr; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; display: flex; align-items: flex-start; gap: 8px; }
.alert-danger { background: #fff5f5; border: 1px solid #fed7d7; color: #c53030; }
.alert-warning { background: #fffbeb; border: 1px solid #fef3c7; color: #d69e2e; }
.alert-success { background: #f0fff4; border: 1px solid #c6f6d5; color: #276749; }
.alert-info { background: #ebf8ff; border: 1px solid #bee3f8; color: #2b6cb0; }

/* GPS Map placeholder */
.map-container { background: #e8f4fd; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }

/* Signature pad */
.sig-canvas { border: 2px dashed var(--border); border-radius: 8px; background: #fafafa; display: block; width: 100%; }
.sig-actions { display: flex; gap: 8px; margin-top: 8px; }

/* Mobile view for trasladistas */
.mobile-card { background: white; border-radius: 16px; padding: 20px; margin-bottom: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); border-left: 4px solid var(--primary); }
.mobile-card.status-iniciado { border-left-color: #38a169; }
.mobile-card.status-detenido { border-left-color: #d69e2e; }
.mobile-card.status-terminado { border-left-color: #4a5568; }
.mobile-card.status-cancelado { border-left-color: #e53e3e; }
.status-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.status-btn { padding: 14px; border: none; border-radius: 10px; font-size: 14px; font-weight: 700; transition: all 0.2s; }
.status-btn.iniciado { background: #c6f6d5; color: #276749; }
.status-btn.detenido { background: #fef3c7; color: #d69e2e; }
.status-btn.terminado { background: #e2e8f0; color: #4a5568; }
.status-btn.cancelado { background: #fed7d7; color: #c53030; }
.status-btn:hover { transform: scale(1.02); }
.status-btn.current { filter: brightness(0.72); box-shadow: inset 0 2px 6px rgba(0,0,0,0.22); cursor: default; transform: none !important; pointer-events: none; }

/* Vehicle catalog search results */
.catalog-result-item {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 4px;
  transition: background 0.15s;
}
.catalog-result-item:hover { background: #ebf8ff; border-color: var(--primary-light); }

/* ============================================================
   LIVE MONITOR
   ============================================================ */
.monitor-layout {
  display: flex;
  flex-direction: row;
  height: calc(100vh - 65px);
  margin: -24px;
  overflow: hidden;
}
.monitor-sidebar {
  width: 300px;
  flex-shrink: 0;
  background: white;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.monitor-sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  background: #f8fafc;
  flex-shrink: 0;
}
#monitor-list {
  overflow-y: auto;
  flex: 1;
}
.monitor-trip-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.monitor-trip-item:hover { background: #f0f4ff; }
.monitor-trip-item.selected { background: #ebf8ff; border-left: 3px solid var(--primary-light); }
.monitor-trip-item.no-gps { opacity: 0.65; }
.monitor-map-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-width: 0;
}
#live-map {
  width: 100%;
  height: 100%;
  z-index: 1;
}
.monitor-no-gps {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  background: white;
  border-radius: 12px;
  padding: 24px 32px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  z-index: 10;
  color: var(--text-light);
}
.monitor-no-gps .icon { font-size: 40px; margin-bottom: 8px; }

/* Vehicle markers on map */
.map-vehicle-marker {
  background: #1a365d;
  color: white;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 11px;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  border: 2px solid white;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
  position: relative;
}
.map-vehicle-marker::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: #1a365d;
}
.map-vehicle-marker.stopped { background: #d69e2e; }
.map-vehicle-marker.stopped::after { border-top-color: #d69e2e; }
.map-vehicle-icon { font-size: 16px; line-height: 1; }
.map-vehicle-label { font-size: 10px; font-weight: 700; line-height: 1.2; max-width: 56px; overflow: hidden; text-overflow: ellipsis; }
.map-vehicle-speed { font-size: 9px; opacity: 0.85; }

@media (max-width: 768px) {
  .monitor-layout { flex-direction: column; }
  .monitor-sidebar { max-height: 200px; width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  #geofence-panel { width: 100% !important; max-height: 250px; border-left: none !important; border-top: 1px solid var(--border); }
}

/* Sidebar backdrop (mobile overlay to close sidebar by tapping outside) */
#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 99;
  -webkit-tap-highlight-color: transparent;
}
#sidebar-backdrop.visible { display: block; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.3s; z-index: 100; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .form-row { grid-template-columns: 1fr; }
  .mobile-menu-btn { display: flex !important; }

  /* Prevent zoom on input focus (iOS requires font-size >= 16px) */
  input, select, textarea {
    font-size: 16px !important;
  }

  /* Bigger tap targets for nav items */
  .sidebar nav ul li a {
    padding: 14px 20px;
    font-size: 15px;
  }

  /* Make modals full-width on small screens */
  .modal {
    width: 96%;
    padding: 20px 16px;
    max-height: 88vh;
  }

  /* Prevent horizontal page scroll when sidebar is open */
  body.sidebar-open { overflow: hidden; }

  /* Table horizontal scroll on mobile */
  .table-wrap { -webkit-overflow-scrolling: touch; }
}
.mobile-menu-btn { display: none; background: none; border: none; font-size: 24px; color: var(--primary); cursor: pointer; }

/* Loading */
.loading { display: flex; align-items: center; justify-content: center; padding: 40px; color: var(--text-light); gap: 10px; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Search & Filters */
.filters-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.search-input { padding: 8px 14px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 13px; min-width: 200px; }
.search-input:focus { outline: none; border-color: var(--primary-light); }

/* Sinistro alert animation */
.sinistro-alert { animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }

/* Photo grid */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.photo-thumb { border-radius: 8px; overflow: hidden; aspect-ratio: 1; background: var(--border); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* Tab nav */
.tab-nav { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab-btn { padding: 10px 20px; background: none; border: none; font-size: 13px; font-weight: 600; color: var(--text-light); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.2s; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

.empty-state { text-align: center; padding: 48px 20px; color: var(--text-light); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; color: var(--text); margin-bottom: 6px; }

/* Trip status timeline */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.timeline-item { position: relative; margin-bottom: 16px; }
.timeline-dot { position: absolute; left: -20px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); border: 2px solid white; box-shadow: 0 0 0 2px var(--primary); }
.timeline-item.iniciado .timeline-dot { background: #38a169; box-shadow: 0 0 0 2px #38a169; }
.timeline-item.detenido .timeline-dot { background: #d69e2e; box-shadow: 0 0 0 2px #d69e2e; }
.timeline-item.terminado .timeline-dot { background: #4a5568; box-shadow: 0 0 0 2px #4a5568; }
.timeline-item.cancelado .timeline-dot { background: #e53e3e; box-shadow: 0 0 0 2px #e53e3e; }
.timeline-content { background: #f8fafc; border-radius: 8px; padding: 10px 14px; }
.timeline-content strong { display: block; font-size: 13px; color: var(--text); }
.timeline-content small { color: var(--text-light); font-size: 11px; }
