@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  --ink: #0f172a;
  --paper: #f8fafc;
  --line: #e2e8f0;
  --muted: #64748b;
  --amber: #f59e0b;
  --amber-dark: #d97706;
  --red: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: #1e293b;
  font-family: 'Inter', sans-serif;
}

h1, h2, h3 { font-family: 'Space Grotesk', sans-serif; margin: 0; }

.mono { font-family: 'IBM Plex Mono', monospace; }

a { color: inherit; }

/* Barra superior */
.topbar { background: var(--ink); color: #fff; }
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 18px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.brand-eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: #94a3b8; }
.topbar h1 { font-size: 20px; font-weight: 600; margin-top: 2px; }
.nav { display: flex; align-items: center; gap: 16px; font-size: 14px; flex-wrap: wrap; }
.nav a { text-decoration: none; color: #cbd5e1; }
.nav a:hover { color: #fff; }
.nav-user { color: #64748b; font-size: 13px; }
.nav-logout { color: #f59e0b !important; font-weight: 500; }

.page { max-width: 1080px; margin: 0 auto; padding: 24px; }

/* Mensajes flash */
.flash { border-radius: 10px; padding: 10px 14px; font-size: 14px; margin-bottom: 16px; }
.flash-ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* Tira de totales */
.totales { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 24px; }
@media (min-width: 720px) { .totales { grid-template-columns: repeat(5, 1fr); } }
.total-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; }
.total-card .bar { width: 6px; flex-shrink: 0; }
.total-card .body { padding: 12px 14px; min-width: 0; }
.total-card .label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.total-card .amount { font-size: 16px; font-weight: 600; margin-top: 3px; }
.total-card .detail { font-size: 12px; color: #94a3b8; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.total-card.general { background: var(--ink); color: #fff; border-color: var(--ink); }
.total-card.general .label { color: #94a3b8; }
.total-card.general .detail { color: #94a3b8; }

/* Colores por departamento */
.bar-buses { background: #2563eb; }
.tag-buses { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

.bar-siniestros { background: #c2410c; }
.tag-siniestros { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }

.bar-servicios { background: #0d9488; }
.tag-servicios { background: #f0fdfa; color: #115e59; border: 1px solid #99f6e4; }

.bar-oficinas { background: #7c3aed; }
.tag-oficinas { background: #f5f3ff; color: #5b21b6; border: 1px solid #ddd6fe; }

.bar-otro { background: #64748b; }
.tag-otro { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }

.tag {
  display: inline-flex; align-items: center; border-radius: 999px;
  padding: 2px 10px; font-size: 12px; font-weight: 500;
}

/* Barra de filtros */
.filtros { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 18px; }
.filtros input[type=text], .filtros input[type=date], .filtros select {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: 14px; background: #fff;
}
.filtros input[type=text] { flex: 1; min-width: 200px; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 999px;
  padding: 9px 16px; font-size: 14px; font-weight: 600; border: none; cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--amber); color: var(--ink); }
.btn-primary:hover { background: var(--amber-dark); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn-ghost:hover { background: #f1f5f9; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-danger-text { background: none; border: none; color: #94a3b8; cursor: pointer; font-size: 13px; }
.btn-danger-text:hover { color: var(--red); }
.link-edit { color: #475569; text-decoration: none; font-size: 13px; }
.link-edit:hover { text-decoration: underline; }

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

/* Tabla */
.tabla-wrap { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); background: #f8fafc; padding: 10px 14px; border-bottom: 1px solid var(--line);
}
tbody td { padding: 10px 14px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
.desc-principal { color: #1e293b; }
.desc-secundaria { color: #94a3b8; font-size: 12px; margin-top: 2px; }
.text-right { text-align: right; }
.acciones { display: flex; gap: 10px; justify-content: flex-end; align-items: center; }

/* Estado vacío */
.empty-state {
  text-align: center; padding: 60px 20px; border: 1px dashed var(--line); border-radius: 12px; background: #fff;
}
.empty-state p { color: #475569; margin: 0 0 12px; }

/* Formularios */
.form-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 24px; max-width: 640px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 5px; }
.form-grid input, .form-grid select, .form-grid textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; font-size: 14px;
  font-family: inherit; background: #fff;
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus {
  outline: none; border-color: var(--amber); box-shadow: 0 0 0 3px rgba(245, 158, 11, .18);
}
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.error-text { color: var(--red); font-size: 13px; margin: 4px 0 0; }

/* Auth (login / setup) */
.auth-wrap { display: flex; align-items: center; justify-content: center; min-height: 80vh; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 32px; width: 100%; max-width: 360px; }
.auth-card h2 { font-size: 20px; margin-bottom: 4px; }
.auth-card .muted { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.auth-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; margin-top: 12px; }
.auth-card input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 14px;
}

/* Tabla simple (usuarios / log) */
.simple-table { width: 100%; border-collapse: collapse; font-size: 14px; background: #fff; }
.simple-table th { text-align: left; font-size: 11px; text-transform: uppercase; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); background: #f8fafc; }
.simple-table td { padding: 10px 14px; border-bottom: 1px solid #f1f5f9; }
.badge-rol { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #f1f5f9; color: #475569; }
.badge-rol.admin { background: #fef3c7; color: #92400e; }
.badge-rol.director { background: #ede9fe; color: #5b21b6; }
.badge-inactivo { color: #94a3b8; font-style: italic; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
}

/* Reportes */
.barra-mini { background: #f1f5f9; border-radius: 4px; height: 7px; overflow: hidden; margin-top: 5px; }
.barra-mini-fill { background: var(--amber); height: 100%; }
.barra-mini-fill.rose { background: #e11d48; }
.barra-mini-fill.blue { background: #2563eb; }
.reporte-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.reporte-bloque { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 22px; }
.reporte-bloque h3 { font-size: 15px; margin-bottom: 4px; display: flex; align-items: center; }
.reporte-bloque .sub { font-size: 12px; color: #94a3b8; margin-bottom: 14px; }
.grafica-wrap { position: relative; height: 260px; margin-bottom: 18px; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; flex-shrink: 0; }
.dot-amber { background: #f59e0b; }
.dot-rose { background: #e11d48; }
.dot-blue { background: #2563eb; }
.dot-violet { background: #7c3aed; }

.kpi-strip { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 22px; }
@media (min-width: 720px) { .kpi-strip { grid-template-columns: repeat(4, 1fr); } }
.kpi-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.kpi-card .label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.kpi-card .value { font-size: 20px; font-weight: 700; margin-top: 6px; font-family: 'Space Grotesk', sans-serif; color: var(--ink); }
.kpi-card .sub { font-size: 12px; color: #94a3b8; margin-top: 3px; }
.kpi-card.destacado { background: var(--ink); border-color: var(--ink); }
.kpi-card.destacado .label { color: #94a3b8; }
.kpi-card.destacado .value { color: #fff; }
.kpi-card.destacado .sub { color: #94a3b8; }
.fila-atipica { background: #fef2f2; }
.texto-rojo { color: var(--red); }

/* Variación (sube/baja) */
.delta { font-weight: 600; }
.delta.sube { color: #e11d48; }
.delta.baja { color: #0d9488; }

/* Presets de fecha */
.preset-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.preset-chip {
  font-size: 13px; padding: 6px 14px; border-radius: 999px; text-decoration: none;
  border: 1px solid var(--line); background: #fff; color: var(--muted);
}
.preset-chip:hover { border-color: #cbd5e1; color: #1e293b; }
.preset-chip.activo { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 500; }

/* Barra de filtros pegada al hacer scroll */
.barra-sticky {
  position: sticky; top: 0; z-index: 20; background: var(--paper);
  padding: 12px 0; border-bottom: 1px solid var(--line); margin-bottom: 16px;
}
.barra-sticky label { font-size: 11px; color: var(--muted); display: block; margin-bottom: 2px; }

/* Chips de filtros activos */
.chip-filtro {
  display: inline-flex; align-items: center; font-size: 12px; font-weight: 500;
  padding: 4px 12px; border-radius: 999px; text-decoration: none;
  background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe;
}
.chip-filtro:hover { background: #dbeafe; }

/* Panel de hallazgos automáticos */
.hallazgos { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 22px; }
.hallazgos-titulo {
  font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 14px;
  color: var(--ink); margin-bottom: 12px;
}
.hallazgo { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; padding: 6px 0; line-height: 1.5; }
.hallazgo + .hallazgo { border-top: 1px solid #f8fafc; }
.hallazgo-icono { font-size: 11px; line-height: 1.7; flex-shrink: 0; }
.hallazgo-alerta .hallazgo-icono { color: #e11d48; }
.hallazgo-bien   .hallazgo-icono { color: #0d9488; }
.hallazgo-neutro .hallazgo-icono { color: #cbd5e1; }
.hallazgo-alerta { color: #1e293b; }
.hallazgo-neutro { color: #475569; }

/* Presupuestos */
.presupuesto-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.presupuesto-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; }
.barra-presupuesto { background: #f1f5f9; border-radius: 999px; height: 9px; overflow: hidden; }
.barra-presupuesto-fill { height: 100%; border-radius: 999px; }
.barra-presupuesto-fill.ok       { background: #0d9488; }
.barra-presupuesto-fill.cerca    { background: #f59e0b; }
.barra-presupuesto-fill.excedido { background: #e11d48; }
.presupuesto-pie { font-size: 12px; color: #94a3b8; margin-top: 6px; }

.dot-teal { background: #0d9488; }
.vacio { color: #94a3b8; font-size: 14px; }
.celda-num { font-size: 13px; white-space: nowrap; }
.celda-fecha { font-size: 12px; color: var(--muted); white-space: nowrap; }
.link-tabla { color: #1e293b; text-decoration: none; border-bottom: 1px dotted #cbd5e1; }
.link-tabla:hover { border-bottom-color: var(--amber); }

.bloque-dos-columnas { display: grid; grid-template-columns: 240px 1fr; gap: 24px; align-items: center; }
@media (max-width: 720px) { .bloque-dos-columnas { grid-template-columns: 1fr; } }

/* Tabla de detalle: filas clicables y ordenables */
.fila-clic { cursor: pointer; }
.buscador-tabla {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; font-size: 13px; margin-bottom: 12px; font-family: inherit;
}
.buscador-tabla:focus { outline: none; border-color: var(--amber); box-shadow: 0 0 0 3px rgba(245,158,11,.15); }
.tabla-ordenable thead th { user-select: none; position: relative; }
.tabla-ordenable thead th[data-orden]:hover { color: #1e293b; background: #f1f5f9; }
.tabla-ordenable thead th.orden-asc::after  { content: ' ↑'; color: var(--amber); }
.tabla-ordenable thead th.orden-desc::after { content: ' ↓'; color: var(--amber); }

/* Ficha de una requisición */
.ficha-header {
  background: var(--ink); color: #fff; border-radius: 12px; padding: 22px 24px;
  margin-bottom: 20px; display: flex; justify-content: space-between;
  align-items: center; gap: 20px; flex-wrap: wrap;
}
.ficha-monto .label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #94a3b8; }
.ficha-monto .valor { font-size: 30px; font-weight: 700; margin-top: 4px; font-family: 'Space Grotesk', sans-serif; }
.ficha-monto .desglose { font-size: 12px; color: #94a3b8; margin-top: 4px; }
.ficha-meta { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.ficha-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 22px; }
@media (max-width: 800px) { .ficha-grid { grid-template-columns: 1fr; } }
.ficha-datos { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; align-items: baseline; }
.ficha-datos dt { font-size: 12px; color: var(--muted); }
.ficha-datos dd { margin: 0; font-size: 14px; color: #1e293b; }

@media print {
  .topbar, .filtros, .toolbar a, .no-print, .nav { display: none !important; }
  body { background: #fff; }
  .reporte-bloque { border: none; padding: 0; box-shadow: none; page-break-inside: avoid; }
  .page { padding: 0; max-width: 100%; }
}
