/* =========================================================
   FlotaOps · Sistema de diseño
   Inspirado en paneles de despacho de flotas: legibilidad
   operativa, codificación de estado por color y matrículas
   con estética de placa real como elemento de identidad.
   ========================================================= */

:root {
  /* Color */
  --ink:        #161B22;
  --ink-soft:   #232B36;
  --paper:      #EEF1F4;
  --surface:    #FFFFFF;
  --line:       #DEE3E9;
  --text:       #1B1F24;
  --text-muted: #5B6472;
  --accent:     #2F6F5E;
  --accent-dark:#1F4D40;
  --accent-soft:#E4EFEC;
  --amber:      #B9720F;
  --amber-soft: #FBEDD8;
  --danger:     #B3261E;
  --danger-soft:#FBE9E7;
  --plate-blue: #1B4FA0;

  /* Tipografía */
  --font-display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;

  /* Layout */
  --sidebar-w: 240px;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(22,27,34,.06), 0 4px 14px rgba(22,27,34,.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: .01em;
  margin: 0;
}

.eyebrow {
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 12px;
  color: var(--text-muted);
}

/* =========================================================
   Estructura general
   ========================================================= */

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--ink);
  color: #C9D1DB;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
  transition: transform .25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-brand .mark {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: linear-gradient(155deg, var(--accent), var(--accent-dark));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-brand .name {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  color: #fff;
  letter-spacing: .01em;
}

.sidebar-brand .sub {
  font-size: 11px;
  color: #8993A3;
  text-transform: uppercase;
  letter-spacing: .1em;
}

.sidebar-nav {
  padding: 14px 12px;
  flex: 1;
  overflow-y: auto;
}

.sidebar-nav .nav-label {
  font-family: var(--font-display);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: #6A7484;
  padding: 14px 10px 6px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-weight: 500;
  color: #C9D1DB;
  margin-bottom: 2px;
}

.sidebar-nav a svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }

.sidebar-nav a.active {
  background: var(--accent);
  color: #fff;
}

.sidebar-foot {
  padding: 14px 16px 18px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.sidebar-user .avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 12.5px;
  flex-shrink: 0;
}

.sidebar-user .info { min-width: 0; }
.sidebar-user .info .name {
  font-size: 13.5px; font-weight: 600; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user .info .role {
  font-size: 11px; color: #8993A3; text-transform: capitalize;
}

.btn-logout {
  display: block;
  width: 100%;
  text-align: center;
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,.14);
  color: #C9D1DB;
  font-size: 13px;
  background: transparent;
  cursor: pointer;
}
.btn-logout:hover { background: rgba(255,255,255,.06); color: #fff; }

/* ---- Contenido principal ---- */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  padding: 26px 30px 60px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.topbar h1 { font-size: 30px; }
.topbar .desc { color: var(--text-muted); font-size: 14px; margin-top: 2px; }

/* Barra de navegación para móvil/tablet: siempre visible, sin hamburguesa.
   Vive FUERA de .app-shell (ver includes/header.php) para no ser un hijo flex
   que se estire a toda la pantalla. position:sticky reserva su propio espacio
   automáticamente, sin necesidad de calcular paddings a mano. Los botones se
   colocan en una rejilla que envuelve a una segunda fila si no caben todos. */
.mobile-topnav {
  display: none;
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--ink);
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
}

.mobile-topnav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.mobile-topnav-brand .mark {
  width: 24px; height: 24px;
  border-radius: 6px;
  background: linear-gradient(155deg, var(--accent), var(--accent-dark));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  color: #fff;
  flex-shrink: 0;
}
.mobile-topnav-brand .name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: .01em;
}

.mobile-topnav-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
}
.mobile-topnav-links a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 7px 2px;
  color: #9AA4B2;
  font-size: 8.8px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .01em;
  border-bottom: 2.5px solid transparent;
  box-sizing: border-box;
}
.mobile-topnav-links a svg { width: 16px; height: 16px; flex-shrink: 0; }
.mobile-topnav-links a.active { color: #fff; border-bottom-color: var(--accent); background: rgba(255,255,255,.06); }
.mobile-topnav-links a.logout-tab { color: #F87171; }

/* =========================================================
   Barra de herramientas: búsqueda, filtros, vista
   ========================================================= */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 220px;
}
.search-box input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  color: var(--text);
}
.search-box input:focus { border-color: var(--accent); }
.search-box svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-muted);
}

