/* ============================================================
   SISTEMA DE ADMINISTRACIÓN DE EDIFICIOS
   Temas (Light/Dark) + Accesibilidad WCAG
   ============================================================ */

/* ── VARIABLES DE TEMA ────────────────────────────────────── */

:root[data-theme="light"] {
  /* Colores base */
  --bg-primary: #ffffff;
  --bg-secondary: #f9f9f9;
  --bg-tertiary: #f0f0f0;

  /* Texto */
  --text-primary: #1a1a1a;
  --text-secondary: #555555;
  --text-muted: #888888;

  /* Bordes */
  --border: #e0e0e0;
  --border-light: #eeeeee;

  /* Colores de marca */
  --gold: #b8901c;
  --gold-light: #d4af37;
  --gold-dark: #8b6f1f;

  /* Colores funcionales */
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;

  /* Variantes claras */
  --success-bg: rgba(16, 185, 129, 0.1);
  --danger-bg: rgba(239, 68, 68, 0.1);
  --warning-bg: rgba(245, 158, 11, 0.1);
  --info-bg: rgba(59, 130, 246, 0.1);

  /* Componentes */
  --card-bg: #ffffff;
  --card-border: #e0e0e0;
  --card-alt: #f9f9f9;
  --input-bg: #ffffff;
  --input-border: #d0d0d0;
  --input-focus: #b8901c;
  --shadow: rgba(0, 0, 0, 0.08);
  --shadow-md: rgba(0, 0, 0, 0.12);
}

:root[data-theme="dark"] {
  /* Colores base */
  --bg-primary: #1a1a1a;
  --bg-secondary: #242424;
  --bg-tertiary: #2d2d2d;

  /* Texto */
  --text-primary: #f0f0f0;
  --text-secondary: #b0b0b0;
  --text-muted: #808080;

  /* Bordes */
  --border: #3a3a3a;
  --border-light: #2d2d2d;

  /* Colores de marca */
  --gold: #ffc107;
  --gold-light: #ffd54f;
  --gold-dark: #d4af37;

  /* Colores funcionales */
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --info: #60a5fa;

  /* Variantes oscuras */
  --success-bg: rgba(52, 211, 153, 0.15);
  --danger-bg: rgba(248, 113, 113, 0.15);
  --warning-bg: rgba(251, 191, 36, 0.15);
  --info-bg: rgba(96, 165, 250, 0.15);

  /* Componentes */
  --card-bg: #242424;
  --card-border: #3a3a3a;
  --card-alt: #2d2d2d;
  --input-bg: #333333;
  --input-border: #444444;
  --input-focus: #ffc107;
  --shadow: rgba(0, 0, 0, 0.3);
  --shadow-md: rgba(0, 0, 0, 0.5);
}

/* ── RESET Y ESTILOS BASE ────────────────────────────────── */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
              'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
              sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ── TRANSICIONES SUAVES ────────────────────────────────── */

button, a, input, select, textarea {
  transition: all 0.2s ease;
}

/* ============================================================
   LAYOUT – SIDEBAR + MAIN CONTENT
   ============================================================ */

body {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.mobile-menu-toggle,
.sidebar-backdrop {
  display: none;
}

.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px;
  overflow-y: auto;
  box-shadow: inset -1px 0 0 var(--border);
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.brand-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

.sidebar-brand h2 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.sidebar-brand small {
  font-size: 11px;
  color: var(--text-muted);
}

.nav-section-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 16px;
  margin-bottom: 8px;
  padding: 0 8px;
}

.nav-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.nav-links a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}

.nav-links a:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-links a.active {
  background: var(--gold);
  color: #000;
  font-weight: 600;
}

.nav-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.sidebar-footer a {
  display: block;
  color: var(--gold);
  text-decoration: none;
  margin-bottom: 8px;
  padding: 8px;
  border-radius: 6px;
  text-align: center;
  font-weight: 500;
}

.sidebar-footer a:hover {
  background: var(--bg-tertiary);
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 3px var(--shadow);
}

.topbar h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.theme-toggle {
  background: var(--input-bg);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.theme-toggle:hover {
  background: var(--bg-tertiary);
  border-color: var(--gold);
}

.user-pill {
  background: var(--bg-tertiary);
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 13px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ── SCROLLBAR PERSONALIZADO ────────────────────────────── */

.page-content::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
  width: 8px;
}

.page-content::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.page-content::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.page-content::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============================================================
   COMPONENTES – CARDS
   ============================================================ */

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 20px;
  transition: all 0.2s ease;
}

