/* ============================================================
   COMUNIDAD TOTAL — CSS Completo
   Design System + Layout + Módulos
   ============================================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ============================================================
   1. DESIGN TOKENS
   ============================================================ */
:root {
  /* Colores primarios */
  --color-primary:       hsl(220, 85%, 60%);
  --color-primary-dark:  hsl(220, 85%, 48%);
  --color-primary-light: hsl(220, 85%, 72%);
  --color-primary-glow:  hsl(220, 85%, 60%, 0.25);

  /* Semáforo de estado */
  --color-success:  hsl(145, 65%, 42%);
  --color-warning:  hsl(38,  90%, 52%);
  --color-danger:   hsl(0,   82%, 55%);
  --color-info:     hsl(200, 85%, 55%);

  /* Superficies dark */
  --surface-base:   hsl(225, 22%, 10%);
  --surface-1:      hsl(225, 20%, 14%);
  --surface-2:      hsl(225, 18%, 19%);
  --surface-3:      hsl(225, 15%, 24%);
  --surface-hover:  hsl(225, 15%, 28%);

  /* Texto */
  --text-primary:   hsl(220, 20%, 95%);
  --text-secondary: hsl(220, 10%, 65%);
  --text-muted:     hsl(220, 8%, 45%);

  /* Bordes */
  --border-subtle:  hsl(225, 15%, 22%);
  --border-default: hsl(225, 15%, 30%);

  /* Sidebar */
  --sidebar-width: 260px;
  --sidebar-collapsed: 68px;
  --topbar-height: 60px;

  /* Tipografía */
  --font-base: 'Inter', system-ui, sans-serif;

  /* Radio */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-xl:  24px;
  --radius-full: 9999px;

  /* Sombras */
  --shadow-sm:  0 1px 3px rgba(0,0,0,.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,.35);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.5);
  --shadow-glow: 0 0 24px var(--color-primary-glow);

  /* Transiciones */
  --transition-fast:   0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow:   0.4s ease;
}

/* ============================================================
   2. RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-base);
  background: var(--surface-base);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; }
img { max-width: 100%; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface-1); }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--border-default); }

/* Visibilidad global */
.hidden { display: none !important; }

/* ============================================================
   3. PANTALLA DE LOGIN
   ============================================================ */
#login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-base);
  background-image:
    radial-gradient(ellipse at 20% 50%, hsl(220, 85%, 60%, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, hsl(200, 85%, 55%, 0.06) 0%, transparent 50%);
  transition: opacity var(--transition-slow), visibility var(--transition-slow);
}

#login-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.login-container {
  width: 100%;
  max-width: 420px;
  padding: 2rem;
}

.login-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-lg), 0 0 60px hsl(220, 85%, 60%, 0.08);
}

.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.login-logo-icon {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--color-primary), hsl(200, 85%, 55%));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px var(--color-primary-glow);
}

.login-logo-icon svg {
  width: 40px;
  height: 40px;
  color: white;
}

.login-logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.login-logo span {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

.form-group input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.btn-login {
  margin-top: 0.5rem;
  padding: 0.85rem;
  background: linear-gradient(135deg, var(--color-primary), hsl(200, 85%, 55%));
  color: white;
  font-weight: 600;
  font-size: 1rem;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  box-shadow: 0 4px 16px var(--color-primary-glow);
}

.btn-login:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--color-primary-glow);
}

.btn-login:active { transform: translateY(0); }

.login-error {
  font-size: 0.85rem;
  color: var(--color-danger);
  text-align: center;
  min-height: 1.2rem;
}

/* ============================================================
   4. APP LAYOUT
   ============================================================ */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--topbar-height) 1fr;
  min-height: 100vh;
  transition: grid-template-columns var(--transition-normal);
}

#app.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed) 1fr;
}

/* ============================================================
   5. TOPBAR
   ============================================================ */
#topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  height: var(--topbar-height);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
  z-index: 100;
  position: sticky;
  top: 0;
}

.topbar-toggle {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.topbar-toggle:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.3px;
  flex: 1;
}

.topbar-brand .brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-primary);
  box-shadow: 0 0 8px var(--color-primary);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.9); }
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.topbar-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  position: relative;
}

