/* ============================================================
   Sistema de Gestión de Personas — Estilos principales
   ============================================================ */

/* ---------- Variables — Modo Oscuro (por defecto) ---------- */
:root {
  --sidebar-w: 230px;
  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #111827;
  --border: #334155;
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(0, 0, 0, .4);
  --transition: .18s ease;

  /* Aliases usados en los templates */
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #1e293b;
  --text: #e2e8f0;
  --primary: #38bdf8;
}

/* ---------- Variables — Modo Claro ---------- */
[data-theme="light"] {
  --bg-main:    #f1f5f9;
  --bg-card:    #ffffff;
  --bg-sidebar: #e2e8f0;
  --border:     #cbd5e1;
  --accent:     #0284c7;
  --accent-2:   #6366f1;
  --text-main:  #0f172a;
  --text-muted: #64748b;
  --success:    #059669;
  --danger:     #dc2626;
  --warning:    #d97706;
  --shadow:     0 4px 20px rgba(0, 0, 0, .1);

  /* Aliases */
  --bg:      #f1f5f9;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --text:    #0f172a;
  --primary: #0284c7;
}

/* Ajustes específicos al modo claro */
[data-theme="light"] body {
  color: var(--text-main);
}

[data-theme="light"] .sidebar-nav li a:hover {
  background: rgba(0,0,0,.05);
}

[data-theme="light"] .sidebar-nav li.active a {
  background: rgba(2, 132, 199, .1);
}

[data-theme="light"] .table th {
  background: rgba(0,0,0,.03);
}

[data-theme="light"] .table td {
  border-bottom-color: rgba(203, 213, 225, .5);
}

[data-theme="light"] .table tbody tr:hover td {
  background: rgba(2, 132, 199, .04);
}

[data-theme="light"] .btn-primary {
  color: #fff;
}

[data-theme="light"] .btn-primary:hover {
  color: #fff;
  background: #0369a1;
}

[data-theme="light"] .btn-secondary {
  background: rgba(0,0,0,.07);
  color: var(--text-main);
}

[data-theme="light"] .btn-secondary:hover {
  background: rgba(0,0,0,.12);
}

[data-theme="light"] .btn-outline {
  color: var(--text-muted);
  background: transparent;
}

[data-theme="light"] .btn-outline:hover {
  background: rgba(0,0,0,.05);
}

[data-theme="light"] .form-control,
[data-theme="light"] .form-select {
  background: #fff;
  color: var(--text-main);
  border-color: var(--border);
}

[data-theme="light"] .form-control:focus,
[data-theme="light"] .form-select:focus {
  background: #fff;
  box-shadow: 0 0 0 3px rgba(2,132,199,.15);
}

[data-theme="light"] .form-control::placeholder {
  color: #94a3b8;
}

[data-theme="light"] select.form-control option,
[data-theme="light"] select.form-select option {
  background: #fff;
  color: var(--text-main);
}

[data-theme="light"] .select2-container--default .select2-selection--single {
  background-color: #fff;
}

[data-theme="light"] .select2-container--default .select2-selection--single .select2-selection__rendered {
  color: var(--text-main);
}

[data-theme="light"] .select2-container--default .select2-dropdown {
  background-color: #fff;
}

[data-theme="light"] .select2-container--default .select2-search--dropdown .select2-search__field {
  background-color: #f8fafc;
  color: var(--text-main);
}

[data-theme="light"] .select2-container--default .select2-results__option {
  color: var(--text-main);
}

[data-theme="light"] .select2-results__option--selectable:hover {
  background-color: #f1f5f9;
}

