/* =========================================================================
   ArguedasOne Fleet Dashboard — paleta corporativa
   ========================================================================= */
:root {
  --ao-deep:   #08476B;
  --ao-cyan:   #07AEDE;
  --ao-green:  #9ABE3C;
  --ao-white:  #FFFFFF;
  --ao-black:  #000000;
  --ao-deep-2: #0a597f;
  --ao-cyan-2: #36c1e8;
  --ao-red:    #d4424c;
  --ao-gray:   #9ba8b3;
  --ao-bg:     #f4f7fa;
  --ao-line:   #e2e8ee;
  --ao-text:   #14222e;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color: var(--ao-text);
  background: var(--ao-bg);
}
.muted { color: #6b7a86; }
.hidden { display: none !important; }
.error { color: var(--ao-red); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---------- Pantallas ---------- */
.screen { display: none; }
.screen.active { display: block; }

/* ---------- Login ---------- */
.screen-login {
  min-height: 100vh;
  display: none;
  align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--ao-deep), var(--ao-cyan));
}
.screen-login.active { display: flex; }
.login-card {
  width: 360px; max-width: 92vw;
  background: var(--ao-white); padding: 32px 28px 28px;
  border-radius: 16px; box-shadow: 0 20px 50px rgba(0,0,0,.25);
  text-align: center;
}
.login-logo { width: 72px; height: 72px; }
.login-card h1 { font-size: 18px; margin: 12px 0 4px; color: var(--ao-deep); }
.login-card form { display: grid; gap: 12px; margin-top: 18px; text-align: left; }
.login-card label { display: grid; gap: 4px; font-size: 12px; color: var(--ao-deep); }
.login-card input {
  padding: 10px 12px; font-size: 14px;
  border: 1px solid var(--ao-line); border-radius: 8px; outline: none;
}
.login-card input:focus { border-color: var(--ao-cyan); box-shadow: 0 0 0 3px rgba(7,174,222,.15); }

/* ---------- Top bar ---------- */
.topbar {
  height: 64px;
  background: linear-gradient(90deg, var(--ao-deep) 0%, var(--ao-deep-2) 100%);
  color: var(--ao-white);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 0 20px; gap: 24px;
  box-shadow: 0 2px 8px rgba(8,71,107,.25);
  position: relative; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 40px; height: 40px; }
.brand-text h1 { font-size: 16px; margin: 0; letter-spacing: .3px; }
.brand-text .subtitle { font-size: 11px; opacity: .8; }

.main-nav { display: flex; gap: 4px; justify-self: center; }
.nav-btn {
  background: transparent; color: rgba(255,255,255,.85);
  border: 0; padding: 8px 14px; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.nav-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-btn.active { background: rgba(255,255,255,.18); color: #fff; }
.nav-btn.admin-only { display: none; }
body.is-admin .nav-btn.admin-only { display: inline-block; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }
.user-chip {
  display: grid; line-height: 1.1;
  padding: 4px 10px; border-radius: 8px;
  background: rgba(255,255,255,.1);
}
.user-chip b { font-size: 13px; }
.user-chip small { font-size: 10px; opacity: .8; }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: rgba(255,255,255,.15);
}
.pill-online { background: var(--ao-green); color: var(--ao-black); }
.pill-offline { background: rgba(255,255,255,.18); }
.pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(154,190,60,.6); }
  70% { box-shadow: 0 0 0 10px rgba(154,190,60,0); }
  100% { box-shadow: 0 0 0 0 rgba(154,190,60,0); }
}

/* ---------- Vistas ---------- */
.view { display: none; height: calc(100vh - 64px); overflow: auto; }
.view.active { display: block; }
.view.admin-only { display: none; }
body.is-admin .view.admin-only.active { display: block; }

/* ---------- Layout mapa ---------- */
.layout { display: grid; grid-template-columns: 340px 1fr; }
.sidebar {
  background: var(--ao-white);
  border-right: 1px solid var(--ao-line);
  display: flex; flex-direction: column; overflow: hidden;
  height: calc(100vh - 64px);
}
.sidebar-header { padding: 16px 18px 8px; border-bottom: 1px solid var(--ao-line); }
.sidebar-header h2 {
  margin: 0 0 8px; font-size: 14px; text-transform: uppercase;
  letter-spacing: 1px; color: var(--ao-deep);
}
.counts { display: flex; gap: 10px; flex-wrap: wrap; }
.count { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--ao-bg); }
.count-active  { border: 1px solid var(--ao-cyan); color: var(--ao-deep); }
.count-stopped { border: 1px solid var(--ao-red); color: var(--ao-red); }
.count-offline { border: 1px solid var(--ao-gray); color: var(--ao-gray); }