.topbar-icon-btn:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

.notification-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: var(--color-danger);
  border-radius: 50%;
  border: 2px solid var(--surface-1);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.3rem 0.75rem 0.3rem 0.3rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.topbar-user:hover { background: var(--surface-2); }
.topbar-user { color: var(--text-primary); }
.topbar-user:focus-visible, .user-menu-action:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
}

.topbar-account { position: relative; }
.user-menu {
  position: absolute;
  top: calc(100% + .65rem);
  right: 0;
  width: min(290px, calc(100vw - 2rem));
  padding: .5rem;
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.user-menu-details {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  padding: .65rem .75rem .9rem;
  margin-bottom: .35rem;
  border-bottom: 1px solid var(--border-subtle);
  overflow-wrap: anywhere;
}
.user-menu-details strong { font-size: .9rem; color: var(--text-primary); }
.user-menu-details span { font-size: .8rem; color: var(--text-secondary); }
.user-menu-action {
  display: block;
  width: 100%;
  padding: .75rem;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  text-align: left;
  font-size: .85rem;
}
.user-menu-action:hover { background: var(--surface-2); }
.user-menu-logout { color: var(--color-danger); }

html[data-text-size="large"] { font-size: 18px; }
.account-dialog .modal { width: 100%; max-width: 480px; }
.account-fields { display: flex; flex-direction: column; gap: 1rem; }
.account-help, .account-role { color: var(--text-secondary); font-size: .82rem; line-height: 1.5; }
.account-fields input[readonly] { color: var(--text-secondary); cursor: default; }
.account-check { display: flex; align-items: center; gap: .65rem; font-size: .9rem; cursor: pointer; }
.account-check input { width: 18px; height: 18px; accent-color: var(--color-primary); }
.account-status { min-height: 1.3em; font-size: .85rem; color: var(--color-danger); }
.account-status.success { color: var(--color-success); }

.topbar-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), hsl(200, 85%, 55%));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: white;
}

.topbar-user-info { display: none; }

@media (min-width: 640px) {
  .topbar-user-info {
    display: block;
    line-height: 1.2;
  }
  .topbar-user-name { font-size: 0.85rem; font-weight: 600; }
  .topbar-user-role { font-size: 0.72rem; color: var(--text-secondary); }
}

/* ============================================================
   6. SIDEBAR
   ============================================================ */
#sidebar {
  grid-column: 1;
  grid-row: 2;
  background: var(--surface-1);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  transition: width var(--transition-normal);
  z-index: 90;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 0.5rem 0.5rem 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--transition-normal);
}

#app.sidebar-collapsed .nav-section-label {
  opacity: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  position: relative;
  overflow: hidden;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--color-primary-glow);
  color: var(--color-primary-light);
  border-color: hsl(220, 85%, 60%, 0.2);
}

.nav-item.active .nav-icon svg {
  color: var(--color-primary);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  background: var(--color-primary);
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
}

.nav-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg {
  width: 20px;
  height: 20px;
  transition: color var(--transition-fast);
}

.nav-label {
  flex: 1;
  transition: opacity var(--transition-normal), width var(--transition-normal);
}

#app.sidebar-collapsed .nav-label,
#app.sidebar-collapsed .nav-badge {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

.nav-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--color-danger);
  color: white;
  transition: opacity var(--transition-normal);
}

.nav-item.danger-item { color: hsl(0, 82%, 70%); }
.nav-item.danger-item:hover { background: hsl(0, 82%, 55%, .12); color: hsl(0, 82%, 80%); }
.nav-item.danger-item.active { background: hsl(0, 82%, 55%, .15); color: hsl(0, 82%, 80%); border-color: hsl(0, 82%, 55%, .25); }
.nav-item.danger-item.active::before { background: var(--color-danger); }

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border-subtle);
}

.sidebar-footer .nav-item { color: var(--text-muted); }

/* Tooltip when collapsed */
#app.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: 0.7rem;
}

/* ============================================================
   7. MAIN CONTENT AREA
   ============================================================ */
#main-content {
  grid-column: 2;
  grid-row: 2;
  overflow-y: auto;
  min-height: calc(100vh - var(--topbar-height));
}

/* ============================================================
   8. MODULE VIEWS
   ============================================================ */