[data-theme="light"] .modal-box {
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

[data-theme="light"] .alert-success { background:rgba(5,150,105,.08); border-color:rgba(5,150,105,.3); color:#065f46; }
[data-theme="light"] .alert-danger  { background:rgba(220,38,38,.08);  border-color:rgba(220,38,38,.3);  color:#7f1d1d; }
[data-theme="light"] .alert-warning { background:rgba(217,119,6,.08);  border-color:rgba(217,119,6,.3);  color:#78350f; }
[data-theme="light"] .alert-info    { background:rgba(2,132,199,.08);  border-color:rgba(2,132,199,.3);  color:#0c4a6e; }

[data-theme="light"] .page-item .page-link:hover {
  background: rgba(0,0,0,.06);
}

[data-theme="light"] .drop-zone:hover,
[data-theme="light"] .drop-zone.dragover {
  background: rgba(2,132,199,.04);
}

/* ---------- Theme toggle button ---------- */
.theme-toggle-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  padding: .25rem .55rem;
  font-size: .85rem;
  color: var(--text-muted);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: .3rem;
  white-space: nowrap;
}

.theme-toggle-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}



/* ---------- Reset / Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: #7dd3fc;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;          /* altura exacta del viewport */
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  overflow: hidden;       /* el wrapper no scrollea */
  transition: width var(--transition);
}

.sidebar-brand {
  padding: 1.4rem 1.2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .75rem;
}

.sidebar-brand .brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.sidebar-brand .brand-name {
  font-size: .85rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-main);
}

.sidebar-brand .brand-name span {
  display: block;
  font-weight: 400;
  font-size: .7rem;
  color: var(--text-muted);
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  list-style: none;
  overflow-y: auto;       /* scroll cuando los ítems no caben */
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem 1.2rem;
  color: var(--text-muted);
  font-size: .88rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all var(--transition);
}

.sidebar-nav li a:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, .05);
  border-left-color: var(--border);
}

.sidebar-nav li.active a {
  color: var(--accent);
  background: rgba(56, 189, 248, .08);
  border-left-color: var(--accent);
}

.sidebar-nav .nav-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 1rem 1.2rem;
  border-top: 1px solid var(--border);
  font-size: .72rem;
  color: var(--text-muted);
  text-align: center;
}

/* ---------- Main layout ---------- */
.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: .9rem 1.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
}

.topbar-sub {
  font-size: .75rem;
  color: var(--text-muted);
}

.page-content {
  padding: 1.8rem;
  flex: 1;
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: .85rem 1.1rem;
  background: rgba(255, 255, 255, .03);
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.card-body {
  padding: 1.1rem;
}

/* stat cards */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-icon.blue {
  background: rgba(56, 189, 248, .15);
  color: var(--accent);
}

.stat-icon.green {
  background: rgba(52, 211, 153, .15);
  color: var(--success);
}

.stat-icon.purple {
  background: rgba(129, 140, 248, .15);
  color: var(--accent-2);
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
}

.stat-label {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: .2rem;
}

/* ---------- Tables ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
  color: var(--text-main);
}

.table th {
  background: rgba(255, 255, 255, .04);
  padding: .65rem .9rem;
  text-align: left;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: .6rem .9rem;
  border-bottom: 1px solid rgba(51, 65, 85, .5);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover td {
  background: rgba(56, 189, 248, .04);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem .95rem;
  font-size: .83rem;
  font-weight: 500;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  line-height: 1.4;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #0f172a;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: #7dd3fc;
  color: #0f172a;
}

.btn-success {
  background: var(--success);
  color: #0f172a;
  border-color: var(--success);
}

.btn-success:hover {
  background: #6ee7b7;
  color: #0f172a;
}

.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-outline:hover {
  background: rgba(255, 255, 255, .06);
  color: var(--text-main);
  border-color: var(--text-muted);
}

.btn-outline-primary {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}

.btn-outline-primary:hover {
  background: rgba(56, 189, 248, .1);
  color: var(--accent);
}

.btn-outline-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

.btn-outline-danger:hover {
  background: rgba(248, 113, 113, .1);
  color: var(--danger);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover {
  background: #ef4444;
}

.btn-secondary {
  background: rgba(255, 255, 255, .08);
  color: var(--text-main);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, .14);
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: .45rem .5rem;
}

.btn-link:hover {
  color: var(--text-main);
}

.btn-sm {
  padding: .3rem .65rem;
  font-size: .78rem;
}

/* ---------- Forms ---------- */
.form-control,
.form-select {
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: 7px;
  padding: .48rem .75rem;
  font-size: .85rem;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, .15);
  background: rgba(255, 255, 255, .07);
}

.form-control::placeholder {
  color: var(--text-muted);
}