.card:hover {
  border-color: var(--gold);
  box-shadow: 0 4px 12px var(--shadow-md);
}

.card h2, .card h3 {
  margin-bottom: 16px;
  font-size: 16px;
  font-weight: 600;
}

/* ============================================================
   COMPONENTES – TABLAS DE DATOS
   ============================================================ */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table thead {
  background: var(--gold);
  color: #000;
}

.data-table thead th {
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.3px;
}

.data-table thead th.numeric {
  text-align: right;
}

.data-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.data-table tbody tr {
  background: var(--card-bg);
  transition: background 0.2s ease;
}

.data-table tbody tr:nth-child(even) {
  background: var(--bg-secondary);
}

.data-table tbody tr:hover {
  background: var(--bg-tertiary);
  box-shadow: inset 0 0 0 1px var(--border);
}

.data-table .numeric {
  text-align: right;
  font-family: 'Courier New', monospace;
  letter-spacing: 0.5px;
  font-weight: 500;
}

.data-table .text-muted {
  color: var(--text-muted);
  font-size: 13px;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* ============================================================
   COMPONENTES – FORMULARIOS
   ============================================================ */

.form-group {
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
}

.form-group label {
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
  font-size: 14px;
}

.form-group small {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 4px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s ease;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px var(--success-bg);
  background: var(--input-bg);
}

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

input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--bg-tertiary);
}

/* ── Input con icono ────────────────────────────────────── */

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper .currency {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  font-weight: 600;
  pointer-events: none;
}

.currency-input {
  padding-left: 28px !important;
}

/* ============================================================
   COMPONENTES – BOTONES
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  background: var(--gold);
  color: #000;
  transition: all 0.2s ease;
}

.btn:hover {
  background: var(--gold-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(184, 144, 28, 0.3);
}

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

.btn.sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn.primary {
  background: var(--gold);
  color: #000;
}

.btn.primary:hover {
  background: var(--gold-light);
}

.btn.secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn.secondary:hover {
  background: var(--bg-secondary);
  border-color: var(--gold);
}

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

.btn.success:hover {
  opacity: 0.9;
  box-shadow: 0 4px 8px rgba(16, 185, 129, 0.3);
}

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

.btn.danger:hover {
  opacity: 0.9;
  box-shadow: 0 4px 8px rgba(239, 68, 68, 0.3);
}

.btn.warning {
  background: var(--warning);
  color: #000;
}

.btn.warning:hover {
  opacity: 0.9;
  box-shadow: 0 4px 8px rgba(245, 158, 11, 0.3);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ============================================================
   COMPONENTES – BADGES Y ETIQUETAS
   ============================================================ */

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge-gold {
  background: var(--gold);
  color: #000;
}

.badge-green {
  background: var(--success-bg);
  color: var(--success);
}

.badge-red {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge-amber {
  background: var(--warning-bg);
  color: var(--warning);
}

.badge-blue {
  background: var(--info-bg);
  color: var(--info);
}

.badge-muted {
  background: var(--bg-tertiary);
  color: var(--text-muted);
}

.badge-paid {
  background: var(--success-bg);
  color: var(--success);
}

.badge-pending {
  background: var(--warning-bg);
  color: var(--warning);
}

.badge-moroso {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ============================================================
   COMPONENTES – ALERTAS
   ============================================================ */

.flash-list {
  list-style: none;
  margin-bottom: 24px;
}

.flash-list li {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 14px;
  border-left: 4px solid;
  display: flex;
  align-items: center;
  gap: 10px;
}

.flash-list li.success {
  background: var(--success-bg);
  color: var(--success);
  border-left-color: var(--success);
}

.flash-list li.danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-left-color: var(--danger);
}

.flash-list li.warning {
  background: var(--warning-bg);
  color: var(--warning);
  border-left-color: var(--warning);
}

.flash-list li.info {
  background: var(--info-bg);
  color: var(--info);
  border-left-color: var(--info);
}

/* ============================================================
   PÁGINA DE LOGIN
   ============================================================ */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
}

