/* ============================================================
   CRA Flota - Estilos
   Paleta e identidad visual según el Manual de Identidad Visual
   de la Corporación Autónoma Regional del Atlántico - C.R.A. (2024)
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Lato:wght@400;700;900&display=swap');

:root {
  /* Colores institucionales C.R.A. */
  --cra-yellow: #EDB512; /* Pantone 7408   - diversidad social y humana */
  --cra-green:  #8FD400; /* Pantone 375 C  - ecosistemas del Atlántico  */
  --cra-cyan:   #00B5D9; /* Pantone 638 C  - mar y río                  */
  --cra-blue:   #005F96; /* Pantone 7691 C - agua, autoridad ambiental  */
  --cra-gray:   #969491; /* Gris institucional                         */

  --primary: var(--cra-blue);
  --primary-dark: #00466f;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --sidebar-bg: #063452;
  --sidebar-text: #e2e8f0;
  --danger: #dc2626;
  --amber: #b8860a;
  --emerald: #5a8f00;
  --blue: var(--cra-cyan);
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Lato', 'Century Gothic', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
}
h1, h2, h3, h4, .brand-title, .stat-value { font-family: 'Lato', 'Century Gothic', sans-serif; font-weight: 700; }
button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

/* Franja institucional (evoca el separador de sección del manual de marca) */
.brand-stripe {
  display: flex; height: 4px; width: 100%; flex-shrink: 0;
  position: sticky; top: 64px; z-index: 19;
}
.brand-stripe span { flex: 1; }
.brand-stripe span:nth-child(1) { background: var(--cra-gray); }
.brand-stripe span:nth-child(2) { background: var(--cra-yellow); }
.brand-stripe span:nth-child(3) { background: var(--cra-green); }
.brand-stripe span:nth-child(4) { background: var(--cra-cyan); }
.brand-stripe span:nth-child(5) { background: var(--cra-blue); }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.content { flex: 1; padding: 24px; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 256px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px; border-bottom: 1px solid rgba(255,255,255,.1); height: 64px;
}
.brand-icon {
  width: 40px; height: 40px; border-radius: 8px;
  background: #fff; padding: 4px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.brand-icon img { width: 100%; height: 100%; object-fit: contain; }
.brand-title { font-weight: 700; font-size: 14px; letter-spacing: .2px; }
.brand-sub { font-size: 12px; opacity: .7; }
.sidebar-nav { flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-section-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: rgba(255,255,255,.45); padding: 14px 12px 4px;
}
.nav-section-label:first-child { padding-top: 4px; }
.nav-item {
  display: block; width: 100%; text-align: left;
  padding: 9px 12px; border: 0; border-radius: 8px;
  background: transparent; color: var(--sidebar-text); font-weight: 500;
}
.nav-item:hover { background: rgba(255,255,255,.08); }
.nav-item.active { background: var(--cra-cyan); color: #05303f; font-weight: 700; }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.1); }
.user-email {
  font-size: 12px; opacity: .8; padding: 4px 12px 8px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.icon-btn { background: none; border: 0; font-size: 18px; color: inherit; }
.close-sidebar { display: none; margin-left: auto; }
.open-sidebar { display: none; }
.sidebar-overlay { display: none; }

/* ---------- Topbar ---------- */
.topbar {
  height: 64px; background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; }
.topbar-note { margin-left: auto; color: var(--muted); font-size: 13px; }

/* ---------- Panel de bienvenida (Dashboard) ---------- */
.panel-header {
  position: relative; border-radius: var(--radius); overflow: hidden; margin-bottom: 20px;
  background: linear-gradient(160deg, var(--sidebar-bg) 0%, var(--cra-blue) 100%);
  color: #fff;
}
.panel-header::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--cra-gray), var(--cra-yellow), var(--cra-green), var(--cra-cyan), var(--cra-blue));
}
.panel-header-inner { padding: 22px 26px; }
.panel-header h2 { font-size: 19px; margin-bottom: 6px; }
.panel-header p { font-size: 13px; opacity: .85; }

