/* ─── VARIABLES ─────────────────────────────────────────────────────────────── */
:root {
  --acc:        #7C3AED;
  --acc-dark:   #6D28D9;
  --acc-light:  #EDE9FE;
  --bg:         #F8F7FF;
  --surface:    #FFFFFF;
  --surface2:   #F3F0FF;
  --border:     #E5E1F5;
  --text:       #1E1B2E;
  --text-muted: #6B6880;
  --danger:     #DC2626;
  --success:    #16A34A;
  --warning:    #D97706;
  --info:       #0284C7;
  --shadow:     0 1px 3px rgba(124,58,237,.10), 0 1px 2px rgba(124,58,237,.06);
  --shadow-lg:  0 10px 25px rgba(124,58,237,.12);
  --radius:     8px;
  --topbar-h:   56px;
  --sidebar-w:  220px;
  --font:       -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
[data-theme="dark"] {
  --bg:         #0F0D1A;
  --surface:    #1A1626;
  --surface2:   #241E35;
  --border:     #2E2545;
  --text:       #EDE9FE;
  --text-muted: #9D94BC;
  --acc-light:  #2D1F5E;
  --shadow:     0 1px 3px rgba(0,0,0,.4);
  --shadow-lg:  0 10px 25px rgba(0,0,0,.5);
}

/* ─── RESET ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); }
a { color: var(--acc); text-decoration: none; }
button { cursor: pointer; font-family: inherit; font-size: 14px; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--text); }

/* ─── UTILITIES ──────────────────────────────────────────────────────────────── */
.d-none    { display: none !important; }
.d-flex    { display: flex; }
.gap-2     { gap: 8px; }
.gap-3     { gap: 12px; }
.ms-auto   { margin-left: auto; }
.mt-2      { margin-top: 8px; }
.mb-3      { margin-bottom: 12px; }
.mb-4      { margin-bottom: 16px; }
.w-100     { width: 100%; }
.text-muted   { color: var(--text-muted); }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.fs-sm     { font-size: 12px; }
.fs-xs     { font-size: 11px; }
.fw-600    { font-weight: 600; }
.text-center { text-align: center; }

/* ─── LAYOUT ─────────────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - var(--topbar-h));
}
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg);
}

/* ─── TOPBAR ─────────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.brand-icon {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-name { font-weight: 700; font-size: 18px; color: var(--text); line-height: 1.2; }
.brand-sub  { font-size: 11px; color: var(--text-muted); line-height: 1.2; }

/* ─── SIDEBAR ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.nav-section { padding: 8px 0; }
.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  padding: 8px 16px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--text-muted);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 13px;
  border-radius: 0;
  transition: background .15s, color .15s;
  cursor: pointer;
}
.nav-item svg { flex-shrink: 0; }
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active {
  background: var(--acc-light);
  color: var(--acc);
  font-weight: 600;
}

/* ─── LOGIN ──────────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
  position: relative;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.login-brand-icon {
  width: 52px; height: 52px;
  background: var(--acc);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  flex-shrink: 0;
}
.login-brand-name { font-size: 18px; font-weight: 700; color: var(--text); }
.login-brand-sub  { font-size: 12px; color: var(--text-muted); }
.login-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  gap: 0;
}
.login-tab {
  flex: 1;
  padding: 10px 0;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: color .15s, border-color .15s;
}
.login-tab.active { color: var(--acc); border-bottom-color: var(--acc); font-weight: 600; }
.login-tab:hover { color: var(--text); }

/* ─── THEME TOGGLE ───────────────────────────────────────────────────────────── */
.theme-toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s;
}
.theme-toggle-btn:hover { background: var(--acc-light); color: var(--acc); }