.login-box {
  width: 100%;
  max-width: 380px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 40px 32px;
  box-shadow: 0 10px 30px var(--shadow-md);
}

.brand {
  text-align: center;
  margin-bottom: 32px;
}

.brand .icon {
  font-size: 48px;
  display: block;
  margin-bottom: 12px;
}

.brand h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.brand p {
  font-size: 13px;
  color: var(--text-muted);
}

.login-box form .form-group {
  margin-bottom: 16px;
}

.login-box input {
  width: 100%;
}

/* ============================================================
   GRILLAS Y LAYOUTS
   ============================================================ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: center;
  transition: all 0.2s ease;
  border-left: 4px solid var(--gold);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow-md);
}

.stat-card.stat-gold {
  border-left-color: var(--gold);
}

.stat-card.stat-green {
  border-left-color: var(--success);
}

.stat-card.stat-red {
  border-left-color: var(--danger);
}

.stat-card.stat-amber {
  border-left-color: var(--warning);
}

.stat-card.stat-slate {
  border-left-color: #8b8b8b;
}

.stat-card.stat-teal {
  border-left-color: #14b8a6;
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.grid2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

/* ============================================================
   UTILIDADES
   ============================================================ */

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

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

.text-success {
  color: var(--success);
}

.text-danger {
  color: var(--danger);
}

.text-warning {
  color: var(--warning);
}

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }

.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mb-4 { margin-bottom: 32px; }

.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.gap-3 { gap: 24px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1024px) {
  .sidebar {
    width: 220px;
    padding: 16px;
  }

  .grid2 {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
}

@media (max-width: 768px) {
  body {
    display: block;
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1000;
    width: min(82vw, 320px);
    height: 100dvh;
    max-height: none;
    padding: 18px 14px;
    border-right: 1px solid var(--border);
    border-bottom: 0;
    transform: translateX(-105%);
    transition: transform .22s ease;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 18px 0 44px rgba(0,0,0,.35);
  }

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

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 990;
    display: block;
    background: rgba(0,0,0,.48);
  }

  .sidebar-backdrop[hidden] {
    display: none;
  }

  .mobile-menu-toggle {
    position: fixed;
    left: 12px;
    bottom: 14px;
    z-index: 1010;
    display: inline-flex;
    width: 48px;
    height: 48px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--gold);
    color: #111;
    font-size: 23px;
    font-weight: 900;
    box-shadow: 0 12px 28px rgba(0,0,0,.28);
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .nav-links {
    flex-direction: column;
    gap: 4px;
  }

  .sidebar-footer {
    display: none;
  }

  .main-content {
    min-height: 100vh;
    height: auto;
    overflow: visible;
  }

  .page-content {
    padding: 14px;
    max-width: 100%;
    overflow-x: hidden;
  }

  .topbar {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
    padding: 16px 14px;
  }

  .topbar-right {
    width: 100%;
    flex-wrap: wrap;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .grid2,
  .grid3,
  .grid4 {
    grid-template-columns: 1fr !important;
  }

  form,
  .card,
  .panel,
  .table-wrapper {
    max-width: 100%;
    min-width: 0;
  }

  .card {
    padding: 16px;
    overflow: hidden;
  }

  label {
    display: block;
    margin-bottom: 6px;
  }

  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  select,
  textarea {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .data-table,
  table {
    min-width: 720px;
  }

  .data-table {
    font-size: 12px;
  }

  .data-table thead th,
  .data-table tbody td {
    padding: 8px;
  }
}

@media (max-width: 480px) {
  .nav-links a {
    flex-direction: row;
    padding: 10px 12px;
    text-align: left;
    font-size: 14px;
  }

  .login-box {
    margin: 20px;
    padding: 24px 20px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar h1 {
    font-size: 16px;
    padding-left: 0;
  }

  .btn {
    padding: 8px 12px;
    font-size: 12px;
  }
}

/* ============================================================
   ACCESIBILIDAD
   ============================================================ */

/* Focus visible para navegación por teclado */
*:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Reducir movimiento para usuarios que lo soliciten */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Alto contraste */
@media (prefers-contrast: more) {
  :root[data-theme="light"] {
    --text-primary: #000000;
    --border: #333333;
  }

  :root[data-theme="dark"] {
    --text-primary: #ffffff;
    --border: #cccccc;
  }
}