.module-view {
  display: none;
  animation: fadeInUp 0.3s ease;
}

.module-view.active {
  display: block;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Module Header */
.module-header {
  padding: 1.5rem 2rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  background: var(--surface-1);
  position: sticky;
  top: 0;
  z-index: 50;
}

.module-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.module-title-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.module-title-icon svg {
  width: 22px;
  height: 22px;
}

.module-title h2 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.module-title p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.module-actions { display: flex; gap: 0.5rem; }

/* Module Body */
.module-body {
  padding: 1.5rem 2rem;
}

/* ============================================================
   9. COMPONENTS — BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  transition: all var(--transition-fast);
  cursor: pointer;
  border: none;
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), hsl(200, 85%, 55%));
  color: white;
  box-shadow: 0 2px 8px var(--color-primary-glow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px var(--color-primary-glow); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}
.btn-secondary:hover { background: var(--surface-3); }

.btn-danger {
  background: linear-gradient(135deg, var(--color-danger), hsl(0, 85%, 45%));
  color: white;
  box-shadow: 0 2px 8px hsl(0, 82%, 55%, .3);
}
.btn-danger:hover { transform: translateY(-1px); box-shadow: 0 4px 16px hsl(0, 82%, 55%, .4); }

.btn-success {
  background: linear-gradient(135deg, var(--color-success), hsl(145, 65%, 35%));
  color: white;
}
.btn-success:hover { transform: translateY(-1px); }

.btn-sm { padding: 0.4rem 0.85rem; font-size: 0.8rem; }
.btn-lg { padding: 0.9rem 1.75rem; font-size: 1rem; }
.btn-icon { padding: 0.6rem; border-radius: var(--radius-md); }
.btn-icon.btn-sm { padding: 0.4rem; }

/* ============================================================
   10. COMPONENTS — CARDS
   ============================================================ */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  transition: all var(--transition-fast);
}

.card:hover { border-color: var(--border-default); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.kpi-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: all var(--transition-fast);
  cursor: default;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-icon svg { width: 20px; height: 20px; }

.kpi-value {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1;
}

.kpi-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.kpi-trend {
  font-size: 0.75rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.kpi-trend.up { color: var(--color-success); }
.kpi-trend.down { color: var(--color-danger); }

/* ============================================================
   11. COMPONENTS — BADGES & CHIPS
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-success { background: hsl(145, 65%, 42%, .15); color: hsl(145, 65%, 60%); }
.badge-warning { background: hsl(38, 90%, 52%, .15); color: hsl(38, 90%, 65%); }
.badge-danger  { background: hsl(0, 82%, 55%, .15);  color: hsl(0, 82%, 70%); }
.badge-info    { background: hsl(200, 85%, 55%, .15); color: hsl(200, 85%, 70%); }
.badge-muted   { background: var(--surface-3); color: var(--text-secondary); }
.badge-primary { background: var(--color-primary-glow); color: var(--color-primary-light); }

/* ============================================================
   12. COMPONENTS — TABLES
   ============================================================ */
.table-container {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table thead {
  background: var(--surface-2);
  position: sticky;
  top: 0;
}

.data-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.data-table td {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}

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

.data-table tbody tr {
  transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
  background: var(--surface-2);
}

/* ============================================================
   13. COMPONENTS — FORMS
   ============================================================ */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-input,
.form-select,
.form-textarea {
  padding: 0.65rem 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-base);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
  width: 100%;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-muted); }

.form-select option {
  background: var(--surface-2);
  color: var(--text-primary);
}

.form-textarea { resize: vertical; min-height: 100px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
}

/* ============================================================
   14. COMPONENTS — MODAL / DRAWER
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.modal-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95) translateY(10px);
  transition: transform var(--transition-normal);
}

.modal-backdrop.open .modal { transform: scale(1) translateY(0); }

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.modal-close:hover { background: var(--surface-2); color: var(--text-primary); }
.modal-close svg { width: 18px; height: 18px; }

.modal-body { padding: 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

/* ============================================================
   15. COMPONENTS — SEARCH BAR
   ============================================================ */
.search-bar {
  position: relative;
  flex: 1;
  max-width: 360px;
}

.search-bar svg {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-bar input {
  width: 100%;
  padding: 0.6rem 1rem 0.6rem 2.25rem;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.875rem;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-bar input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.search-bar input::placeholder { color: var(--text-muted); }

/* ============================================================
   16. COMPONENTS — EMPTY STATE
   ============================================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
  color: var(--text-secondary);
  gap: 1rem;
}

.empty-state svg { width: 56px; height: 56px; color: var(--text-muted); }
.empty-state h3 { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); }
.empty-state p { font-size: 0.875rem; max-width: 320px; }

/* ============================================================
   17. COMPONENTS — TOAST NOTIFICATIONS
   ============================================================ */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  background: var(--surface-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  font-weight: 500;
  min-width: 280px;
  max-width: 380px;
  pointer-events: all;
  animation: slideInRight 0.3s ease, fadeOut 0.3s ease 3.7s forwards;
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateX(20px); }
}

.toast svg { width: 18px; height: 18px; flex-shrink: 0; }
.toast-success { border-left: 3px solid var(--color-success); }
.toast-error   { border-left: 3px solid var(--color-danger); }
.toast-warning { border-left: 3px solid var(--color-warning); }
.toast-info    { border-left: 3px solid var(--color-primary); }
.toast-success svg { color: var(--color-success); }
.toast-error svg   { color: var(--color-danger); }
.toast-warning svg { color: var(--color-warning); }
.toast-info svg    { color: var(--color-primary); }

/* ============================================================
   18. MÓDULO — MAPA
   ============================================================ */
#module-mapa { }

#map-container {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  height: calc(100vh - var(--topbar-height) - 80px);
  min-height: 500px;
  background: var(--surface-2);
}

#leaflet-map {
  width: 100%;
  height: 100%;
}

