/* ============================================================
   app.css  —  Sistema de Estadísticas de Justicia Cívica
   Estado de Aguascalientes
   ============================================================ */

/* Variables de color */
:root {
  --primary:       #1565C0;
  --primary-dark:  #0D47A1;
  --primary-light: #1976D2;
  --secondary:     #0288D1;
  --accent:        #29B6F6;
  --sidebar-bg:    #0A1929;
  --sidebar-hover: #132F4C;
  --sidebar-active:#1565C0;
  --sidebar-text:  #b8c8d9;
  --sidebar-width: 250px;
  --topbar-height: 60px;
  --body-bg:       #f4f6f9;
  --card-shadow:   0 2px 10px rgba(0,0,0,.08);
}

/* ── Reset / Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--body-bg);
  color: #333;
  margin: 0;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); text-decoration: underline; }

/* ── Layout ────────────────────────────────────────────────── */
.wrapper {
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1000;
  overflow-y: auto;
  transition: transform .3s ease;
}

#sidebar.collapsed {
  transform: translateX(calc(-1 * var(--sidebar-width)));
}

.sidebar-brand {
  padding: 1.25rem 1rem;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: var(--topbar-height);
}

.sidebar-brand-icon {
  font-size: 1.6rem;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-brand-text {
  font-size: .8rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
}

.sidebar-brand-text small {
  display: block;
  font-weight: 400;
  opacity: .75;
  font-size: .7rem;
}

.sidebar-section-title {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #666;
  padding: .75rem 1rem .25rem;
  margin: 0;
}

.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
}

.sidebar-nav li { margin: 0; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem 1rem;
  color: var(--sidebar-text) !important;
  font-size: .875rem;
  border-left: 3px solid transparent;
  transition: background .2s, border-color .2s, color .2s;
  text-decoration: none !important;
}

.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: #fff !important;
}

.sidebar-link.active {
  background: rgba(21,101,192,.35);
  border-left-color: var(--primary-light);
  color: #fff !important;
  font-weight: 600;
}

.sidebar-link .icon {
  font-size: .95rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: .75rem 1rem;
  font-size: .75rem;
  color: #555;
  border-top: 1px solid #2a2a40;
  text-align: center;
}

/* ── Main area (topbar + content) ─────────────────────────── */
.main-area {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  transition: margin-left .3s ease;
  min-width: 0;
}

.main-area.expanded {
  margin-left: 0;
}

/* ── Main content ──────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Top navbar ────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: #ffffff;
  border-bottom: 1px solid #e8eaed;
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 990;
  box-shadow: 0 1px 6px rgba(0,0,0,.06);
}

.topbar-toggle {
  background: none;
  border: none;
  color: #6b7280;
  font-size: 1.1rem;
  cursor: pointer;
  padding: .4rem .5rem;
  border-radius: 6px;
  transition: background .2s, color .2s;
  flex-shrink: 0;
  line-height: 1;
}

.topbar-toggle:hover {
  background: #f3f4f6;
  color: #111827;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex: 1;
  min-width: 0;
}

.topbar-brand-icon {
  font-size: 1.05rem;
  color: var(--primary);
  flex-shrink: 0;
}

.topbar-brand-text {
  font-size: .9rem;
  font-weight: 600;
  color: #1f2937;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-brand-sub {
  font-weight: 400;
  color: #9ca3af;
  font-size: .82rem;
}

.topbar-title {
  color: #1f2937;
  font-size: .95rem;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: .65rem;
  flex-shrink: 0;
}

.topbar-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: grid;
  place-items: center;
  font-size: .73rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: .03em;
  box-shadow: 0 1px 4px rgba(21,101,192,.35);
}

.topbar-userinfo {
  line-height: 1;
}

.topbar-username {
  font-size: .82rem;
  font-weight: 600;
  color: #1f2937;
  line-height: 1.3;
}

.topbar-role {
  font-size: .71rem;
  color: #9ca3af;
  line-height: 1.3;
  text-transform: capitalize;
}

.topbar-logout {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: #9ca3af;
  border: 1px solid #e5e7eb;
  transition: background .2s, color .2s, border-color .2s;
  text-decoration: none !important;
  flex-shrink: 0;
}

.topbar-logout:hover {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fecaca;
}

/* ── Page area ─────────────────────────────────────────────── */
.page-content {
  padding: 1.5rem;
  flex: 1;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.5rem;
}

.page-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: #222;
  margin: 0;
}

.page-header .breadcrumb {
  font-size: .8rem;
  margin: .15rem 0 0;
}

/* ── KPI Cards ─────────────────────────────────────────────── */
.kpi-card {
  border: none;
  border-radius: .75rem;
  padding: 1.25rem 1.5rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--card-shadow);
  transition: transform .2s, box-shadow .2s;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,.12);
}

.kpi-icon {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  font-size: 3rem;
  opacity: .12;
}

.kpi-label {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  opacity: .85;
  margin-bottom: .25rem;
}

.kpi-number {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1;
  margin-bottom: .25rem;
}

.kpi-sub {
  font-size: .78rem;
  opacity: .75;
}