.select-filter {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13.5px;
  color: var(--text);
}

.view-toggle {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
}
.view-toggle button {
  border: none;
  background: var(--surface);
  padding: 9px 12px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex; align-items: center;
}
.view-toggle button.active { background: var(--ink); color: #fff; }
.view-toggle svg { width: 16px; height: 16px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-dark); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* =========================================================
   KPIs del dashboard
   ========================================================= */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}

.kpi-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(22,27,34,.12); }

.kpi-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
  background: rgba(255,255,255,.28);
}
.kpi-icon svg { width: 20px; height: 20px; }

.kpi-card .value {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 700;
  line-height: 1;
}
.kpi-card .label {
  margin-top: 6px;
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* Tarjetas de color vivo con icono propio, una por categoría del resumen */
.kpi-card.kpi-green { background: linear-gradient(135deg, #22C55E, #15803D); border-color: transparent; }
.kpi-card.kpi-emerald { background: linear-gradient(135deg, #10B981, #047857); border-color: transparent; }
.kpi-card.kpi-yellow { background: linear-gradient(135deg, #FBBF24, #D97706); border-color: transparent; }
.kpi-card.kpi-orange { background: linear-gradient(135deg, #FB923C, #C2410C); border-color: transparent; }
.kpi-card.kpi-red { background: linear-gradient(135deg, #F87171, #B91C1C); border-color: transparent; }
.kpi-card.kpi-green-dark { background: linear-gradient(135deg, #166534, #0B3B1E); border-color: transparent; }
.kpi-card.kpi-blue { background: linear-gradient(135deg, #60A5FA, #1D4ED8); border-color: transparent; }

.kpi-card.kpi-green, .kpi-card.kpi-emerald, .kpi-card.kpi-yellow,
.kpi-card.kpi-orange, .kpi-card.kpi-red, .kpi-card.kpi-green-dark,
.kpi-card.kpi-blue { color: #ffffff; }
.kpi-card.kpi-green .label, .kpi-card.kpi-emerald .label, .kpi-card.kpi-yellow .label,
.kpi-card.kpi-orange .label, .kpi-card.kpi-red .label, .kpi-card.kpi-green-dark .label,
.kpi-card.kpi-blue .label { opacity: .92; }

/* Vehículos libres: fondo claro para diferenciarse del resto de verdes, pero con icono y borde vivos */
.kpi-card.kpi-green-light { background: #F0FDF4; border: 1.5px solid #4ADE80; }
.kpi-card.kpi-green-light .value { color: #15803D; }
.kpi-card.kpi-green-light .label { color: #16653A; font-weight: 700; }
.kpi-card.kpi-green-light .kpi-icon { background: #DCFCE7; }
.kpi-card.kpi-green-light .kpi-icon svg { color: #16A34A; }

.dash-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 18px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-head h3 { font-size: 18px; }
.panel-body { padding: 10px 8px; }
.panel-body.pad { padding: 18px 20px; }

.row-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
}
.row-item:hover { background: var(--paper); }
.row-item .avatar-sm {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; flex-shrink: 0;
}
.row-item .meta { min-width: 0; flex: 1; }
.row-item .meta .title { font-weight: 600; font-size: 14px; }
.row-item .meta .sub { font-size: 12.5px; color: var(--text-muted); }

.empty-hint {
  padding: 26px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* =========================================================
   Tarjetas de contenido (técnicos, equipos, vehículos)
   ========================================================= */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
}

.entity-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.entity-card .head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.entity-card .avatar-lg {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; flex-shrink: 0;
}

.entity-card .head .title { font-weight: 700; font-size: 16px; }
.entity-card .head .subtitle { font-size: 12.5px; color: var(--text-muted); margin-top: 1px; }

.entity-card .fields { display: flex; flex-direction: column; gap: 7px; font-size: 13.5px; }
.entity-card .fields .f-row { display: flex; justify-content: space-between; gap: 10px; }
.entity-card .fields .f-label { color: var(--text-muted); }
.entity-card .fields .f-val { text-align: right; font-weight: 500; }

.entity-card .actions {
  margin-top: auto;
  display: flex;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.entity-card .actions .btn { flex: 1; justify-content: center; }

/* Vista lista */
.list-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list-table th {
  text-align: left;
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-size: 11.5px;
  color: var(--text-muted);
  padding: 12px 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.list-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  vertical-align: middle;
}
.list-table tr:last-child td { border-bottom: none; }
.list-table tr:hover td { background: var(--paper); }
.list-table .actions-cell { display: flex; gap: 6px; justify-content: flex-end; }

.name-cell { display: flex; align-items: center; gap: 10px; }

/* =========================================================
   Badges de estado
   ========================================================= */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-activo { background: var(--accent-soft); color: var(--accent-dark); }
.badge-vacaciones { background: var(--amber-soft); color: var(--amber); }
.badge-baja { background: var(--danger-soft); color: var(--danger); }
.badge-neutro { background: var(--paper); color: var(--text-muted); }
.badge-proxima { background: #E3F2FD; color: #1565C0; }
.badge-tipo { background: #EDE7F6; color: #5E35B1; }
.badge-rol-administrador { background: #FBE9E7; color: var(--danger); }
.badge-rol-editor { background: #E3F2FD; color: #1565C0; }
.badge-rol-usuario { background: var(--paper); color: var(--text-muted); }

/* =========================================================
   Placa de matrícula — elemento de identidad visual
   ========================================================= */

.plate {
  display: inline-flex;
  align-items: stretch;
  border-radius: 4px;
  overflow: hidden;
  border: 1.5px solid #B9BFC8;
  font-family: var(--font-mono);
  font-weight: 700;
  box-shadow: 0 1px 0 rgba(0,0,0,.05);
  height: 26px;
}
.plate .eu {
  background: var(--plate-blue);
  color: #fff;
  font-size: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  letter-spacing: -.02em;
}
.plate .num {
  background: #fff;
  color: #101317;
  padding: 0 9px;
  display: flex;
  align-items: center;
  font-size: 13px;
  letter-spacing: .04em;
}
.plate.sm { height: 22px; }
.plate.sm .num { font-size: 11.5px; padding: 0 7px; }
.plate-empty {
  font-size: 12.5px;
  color: var(--text-muted);
  font-style: italic;
}

/* =========================================================
   Formularios
   ========================================================= */

.form-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
  max-width: 640px;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field .hint { font-size: 12px; color: var(--text-muted); }

.field input[type=text],
.field input[type=email],
.field input[type=tel],
.field input[type=date],
.field input[type=password],
.field select,
.field textarea {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 80px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: 16px; height: 16px; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 18px;
}
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--accent-soft); color: var(--accent-dark); }
.alert-info { background: #E3F2FD; color: #1565C0; }

/* =========================================================
   Login
   ========================================================= */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 34px 30px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
.login-brand {
  display: flex; align-items: center; gap: 11px; margin-bottom: 22px;
}
.login-brand .mark {
  width: 40px; height: 40px; border-radius: 9px;
  background: linear-gradient(155deg, var(--accent), var(--accent-dark));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 18px;
}
.login-brand .name { font-family: var(--font-display); font-size: 24px; font-weight: 700; }
.login-brand .sub { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .1em; }

.login-card .btn-primary { width: 100%; justify-content: center; margin-top: 6px; }
.login-hint { margin-top: 16px; font-size: 12px; color: var(--text-muted); text-align: center; }

/* =========================================================
   Utilidades
   ========================================================= */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state h3 { font-size: 18px; color: var(--text); margin-bottom: 6px; }
.empty-state svg { width: 44px; height: 44px; margin-bottom: 14px; color: var(--line); }

.hidden { display: none !important; }

/* =========================================================
   Responsive
   ========================================================= */

@media (max-width: 1080px) {
  .dash-grid { grid-template-columns: 1fr; }
}

@media (max-width: 880px) {
  .sidebar { display: none; }
  .mobile-topnav { display: block; }
  .main { margin-left: 0; padding: 14px 16px 50px; }
  .form-grid { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 24px; }
}

@media (max-width: 560px) {
  .row-item { flex-wrap: wrap; }
  .row-item .meta { flex-basis: 100%; }
  .list-table thead { display: none; }
  .list-table, .list-table tbody, .list-table tr, .list-table td { display: block; width: 100%; }
  .list-table tr { border-bottom: 1px solid var(--line); padding: 10px 4px; }
  .list-table td { border: none; padding: 4px 12px; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
  .list-table td::before { content: attr(data-label); font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
  .list-table td.name-cell-wrap::before { content: ''; }
  .list-table .actions-cell { justify-content: flex-start; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}