/* ─── CARDS ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1; }
.kpi-sub   { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ─── TABLES ─────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
thead tr { background: var(--surface2); }
th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }

/* ─── FORMS ──────────────────────────────────────────────────────────────────── */
.field-group { margin-bottom: 14px; }
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.field-input {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.field-input:focus { border-color: var(--acc); box-shadow: 0 0 0 3px rgba(124,58,237,.15); }
.field-select {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  outline: none;
  appearance: none;
  cursor: pointer;
}
.field-select:focus { border-color: var(--acc); box-shadow: 0 0 0 3px rgba(124,58,237,.15); }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row { display: flex; gap: 12px; align-items: flex-start; }
.form-row .field-group { flex: 1; }

/* ─── BUTTONS ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 500;
  font-size: 13px;
  transition: background .15s, border-color .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--acc); color: #fff; }
.btn-primary:hover { background: var(--acc-dark); }
.btn-secondary { background: var(--surface2); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #B91C1C; }
.btn-ghost { background: none; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; border-radius: 6px; }

/* ─── MODALS ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,13,26,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-wide { max-width: 820px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
  border-radius: 0 0 12px 12px;
  position: sticky; bottom: 0;
}

/* ─── TOASTS ─────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; gap: 12px;
  z-index: 2000;
  align-items: center;
}
.toast {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 18px 32px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  animation: slideDown .35s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 500px;
  min-width: 320px;
  text-align: center;
}
.toast-success { background: #DCFCE7; color: #14532D; border: 1px solid #86EFAC; }
.toast-danger  { background: #FEE2E2; color: #7F1D1D; border: 1px solid #FCA5A5; }
.toast-info    { background: #DBEAFE; color: #1E3A5F; border: 1px solid #93C5FD; }
@keyframes slideDown { from { transform: translate(-50%, -100%); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ─── BADGES ─────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-success { background: #DCFCE7; color: #15803D; }
.badge-danger  { background: #FEE2E2; color: #DC2626; }
.badge-warning { background: #FEF3C7; color: #B45309; }
.badge-info    { background: #DBEAFE; color: #1D4ED8; }
.badge-neutral { background: var(--surface2); color: var(--text-muted); }
.badge-acc     { background: var(--acc-light); color: var(--acc); }

/* ─── VEHICLE TYPE DOT ───────────────────────────────────────────────────────── */
.tipo-dot {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px;
}
.tipo-dot-icon {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--acc-light);
  color: var(--acc);
}

/* ─── MAP CONTAINER ──────────────────────────────────────────────────────────── */
.map-container {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.map-container .leaflet-container {
  font-family: var(--font);
}

/* ─── PAGE HEADER ────────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title { font-size: 20px; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ─── EMPTY STATE ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state svg { margin-bottom: 12px; opacity: .4; }
.empty-state p { margin-top: 8px; font-size: 13px; }

/* ─── SPINNER ────────────────────────────────────────────────────────────────── */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--acc);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── COLOR DOT ──────────────────────────────────────────────────────────────── */
.color-dot {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ─── ROUTE LINE PREVIEW ─────────────────────────────────────────────────────── */
.ruta-color-bar {
  display: inline-block;
  width: 18px; height: 4px;
  border-radius: 2px;
  vertical-align: middle;
}

/* ─── STOP LIST IN ROUTE EDITOR ──────────────────────────────────────────────── */
.stop-list {
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 240px;
  overflow-y: auto;
  background: var(--surface);
}
.stop-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.stop-list-item:last-child { border-bottom: none; }
.stop-num {
  min-width: 22px; height: 22px;
  background: var(--acc);
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}
.stop-list-item .btn-icon { margin-left: auto; }

/* ─── SPLIT LAYOUT (editor ruta) ─────────────────────────────────────────────── */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  align-items: start;
}
@media (max-width: 900px) {
  .editor-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

/* ─── INCIDENT CARD ──────────────────────────────────────────────────────────── */
.incident-card {
  border-left: 3px solid var(--acc);
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0;
  border-top: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.incident-card.abierto { border-left-color: var(--danger); }
.incident-card.en_atencion { border-left-color: var(--warning); }
.incident-card.cerrado { border-left-color: var(--success); opacity: .7; }

/* ─── CENTRO DE CONTROL (stub) ───────────────────────────────────────────────── */
.cc-stub {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  min-height: 300px;
  background: var(--surface2);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  text-align: center;
  padding: 32px;
}

/* ─── HORARIOS: chips editables al toque ─────────────────────────────────────── */
.hor-edit:hover { border-color: var(--acc) !important; background: var(--acc-light); }
