/* =====================================================================
   Flota CASEI — hoja de estilos (móvil primero, sin dependencias)
   ===================================================================== */
:root {
  --primario: #1f4e79;
  --primario-oscuro: #163a5a;
  --primario-claro: #e8f0f8;
  --acento: #e8891d;
  --fondo: #f3f5f8;
  --superficie: #ffffff;
  --borde: #dfe4ec;
  --texto: #1c2431;
  --texto-suave: #5f6b7a;
  --verde: #1e8e3e; --verde-fondo: #e6f4ea;
  --ambar: #b45309; --ambar-fondo: #fdf1e0;
  --rojo: #c62828; --rojo-fondo: #fdecea;
  --azul: #1d6fb8; --azul-fondo: #e6f0fa;
  --gris: #6b7686; --gris-fondo: #eef1f5;
  --radio: 10px;
  --sombra: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --topbar: 56px;
  --tabbar: 62px;
  --fuente: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--fuente); font-size: 15px; line-height: 1.45;
  color: var(--texto); background: var(--fondo);
}
a { color: var(--primario); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.25; color: var(--texto); }
.h1 { font-size: 1.45rem; font-weight: 700; }
.h2 { font-size: 1.15rem; font-weight: 700; }
.h3 { font-size: 1rem; font-weight: 700; color: var(--texto-suave); text-transform: uppercase; letter-spacing: .03em; }
p { margin: 0 0 .8em; }
.suave { color: var(--texto-suave); }
.peq { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.pre { background: var(--gris-fondo); padding: 12px; border-radius: 8px; overflow: auto; font-size: .82rem; }
.ico { width: 22px; height: 22px; flex: none; }
.oculto { display: none !important; }
.derecha { text-align: right; }
.centro { text-align: center; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar);
  background: var(--primario); color: #fff; display: flex; align-items: center; gap: 10px;
  padding: 0 12px; padding-top: env(safe-area-inset-top);
  box-shadow: 0 1px 0 rgba(0,0,0,.15);
}
.marca { display: flex; align-items: center; color: #fff; font-weight: 700; font-size: 1.05rem; flex: 1; min-width: 0; }
.marca:hover { text-decoration: none; }
.marca img { height: 34px; max-width: 160px; object-fit: contain; }
.marca-texto { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.marca-texto.grande { font-size: 1.5rem; color: var(--primario); }
.marca-texto.marca-sub { margin-left: 10px; padding-left: 10px; border-left: 1px solid rgba(255,255,255,.35); font-size: .9rem; font-weight: 600; opacity: .95; }
.btn-menu { display: inline-flex; background: transparent; border: 0; color: #fff; padding: 8px; margin-left: -8px; border-radius: 8px; cursor: pointer; }
.btn-menu:hover { background: rgba(255,255,255,.12); }
.topbar-derecha { display: flex; align-items: center; gap: 4px; }
.topbar-usuario { color: #fff; display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; padding: 4px 8px; border-radius: 8px; }
.topbar-usuario:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.topbar-nombre { font-weight: 600; font-size: .9rem; max-width: 40vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-rol { font-size: .72rem; opacity: .85; }
.btn-icono { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 8px; color: inherit; border: 0; background: transparent; cursor: pointer; }
.topbar .btn-icono:hover { background: rgba(255,255,255,.12); }

/* ---------- Estructura ---------- */
.shell { display: block; min-height: calc(100vh - var(--topbar)); }
.contenido { padding: 16px; padding-bottom: calc(var(--tabbar) + 24px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.sidenav {
  position: fixed; top: var(--topbar); left: 0; bottom: 0; width: 250px; z-index: 25;
  background: var(--superficie); border-right: 1px solid var(--borde); padding: 10px;
  transform: translateX(-105%); transition: transform .2s ease; overflow-y: auto;
}
.sidenav.abierta { transform: none; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 8px; color: var(--texto); font-weight: 500; }
.nav-item:hover { background: var(--gris-fondo); text-decoration: none; }
.nav-item.activo { background: var(--primario-claro); color: var(--primario); font-weight: 600; }
.nav-pie { margin-top: 18px; padding: 0 12px; color: var(--texto-suave); font-size: .75rem; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--superficie); border-top: 1px solid var(--borde);
  display: flex; justify-content: space-around;
}
.tab-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--texto-suave); font-size: .68rem; font-weight: 500; }
.tab-item:hover { text-decoration: none; }
.tab-item.activo { color: var(--primario); }
.tab-item .ico { width: 24px; height: 24px; }

@media (min-width: 900px) {
  .btn-menu, .tabbar { display: none; }
  .shell { display: grid; grid-template-columns: 240px 1fr; }
  .sidenav { position: sticky; top: var(--topbar); height: calc(100vh - var(--topbar)); transform: none; width: auto; box-shadow: none; }
  .contenido { padding: 24px 28px; padding-bottom: 40px; }
}

/* ---------- Encabezado de página ---------- */
.encabezado { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.encabezado .h1 { margin: 0; flex: 1 1 auto; }
.encabezado .acciones { display: flex; gap: 8px; flex-wrap: wrap; }
.migas { font-size: .85rem; color: var(--texto-suave); margin-bottom: 6px; }
.migas a { color: var(--texto-suave); }

/* ---------- Tarjetas y rejillas ---------- */
.card { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); padding: 16px; box-shadow: var(--sombra); margin-bottom: 16px; }
.card-titulo { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-titulo .h2 { margin: 0; }
.card-centro { max-width: 640px; margin: 24px auto; }
.grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .grid-4 { grid-template-columns: repeat(4, 1fr); } }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); margin-bottom: 16px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px; box-shadow: var(--sombra); display: block; color: inherit; }
.stat:hover { text-decoration: none; border-color: var(--primario); }
.stat-valor { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat-etiqueta { color: var(--texto-suave); font-size: .82rem; margin-top: 4px; }
.stat.rojo .stat-valor { color: var(--rojo); }
.stat.ambar .stat-valor { color: var(--ambar); }
.stat.verde .stat-valor { color: var(--verde); }
.stat.azul .stat-valor { color: var(--azul); }

/* ---------- Definiciones (ficha) ---------- */
.ficha { display: grid; grid-template-columns: 1fr; gap: 6px 16px; margin: 0; }
@media (min-width: 640px) { .ficha { grid-template-columns: 1fr 1fr; } }
.ficha div { padding: 6px 0; border-bottom: 1px solid var(--gris-fondo); }
.ficha dt { font-size: .78rem; color: var(--texto-suave); text-transform: uppercase; letter-spacing: .03em; }
.ficha dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

/* ---------- Tablas ---------- */
.tabla-wrap { overflow-x: auto; }
.tabla { width: 100%; border-collapse: collapse; background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); overflow: hidden; }
.tabla th, .tabla td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--borde); vertical-align: middle; }
.tabla th { background: var(--gris-fondo); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--texto-suave); }
.tabla tr:last-child td { border-bottom: 0; }
.tabla tbody tr:hover { background: #f8fafc; }
.tabla .acciones-fila { white-space: nowrap; text-align: right; }
.tabla-vacia { padding: 28px 12px; text-align: center; color: var(--texto-suave); }
@media (max-width: 700px) {
  .tabla.responsiva thead { display: none; }
  .tabla.responsiva, .tabla.responsiva tbody, .tabla.responsiva tr, .tabla.responsiva td { display: block; width: 100%; }
  .tabla.responsiva tr { border-bottom: 6px solid var(--fondo); padding: 6px 0; }
  .tabla.responsiva td { border: 0; padding: 5px 12px; display: flex; gap: 10px; justify-content: space-between; align-items: center; }
  .tabla.responsiva td::before { content: attr(data-label); color: var(--texto-suave); font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; flex: 0 0 38%; }
  .tabla.responsiva td.principal { font-weight: 600; font-size: 1.02rem; }
  .tabla.responsiva td.principal::before { display: none; }
  .tabla.responsiva td.acciones-fila { justify-content: flex-end; }
  .tabla.responsiva td.acciones-fila::before { display: none; }
  .tabla.responsiva td .badge { white-space: normal; text-align: right; }
}

/* ---------- Insignias ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: .76rem; font-weight: 600; white-space: nowrap; line-height: 1.3; }
.badge-verde { background: var(--verde-fondo); color: var(--verde); }
.badge-ambar { background: var(--ambar-fondo); color: var(--ambar); }
.badge-rojo { background: var(--rojo-fondo); color: var(--rojo); }
.badge-azul { background: var(--azul-fondo); color: var(--azul); }
.badge-gris { background: var(--gris-fondo); color: var(--gris); }
.punto { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.punto-verde { background: var(--verde); } .punto-ambar { background: #f59e0b; } .punto-rojo { background: var(--rojo); } .punto-gris { background: #b7c0cc; }

/* ---------- Botones ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 9px 16px; border-radius: 8px; border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s; }
.btn:hover { text-decoration: none; }
.btn .ico { width: 18px; height: 18px; }
.btn-primario { background: var(--primario); color: #fff; }
.btn-primario:hover { background: var(--primario-oscuro); }
.btn-secundario { background: var(--superficie); color: var(--primario); border-color: var(--borde); }
.btn-secundario:hover { border-color: var(--primario); background: var(--primario-claro); }
.btn-peligro { background: var(--rojo-fondo); color: var(--rojo); border-color: transparent; }
.btn-peligro:hover { background: #f9d6d3; }
.btn-acento { background: var(--acento); color: #fff; }
.btn-sm { min-height: 34px; padding: 5px 11px; font-size: .85rem; }
.btn-bloque { width: 100%; }
.btn[disabled], .btn.deshabilitado { opacity: .55; pointer-events: none; }
.acciones { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.acciones-form { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Formularios ---------- */
.form-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } .campo-ancho { grid-column: 1 / -1; } }
.campo label { display: block; font-size: .82rem; font-weight: 600; color: var(--texto-suave); margin-bottom: 5px; }
.campo label .req { color: var(--rojo); }
.campo input[type=text], .campo input[type=email], .campo input[type=password], .campo input[type=number], .campo input[type=date], .campo input[type=time], .campo input[type=tel], .campo input[type=url], .campo select, .campo textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--borde); border-radius: 8px; background: #fff; font: inherit; font-size: 16px; color: var(--texto);
}
.campo textarea { min-height: 90px; resize: vertical; }
.campo input:focus, .campo select:focus, .campo textarea:focus { outline: 2px solid rgba(31,78,121,.35); border-color: var(--primario); }
.campo input[type=file] { width: 100%; font-size: 15px; padding: 8px 0; }
.campo .ayuda { font-size: .78rem; color: var(--texto-suave); margin-top: 4px; }
.campo.error input, .campo.error select { border-color: var(--rojo); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; min-height: 44px; }
.check input { width: 20px; height: 20px; }
.campo-clave { position: relative; }
.campo-clave input { padding-right: 46px; }
.campo-clave .ver-clave { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; }
.filtros { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filtros input[type=search], .filtros input[type=text], .filtros input[type=date], .filtros select { min-height: 42px; padding: 8px 12px; border: 1px solid var(--borde); border-radius: 8px; font: inherit; font-size: 16px; background: #fff; }
.filtros input[type=search] { flex: 1 1 200px; }

.tabla input[type=checkbox] { width: 22px; height: 22px; }
.badges { display: inline-flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.stat.gris .stat-valor { color: var(--gris); }
/* ---------- Avisos ---------- */
.flash { position: relative; padding: 12px 40px 12px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; font-weight: 500; }
.flash-ok { background: var(--verde-fondo); border-color: #b7e0c3; color: #166534; }
.flash-error { background: var(--rojo-fondo); border-color: #f2b8b5; color: #8a1c1c; }
.flash-aviso { background: var(--ambar-fondo); border-color: #f4d29a; color: #7c3a03; }
.flash-info { background: var(--azul-fondo); border-color: #b9d4f0; color: #124c86; }
.flash-cerrar { position: absolute; right: 6px; top: 6px; background: transparent; border: 0; font-size: 1.3rem; line-height: 1; cursor: pointer; color: inherit; padding: 4px 8px; }
.nota { background: var(--primario-claro); border-left: 4px solid var(--primario); padding: 10px 12px; border-radius: 6px; font-size: .9rem; }
.nota-ambar { background: var(--ambar-fondo); border-left-color: #f59e0b; }
.nota-rojo { background: var(--rojo-fondo); border-left-color: var(--rojo); }

/* ---------- Pestañas ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--borde); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; white-space: nowrap; color: var(--texto-suave); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--primario); }
.tabs a.activo { color: var(--primario); border-bottom-color: var(--primario); }

/* ---------- Listas y miniaturas ---------- */
.lista { list-style: none; margin: 0; padding: 0; }
.lista li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--gris-fondo); }
.lista li:last-child { border-bottom: 0; }
.lista .crece { flex: 1; min-width: 0; }
.lista .titulo { font-weight: 600; }
.lista .sub { font-size: .82rem; color: var(--texto-suave); }
.miniatura { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--gris-fondo); flex: none; }
.foto-grande { width: 100%; max-height: 320px; object-fit: cover; border-radius: var(--radio); background: var(--gris-fondo); }
.avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: var(--primario-claro); color: var(--primario); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.doc-vista { display: flex; gap: 12px; align-items: center; }
.doc-vista img { width: 90px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--borde); }
.doc-pdf { width: 90px; height: 64px; border-radius: 6px; border: 1px solid var(--borde); display: flex; align-items: center; justify-content: center; background: var(--gris-fondo); color: var(--texto-suave); font-size: .75rem; font-weight: 700; }

/* ---------- Pantallas simples (acceso) ---------- */
.cuerpo-simple { background: linear-gradient(180deg, var(--primario) 0, var(--primario) 180px, var(--fondo) 180px); min-height: 100vh; }
.simple { max-width: 440px; margin: 0 auto; padding: 32px 16px 24px; }
.simple.ancho { max-width: 820px; }
.simple-marca { text-align: center; margin-bottom: 20px; }
.simple-marca img { max-height: 64px; max-width: 240px; object-fit: contain; background: #fff; padding: 8px 14px; border-radius: 10px; }
.simple-marca .marca-texto.grande { color: #fff; }
.simple .card { padding: 22px; }
.simple-pie { text-align: center; color: var(--texto-suave); font-size: .8rem; margin-top: 18px; }
.instalador .paso { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.instalador .ok { color: var(--verde); font-weight: 700; }
.instalador .falla { color: var(--rojo); font-weight: 700; }

/* ---------- Impresión ---------- */
@media print {
  .topbar, .sidenav, .tabbar, .btn, .filtros, .flash { display: none !important; }
  .shell { display: block; }
  .contenido { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
}
