/* =====================================================================
   Sistema de Gestión — estilos generales
   Paleta: indigo/slate, estilo SaaS limpio y minimalista
   ===================================================================== */

:root {
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --brand-light: #eef2ff;
  --ink: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --bg: #f6f7fb;
  --card-bg: #ffffff;
  --danger: #ef4444;
  --success: #16a34a;
  --warning: #f59e0b;
  --info: #0ea5e9;
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar-w: 250px;
  --topbar-h: 64px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow-md: 0 4px 10px rgba(15, 23, 42, .06), 0 2px 4px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; }

/* ---------- Layout ---------- */
.app-wrapper { display: flex; min-height: 100vh; }

.app-sidebar {
  width: var(--sidebar-w);
  background: #12142b;
  color: #cbd0e6;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform .25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: 1.25rem 1.25rem;
  color: #fff;
  font-weight: 700;
  font-size: 1.02rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo { width: 32px; height: 32px; border-radius: 8px; object-fit: cover; }
.sidebar-logo-fallback {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), #818cf8);
  display: flex; align-items: center; justify-content: center; font-size: 1rem; color: #fff;
}
.sidebar-brand-text { line-height: 1.15; }

.sidebar-nav { padding: .85rem .65rem; flex: 1; overflow-y: auto; }
.sidebar-link {
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem .85rem;
  border-radius: var(--radius-sm);
  color: #b7bdda;
  font-weight: 500;
  margin-bottom: 2px;
  font-size: .92rem;
}
.sidebar-link i { font-size: 1.05rem; width: 20px; text-align: center; }
.sidebar-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-link.active { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }

.sidebar-footer { padding: 1rem 1.25rem; border-top: 1px solid rgba(255,255,255,.08); }

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 1035;
}

.app-main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }

.app-topbar {
  height: var(--topbar-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1.5rem;
  position: sticky; top: 0; z-index: 1020;
}

.btn-icon {
  background: transparent; border: 1px solid var(--border); border-radius: 10px;
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  color: var(--ink);
}

.global-search { position: relative; flex: 1; max-width: 480px; }
.global-search i.bi-search { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.global-search input {
  width: 100%; border: 1px solid var(--border); background: var(--bg);
  border-radius: 10px; padding: .55rem .75rem .55rem 2.2rem; font-size: .9rem;
}
.global-search input:focus { outline: none; border-color: var(--brand); background: #fff; }
.global-search-results {
  display: none; position: absolute; top: 110%; left: 0; right: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-md);
  max-height: 380px; overflow-y: auto; z-index: 1050;
}
.global-search-results.show { display: block; }
.gsr-group-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .5rem .9rem 0; }
.gsr-item { display: block; padding: .55rem .9rem; color: var(--ink); border-bottom: 1px solid #f1f5f9; }
.gsr-item:hover { background: var(--brand-light); }
.gsr-item small { display: block; color: var(--muted); }
.gsr-empty { padding: .9rem; color: var(--muted); font-size: .85rem; }

.topbar-right { display: flex; align-items: center; gap: 1rem; margin-left: auto; }
.user-chip { display: flex; align-items: center; gap: .5rem; background: transparent; border: none; padding: .35rem .5rem; border-radius: 10px; }
.user-chip:hover { background: var(--bg); }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .82rem;
}

.app-content { padding: 1.5rem; flex: 1; }
.app-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); background: var(--card-bg); }

/* ---------- Page header ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.page-title { font-size: 1.35rem; font-weight: 800; margin: 0; }
.page-subtitle { color: var(--muted); font-size: .88rem; margin-top: .15rem; }

/* ---------- Cards ---------- */
.card-block {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
}

.kpi-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
@media (max-width: 1400px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 768px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .kpi-grid { grid-template-columns: 1fr; } }

.kpi-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.2rem;
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--kpi-color, var(--brand));
}
.kpi-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; display:flex; align-items:center; gap:.4rem;}
.kpi-value { font-size: 1.55rem; font-weight: 800; margin-top: .35rem; color: var(--ink); }
.kpi-icon { width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center; background: var(--kpi-bg, var(--brand-light)); color: var(--kpi-color, var(--brand)); font-size: 1rem; }
.kpi-top { display: flex; align-items: flex-start; justify-content: space-between; }

