/* Kontrolina Tracker — Dark mode tech design */
:root {
  --bg-base:     #0b0f1a;
  --bg-card:     #111827;
  --bg-elevated: #1a2235;
  --bg-input:    #0f1623;
  --border:      #1e2d45;
  --border-light:#263450;
  --cyan:        #00d4ff;
  --cyan-dim:    rgba(0,212,255,.12);
  --cyan-glow:   0 0 20px rgba(0,212,255,.25);
  --purple:      #7c3aed;
  --purple-dim:  rgba(124,58,237,.15);
  --green:       #10b981;
  --green-dim:   rgba(16,185,129,.12);
  --red:         #ef4444;
  --yellow:      #f59e0b;
  --text:        #e2e8f0;
  --text-muted:  #64748b;
  --text-dim:    #94a3b8;
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;
  --shadow:      0 4px 24px rgba(0,0,0,.5);
  --shadow-glow: 0 0 0 1px var(--border), 0 4px 24px rgba(0,0,0,.5);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}

*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; }
body { margin: 0; background: var(--bg-base); color: var(--text); height: 100%; }
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }

/* ─── SCROLLBAR ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── LOGIN ───────────────────────────────────────────────── */
.app-shell { min-height: 100vh; }

.login-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr minmax(340px, 440px);
  gap: 48px;
  align-items: center;
  padding: 48px;
  background: var(--bg-base);
  position: relative;
  overflow: hidden;
}
/* Decorative glow blobs */
.login-view::before {
  content: '';
  position: absolute;
  top: -200px; left: -200px;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(0,212,255,.07) 0%, transparent 70%);
  pointer-events: none;
}
.login-view::after {
  content: '';
  position: absolute;
  bottom: -200px; right: -200px;
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(124,58,237,.07) 0%, transparent 70%);
  pointer-events: none;
}

.brand-panel { position: relative; z-index: 1; }

.brand-mark {
  width: 64px; height: 64px;
  display: grid; place-items: center;
  border-radius: var(--radius-md);
  background: var(--cyan-dim);
  border: 1px solid var(--cyan);
  color: var(--cyan);
  font-size: 28px; font-weight: 900;
  margin-bottom: 28px;
  box-shadow: var(--cyan-glow);
}
.brand-mark.small {
  width: 36px; height: 36px;
  margin: 0; font-size: 16px;
}

.brand-panel h1 {
  margin: 0 0 14px;
  font-size: 48px; font-weight: 700; line-height: 1.1;
  background: linear-gradient(120deg, #fff 0%, var(--cyan) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.brand-panel > p {
  margin: 0 0 40px;
  color: var(--text-muted);
  font-size: 16px; line-height: 1.6; max-width: 500px;
}

.brand-badges {
  display: flex; gap: 10px; flex-wrap: wrap;
}
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  border-radius: 99px;
  border: 1px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 12px; font-weight: 500;
}
.badge::before { content: '●'; color: var(--cyan); font-size: 8px; }

/* ─── LOGIN CARD ──────────────────────────────────────────── */
.login-card {
  position: relative; z-index: 1;
  display: grid; gap: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow), var(--cyan-glow);
}
.login-card-header { display: grid; gap: 4px; }
.login-card-header h2 { margin: 0; font-size: 22px; font-weight: 600; color: var(--text); }
.login-card-header p { margin: 0; color: var(--text-muted); font-size: 13px; }

/* ─── FORM ELEMENTS ───────────────────────────────────────── */
label {
  display: grid; gap: 7px;
  font-size: 12px; font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .5px;
}
input, select, textarea {
  width: 100%;
  min-height: 44px;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  transition: border-color .2s, box-shadow .2s;
  appearance: none;
  -webkit-appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(0,212,255,.12);
}
input::placeholder { color: var(--text-muted); }

button {
  min-height: 44px;
  padding: 0 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--cyan);
  color: #0b0f1a;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: all .2s;
  letter-spacing: .3px;
}
button:hover:not(:disabled) {
  background: #33ddff;
  box-shadow: 0 0 20px rgba(0,212,255,.35);
  transform: translateY(-1px);
}
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { opacity: .4; cursor: not-allowed; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-dim);
  font-weight: 500;
}
.ghost-btn:hover:not(:disabled) {
  background: var(--bg-elevated);
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: none;
  transform: none;
}

