:root {
  --color-navy: #0a1628;
  --color-navy-soft: #0f2340;
  --color-primary: #1656d3;
  --color-primary-dark: #0f3fa8;
  --color-bg: #f4f6fb;
  --color-card: #ffffff;
  --color-border: #e7eaf1;
  --color-text: #10182b;
  --color-muted: #6b7280;
  --color-accent: #1656d3;
  --color-accent-tint: #dce9fb;
  --color-success: #15803d;
  --color-success-tint: #e6f4ea;
  --color-danger: #dc2626;
  --color-danger-tint: #fbd5d5;
  --color-warning: #b45309;
  --color-warning-tint: #fdf0dd;
  --radius: 18px;
  --radius-sm: 12px;
  --radius-pill: 999px;
  --shadow-card: 0 8px 24px rgba(16, 24, 43, 0.06);
}

* { box-sizing: border-box; }

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

.table-scroll table {
  min-width: 480px;
}

table { border-collapse: collapse; }
th, td { text-align: left; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

/* ---------- Splash / Login ---------- */

/* Isotipo real de Altia (assets/altia-icon.png) — sin badge/fondo propio
   (la marca ya viene recortada a solo el trazo), por eso se fija la altura
   y se deja el ancho automático en vez del cuadro cuadrado que usaba el
   placeholder anterior. */
.logo-mark {
  height: 40px;
  width: auto;
  display: block;
}

.logo-mark.lg { height: 96px; }

/* Logotipo completo (ícono + wordmark "Altia", assets/altia-logo-full.png)
   para el login, donde se calca la maqueta mostrando la marca completa
   arriba de "Bienvenido de nuevo". */
.logo-full {
  height: 32px;
  width: auto;
  display: block;
}

/* Pantalla de bienvenida (portada) — fondo oscuro a pantalla completa,
   isotipo grande, wordmark, tagline y un único CTA hacia el login. */
.splash-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 32px calc(64px + env(safe-area-inset-bottom));
  background:
    linear-gradient(180deg, rgba(10, 22, 40, 0.75) 0%, rgba(10, 22, 40, 0.92) 100%),
    linear-gradient(160deg, #142c4d 0%, #0a1628 60%);
  color: #ffffff;
}

.splash-screen .splash-top {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.splash-screen .logo-mark.lg { margin-bottom: 24px; }

.splash-brand {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
}

.splash-tagline {
  color: rgba(255, 255, 255, 0.75);
  font-size: 15px;
  margin-bottom: 56px;
}

.splash-screen .primary {
  max-width: 320px;
}

.centered-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, var(--color-navy) 0%, var(--color-navy) 38%, var(--color-bg) 38%);
}

.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 16px 40px rgba(11, 31, 58, 0.16);
}

.card .logo-mark { margin-bottom: 16px; }

.brand {
  font-size: 24px;
  font-weight: 800;
  color: var(--color-navy);
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}

.subtitle {
  color: var(--color-muted);
  margin-bottom: 24px;
  font-size: 14px;
}

.password-field-wrap { position: relative; }
.password-field-wrap input { padding-right: 44px; }
.password-toggle {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--color-muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 4px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  margin-top: 16px;
  color: var(--color-text);
}

input, select, textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  font-size: 14px;
  background: var(--color-bg);
  font-family: inherit;
  color: var(--color-text);
}

textarea { border-radius: var(--radius-sm); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  background: var(--color-card);
}

button.primary,
a.primary {
  margin-top: 24px;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--color-primary);
  color: white;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease;
  box-sizing: border-box;
}

button.primary:hover,
a.primary:hover { background: var(--color-primary-dark); }

.error-banner {
  margin-top: 16px;
  background: var(--color-danger-tint);
  color: var(--color-danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  display: none;
}

.demo-hint {
  margin-top: 20px;
  font-size: 12px;
  color: var(--color-muted);
  line-height: 1.5;
}

/* ---------- App shell ---------- */

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--color-card);
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
}

.topbar .brand { color: var(--color-primary); margin: 0; font-size: 19px; }

.role-badge {
  background: var(--color-accent-tint);
  color: var(--color-primary);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  margin-left: 12px;
}

.logout-btn {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-muted);
  padding: 7px 16px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.logout-btn:hover { border-color: var(--color-danger); color: var(--color-danger); }

.notif-wrap { position: relative; margin-right: 12px; }

.notif-bell {
  background: var(--color-bg);
  border: none;
  color: var(--color-text);
  font-size: 16px;
  cursor: pointer;
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--color-danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 1px 5px;
  line-height: 1.4;
}