/* Fondo del plano ilustrado (mismo tono que su exterior) */
#leaflet-map.leaflet-container { background: #f1efe7; }

.map-legend {
  position: absolute;
  bottom: 1.5rem;
  right: 1rem;
  background: hsl(225, 20%, 12%, .9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 0.75rem 1rem;
  z-index: 500;
  font-size: 0.78rem;
}

.legend-title {
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.5px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.2rem 0;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.map-info-panel {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 280px;
  background: hsl(225, 20%, 12%, .95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  z-index: 500;
  transform: translateX(310px);
  visibility: hidden;
  pointer-events: none;
  transition: transform var(--transition-normal);
  box-shadow: var(--shadow-lg);
}

.map-info-panel.open { transform: translateX(0); visibility: visible; pointer-events: auto; }

.map-modelo { margin-bottom: 1rem; overflow: hidden; border: 1px solid var(--border-subtle); border-radius: .65rem; }
.map-modelo img { display: block; width: 100%; height: auto; }
.map-modelo > div { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .55rem .65rem; }
.map-modelo span { font-size: .7rem; color: var(--text-secondary); }
.map-info-panel { max-height: calc(100% - 2rem); overflow-y: auto; }

.map-info-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.map-etapa-filter {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.map-filter-btn {
  flex: 1;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.map-filter-btn.active {
  background: var(--color-primary-glow);
  color: var(--color-primary-light);
  border-color: hsl(220, 85%, 60%, .3);
}

/* Módulo Usuarios */
.usuarios-aviso {
  margin-bottom: 1rem;
  padding: .75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid hsl(38, 90%, 52%, .35);
  background: hsl(38, 90%, 52%, .08);
  color: hsl(38, 90%, 70%);
  font-size: .85rem;
}

.usuario-activo {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  margin-bottom: .5rem;
  cursor: pointer;
}

.usuario-form-error {
  min-height: 1.1rem;
  font-size: .8rem;
  color: var(--color-danger);
}

/* Contenedores de casas y ficha de residentes */
.leaflet-interactive.casa-contenedor { cursor: pointer; }

.map-panel-section-title {
  font-size: .7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: .75rem;
}

.map-residente {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .6rem;
}

.map-residente-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--color-primary-glow);
  color: var(--color-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .8rem;
  flex-shrink: 0;
}

.map-residente-nombre {
  font-weight: 600;
  font-size: .9rem;
}

.map-panel-muted {
  font-size: .8rem;
  color: var(--text-muted);
}

.map-entrega {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: 1rem;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
}

.map-entrega input { width: 16px; height: 16px; accent-color: #22c55e; cursor: pointer; }

.map-panel-admin {
  margin-top: 1rem;
  padding-top: .75rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

@media (max-width: 768px) {
  .map-info-panel { left: 1rem; right: 1rem; width: auto; transform: translateY(calc(-100% - 2rem)); }
  .map-info-panel.open { transform: translateY(0); }
}

/* ============================================================
   19. MÓDULO — PÁNICO
   ============================================================ */
#module-panico .panico-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 2rem;
  min-height: 70vh;
  gap: 2rem;
}

.panico-warning {
  max-width: 480px;
  text-align: center;
  background: hsl(38, 90%, 52%, .08);
  border: 1px solid hsl(38, 90%, 52%, .2);
  border-radius: var(--radius-lg);
  padding: 1rem 1.5rem;
  font-size: 0.875rem;
  color: hsl(38, 90%, 65%);
}

.panico-buttons {
  display: flex;
  gap: 2.5rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.panico-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  cursor: pointer;
  border: none;
  background: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.panico-btn-circle {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform var(--transition-fast);
  user-select: none;
  -webkit-user-select: none;
}

.panico-btn-circle svg:not(.progress-ring) {
  width: 52px;
  height: 52px;
  color: white;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
}

.panico-btn-circle::before {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  opacity: 0.3;
  animation: panico-ring 2s infinite;
}

@keyframes panico-ring {
  0%, 100% { transform: scale(1); opacity: 0.3; }
  50% { transform: scale(1.08); opacity: 0.1; }
}

.panico-alerta .panico-btn-circle {
  background: linear-gradient(135deg, hsl(38, 90%, 52%), hsl(30, 90%, 45%));
  box-shadow: 0 8px 32px hsl(38, 90%, 52%, .4);
}

.panico-alerta .panico-btn-circle::before {
  background: hsl(38, 90%, 52%);
}

.panico-emergencia .panico-btn-circle {
  background: linear-gradient(135deg, var(--color-danger), hsl(0, 85%, 40%));
  box-shadow: 0 8px 32px hsl(0, 82%, 55%, .5);
}

.panico-emergencia .panico-btn-circle::before {
  background: var(--color-danger);
}

.panico-btn:active .panico-btn-circle { transform: scale(0.95); }

.panico-btn-label {
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.panico-alerta .panico-btn-label { color: hsl(38, 90%, 65%); }
.panico-emergencia .panico-btn-label { color: hsl(0, 82%, 70%); }

.panico-btn-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 120px;
}

.panico-history {
  width: 100%;
  max-width: 600px;
}

/* --- ESTILOS DE ANILLO DE PROGRESO DE PÁNICO --- */
.progress-ring {
  position: absolute;
  top: -8px;
  left: -8px;
  width: calc(100% + 16px);
  height: calc(100% + 16px);
  transform: rotate(-90deg); /* Empezar en el tope superior */
  pointer-events: none;
  z-index: 2;
}

.progress-ring__circle {
  stroke-dasharray: 402.12; /* 2 * pi * r = 2 * 3.14159 * 64 ≈ 402.12 */
  stroke-dashoffset: 402.12;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.05s linear;
}

/* Efectos Premium de Pánico */
.panico-btn.holding .panico-btn-circle {
  transform: scale(1.08);
  box-shadow: 0 0 35px var(--color-danger), 0 0 70px hsl(0, 82%, 55%, 0.4);
}

.panico-alerta .panico-btn.holding .panico-btn-circle {
  box-shadow: 0 0 35px var(--color-warning), 0 0 70px hsl(38, 90%, 52%, .4);
}

.panico-btn.holding .panico-btn-circle::before {
  animation: panico-ring-holding 0.8s infinite;
}

@keyframes panico-ring-holding {
  0% { transform: scale(1); opacity: 0.5; }
  100% { transform: scale(1.25); opacity: 0; }
}

/* Tarjetas de alertas premium con vidrio / desenfoque de fondo */
.panico-alert-card {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1.25rem;
  margin-bottom: 0.75rem;
  background: hsl(225, 20%, 14%, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  animation: slideInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  transition: all var(--transition-fast);
}

.panico-alert-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-default);
  box-shadow: var(--shadow-md);
}

.panico-alert-card.type-emergencia {
  border-left: 4px solid var(--color-danger);
  background: linear-gradient(90deg, hsl(0, 82%, 55%, 0.08), transparent);
}

.panico-alert-card.type-alerta {
  border-left: 4px solid var(--color-warning);
  background: linear-gradient(90deg, hsl(38, 90%, 52%, 0.08), transparent);
}

.alert-card-icon {
  font-size: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface-3);
  flex-shrink: 0;
}

.panico-alert-card.type-emergencia .alert-card-icon {
  background: hsl(0, 82%, 55%, 0.15);
}

.panico-alert-card.type-alerta .alert-card-icon {
  background: hsl(38, 90%, 52%, 0.15);
}

.alert-card-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.alert-card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.alert-card-title {
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
}

.type-emergencia .alert-card-title { color: hsl(0, 82%, 70%); }
.type-alerta .alert-card-title { color: hsl(38, 90%, 65%); }

.alert-card-time {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.alert-card-emisor {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.alert-card-message {
  font-size: 0.875rem;
  color: var(--text-primary);
  margin-top: 0.25rem;
  line-height: 1.4;
}

@keyframes slideInUp {
  from { opacity: 0; transform: translateY(15px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   20. MÓDULO — CÁMARAS
   ============================================================ */
.cameras-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.view-toggle {
  display: flex;
  gap: 0.25rem;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 0.25rem;
}

.view-toggle-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  transition: all var(--transition-fast);
}
.view-toggle-btn.active {
  background: var(--surface-3);
  color: var(--text-primary);
}

.cameras-grid {
  display: grid;
  gap: 1rem;
  padding: 1.5rem 2rem;
}

.cameras-grid[data-view="1"] { grid-template-columns: 1fr; }
.cameras-grid[data-view="2"] { grid-template-columns: repeat(2, 1fr); }
.cameras-grid[data-view="4"] { grid-template-columns: repeat(2, 1fr); }
.cameras-grid[data-view="9"] { grid-template-columns: repeat(3, 1fr); }

.camera-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.camera-card:hover { border-color: var(--border-default); box-shadow: var(--shadow-md); }

.camera-feed {
  aspect-ratio: 16/9;
  background: #000;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-no-signal {
  text-align: center;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.camera-no-signal svg { width: 40px; height: 40px; }
.camera-no-signal span { font-size: 0.8rem; }

.camera-status-dot {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.camera-status-dot.online { background: var(--color-success); box-shadow: 0 0 6px var(--color-success); }
.camera-status-dot.offline { background: var(--color-danger); }

.camera-rec-badge {
  position: absolute;
  top: 0.6rem;
  left: 0.6rem;
  background: var(--color-danger);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.camera-rec-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: white;
  animation: blink 1s infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.camera-info {
  padding: 0.6rem 0.875rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.camera-name { font-size: 0.85rem; font-weight: 600; }
.camera-location { font-size: 0.75rem; color: var(--text-secondary); }

/* ============================================================
   21. MÓDULO — INFORMACIÓN
   ============================================================ */
.info-contacts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.contact-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: all var(--transition-fast);
  cursor: pointer;
  text-decoration: none;
}

.contact-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-default);
}

.contact-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}
.contact-icon svg { width: 24px; height: 24px; color: white; }

.contact-name { font-weight: 600; font-size: 0.95rem; }
.contact-number { font-size: 0.8rem; color: var(--text-secondary); }
.contact-cta {
  margin-top: auto;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-primary);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.announcements-feed {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.announcement-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  gap: 1rem;
}

.announcement-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.announcement-content h4 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.3rem; }
.announcement-content p { font-size: 0.85rem; color: var(--text-secondary); }

/* ============================================================
   22. MÓDULO — VECINOS
   ============================================================ */
.vecino-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), hsl(200, 85%, 55%));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.table-actions { display: flex; gap: 0.4rem; }

/* ============================================================
   23. MÓDULO — FINANZAS
   ============================================================ */
.finance-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ============================================================
   24. RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  #app {
    grid-template-columns: 0 1fr;
  }

  #app.sidebar-open {
    grid-template-columns: var(--sidebar-width) 1fr;
  }

  #sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-height);
    bottom: 0;
    z-index: 150;
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    width: var(--sidebar-width);
  }

  #app.sidebar-open #sidebar {
    transform: translateX(0);
  }

  .mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 140;
    backdrop-filter: blur(2px);
  }

  #app.sidebar-open .mobile-overlay {
    display: block;
  }

  .module-header { padding: 1rem; }
  .module-body { padding: 1rem; }
  .panico-btn-circle { width: 120px; height: 120px; }
  .cameras-grid[data-view="4"],
  .cameras-grid[data-view="9"] { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .info-contacts-grid { grid-template-columns: repeat(2, 1fr); }
  .panico-buttons { gap: 1.5rem; }
  .panico-btn-circle { width: 110px; height: 110px; }
}