/* KPI color variants */
.kpi-primary   { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: #fff; }
.kpi-danger    { background: linear-gradient(135deg, #C62828, #ef5350); color: #fff; }
.kpi-warning   { background: linear-gradient(135deg, #e65100, #fb8c00); color: #fff; }
.kpi-success   { background: linear-gradient(135deg, #1b5e20, #388e3c); color: #fff; }
.kpi-info      { background: linear-gradient(135deg, #0d47a1, #1976d2); color: #fff; }
.kpi-teal      { background: linear-gradient(135deg, #004d40, #00796b); color: #fff; }
.kpi-purple    { background: linear-gradient(135deg, #4a148c, #7b1fa2); color: #fff; }
.kpi-dark      { background: linear-gradient(135deg, #212121, #424242); color: #fff; }

/* ── Cards genéricas ───────────────────────────────────────── */
.card {
  border: none;
  border-radius: .75rem;
  box-shadow: var(--card-shadow);
  margin-bottom: 1.25rem;
}

.card-header {
  border-radius: .75rem .75rem 0 0 !important;
  padding: .85rem 1.25rem;
  font-weight: 600;
  font-size: .9rem;
  background: #fff;
  border-bottom: 2px solid #f0f0f0;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.card-body { padding: 1.25rem; }

/* ── Filter bar ────────────────────────────────────────────── */
.filter-card {
  background: #fff;
  border-radius: .75rem;
  padding: 1rem 1.25rem;
  box-shadow: var(--card-shadow);
  margin-bottom: 1.25rem;
}

.filter-card .row { align-items: flex-end; }

.filter-card label {
  font-size: .78rem;
  font-weight: 600;
  color: #555;
  margin-bottom: .2rem;
}

/* ── Tables ────────────────────────────────────────────────── */
.table-responsive { border-radius: .5rem; overflow: hidden; }

.table thead th {
  background: #f8f9fa;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #555;
  border-bottom: 2px solid #e9ecef;
  white-space: nowrap;
  padding: .75rem 1rem;
}

.table tbody td { padding: .65rem 1rem; vertical-align: middle; font-size: .875rem; }
.table tbody tr:hover { background-color: rgba(21,101,192,.04); }

/* ── Badges ────────────────────────────────────────────────── */
.badge { font-size: .72rem; font-weight: 600; padding: .3em .6em; border-radius: .35rem; }

/* ── Formularios ───────────────────────────────────────────── */
.form-section-title {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--primary);
  border-bottom: 2px solid var(--primary);
  padding-bottom: .35rem;
  margin: 1.25rem 0 .75rem;
}

.form-label {
  font-size: .82rem;
  font-weight: 600;
  color: #444;
  margin-bottom: .25rem;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 .2rem rgba(21,101,192,.15);
}

/* ── Charts ────────────────────────────────────────────────── */
.chart-container {
  position: relative;
  padding: .5rem;
}

canvas { max-width: 100%; }

/* ── Login page ────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--sidebar-bg), var(--primary-dark));
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: #fff;
  border-radius: 1rem;
  padding: 2.5rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.login-logo {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 2rem;
  color: #fff;
  margin: 0 auto 1.25rem;
}

.login-card h4 {
  text-align: center;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: .25rem;
}

.login-card p {
  text-align: center;
  color: #777;
  font-size: .85rem;
  margin-bottom: 1.5rem;
}

/* ── Utilities ─────────────────────────────────────────────── */
.text-primary-app { color: var(--primary) !important; }
.bg-primary-app   { background-color: var(--primary) !important; }
.border-primary-app { border-color: var(--primary) !important; }
.bg-pink          { background-color: #fce4ec !important; color: #880e4f !important; }

.folio-badge {
  font-family: 'Courier New', monospace;
  font-size: .78rem;
  font-weight: 700;
  background: #e3f2fd;
  color: var(--primary-dark);
  padding: .2em .5em;
  border-radius: .3rem;
  letter-spacing: .05em;
}

/* Detail view key-value pairs */
.detail-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #888;
  letter-spacing: .04em;
  margin-bottom: .1rem;
}

.detail-value {
  font-size: .92rem;
  color: #222;
  margin-bottom: .75rem;
  word-break: break-word;
}

/* ── Print styles ──────────────────────────────────────────── */
@media print {
  #sidebar, .topbar, .filter-card, .no-print,
  .btn, .dataTables_wrapper .dataTables_filter,
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_paginate,
  .dataTables_wrapper .dataTables_info { display: none !important; }

  .main-content { margin-left: 0 !important; }
  .page-content { padding: 0 !important; }
  body { background: #fff !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; }
  .table thead th { background: #eee !important; }

  .print-header {
    display: block !important;
    text-align: center;
    margin-bottom: 1rem;
  }
}

.print-header { display: none; }

/* ── Normalización de texto: mayúsculas en campos de formulario ── */
form input[type="text"]:not(.no-upper),
form textarea:not(.no-upper) {
  text-transform: uppercase;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 991.98px) {
  #sidebar {
    transform: translateX(calc(-1 * var(--sidebar-width)));
  }

  #sidebar.open {
    transform: translateX(0);
  }

  .main-area {
    margin-left: 0;
  }

  .page-content {
    padding: 1rem;
  }

  .kpi-number {
    font-size: 1.8rem;
  }

  .topbar-title {
    font-size: .85rem;
  }

  /* Overlay when sidebar open */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 999;
  }

  .sidebar-overlay.active {
    display: block;
  }
}

@media (max-width: 575.98px) {
  .kpi-number { font-size: 1.5rem; }
  .page-header { flex-direction: column; }
  .login-card { padding: 1.5rem; }
}