.icon-btn {
  width: 36px; min-height: 36px; padding: 0;
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  font-size: 18px; border-radius: var(--radius-sm);
}
.icon-btn:hover:not(:disabled) {
  border-color: var(--cyan);
  color: var(--cyan);
  background: var(--cyan-dim);
  box-shadow: none;
  transform: none;
}

.form-error {
  min-height: 18px;
  color: var(--red);
  font-size: 13px;
  font-weight: 500;
}

/* ─── DASHBOARD LAYOUT ────────────────────────────────────── */
.dashboard-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

/* ─── SIDEBAR ─────────────────────────────────────────────── */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px 16px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-row strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.brand-row span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── METRICS ─────────────────────────────────────────────── */
.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.metric {
  padding: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-align: center;
}
.metric span {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text-muted);
}
.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 30px;
  font-weight: 700;
  color: var(--cyan);
  line-height: 1;
}

/* ─── NAV MENU ────────────────────────────────────────────── */
.nav-menu {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.nav-item {
  min-height: 36px;
  padding: 0 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .2s;
  letter-spacing: .2px;
}
.nav-item:hover:not(.active) {
  border-color: var(--border-light);
  color: var(--text);
  background: var(--bg-elevated);
  box-shadow: none;
  transform: none;
}
.nav-item.active {
  background: var(--cyan-dim);
  border-color: var(--cyan);
  color: var(--cyan);
  font-weight: 600;
  box-shadow: none;
  transform: none;
}

/* ─── UNIT FILTER (COMBOBOX CORREGIDO) ─────────────────────── */
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.section-title h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text-muted);
}

/* El label ya no stack verticalmente — es solo el select */
.unit-filter {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
}
.unit-filter select {
  display: block;
  width: 100%;
  min-height: 36px;
  height: 36px;
  margin-top: 6px;
  padding: 0 32px 0 10px;
  font-size: 13px;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
}
.unit-filter select:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(0,212,255,.1);
}

/* ─── UNIT LIST ───────────────────────────────────────────── */
.unit-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1;
}
.unit-card {
  width: 100%;
  text-align: left;
  padding: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  cursor: pointer;
  transition: all .2s;
  box-shadow: none;
}
.unit-card:hover {
  border-color: var(--border-light);
  box-shadow: none;
  transform: none;
}
.unit-card.active {
  border-color: var(--cyan);
  background: var(--cyan-dim);
  box-shadow: inset 3px 0 0 var(--cyan);
}
.unit-card strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.unit-card span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}

.empty-state {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-md);
  line-height: 1.5;
}

/* ─── MAP AREA ────────────────────────────────────────────── */
.map-area {
  position: relative;
  min-width: 0;
  background: var(--bg-base);
}
#map {
  width: 100%;
  height: 100vh;
  background: var(--bg-base);
}

.map-toolbar {
  position: absolute;
  z-index: 500;
  top: 14px; left: 14px; right: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(17,24,39,.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}
.map-toolbar strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.map-toolbar span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.map-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#recenter-btn {
  min-height: 30px;
  padding: 0 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--cyan-dim);
  border-color: var(--cyan);
  color: var(--cyan);
  border-radius: 99px;
}
#recenter-btn:hover {
  background: var(--cyan);
  color: #0b0f1a;
  border-color: var(--cyan);
  transform: none;
  box-shadow: none;
}

.health-pill {
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid rgba(16,185,129,.3);
  white-space: nowrap;
}

/* ─── ADMIN PANEL ─────────────────────────────────────────── */
.admin-panel {
  position: absolute;
  z-index: 520;
  top: 72px; left: 14px;
  width: min(780px, calc(100% - 28px));
  max-height: calc(100vh - 90px);
  overflow-y: auto;
}
.admin-card {
  background: rgba(17,24,39,.96);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}