/* ============================================================
   25. LOADING SPINNER
   ============================================================ */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--surface-3);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-1);
  z-index: 10;
}

/* ============================================================
   26. MISC
   ============================================================ */
.divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 1rem 0;
}

.text-success { color: var(--color-success); }
.text-danger  { color: var(--color-danger); }
.text-warning { color: var(--color-warning); }
.text-muted   { color: var(--text-muted); }
.text-primary { color: var(--color-primary); }

.font-mono {
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

/* ============================================================
   27. APP DOWNLOAD SECTIONS
   ============================================================ */
.login-divider {
  margin: 1.5rem 0 1rem;
  border-top: 1px solid var(--border-subtle);
  position: relative;
}

.login-divider-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface-1);
  padding: 0 0.75rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.login-download-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 1.25rem;
}

.download-badge-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--surface-2);
  transition: all var(--transition-fast);
  gap: 0.5rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary);
}

.download-badge-btn:hover {
  background: var(--surface-3);
  border-color: var(--border-default);
  transform: translateY(-1px);
}

.download-badge-btn:active {
  transform: translateY(0);
}

.app-download-banner {
  margin-top: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  background: linear-gradient(135deg, var(--surface-1), var(--surface-2));
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  flex-wrap: wrap;
}

.app-download-banner:hover {
  border-color: var(--border-default);
}