.form-label {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .35rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.form-label.required::after {
  content: ' *';
  color: var(--danger);
}

/* ---------- Select personalizado ---------- */
select.form-control,
select.form-select,
select[class*="form-"] {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  /* Flecha SVG en color acento */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2338bdf8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .75rem center;
  background-size: 12px;
  padding-right: 2.2rem;
  cursor: pointer;
}

select.form-control:hover,
select.form-select:hover,
select[class*="form-"]:hover {
  border-color: var(--accent);
}

/* Opciones del dropdown */
select.form-control option,
select.form-select option,
select[class*="form-"] option {
  background: #1e293b;
  color: var(--text-main);
}

/* ---------- Select2 Dark Theme Overrides ---------- */
.select2-container--default .select2-selection--single {
  background-color: var(--surface2, #1e293b);
  border: 1px solid var(--border, #334155);
  border-radius: 6px;
  height: 38px;
  padding: 0.25rem 0.5rem;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
  color: var(--text-main, #f8fafc);
  line-height: 28px;
}

.select2-container--default .select2-dropdown {
  background-color: var(--surface2, #1e293b);
  border: 1px solid var(--border, #334155);
  border-radius: 6px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.select2-container--default .select2-search--dropdown .select2-search__field {
  background-color: var(--surface, #0f172a);
  border: 1px solid var(--border, #334155);
  color: var(--text-main, #f8fafc);
  border-radius: 4px;
}

.select2-container--default .select2-results__option {
  color: var(--text-main, #f8fafc);
  background-color: transparent;
}

.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
  background-color: var(--accent, #38bdf8);
  color: #0f172a;
}

.select2-results__option--selectable:hover {
  background-color: var(--surface, #0f172a);
  color: var(--text-main, #f8fafc);
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 36px;
}

.select2-container--default .select2-selection--single .select2-selection__arrow b {
  border-color: var(--text-muted, #94a3b8) transparent transparent transparent;
}


/* ---------- Alerts ---------- */
.alert {
  padding: .75rem 1rem;
  border-radius: 8px;
  font-size: .84rem;
  border: 1px solid transparent;
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  margin-bottom: .75rem;
}

.alert-success {
  background: rgba(52, 211, 153, .1);
  border-color: rgba(52, 211, 153, .3);
  color: #6ee7b7;
}

.alert-danger {
  background: rgba(248, 113, 113, .1);
  border-color: rgba(248, 113, 113, .3);
  color: #fca5a5;
}

.alert-warning {
  background: rgba(251, 191, 36, .1);
  border-color: rgba(251, 191, 36, .3);
  color: #fcd34d;
}

.alert-info {
  background: rgba(56, 189, 248, .1);
  border-color: rgba(56, 189, 248, .3);
  color: #7dd3fc;
}

.alert .btn-close-alert {
  margin-left: auto;
  background: none;
  border: none;
  color: inherit;
  opacity: .6;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}

.alert .btn-close-alert:hover {
  opacity: 1;
}

/* ---------- Badge ---------- */
.badge {
  display: inline-block;
  padding: .25em .55em;
  font-size: .7rem;
  font-weight: 600;
  border-radius: 20px;
  background: rgba(56, 189, 248, .15);
  color: var(--accent);
}

/* ---------- Filter bar ---------- */
.filter-bar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin-bottom: 1.2rem;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .75rem;
  align-items: end;
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  gap: .3rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.page-item .page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 .6rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-muted);
  font-size: .82rem;
  transition: all var(--transition);
}

.page-item .page-link:hover {
  background: rgba(255, 255, 255, .08);
  color: var(--text-main);
  border-color: var(--text-muted);
}

.page-item.active .page-link {
  background: var(--accent);
  color: #0f172a;
  border-color: var(--accent);
  font-weight: 700;
}

.page-item.disabled .page-link {
  opacity: .35;
  pointer-events: none;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(3px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
  transform: scale(.95);
  transition: transform .2s;
}

.modal-overlay.open .modal-box {
  transform: scale(1);
}

.modal-icon {
  font-size: 2.5rem;
  margin-bottom: .75rem;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: .5rem;
}

.modal-body {
  font-size: .88rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* ---------- Drop zone ---------- */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, .04);
}

.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.drop-zone-icon {
  font-size: 2.5rem;
  margin-bottom: .75rem;
}

.drop-zone-text {
  font-size: .88rem;
  color: var(--text-muted);
}

.drop-zone-file-name {
  margin-top: .5rem;
  font-size: .83rem;
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Import result bars ---------- */
.result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .86rem;
}

.result-row:last-child {
  border-bottom: none;
}

.result-label {
  color: var(--text-muted);
}

.result-value {
  font-weight: 700;
}

.result-value.ok {
  color: var(--success);
}

.result-value.dup {
  color: var(--warning);
}

.result-value.err {
  color: var(--danger);
}

.result-value.total {
  color: var(--text-main);
}

/* ---------- Chart container ---------- */
.chart-wrap {
  position: relative;
  height: 220px;
}

/* ---------- Section heading ---------- */
.page-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.4rem;
  flex-wrap: wrap;
  gap: .75rem;
}

.page-heading h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-main);
}

.page-heading .actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

/* ---------- Dashboard Grids ---------- */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.4rem;
}

.dashboard-grid.wide {
  grid-template-columns: 1.5fr 1fr;
}

/* ---------- Sidebar Overlay ---------- */
.mobile-sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.mobile-sidebar-overlay.open {
  opacity: 1;
  pointer-events: all;
}

@media (min-width: 769px) {
  .mobile-sidebar-overlay {
    display: none !important;
  }
}

/* ---------- Topbar layout (clase-based) ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: nowrap;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-shrink: 0;
}

/* El botón hamburguesa: oculto por defecto en desktop */
.topbar-hamburger {
  display: none;
  padding: .3rem .5rem;
  flex-shrink: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-left: auto;
  flex-wrap: nowrap;
  min-width: 0;
}

/* Búsqueda */
.topbar-search {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-shrink: 1;
  min-width: 0;
}

.topbar-search-input {
  background: var(--surface2, #1e293b);
  border: 1px solid var(--border, #334155);
  color: var(--text, #e2e8f0);
  border-radius: 6px;
  padding: .35rem .75rem;
  font-size: .85rem;
  width: 200px;
  outline: none;
  transition: border-color .2s, width .2s;
  min-width: 0;
}

.topbar-search-input:focus,
.topbar-search-input.focused {
  border-color: var(--primary, #38bdf8);
  width: 240px;
}

.topbar-search-btn {
  background: var(--primary, #38bdf8);
  color: #0f172a;
  border: none;
  border-radius: 6px;
  padding: .35rem .7rem;
  cursor: pointer;
  font-size: .85rem;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Botón Favor Rápido */
.topbar-favor-btn {
  background: var(--warning, #fbbf24);
  color: #000;
  border: none;
  border-radius: 6px;
  padding: .35rem .75rem;
  font-weight: 700;
  font-size: .85rem;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Bloque usuario */
.topbar-user {
  display: flex;
  align-items: center;
  gap: .5rem;
  border-left: 1px solid var(--border, #334155);
  padding-left: .65rem;
  flex-shrink: 0;
}

.topbar-user-info { text-align: right; }
.topbar-user-name { font-size: .8rem; font-weight: 600; color: var(--text, #e2e8f0); line-height: 1.2; }
.topbar-user-role { font-size: .7rem; color: var(--text-muted, #94a3b8); line-height: 1.2; }

.topbar-logout-btn {
  background: rgba(239,68,68,.15);
  color: #fca5a5;
  border: 1px solid rgba(239,68,68,.3);
  border-radius: 6px;
  padding: .35rem .65rem;
  font-size: .8rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: .25rem;
  transition: background .15s;
}
.topbar-logout-btn:hover { background: rgba(239,68,68,.28); color: #fca5a5; }

/* Modo claro: ajustes topbar */
[data-theme="light"] .topbar-search-input {
  background: #fff;
  border-color: var(--border);
  color: var(--text-main);
}
[data-theme="light"] .topbar-search-btn { color: #fff; }
[data-theme="light"] .topbar-user-name  { color: var(--text-main); }
[data-theme="light"] .topbar-logout-btn {
  background: rgba(220,38,38,.08);
  color: #dc2626;
  border-color: rgba(220,38,38,.3);
}
[data-theme="light"] .topbar-logout-btn:hover { background: rgba(220,38,38,.15); }

/* ---------- Tablet (769 – 1180px) ---------- */
@media (min-width: 769px) and (max-width: 1180px) {
  .topbar-search-input { width: 150px; }
  .topbar-search-input:focus,
  .topbar-search-input.focused { width: 180px; }
  .topbar-user-info { display: none; }
}

/* ---------- Sidebar reducida en pantallas medianas (900 – 1180px) ---------- */
@media (min-width: 900px) and (max-width: 1180px) {
  :root { --sidebar-w: 200px; }

  .sidebar-nav li a {
    padding: .55rem 1rem;
    font-size: .83rem;
  }
  .sidebar-brand { padding: 1rem; }
}

/* ---------- Sidebar colapsada a íconos (769px – 900px) ---------- */
@media (min-width: 769px) and (max-width: 900px) {
  :root { --sidebar-w: 58px; }

  /* Ocultar textos */
  .sidebar-brand .brand-name,
  .sidebar-nav li a span:not(.nav-icon),
  .sidebar-footer,
  .sidebar-delete-container .brand-name-text,
  /* etiquetas de sección */
  .sidebar-nav > li[style*="font-size:.7rem"] {
    display: none !important;
  }

  .sidebar-brand { padding: .8rem; justify-content: center; }
  .sidebar-brand .brand-icon { margin: 0; }

  .sidebar-nav li a {
    padding: .7rem 0;
    justify-content: center;
    gap: 0;
    border-left: 3px solid transparent;
    position: relative;
  }

  .sidebar-nav .nav-icon {
    font-size: 1.15rem;
    width: auto;
  }

  /* Tooltip al hacer hover */
  .sidebar-nav li a::after {
    content: attr(title);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .3rem .65rem;
    font-size: .78rem;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity .15s;
    z-index: 200;
    box-shadow: 0 4px 12px rgba(0,0,0,.3);
  }

  .sidebar-nav li a:hover::after { opacity: 1; }

  /* Botón Borrar Todo compacto */
  .sidebar-delete-container {
    padding: .75rem 0;
    display: flex;
    justify-content: center;
  }
  .sidebar-delete-container .btn {
    width: 40px !important;
    min-width: 40px;
    padding: .5rem !important;
    justify-content: center;
  }

  /* Ajustar main-wrapper */
  .main-wrapper { margin-left: var(--sidebar-w); }
}


/* ---------- Responsive (≤ 768px) ---------- */
@media (max-width: 768px) {

  /* Hamburguesa visible en móvil */
  .topbar-hamburger { display: flex !important; }

  /* El viejo id también, por si alguna plantilla lo usa */
  #mobile-menu-btn { display: flex !important; }

  .desktop-only-action { display: none !important; }

  .sidebar {
    transform: translateX(-100%);
    width: 250px;
    transition: transform var(--transition);
  }
  .sidebar.open { transform: translateX(0); }

  .main-wrapper { margin-left: 0; }

  .page-content {
    padding: 0.75rem;
    padding-bottom: 90px !important;
  }

  /* Topbar en móvil: compacto */
  .topbar {
    padding: .65rem 1rem;
    flex-wrap: nowrap;
    gap: .5rem;
  }
  .topbar-right { gap: .4rem; }
  .topbar-title  { font-size: .88rem; }
  .topbar-sub    { font-size: .68rem; }

  /* Grids del dashboard */
  .dashboard-grid,
  .dashboard-grid.wide,
  #kpi-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  #period-tabs { flex-wrap: wrap !important; }
  #period-tabs button { flex: 1 1 auto; }

  .stat-card { padding: 1.2rem 1rem; }
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- App-like Mobile UI ---------- */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Modo claro: bottom nav */
[data-theme="light"] .bottom-nav {
  background: rgba(241, 245, 249, 0.92);
  border-top-color: rgba(0,0,0,.1);
}
[data-theme="light"] .mobile-sidebar-overlay {
  background: rgba(0,0,0,.35);
}


.bottom-nav-items {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 60px;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  flex: 1;
  height: 100%;
  transition: color 0.2s;
}

.bottom-nav-item.active {
  color: var(--primary);
  font-weight: 600;
}

.bottom-nav-icon {
  font-size: 1.25rem;
  margin-bottom: 2px;
}

/* Floating Action Button (FAB) */
.fab {
  display: none;
  position: fixed;
  bottom: 80px;
  /* Por encima del bottom nav */
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  z-index: 99;
  transition: transform 0.2s, filter 0.2s;
}

.fab:hover,
.fab:focus {
  filter: brightness(1.1);
  color: #fff;
}

.fab:active {
  transform: scale(0.95);
}

@media (max-width: 768px) {
  .bottom-nav {
    display: block;
  }

  .fab {
    display: flex;
  }

  /* Esconder menú hamburguesa superior del header cuando en móvil (porque pasamos a Bottom Nav) */
  #mobile-menu-btn {
    display: none !important;
  }

  /* --- Listas Móviles tipo Native App (Cards) --- */
  .table-card-mobile thead {
    display: none;
  }

  .table-card-mobile tbody {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 0.5rem 0;
  }

  .table-card-mobile tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  }

  .table-card-mobile td {
    display: flex;
    align-items: center;
    border: none !important;
    padding: 0;
  }

  .table-card-mobile td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-right: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: none;
  }

  .table-card-mobile td[data-label]::before {
    display: block;
  }

  /* Personas Card */
  .table-personas tr {
    grid-template-areas:
      "nombre acciones"
      "apellido acciones"
      "doc tel"
      "barrio mun"
      "cat cat";
    grid-template-columns: 1fr auto;
  }

  .table-personas .col-id,
  .table-personas .col-fecha {
    display: none;
  }

  .table-personas .col-nombre {
    grid-area: nombre;
    margin-bottom: -0.3rem;
  }

  .table-personas .col-apellido {
    grid-area: apellido;
    margin-bottom: 0.5rem;
  }

  .table-personas .col-documento {
    grid-area: doc;
  }

  .table-personas .col-telefono {
    grid-area: tel;
    justify-content: flex-end;
  }

  .table-personas .col-barrio {
    grid-area: barrio;
  }

  .table-personas .col-municipio {
    grid-area: mun;
    justify-content: flex-end;
  }

  .table-personas .col-categoria {
    grid-area: cat;
    margin-top: 0.5rem;
  }

  .table-personas .col-acciones {
    grid-area: acciones;
    justify-content: flex-start;
    align-items: flex-end;
    flex-direction: column;
    gap: 0.5rem;
  }

  /* Favores Card */
  .table-atenciones tr {
    grid-template-areas:
      "persona persona"
      "tipo estado"
      "barrio fecha"
      "desc desc"
      "resp acciones";
  }

  .table-atenciones .col-persona {
    grid-area: persona;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border) !important;
    margin-bottom: 0.5rem;
  }

  .table-atenciones .col-tipo {
    grid-area: tipo;
  }

  .table-atenciones .col-estado {
    grid-area: estado;
    justify-content: flex-end;
  }

  .table-atenciones .col-barrio {
    grid-area: barrio;
  }

  .table-atenciones .col-fecha {
    grid-area: fecha;
    justify-content: flex-end;
  }

  .table-atenciones .col-desc {
    grid-area: desc;
    margin-top: 0.5rem;
  }

  .table-atenciones .col-resp {
    grid-area: resp;
    margin-top: 0.5rem;
  }

  .table-atenciones .col-acciones {
    grid-area: acciones;
    justify-content: flex-end;
    align-items: flex-end;
    gap: 0.5rem;
    margin-top: 0.5rem;
  }
}

/* ---------- WhatsApp Preview Mockup ---------- */
.wa-preview-container {
  margin-bottom: 1.5rem;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
}

.wa-preview-badge {
  font-size: 0.7rem;
  position: absolute;
  top: 0;
  left: 0;
  background: var(--accent);
  /* Assuming you want to use theme colors here, or a Whatsapp green */
  color: #fff;
  padding: 4px 8px;
  border-bottom-right-radius: 8px;
  font-weight: bold;
  z-index: 10;
}

.wa-chat-bg {
  background-color: #efeae2;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M54.627 0l.83.83-16.51 16.51A18.877 18.877 0 0030 11c-10.493 0-19 8.507-19 19s8.507 19 19 19c6.452 0 12.16-3.232 15.65-8.23l16.14 16.14.83-.83L5.373 0l-.83.83 16.51 16.51A18.877 18.877 0 0030 49c10.493 0 19-8.507 19-19 0-6.452-3.232-12.16-8.23-15.65l16.14-16.14-.83-.83z' fill='%23dfd8cf' fill-opacity='0.4' fill-rule='evenodd'/%3E%3C/svg%3E");
  padding: 2.5rem 1rem 1rem 1rem;
  min-height: 150px;
  display: flex;
  flex-direction: column;
}

.wa-bubble {
  background-color: #d9fdd3;
  color: #111b21;
  padding: 6px 7px 8px 9px;
  border-radius: 7.5px;
  border-top-right-radius: 0;
  max-width: 90%;
  align-self: flex-end;
  /* Sent message appearance */
  position: relative;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  margin-bottom: 8px;
}

.wa-bubble::before {
  content: "";
  position: absolute;
  top: 0;
  right: -8px;
  width: 0;
  height: 0;
  border-top: 0 solid transparent;
  border-bottom: 13px solid transparent;
  border-left: 13px solid #d9fdd3;
  filter: drop-shadow(1px 0px 0.5px rgba(11, 20, 26, 0.13));
}

.wa-bubble-text {
  font-size: 0.88rem;
  line-height: 1.3;
  margin-bottom: 2px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.wa-bubble-meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  color: #667781;
  margin-top: -4px;
  float: right;
  margin-left: 12px;
}

.wa-ticks {
  color: #53bdeb;
  /* Blue ticks */
  font-weight: bold;
  letter-spacing: -2px;
}

/* ---------- Chart & Card Overflow Fixes ---------- */
.card {
  min-width: 0 !important;
  max-width: 100vw;
}

.chart-wrap {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  position: relative;
}