.admin-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.admin-card h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
.admin-card > p, .admin-head p {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* ─── CRUD FORMS ──────────────────────────────────────────── */
.crud-form {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}
.crud-form button[type="submit"] {
  grid-column: 1 / -1;
  justify-self: start;
  min-width: 160px;
}
.crud-form .ghost-btn {
  grid-column: 1 / -1;
  justify-self: start;
  min-width: 100px;
}

/* ─── CRUD LIST ───────────────────────────────────────────── */
.crud-list {
  display: grid;
  gap: 8px;
}
.crud-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color .15s;
}
.crud-item:hover { border-color: var(--border-light); }
.crud-item strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.crud-item span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.crud-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.crud-actions button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 500;
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
}
.crud-actions button:hover {
  border-color: var(--cyan);
  color: var(--cyan);
  background: var(--cyan-dim);
  box-shadow: none;
  transform: none;
}

/* ─── MAP POPUP ───────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  border: 1px solid var(--border-light) !important;
  border-radius: var(--radius-md) !important;
  color: var(--text) !important;
  box-shadow: var(--shadow) !important;
}
.leaflet-popup-tip { background: var(--bg-card) !important; }
.leaflet-popup-content { color: var(--text); font-size: 13px; line-height: 1.5; }
.popup-title { font-weight: 700; font-size: 14px; color: var(--cyan); margin-bottom: 4px; }

/* ─── BUS MARKER ──────────────────────────────────────────── */
.bus-marker {
  width: 36px; height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,.15);
  background: #374151;
  color: #9ca3af;
  font-size: 16px;
  font-weight: 900;
  box-shadow: 0 4px 12px rgba(0,0,0,.5);
}
.bus-marker.moving {
  background: var(--cyan);
  color: #0b0f1a;
  border-color: rgba(255,255,255,.4);
  box-shadow: 0 0 16px rgba(0,212,255,.5), 0 4px 12px rgba(0,0,0,.4);
  animation: pulse-marker 2s ease-in-out infinite;
}
@keyframes pulse-marker {
  0%, 100% { box-shadow: 0 0 16px rgba(0,212,255,.5), 0 4px 12px rgba(0,0,0,.4); }
  50%       { box-shadow: 0 0 28px rgba(0,212,255,.8), 0 4px 12px rgba(0,0,0,.4); }
}

/* ─── LEAFLET DARK OVERRIDES ──────────────────────────────── */
.leaflet-bar a {
  background: var(--bg-card) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-bar a:hover {
  background: var(--bg-elevated) !important;
  color: var(--cyan) !important;
}
.leaflet-control-attribution {
  background: rgba(17,24,39,.8) !important;
  color: var(--text-muted) !important;
}
.leaflet-control-attribution a { color: var(--cyan) !important; }

/* ─── RESPONSIVE — TABLET 1024px ─────────────────────────── */
@media (max-width: 1024px) {
  .login-view {
    grid-template-columns: 1fr;
    padding: 32px 24px;
    gap: 32px;
  }
  .brand-panel h1 { font-size: 36px; }
  .dashboard-view { grid-template-columns: 260px minmax(0,1fr); }
}

/* ─── RESPONSIVE — MOBILE 768px ──────────────────────────── */
@media (max-width: 768px) {
  .login-view { padding: 24px 16px; }
  .brand-panel h1 { font-size: 28px; }
  .brand-badges { display: none; }

  .dashboard-view {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 16px;
    gap: 14px;
  }
  .unit-list {
    max-height: 160px;
  }
  #map { height: 60vh; }
  .admin-panel {
    position: static;
    width: auto;
    max-height: none;
    overflow: visible;
  }
  .admin-card { margin: 12px; }
}

/* ─── RESPONSIVE — SMALL 480px ───────────────────────────── */
@media (max-width: 480px) {
  .login-view { padding: 16px; }
  .login-card { padding: 20px; gap: 16px; }
  .brand-panel h1 { font-size: 26px; }
  .brand-mark { width: 52px; height: 52px; font-size: 24px; margin-bottom: 16px; }

  .sidebar { padding: 12px; gap: 12px; }
  .nav-menu { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .nav-item { font-size: 11px; min-height: 32px; }

  .crud-form { grid-template-columns: 1fr; }
  .crud-form button[type="submit"],
  .crud-form .ghost-btn { grid-column: 1; }

  .crud-item { grid-template-columns: 1fr; }
  .crud-actions { justify-content: stretch; }
  .crud-actions button { flex: 1; }

  .admin-card { padding: 16px; margin: 8px; }
  .map-toolbar { flex-wrap: wrap; gap: 8px; }
}