.app-download-banner h4 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-download-banner p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.download-btn-action {
  padding: 0.6rem 1rem;
  font-size: 0.8rem;
  background: var(--surface-3);
  border: 1px solid var(--border-default);
}

.download-btn-action:hover {
  background: var(--surface-hover);
  border-color: var(--color-primary);
  transform: translateY(-1px);
}

/* ============================================================
   28. RESPONSIVE FINANCE TABLE & TOOLBAR
   ============================================================ */
#finanzas-search {
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

#finanzas-search:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

@media (max-width: 768px) {
  /* Ocultar encabezados de la tabla de finanzas y vecinos en móvil */
  #finanzas-table thead,
  #vecinos-table thead {
    display: none;
  }
  
  /* Hacer que la tabla de finanzas, vecinos y sus componentes sean bloques */
  #finanzas-table, 
  #finanzas-table tbody, 
  #finanzas-table tr, 
  #finanzas-table td,
  #vecinos-table, 
  #vecinos-table tbody, 
  #vecinos-table tr, 
  #vecinos-table td {
    display: block;
    width: 100%;
  }
  
  /* Cada fila se visualiza como una tarjeta */
  #finanzas-table tr,
  #vecinos-table tr {
    background: var(--surface-1);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    margin-bottom: 1.25rem;
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-sm);
  }
  
  /* Cada celda se divide en etiqueta (izquierda) y valor (derecha) */
  #finanzas-table td,
  #vecinos-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border-subtle);
    text-align: right;
  }
  
  /* Eliminar borde de la última celda de acciones */
  #finanzas-table td:last-child,
  #vecinos-table td:last-child {
    border-bottom: none;
    margin-top: 0.5rem;
    padding-top: 0.75rem;
    justify-content: flex-end;
  }
  
  /* Inyectar la etiqueta responsiva antes del valor */
  #finanzas-table td::before,
  #vecinos-table td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    text-align: left;
    margin-right: 1.5rem;
  }
  
  /* La primera celda (Vecino) tiene un diseño de cabecera de tarjeta */
  #finanzas-table td[data-label="Vecino"],
  #vecinos-table td[data-label="Vecino"] {
    border-bottom: 2px solid var(--border-default);
    padding-bottom: 0.75rem;
    margin-bottom: 0.5rem;
    text-align: left;
    flex-direction: column;
    align-items: flex-start;
  }
  
  #finanzas-table td[data-label="Vecino"]::before,
  #vecinos-table td[data-label="Vecino"]::before {
    display: none;
  }
}