/* ---------- Badges de estado ---------- */
.badge-status {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .28rem .65rem; border-radius: 999px; font-size: .76rem; font-weight: 600;
  background: color-mix(in srgb, var(--bs-c, #64748b) 14%, white);
  color: var(--bs-c, #64748b);
  border: 1px solid color-mix(in srgb, var(--bs-c, #64748b) 30%, white);
  white-space: nowrap;
}
.badge-status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--bs-c, #64748b); }

/* ---------- Tablas ---------- */
.table-wrap { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.table-modern { width: 100%; border-collapse: collapse; margin: 0; }
.table-modern thead th {
  background: #fafbfe; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  padding: .8rem 1rem; border-bottom: 1px solid var(--border); text-align: left; font-weight: 700; white-space: nowrap;
}
.table-modern tbody td { padding: .8rem 1rem; border-bottom: 1px solid #f1f5f9; vertical-align: middle; font-size: .88rem; }
.table-modern tbody tr:last-child td { border-bottom: none; }
.table-modern tbody tr:hover { background: #fafbff; }
.table-responsive-wrap { overflow-x: auto; }
.text-right { text-align: right; }
.amount-cell { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Formularios ---------- */
.form-label { font-weight: 600; font-size: .84rem; }
.form-control, .form-select {
  border-radius: 10px; border: 1px solid var(--border); font-size: .9rem;
}
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light); }

.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-brand:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn { border-radius: 10px; font-weight: 600; font-size: .88rem; }

/* ---------- Alertas del dashboard ---------- */
.alert-list { display: flex; flex-direction: column; gap: .6rem; }
.alert-pill {
  display: flex; align-items: center; gap: .65rem; padding: .7rem 1rem; border-radius: 12px; font-size: .87rem; font-weight: 500;
}
.alert-pill.warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-pill.info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-pill.danger { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at top left, #1e1b4b, #0f172a 60%);
  padding: 1.5rem;
}
.login-card {
  width: 100%; max-width: 400px; background: #fff; border-radius: 18px; padding: 2.25rem 2rem;
  box-shadow: 0 20px 40px rgba(0,0,0,.25);
}
.login-logo { width: 54px; height: 54px; border-radius: 14px; background: linear-gradient(135deg, var(--brand), #818cf8); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 1.5rem; margin: 0 auto 1rem; }

/* ---------- Tabs proyecto ---------- */
.nav-tabs .nav-link { border: none; color: var(--muted); font-weight: 600; font-size: .88rem; }
.nav-tabs .nav-link.active { color: var(--brand); border-bottom: 2px solid var(--brand); background: transparent; }

/* ---------- Responsive sidebar ---------- */
@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); }
  .app-sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
  .app-main { margin-left: 0; }
  .sidebar-backdrop.show { display: block; }
}

@media (max-width: 576px) {
  .app-content { padding: 1rem; }
  .app-topbar { padding: 0 1rem; gap: .5rem; }
  .page-title { font-size: 1.15rem; }
}

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state i { font-size: 2.2rem; margin-bottom: .6rem; display: block; }

.stat-inline { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.stat-inline .item { min-width: 120px; }
.stat-inline .label { font-size: .74rem; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.stat-inline .value { font-size: 1.1rem; font-weight: 700; }

/* ---------------- Scroll interno de modales (formularios largos) ---------------- */
/* Fuerza una altura máxima con scroll propio en el cuerpo del modal, para que
   los formularios largos (ej. Nuevo proyecto) siempre muestren una barra de
   desplazamiento visible en vez de depender del cálculo automático de Bootstrap. */
.modal-body {
  max-height: min(65vh, 620px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}
.modal-body::-webkit-scrollbar { width: 8px; }
.modal-body::-webkit-scrollbar-track { background: transparent; }
.modal-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }
.modal-body::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

@media (max-width: 576px) {
  .modal-body { max-height: 60vh; }
}
