/* ==========================================================================
   Centris · Tema de la plataforma (claro + oscuro)
   Construido sobre Bootstrap 5.3 (data-bs-theme). Todo el color se controla
   con variables para que el modo oscuro sea solo un override.
   ========================================================================== */

:root {
  --c-brand: #2563eb;
  --c-brand-dark: #1d4ed8;
  --c-brand-soft: #e8f0ff;

  /* Sidebar — claro en modo claro (texto y título oscuros y legibles) */
  --c-sidebar: #ffffff;
  --c-sidebar-hover: #eef3ff;
  --c-sidebar-text: #334155;
  --c-sidebar-muted: #64748b;
  --c-sidebar-title: #16203a;
  --c-sidebar-hover-text: #1d4ed8;
  --c-sidebar-border: #e6eaf2;

  /* Superficies y texto (modo claro) */
  --c-bg: #f3f5fa;
  --c-surface: #ffffff;
  --c-surface-2: #f4f6fb;
  --c-ink: #16203a;
  --c-muted: #51607a;
  --c-line: #dde2ec;
  --c-hover: #eef3ff;

  --radius: .65rem;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
  --shadow: 0 6px 22px rgba(15, 23, 42, .10);
}

[data-bs-theme="dark"] {
  --c-brand: #5b8cff;
  --c-brand-dark: #7aa2ff;
  --c-brand-soft: rgba(91, 140, 255, .16);

  --c-sidebar: #0b1322;
  --c-sidebar-hover: #1b2942;
  --c-sidebar-text: #cdd6e4;
  --c-sidebar-muted: #8595af;
  --c-sidebar-title: #ffffff;
  --c-sidebar-hover-text: #ffffff;
  --c-sidebar-border: rgba(255, 255, 255, .08);

  --c-bg: #0a1120;
  --c-surface: #141d30;
  --c-surface-2: #1a2540;
  --c-ink: #e8edf6;
  --c-muted: #a9b5cb;
  --c-line: #283349;
  --c-hover: rgba(91, 140, 255, .12);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow: 0 8px 26px rgba(0, 0, 0, .45);
}

/* Bootstrap overrides */
.btn-primary {
  --bs-btn-bg: var(--c-brand);
  --bs-btn-border-color: var(--c-brand);
  --bs-btn-hover-bg: var(--c-brand-dark);
  --bs-btn-hover-border-color: var(--c-brand-dark);
  --bs-btn-active-bg: var(--c-brand-dark);
  --bs-btn-color: #fff;
  --bs-btn-hover-color: #fff;
}
.btn-outline-primary {
  --bs-btn-color: var(--c-brand);
  --bs-btn-border-color: var(--c-brand);
  --bs-btn-hover-bg: var(--c-brand);
  --bs-btn-hover-border-color: var(--c-brand);
  --bs-btn-active-bg: var(--c-brand);
  --bs-btn-hover-color: #fff;
}
a { color: var(--c-brand); text-decoration: none; }
a:hover { color: var(--c-brand-dark); text-decoration: underline; }
.text-primary { color: var(--c-brand) !important; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--c-bg);
  color: var(--c-ink);
}