/* ============================================================
   29. ADVANCED SEARCH DROPDOWN & VECINO VIEW
   ============================================================ */
.search-results-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.5rem;
  background: hsl(225, 20%, 12%, 0.98);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  max-height: 280px;
  overflow-y: auto;
  z-index: 1100;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.6), 0 8px 10px -6px rgba(0, 0, 0, 0.6);
  animation: dropdownFadeIn 0.15s ease-out;
}

@keyframes dropdownFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.search-results-dropdown.hidden {
  display: none !important;
}

.search-result-item {
  padding: 0.8rem 1rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--transition-fast);
}

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

.search-result-item:hover {
  background: var(--surface-3);
}

.search-result-item .result-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  text-align: left;
}

.search-result-item .result-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.search-result-item .result-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Estilo para un cuadro de búsqueda más grande y premium */
.search-bar input[type="search"] {
  height: 42px;
  font-size: 0.9rem;
}

/* Estilos adicionales para la vista personal del vecino */
#finanzas-vecino-view {
  animation: fadeInUp 0.4s ease;
}

#finanzas-vecino-deuda-list .deuda-item {
  display: flex;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.875rem;
}

#finanzas-vecino-deuda-list .deuda-item:last-child {
  border-bottom: none;
}

#finanzas-vecino-deuda-list .deuda-name {
  font-weight: 500;
  color: var(--text-secondary);
}