/* ---------- Cards / stats ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; margin-bottom: 20px;
}
.card.pad { padding: 20px; }
.card.pad h3 { margin-bottom: 12px; font-size: 16px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: #f8fafc; font-weight: 600;
}
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px;
}
.stat-grid.three { grid-template-columns: repeat(3, 1fr); }
.stat-grid.six { grid-template-columns: repeat(3, 1fr); }
.stat {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.stat-icon {
  width: 46px; height: 46px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.stat-icon.blue    { background: #d6f2f9; }
.stat-icon.emerald { background: #e6f7cc; }
.stat-icon.amber   { background: #fbecc3; }
.stat-icon.red     { background: #fee2e2; }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 22px; font-weight: 700; }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }

/* ---------- Listas dashboard ---------- */
.list-item {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: 0; }
.list-empty { padding: 24px; text-align: center; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.blue { background: var(--cra-cyan); }
.dot.orange { background: var(--cra-yellow); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { max-width: 220px; width: auto; }
.spacer { flex: 1; }

/* ---------- Tabla ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 600;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: #f8fafc;
}
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #f8fafc; }
.table .right { text-align: right; }
.table input[type=number] { width: 110px; padding: 5px 8px; }
.plate-link { background: none; border: 0; font-weight: 600; color: var(--text); }
.plate-link:hover { text-decoration: underline; }
.mono { font-family: Consolas, monospace; font-size: 12px; color: var(--muted); }
.desc-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge.active      { background: #e6f7cc; color: #4a7300; }
.badge.maintenance { background: #fbecc3; color: #8a6300; }
.badge.alert       { background: #fee2e2; color: #991b1b; }
.badge.type-preventive { background: #d6f2f9; color: #00495c; border-radius: 6px; }
.badge.type-corrective { background: #fbecc3; color: #8a6300; border-radius: 6px; }
.badge.type-otro       { background: #e2e8f0; color: #334155; border-radius: 6px; }
.badge.lic-vigente     { background: #e6f7cc; color: #4a7300; }
.badge.lic-por_vencer  { background: #fbecc3; color: #8a6300; }
.badge.lic-vencida     { background: #fee2e2; color: #991b1b; }
.badge.lic-sin_fecha   { background: #e2e8f0; color: #475569; }
.status-inline { font-weight: 600; font-size: 13px; }
.status-inline.progress { color: var(--amber); }
.status-inline.done { color: var(--emerald); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
  font-weight: 600; font-size: 13.5px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: #f8fafc; }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: #f1f5f9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-icon { padding: 5px 8px; }
.btn-icon.red { color: var(--danger); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Formularios ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.muted { color: var(--muted); margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- Modales ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: #fff; border-radius: 14px; padding: 22px;
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal.small { max-width: 420px; }
.modal h3 { margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }

/* ---------- Drawer historial ---------- */
.modal-backdrop:has(.drawer) { justify-content: flex-end; padding: 0; }
.drawer {
  background: #fff; width: 100%; max-width: 440px; height: 100vh;
  overflow-y: auto; padding: 22px; box-shadow: -10px 0 40px rgba(0,0,0,.2);
}
.drawer h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.drawer .sub { color: var(--muted); margin-bottom: 16px; font-size: 13px; }
.mini-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.mini { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.mini p:first-child { font-size: 12px; color: var(--muted); }
.mini p:last-child { font-size: 17px; font-weight: 700; }
.hist-item { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; font-size: 13.5px; }
.hist-item .top { display: flex; justify-content: space-between; margin-bottom: 4px; }
.hist-item .top span:last-child { color: var(--muted); font-size: 12px; }

/* ---------- Fotos ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.photo-grid .ph { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.photo-grid img { width: 100%; height: 100%; object-fit: cover; }
.photo-grid .rm {
  position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.6); color: #fff;
  border: 0; border-radius: 50%; width: 20px; height: 20px; font-size: 11px; line-height: 1;
}

/* ---------- Dependencias ---------- */
.dep-add { display: flex; gap: 8px; margin-bottom: 12px; }
.dep-list { list-style: none; }
.dep-list li {
  display: flex; align-items: center; justify-content: space-between;
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; margin-bottom: 8px;
}

/* ---------- IA ---------- */
.ai-result { margin-top: 18px; line-height: 1.65; }
.ai-result h1, .ai-result h2, .ai-result h3 { margin: 16px 0 8px; }
.ai-result ul, .ai-result ol { margin: 8px 0 8px 22px; }
.ai-result p { margin-bottom: 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: 18px; right: 18px; z-index: 100;
  background: var(--sidebar-bg); color: #fff; padding: 11px 18px; border-radius: 10px;
  font-weight: 500; opacity: 0; transform: translateY(-8px);
  transition: all .25s; pointer-events: none; max-width: 360px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

/* ---------- Login ---------- */
.auth-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 8% 88%, rgba(255,255,255,.06) 0%, rgba(255,255,255,.06) 18%, transparent 19%),
    radial-gradient(circle at 92% 15%, rgba(255,255,255,.05) 0%, rgba(255,255,255,.05) 22%, transparent 23%),
    linear-gradient(160deg, #0a4a78 0%, var(--cra-blue) 45%, #0d3a5c 100%);
  padding: 16px;
  position: relative;
  overflow: hidden;
}
.auth-card {
  width: 100%; max-width: 420px; background: #fff;
  border-radius: 18px; overflow: hidden;
  box-shadow: 0 25px 60px rgba(0,0,0,.35);
}
.auth-card-head {
  position: relative;
  background: linear-gradient(160deg, var(--sidebar-bg) 0%, var(--cra-blue) 100%);
  color: #fff; text-align: center; padding: 34px 24px 26px;
}
.auth-card-head::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--cra-gray), var(--cra-yellow), var(--cra-green), var(--cra-cyan), var(--cra-blue));
}
.auth-card-head .brand-icon { width: 64px; height: 64px; padding: 8px; margin: 0 auto 14px; border-radius: 12px; }
.auth-card-head h1 { font-size: 19px; margin-bottom: 4px; }
.auth-card-sub { font-size: 11px; letter-spacing: .6px; opacity: .75; }
.auth-card-body { padding: 28px 26px 26px; }
.auth-title { font-size: 15px; font-weight: 700; margin-bottom: 18px; color: var(--text); }
.auth-tagline { margin-top: 18px; text-align: center; font-size: 11.5px; color: var(--muted); }
.auth-footer { margin-top: 10px; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .stat-grid, .stat-grid.three { grid-template-columns: repeat(2, 1fr); }
  .two-cols { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 60; transform: translateX(-100%);
    transition: transform .25s;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 55;
  }
  .close-sidebar, .open-sidebar { display: block; }
  .content { padding: 16px; }
  .desc-cell { max-width: 140px; }
}

/* ========== Preoperacional ========== */
.preop-step { animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.check-group { display: flex; flex-direction: column; gap: .55rem; }
.check-opt, .radio-opt { display: flex; align-items: center; gap: .5rem; font-size: .94rem; cursor: pointer; }
.check-opt input, .radio-opt input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
.elementos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .75rem; }
.elemento-item { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: .7rem 1rem; }
.elemento-item label { font-size: .88rem; font-weight: 600; color: var(--text); display: block; margin-bottom: .45rem; }
.elemento-item .radio-group { display: flex; gap: 1rem; }
.req { color: var(--danger); }
.preop-table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.preop-table th { background: var(--bg); font-weight: 600; padding: .55rem .8rem; text-align: left; border-bottom: 2px solid var(--border); white-space: nowrap; }
.preop-table td { padding: .5rem .8rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.preop-table tr:last-child td { border-bottom: none; }
.badge-ok { background: #d1fae5; color: #065f46; padding: 2px 8px; border-radius: 99px; font-size: .8rem; }
.badge-no { background: #fee2e2; color: #991b1b; padding: 2px 8px; border-radius: 99px; font-size: .8rem; }