/* ----------------------------------------------------------- App shell ---- */
.app-shell { display: flex; min-height: 100vh; }
.main-wrap { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

/* ------------------------------------------------------------- Sidebar ---- */
.sidebar {
  background: var(--c-sidebar);
  color: var(--c-sidebar-text);
  border-right: 1px solid var(--c-sidebar-border);
  --bs-offcanvas-width: 270px;
  --bs-offcanvas-bg: var(--c-sidebar);
  --bs-offcanvas-color: var(--c-sidebar-text);
}
.sidebar .sidebar-brand {
  display: flex; align-items: center; gap: .6rem;
  padding: 1.15rem 1.25rem;
  color: var(--c-sidebar-title); font-weight: 700; font-size: 1.25rem; letter-spacing: .2px;
  border-bottom: 1px solid var(--c-sidebar-border);
}
.sidebar .sidebar-brand:hover { text-decoration: none; color: var(--c-sidebar-title); }
.sidebar .sidebar-brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  color: #fff; font-size: 1.05rem;
}
.sidebar .nav-section {
  padding: 1.1rem 1.25rem .35rem;
  font-size: .7rem; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--c-sidebar-muted);
}
.sidebar .nav-link {
  display: flex; align-items: center; gap: .7rem;
  margin: .12rem .6rem; padding: .58rem .75rem;
  border-radius: .55rem;
  color: var(--c-sidebar-text); font-weight: 500; font-size: .92rem;
  transition: background .12s ease, color .12s ease;
}
.sidebar .nav-link:hover { background: var(--c-sidebar-hover); color: var(--c-sidebar-hover-text); text-decoration: none; }
.sidebar .nav-link.active {
  background: linear-gradient(135deg, #2563eb, #3b82f6); color: #fff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, .4);
}
.sidebar .nav-link.active i { color: #fff; }
.sidebar .nav-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; }
.sidebar .sidebar-footer {
  margin-top: auto; padding: 1rem 1.1rem;
  border-top: 1px solid var(--c-sidebar-border);
}
.sidebar .user-chip { display: flex; align-items: center; gap: .6rem; color: var(--c-sidebar-text); font-size: .88rem; }
.sidebar .user-chip .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--c-brand); color: #fff; font-weight: 600;
}
/* Botón "Salir" adaptado al tema del sidebar. */
.sidebar .btn-outline-light {
  --bs-btn-color: var(--c-sidebar-text);
  --bs-btn-border-color: var(--c-sidebar-border);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--c-brand);
  --bs-btn-hover-border-color: var(--c-brand);
}

@media (min-width: 992px) {
  .sidebar {
    width: 270px; flex: 0 0 270px;
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
  }
}