#finanzas-vecino-deuda-list .deuda-val {
  font-weight: 600;
  color: var(--text-primary);
}

/* ============================================================
   16. FOOTER
   ============================================================ */
.app-footer {
  padding: 1.5rem 2rem;
  border-top: 1px solid var(--border-subtle);
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface-base);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.25rem;
}

/* Finanzas: estado acumulado y movimientos. */
.finance-tabs { display:flex; flex-wrap:wrap; gap:.6rem; margin-bottom:1.5rem; }
.finance-explanation { padding:1.25rem; margin:1rem 0; }
.finance-explanation p { margin-top:.65rem; color:var(--text-secondary); line-height:1.6; }
.finance-heading { margin:1.8rem 0 1rem; font-size:1rem; }
.finance-note { color:var(--text-secondary); line-height:1.6; margin-bottom:1rem; }
.finance-filter { display:flex; flex-direction:column; gap:.5rem; margin-bottom:1rem; max-width:360px; }
.finance-filter input { padding:.75rem; background:var(--surface-2); border:1px solid var(--border-subtle); border-radius:var(--radius-md); color:var(--text-primary); }
.finance-empty { padding:2rem; text-align:center; color:var(--text-muted); }
#finanzas-content .data-table { min-width:700px; }
#finanzas-content .data-table tr[hidden] { display:none; }
#finanzas-detail-body .data-table { min-width:420px; }

.app-footer a {
  font-weight: 600;
  color: var(--color-primary-light);
  transition: all var(--transition-fast);
  position: relative;
  display: inline-block;
  padding: 0 0.25rem;
}

.app-footer a::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(135deg, var(--color-primary), hsl(200, 85%, 55%));
  transform: scaleX(0);
  transform-origin: right;
  transition: transform var(--transition-normal);
}

.app-footer a:hover {
  color: white;
  text-shadow: 0 0 8px var(--color-primary-glow);
}

.app-footer a:hover::after {
  transform: scaleX(1);
  transform-origin: left;
}



/* Cámara principal: conservar proporción y controles nativos accesibles. */
#camera-main-video { display: block; width: 100%; height: 100%; aspect-ratio: 16 / 9; object-fit: contain; background: #000; }
#camera-status { font-size: .85rem; max-width: 60%; text-align: right; }