.notif-panel {
  position: absolute;
  top: 44px;
  right: 0;
  width: 320px;
  max-width: 85vw;
  max-height: 400px;
  overflow-y: auto;
  background: var(--color-card);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  z-index: 50;
  text-align: left;
}

.notif-panel-header {
  padding: 12px 16px;
  font-weight: 700;
  border-bottom: 1px solid var(--color-border);
}

.notif-item {
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
}

.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: var(--color-accent-tint); }

.notif-empty {
  padding: 16px;
  color: var(--color-muted);
  font-size: 13px;
  text-align: center;
}

.content {
  flex: 1;
  padding: 24px 24px 96px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

.section-title {
  font-size: 21px;
  font-weight: 800;
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}

.section-subtitle {
  color: var(--color-muted);
  margin-bottom: 24px;
  font-size: 14px;
}

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

.tile {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

.tile-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--color-accent-tint);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 14px;
}

.tile h3 { margin: 0 0 6px; font-size: 15px; font-weight: 700; }
.tile p { margin: 0; color: var(--color-muted); font-size: 13px; line-height: 1.4; }
.tile .tag {
  display: inline-block;
  margin-top: 14px;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------- Componentes reutilizables del nuevo sistema de diseño ---------- */

/* Barra de navegación inferior — inyectada por js/api.js en cada página
   autenticada, misma idea que la campana de notificaciones. */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  background: var(--color-card);
  border-top: 1px solid var(--color-border);
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  z-index: 30;
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--color-muted);
  font-size: 10px;
  font-weight: 600;
  padding: 4px 2px;
}

.bottom-nav a .bn-icon { font-size: 19px; line-height: 1; }
.bottom-nav a.active { color: var(--color-primary); }

/* Tarjetas de lista (residentes, incidencias, reservaciones, pagos, etc.) */
.list-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-card);
}

.avatar-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-accent-tint);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

/* Badges de estado — success/warning/danger, usados vía JS para reactivos,
   estatus de incidencias/reservaciones/pagos, etc. */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.status-badge.success { background: var(--color-success-tint); color: var(--color-success); }
.status-badge.warning { background: var(--color-warning-tint); color: var(--color-warning); }
.status-badge.danger { background: var(--color-danger-tint); color: var(--color-danger); }

/* Tabs tipo segmented control (Todos / Activos / Inactivos) */
.segmented {
  display: inline-flex;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}
.segmented button {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  color: var(--color-muted);
  cursor: pointer;
}
.segmented button.active { background: var(--color-card); color: var(--color-primary); box-shadow: 0 1px 4px rgba(16,24,43,0.1); }

/* Búsqueda con ícono */
.search-input-wrap { position: relative; }
.search-input-wrap input { padding-left: 38px; }
.search-input-wrap .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-muted);
  font-size: 14px;
}

/* ---------- Componentes del rediseño (Fase A) ---------- */

/* Fila de KPIs numéricos — dashboards de los 3 roles admin. */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
}

.stat-card .stat-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--color-muted);
  margin-top: 2px;
}

/* Fila/lista con ícono + título + subtítulo — documentos, incidencias,
   anuncios, actividad reciente, etc. */
.icon-list-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 14px 16px;
}

.icon-list-item .ili-body { flex-basis: 160px; }

/* Fuerza las acciones (Descargar/Eliminar, etc.) a su propia línea cuando no
   caben junto al título en pantallas angostas, en vez de aplastar el texto. */
.icon-list-item .ili-actions {
  flex-basis: 100%;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.icon-list-item + .icon-list-item { border-top: 1px solid var(--color-border); }

.icon-list-item .ili-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--color-accent-tint);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.icon-list-item .ili-body { flex: 1; min-width: 0; }
.icon-list-item .ili-title { font-weight: 700; font-size: 14px; }
.icon-list-item .ili-subtitle { color: var(--color-muted); font-size: 12px; margin-top: 2px; }

/* Lista agrupada en una tarjeta (reemplaza las <table> que no cabían en
   móvil — Documentos, Residentes, etc.) */
.list-group {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

/* Placeholder circular de foto de perfil con botón de editar — Crear/editar
   residente. */
.avatar-photo-wrap { display: flex; justify-content: center; margin-bottom: 18px; position: relative; width: fit-content; margin-left: auto; margin-right: auto; }

.avatar-photo {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--color-accent-tint);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 700;
  overflow: hidden;
}

.avatar-photo img { width: 100%; height: 100%; object-fit: cover; }

.avatar-edit-btn {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  border: 2px solid var(--color-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
}