#vehicle-search {
  margin: 12px 14px; padding: 10px 12px;
  border: 1px solid var(--ao-line); border-radius: 8px;
  font-size: 13px; outline: none;
}
.vehicle-list { list-style: none; margin: 0; padding: 4px 8px 12px; overflow-y: auto; }
.vehicle-item {
  display: grid; grid-template-columns: 14px 1fr auto; gap: 10px;
  align-items: center; padding: 10px 12px; border-radius: 8px; cursor: pointer;
}
.vehicle-item:hover { background: var(--ao-bg); }
.vehicle-item.selected { background: rgba(7,174,222,.10); outline: 1px solid var(--ao-cyan); }
.vehicle-item .v-name { font-weight: 600; font-size: 13px; color: var(--ao-deep); }
.vehicle-item .v-sub  { font-size: 11px; color: #6b7a86; }
.vehicle-item .v-speed { font-size: 12px; font-weight: 700; }
.v-dot {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--ao-white); box-shadow: 0 0 0 1px var(--ao-line);
}
.v-dot.active { background: var(--ao-cyan); }
.v-dot.stopped { background: var(--ao-red); }
.v-dot.offline { background: var(--ao-gray); }

.map-area { position: relative; height: calc(100vh - 64px); }
#map { width: 100%; height: 100%; background: #dde6ee; }

.vehicle-marker {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 3px solid var(--ao-white);
  box-shadow: 0 2px 6px rgba(0,0,0,.35); color: var(--ao-white);
  font-size: 18px; position: relative;
}
.vehicle-marker.active { background: var(--ao-cyan); }
.vehicle-marker.stopped { background: var(--ao-red); }
.vehicle-marker.offline { background: var(--ao-gray); }
.vehicle-marker .arrow {
  position: absolute; top: -8px; left: 50%;
  width: 0; height: 0;
  border-left: 6px solid transparent; border-right: 6px solid transparent;
  border-bottom: 10px solid var(--ao-white);
  transform-origin: 50% 28px;
}

.vehicle-card {
  position: absolute; top: 16px; right: 16px;
  width: 320px; background: var(--ao-white); border-radius: 12px;
  box-shadow: 0 6px 24px rgba(8,71,107,.25);
  padding: 18px 18px 14px; z-index: 500;
  border-top: 4px solid var(--ao-cyan);
}
.vehicle-card h3 { margin: 0 0 12px; color: var(--ao-deep); font-size: 16px; }
.card-row {
  display: flex; justify-content: space-between;
  padding: 6px 0; border-bottom: 1px dashed var(--ao-line); font-size: 13px;
}
.card-row span { color: #6b7a86; }
.card-actions { display: flex; gap: 8px; margin-top: 14px; }
.card-close {
  position: absolute; top: 6px; right: 10px;
  border: 0; background: transparent; font-size: 22px;
  cursor: pointer; color: var(--ao-deep);
}

/* ---------- Botones ---------- */
.btn {
  padding: 9px 12px; border: 0; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--ao-green); color: var(--ao-black); }
.btn-primary:hover { background: #aacf4a; }
.btn-ghost { background: rgba(255,255,255,.18); color: var(--ao-white); }
.btn-ghost:hover { background: rgba(255,255,255,.28); }
.view .btn-ghost { background: var(--ao-bg); color: var(--ao-deep); }
.btn-danger { background: var(--ao-red); color: var(--ao-white); }

/* ---------- Tablas admin ---------- */
.admin-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 24px;
}
.admin-toolbar h2 { margin: 0; color: var(--ao-deep); font-size: 18px; }
.table-wrap { margin: 0 24px 24px; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 4px rgba(8,71,107,.08); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th {
  text-align: left; padding: 10px 12px; background: var(--ao-bg);
  color: var(--ao-deep); font-size: 11px; letter-spacing: 1px; text-transform: uppercase;
  border-bottom: 1px solid var(--ao-line);
}
.admin-table td { padding: 10px 12px; border-bottom: 1px solid var(--ao-line); }
.admin-table tr:hover { background: #fafcfe; }
.admin-table .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.tag { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.tag-admin { background: var(--ao-deep); color: #fff; }
.tag-operator { background: var(--ao-cyan); color: #fff; }
.tag-on { background: var(--ao-green); color: var(--ao-black); }
.tag-off { background: #cdd3d8; color: #444; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(8,34,48,.55);
  display: flex; align-items: center; justify-content: center; z-index: 2000;
}
.modal {
  background: #fff; border-radius: 12px; min-width: 420px; max-width: 90vw; max-height: 90vh;
  box-shadow: 0 20px 60px rgba(0,0,0,.35); display: flex; flex-direction: column;
}
.modal-head {
  padding: 14px 18px; border-bottom: 1px solid var(--ao-line);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-head h3 { margin: 0; color: var(--ao-deep); font-size: 16px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-actions {
  padding: 12px 18px; border-top: 1px solid var(--ao-line);
  display: flex; gap: 8px; justify-content: flex-end;
}
.form-grid { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.form-grid label { display: grid; gap: 4px; font-size: 12px; color: var(--ao-deep); }
.form-grid label.col-span-2 { grid-column: span 2; }
.form-grid input, .form-grid select, .form-grid textarea {
  padding: 8px 10px; border: 1px solid var(--ao-line); border-radius: 6px;
  font-size: 13px; outline: none;
}
.form-grid input:focus, .form-grid select:focus { border-color: var(--ao-cyan); box-shadow: 0 0 0 3px rgba(7,174,222,.15); }
.checkbox-list {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px;
  border: 1px solid var(--ao-line); border-radius: 6px; padding: 8px;
  max-height: 200px; overflow-y: auto;
}
.checkbox-list label { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--ao-text); }