/* -------------------------------------------------------------- Topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 1020;
  display: flex; align-items: center; gap: .75rem;
  background: var(--c-surface); border-bottom: 1px solid var(--c-line);
  padding: .6rem 1.1rem; min-height: 56px;
}
.topbar .topbar-title { font-weight: 600; color: var(--c-ink); margin: 0; }
.topbar .btn-menu { border: 0; background: transparent; font-size: 1.4rem; color: var(--c-ink); }
.theme-toggle {
  border: 1px solid var(--c-line); background: var(--c-surface); color: var(--c-ink);
  width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center;
  font-size: 1.05rem; line-height: 1;
}
.theme-toggle:hover { background: var(--c-hover); color: var(--c-brand); }

.content { padding: 1.5rem; }

/* --------------------------------------------------------------- Cards ---- */
.card {
  background: var(--c-surface);
  color: var(--c-ink);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card .card-header { background: var(--c-surface); border-bottom: 1px solid var(--c-line); font-weight: 600; color: var(--c-ink); }
.card .card-footer { background: var(--c-surface-2); border-top: 1px solid var(--c-line); }
.bg-light { background: var(--c-surface-2) !important; color: var(--c-ink) !important; }
.list-group-item { background: var(--c-surface); color: var(--c-ink); border-color: var(--c-line); }

/* Stat / KPI cards */
.stat-card { position: relative; overflow: hidden; }
.stat-card .stat-label { color: var(--c-muted); font-size: .8rem; font-weight: 500; }
.stat-card .stat-value { font-size: 2rem; font-weight: 700; line-height: 1.1; color: var(--c-ink); }
.stat-card .stat-icon {
  position: absolute; top: 1rem; right: 1rem;
  width: 42px; height: 42px; border-radius: 11px;
  display: grid; place-items: center; font-size: 1.25rem;
  background: var(--c-brand-soft); color: var(--c-brand);
}
.stat-card.accent-success .stat-icon { background: rgba(22, 163, 74, .15); color: #16a34a; }
.stat-card.accent-warning .stat-icon { background: rgba(217, 119, 6, .15); color: #d97706; }
.stat-card.accent-danger  .stat-icon { background: rgba(220, 38, 38, .15); color: #ef4444; }
[data-bs-theme="dark"] .stat-card.accent-success .stat-icon { color: #4ade80; }
[data-bs-theme="dark"] .stat-card.accent-warning .stat-icon { color: #fbbf24; }
[data-bs-theme="dark"] .stat-card.accent-danger  .stat-icon { color: #f87171; }

/* -------------------------------------------------------------- Tables ---- */
.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--c-ink);
  margin-bottom: 0;
}
.table > thead th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--c-muted); font-weight: 700;
  border-bottom: 1px solid var(--c-line); background: var(--c-surface-2);
}
.table > tbody td { border-color: var(--c-line); vertical-align: middle; color: var(--c-ink); }
.table-hover > tbody > tr:hover > * { background: var(--c-hover); color: var(--c-ink); }
.card > .table-responsive { border-radius: var(--radius); overflow: hidden; }

/* -------------------------------------------------------------- Badges ---- */
.badge { font-weight: 600; letter-spacing: .2px; padding: .42em .68em; }

/* -------------------------------------------------------- Page header ---- */
.page-header { margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; margin: 0; color: var(--c-ink); }
.page-header .subtitle { color: var(--c-muted); font-size: .9rem; margin-top: .15rem; }

/* --------------------------------------------------------------- Forms ---- */
.form-control, .form-select { border-color: var(--c-line); }
.form-control:focus, .form-select:focus {
  border-color: var(--c-brand);
  box-shadow: 0 0 0 .2rem rgba(37, 99, 235, .2);
}
.form-label { font-weight: 500; font-size: .88rem; color: var(--c-ink); }
.text-muted { color: var(--c-muted) !important; }

/* --------------------------------------------------------------- Login ---- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(1200px 600px at 0% 0%, #1e3a8a 0%, #0b1322 55%); }
.login-card {
  width: 100%; max-width: 400px; background: var(--c-surface); color: var(--c-ink);
  border-radius: 1rem; box-shadow: 0 20px 50px rgba(2, 6, 23, .45); overflow: hidden;
}
.login-card .login-head { text-align: center; padding: 2rem 2rem .5rem; }
.login-card .login-logo {
  width: 56px; height: 56px; border-radius: 14px; margin: 0 auto .75rem;
  display: grid; place-items: center; font-size: 1.6rem; color: #fff;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
}
.login-card .login-body { padding: .5rem 2rem 2rem; }

/* --------------------------------------------------------------- Misc ---- */
.empty-state { text-align: center; color: var(--c-muted); padding: 3rem 1rem; }
.empty-state i { font-size: 2.5rem; opacity: .4; display: block; margin-bottom: .5rem; }

/* ----------------------------------------------- Audit evaluation form ---- */
.audit-toolbar {
  position: sticky; top: 56px; z-index: 1000;
  background: var(--c-surface); border: 1px solid var(--c-line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: .6rem .9rem; margin-bottom: 1rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
}
.audit-toolbar .counters { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .9rem; font-size: .85rem; }
.audit-toolbar .progress { width: 100%; height: 6px; margin-top: .2rem; background: var(--c-surface-2); }
.audit-toolbar .progress-bar { background: var(--c-brand); }
.audit-score-live { font-weight: 700; font-size: 1.05rem; }

.audit-cat .card-header { display: flex; justify-content: space-between; align-items: center; }
.audit-cat .cat-progress { font-size: .75rem; color: var(--c-muted); font-weight: 500; }

.audit-item { padding: .8rem 1rem; border-bottom: 1px solid var(--c-line); }
.audit-item:last-child { border-bottom: 0; }
.audit-item.is-bad { background: rgba(220, 38, 38, .05); }
.audit-item .ai-q { font-size: .9rem; line-height: 1.35; }
.audit-item .ai-num {
  display: inline-grid; place-items: center; min-width: 1.6rem; height: 1.6rem;
  border-radius: 6px; background: var(--c-surface-2); color: var(--c-muted);
  font-size: .75rem; font-weight: 700; margin-right: .5rem; padding: 0 .3rem;
}
.audit-item .ai-pts { color: var(--c-muted); font-size: .78rem; white-space: nowrap; }
.audit-item .ai-controls { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .6rem; }
.audit-item .result-seg .btn { font-weight: 600; }
.audit-item .ai-ng { flex: 1 1 240px; min-width: 200px; }
.audit-item .ai-ng.d-none { display: none !important; }

.audit-savebar {
  position: sticky; bottom: 0; z-index: 1000;
  background: var(--c-surface); border: 1px solid var(--c-line);
  border-radius: var(--radius); box-shadow: 0 -4px 16px rgba(15, 23, 42, .08);
  padding: .7rem 1rem; margin-top: 1rem;
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .6rem;
}

/* ----------------------------------------------- Evidence photo grid ---- */
.evidence-grid {
  display: grid; gap: .75rem;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.evidence-item {
  margin: 0; border: 1px solid var(--c-line); border-radius: var(--radius);
  overflow: hidden; background: var(--c-surface-2);
}
.evidence-item img {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block;
  transition: transform .2s ease;
}
.evidence-item a:hover img { transform: scale(1.04); }
.evidence-item figcaption {
  display: flex; align-items: center; justify-content: space-between; gap: .4rem;
  padding: .4rem .55rem; font-size: .8rem; color: var(--c-muted);
}
.evidence-item figcaption .text-truncate { max-width: 80%; }

/* ------------------------------------------------- Cruz de Seguridad ---- */
.cruz-grid {
  --cell: 46px;
  display: grid; grid-template-columns: repeat(9, var(--cell));
  gap: 4px; justify-content: center; margin: 0 auto;
}
.cruz-grid.cruz-lg { --cell: 64px; }
.cruz-grid.cruz-sm { --cell: 30px; gap: 3px; }
.cruz-cell {
  aspect-ratio: 1 / 1; border-radius: 8px;
  display: grid; place-items: center;
  font-weight: 700; font-size: .85rem; color: #fff;
  user-select: none;
}
.cruz-grid.cruz-sm .cruz-cell { font-size: .68rem; border-radius: 5px; }
.cruz-empty { background: transparent; }
.cruz-green  { background: #16a34a; }
.cruz-yellow { background: #f59e0b; color: #3a2a00; }
.cruz-red    { background: #dc2626; }
.cruz-future { background: var(--c-surface-2); color: var(--c-muted); border: 1px dashed var(--c-line); }
[data-bs-theme="dark"] .cruz-green  { background: #1f9d57; }
[data-bs-theme="dark"] .cruz-yellow { background: #d99411; color: #1a1300; }

.cruz-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem 1.1rem; font-size: .82rem; color: var(--c-muted); }
.cruz-dot { display: inline-block; width: .85rem; height: .85rem; border-radius: 3px; vertical-align: -1px; margin-right: .25rem; }
.cruz-dot.cruz-future { border: 1px dashed var(--c-line); }

/* ------------------------------------------- Phase track (servicios) ---- */
.phase-track { display: flex; align-items: flex-start; justify-content: space-between; gap: .25rem; }
.phase-step { flex: 1; text-align: center; position: relative; }
.phase-step::before {
  content: ""; position: absolute; top: 16px; left: -50%; width: 100%; height: 3px;
  background: var(--c-line); z-index: 0;
}
.phase-step:first-child::before { display: none; }
.phase-step .dot {
  position: relative; z-index: 1; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; margin: 0 auto .35rem;
  background: var(--c-surface-2); color: var(--c-muted);
  border: 2px solid var(--c-line); font-weight: 700; font-size: .85rem;
}
.phase-step .lbl { font-size: .76rem; color: var(--c-muted); }
.phase-step.current .dot { background: var(--c-brand); color: #fff; border-color: var(--c-brand); }
.phase-step.current .lbl { color: var(--c-ink); font-weight: 600; }
.phase-step.done .dot { background: var(--c-success, #16a34a); color: #fff; border-color: var(--c-success, #16a34a); }
.phase-step.done::before { background: var(--c-success, #16a34a); }

/* ------------------------------------------------ Calendario servicios -- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head { text-align: center; font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--c-muted); padding: .3rem 0; }
.cal-cell { min-height: 96px; border: 1px solid var(--c-line); border-radius: 8px;
  background: var(--c-surface); padding: .3rem; display: flex; flex-direction: column; gap: 3px; }
.cal-cell.cal-out { background: var(--c-surface-2); opacity: .55; }
.cal-cell.cal-today { border-color: var(--c-brand); box-shadow: 0 0 0 2px rgba(37,99,235,.18); }
.cal-day { font-size: .78rem; font-weight: 600; color: var(--c-muted); }
.cal-cell.cal-today .cal-day { color: var(--c-brand); }
.cal-event { display: block; font-size: .72rem; font-weight: 600; color: #fff !important;
  padding: .12rem .35rem; border-radius: 5px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; text-decoration: none; }
.cal-event:hover { text-decoration: none; filter: brightness(1.05); color: #fff !important; }
.cal-event.text-dark, .cal-event.bg-warning { color: #3a2a00 !important; }
@media (max-width: 575px) {
  .cal-cell { min-height: 64px; }
  .cal-event { font-size: .6rem; }
}
