/* ============================================================
   PORTAL INVERSEGUR - DESIGN SYSTEM (identidad Mas Duenos)
   Fuente: terravinci-config/DESIGN_SYSTEM.md (brand book v3, valores
   "definitivos") + terravinci-agents/agents/ux/tokens.css.
   Usar SOLO estas variables para colores, espaciado, radios y sombras.
   ============================================================ */

:root {
  /* COLORES (rojo #ff4433 - brand book v3, no el #FC4430 viejo) */
  --color-primary: #FF4433;
  --color-primary-dark: #D93020;
  --color-primary-light: #FFF2F0;
  --color-accent: #D93020;
  --color-bg: #FFFFFF;
  --color-bg-soft: #FFF2F0;
  --color-surface: #FFFFFF;
  --color-border: #EAE2E1;
  --color-text-primary: #1A1A1A;
  --color-text-secondary: #878A8C;
  --color-text-on-primary: #FFFFFF;
  --color-success: #2D8A4E;
  --color-warning: #B86C00;
  --color-danger: #B71C1C;
  --color-success-light: #E3F3E8;
  --color-warning-light: #FBEED9;
  --color-danger-light: #FBE4E1;
  --color-info: #1565C0;
  --color-info-light: #E3F2FD;
  --color-muted-light: #F0ECEB;

  /* NAV-LINK (sidebar sobre fondo rojo primario) */
  --nav-link-color: rgba(255, 255, 255, 0.75);
  --nav-link-hover-bg: rgba(255, 255, 255, 0.06);
  --nav-link-active-bg: rgba(255, 255, 255, 0.1);

  /* TIPOGRAFIA (Alexandria - fuente web unificada del ecosistema Terravinci) */
  --font-display: 'Alexandria', Arial, sans-serif;
  --font-body: 'Alexandria', Arial, sans-serif;

  /* ESPACIADO (4px base) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* BORDES */
  --radius-sm: 4px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* SOMBRAS (tintadas con el rojo primario, igual que el token set oficial) */
  --shadow-sm: 0 1px 3px rgba(255, 68, 51, 0.08);
  --shadow-md: 0 4px 12px rgba(255, 68, 51, 0.10);
  --shadow-lg: 0 8px 24px rgba(255, 68, 51, 0.14);

  /* LAYOUT */
  --sidebar-width: 220px;
  --sidebar-width-collapsed: 72px;
  --header-height: 56px;
}

/* ============================================================
   RESET BASICO
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--color-text-primary);
  background: var(--color-bg-soft);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }

/* ============================================================
   TIPOGRAFIA
   ============================================================ */

.display-1 { font-family: var(--font-display); font-size: 2.5rem; font-weight: 700; line-height: 1.2; margin: 0; }
.display-2 { font-family: var(--font-display); font-size: 2rem; font-weight: 700; line-height: 1.2; margin: 0; }
.heading-1 { font-family: var(--font-display); font-size: 1.5rem; font-weight: 600; margin: 0; }
.heading-2 { font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; margin: 0; }
.heading-3 { font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; margin: 0; }
.body-lg { font-size: 1rem; line-height: 1.5; }
.label { font-size: 0.85rem; font-weight: 600; color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: 0.03em; }
.caption { font-size: 0.75rem; color: var(--color-text-secondary); }

/* ============================================================
   BOTONES
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, opacity .15s ease;
}

.btn-primary { background: var(--color-primary); color: var(--color-text-on-primary); }
.btn-primary:hover { background: var(--color-primary-dark); }

.btn-secondary { background: var(--color-primary-light); color: var(--color-primary); }
.btn-secondary:hover { background: #EFE8E7; }

.btn-ghost { background: transparent; color: var(--color-text-primary); border-color: var(--color-border); }
.btn-ghost:hover { background: var(--color-bg-soft); }

.btn-sm { padding: var(--space-2) var(--space-3); font-size: 0.8rem; }
.btn-lg { padding: var(--space-4) var(--space-6); font-size: 1rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Para paginacion (<a>/<span> sin href) en el limite (page=1 o ultima
   pagina) - :disabled nativo solo aplica a <button>, un <a> nunca puede
   estar realmente deshabilitado, por eso hace falta esta clase. */
.btn-disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* ============================================================
   INPUTS
   ============================================================ */

.input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--color-text-primary);
  background: var(--color-surface);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(255, 68, 51, 0.18);
}

/* Modificador para inputs/selects mas compactos (paneles de filtros con
   muchos campos). No cambia el .input por defecto. */
.input-sm { padding: var(--space-2) var(--space-3); font-size: 0.85rem; }

.input::placeholder { color: var(--color-text-secondary); }

/* Grupo de checkboxes para filtros (alternativa a un select cuando se
   quieren combinar varios valores a la vez, ej. Vigente + No vigente). */
.checkbox-group { display: flex; flex-direction: column; gap: var(--space-1); }
.checkbox-item { display: flex; align-items: center; gap: var(--space-2); font-size: 0.85rem; cursor: pointer; }
.checkbox-item input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--color-primary); cursor: pointer; }

/* Grupo de checkboxes tipo "chip" contra un catalogo de tags (ver
   campo_tags en templates/_macros.html - Ubicacion/Amenities/Ambientes de
   Boleto/Reserva). */
.tags-grupo { display: flex; flex-wrap: wrap; gap: var(--space-2); max-height: 260px; overflow-y: auto; padding: var(--space-1); }
.tags-opcion { border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--space-1) var(--space-3); margin: 0; }

/* Buscador + dropdown + chips (campo_tags con buscador=true, ver
   static/js/tags_buscador.js - progressive enhancement sobre .tags-grupo,
   que queda oculto pero sigue siendo la fuente real de los checkboxes). */
.tags-buscador-wrapper { position: relative; }
.tags-dropdown {
  display: none;
  position: absolute;
  z-index: 20;
  top: calc(100% + var(--space-1));
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}
.tags-dropdown.open { display: block; }
.tags-dropdown-opcion { padding: var(--space-2) var(--space-3); font-size: 0.85rem; cursor: pointer; }
.tags-dropdown-opcion:hover { background: var(--color-primary-light); }
.tags-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.tags-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-primary);
  color: var(--color-primary);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
}
.tags-chip-del { background: none; border: none; color: inherit; cursor: pointer; font-size: 1rem; line-height: 1; padding: 0; }

/* Modificadores para paneles de filtros mas compactos (menos padding,
   etiquetas mas chicas). No cambian .card ni .label por defecto. */
.card-compact { padding: var(--space-4); }
.label-sm { font-size: 0.7rem; }

/* ============================================================
   CARDS
   ============================================================ */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.card-elevated {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-md);
}

/* Titulo de card (usar dentro de .card/.card-elevated) - texto en rojo
   de marca sobre fondo blanco, sin banda de color de fondo. */
.card-header {
  background: transparent;
  color: var(--color-primary);
  margin: 0 0 var(--space-4);
  padding: 0;
  border-radius: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
}

/* ============================================================
   KPIs
   ============================================================ */

.kpi { display: flex; flex-direction: column; gap: var(--space-2); }
.kpi-label { font-size: 0.8rem; color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-value { font-family: var(--font-display); font-size: 1.75rem; font-weight: 700; color: var(--color-text-primary); }
.kpi-delta { font-size: 0.8rem; font-weight: 600; }
.kpi-delta.up { color: var(--color-success); }
.kpi-delta.down { color: var(--color-danger); }

/* Barra de metadatos: fila de celdas etiqueta+valor para el resumen de una
   ficha de detalle (alternativa mas compacta a la grilla de KPIs). */
.meta-bar {
  display: flex;
  flex-wrap: wrap;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-surface);
}
.meta-cell {
  flex: 1;
  min-width: 160px;
  padding: var(--space-2) var(--space-4);
  border-right: 1px solid var(--color-border);
}
.meta-cell:last-child { border-right: none; }
.meta-label {
  font-size: 0.71rem;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}
.meta-val {
  font-weight: 700;
  font-family: var(--font-display);
  color: var(--color-primary);
  font-size: 0.95rem;
}
.meta-val.neutral { color: var(--color-text-primary); }

/* ============================================================
   BADGES
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.badge-primary { background: var(--color-primary-light); color: var(--color-primary); }
.badge-success { background: var(--color-success-light); color: var(--color-success); }
.badge-warning { background: var(--color-warning-light); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-light); color: var(--color-danger); }
.badge-info { background: var(--color-info-light); color: var(--color-info); }
.badge-muted { background: var(--color-muted-light); color: var(--color-text-secondary); }

.flash-messages { display: flex; flex-direction: column; gap: var(--space-2); }

/* Buscador con autocompletado (static/js/buscador.js) - ver campo_buscador
   en templates/_macros.html. .direccion-selector es el mismo patron para
   campo_direccion (static/js/direccion.js) - sin position:relative aca,
   el dropdown .buscador-resultados (position:absolute) no tiene ancla y
   flota relativo a toda la pagina en vez de quedar debajo del input. */
.buscador-selector, .direccion-selector { position: relative; }
.buscador-resultados {
  display: none;
  position: absolute;
  z-index: 20;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  margin-top: 4px;
}
.buscador-opcion { padding: var(--space-2) var(--space-3); cursor: pointer; font-size: 0.85rem; }
.buscador-opcion:hover { background: var(--color-border); }

/* Wizard de alta en una sola pagina (static/js/wizard.js) - ver
   wizard_barra_progreso/wizard_nav en templates/_macros.html. */
.wizard-progreso { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.wizard-nav { border-top: 1px solid var(--color-border); padding-top: var(--space-4); }

/* ============================================================
   TABLAS
   ============================================================ */

.table-container { width: 100%; overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { padding: var(--space-3) var(--space-4); text-align: left; border-bottom: 1px solid var(--color-border); }
.table th { color: var(--color-text-secondary); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.02em; }
.table tbody tr:hover { background: var(--color-bg-soft); }

/* Tabla compacta para formularios con muchas columnas (ej. Conceptos en
   los wizards de Plan/Boleto): table-layout: fixed + columnas por
   porcentaje (via <th style="width: X%">) hace que la tabla siempre
   entre en el ancho del contenedor, en vez de desbordar y depender del
   scroll horizontal de .table-container. */
.tabla-compacta { table-layout: fixed; }
.tabla-compacta th, .tabla-compacta td { padding: var(--space-2); overflow: hidden; }
.tabla-compacta input, .tabla-compacta select { width: 100%; box-sizing: border-box; }

/* ============================================================
   LAYOUT
   ============================================================ */

.layout-root { min-height: 100vh; }

.layout-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-primary);
  color: var(--color-text-on-primary);
  z-index: 40;
  transition: transform .2s ease, width .2s ease;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* El <nav> es lo unico que scrollea internamente si hay muchos modulos -
   asi el logo (arriba) y el usuario logueado (abajo, ver .sidebar-usuario
   mas abajo) quedan siempre visibles sin que el bloque de usuario quede
   empujado fuera de la ventana. min-height:0 es necesario para que
   flex:1 + overflow-y:auto funcione dentro de un flex column (si no, el
   nav no se achica nunca por debajo de su contenido). */
.layout-sidebar nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* Edge viejo */
}

.layout-sidebar nav::-webkit-scrollbar {
  display: none; /* Chrome/Edge/Safari - el scroll con mouse/rueda sigue funcionando igual */
}

.layout-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-4);
  z-index: 30;
  transition: left .2s ease;
}

.layout-main { padding-top: var(--header-height); transition: margin-left .2s ease; }

.layout-content { padding: var(--space-6); }

.layout-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 35;
  display: none;
}

.layout-overlay.is-active { display: block; }

.btn-menu {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--color-text-primary);
}

.btn-menu:hover { background: var(--color-bg-soft); }

/* ============================================================
   NAVEGACION
   ============================================================ */

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  color: var(--nav-link-color);
  font-size: 0.9rem;
  font-weight: 500;
  border-left: 3px solid transparent;
}

.nav-link:hover { background: var(--nav-link-hover-bg); color: var(--color-text-on-primary); }

.nav-icon { flex-shrink: 0; width: 20px; height: 20px; }
.nav-link-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Icono al lado de un <h1 class="heading-1"> de listado - mas grande que
   .nav-icon (pensado para la sidebar angosta), con el color de marca ya
   incluido (no hay un nav-link del que heredarlo aca). */
.heading-icon { flex-shrink: 0; width: 28px; height: 28px; color: var(--color-primary); }

.nav-link.active {
  background: var(--nav-link-active-bg);
  color: var(--color-text-on-primary);
  border-left-color: var(--color-accent);
}

/* Usuario logueado - pie del sidebar (foto/inicial + nombre), con
   submenu (email + Cerrar sesion) que solo aparece al hacer click sobre
   el boton, ver static/js/app.js. */
.sidebar-usuario {
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  position: relative;
}

.sidebar-usuario-boton {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-4) var(--space-5);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-on-primary);
  text-align: left;
}

.sidebar-usuario-boton:hover { background: var(--nav-link-hover-bg); }

.sidebar-usuario-avatar {
  position: relative;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--color-primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.sidebar-usuario-inicial {
  display: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--color-text-on-primary);
}

/* La imagen se auto-elimina via onerror si no hay foto cargada en
   Microsoft 365 (ver base.html) - recien ahi se muestra la inicial. */
.sidebar-usuario-avatar.sin-foto .sidebar-usuario-inicial { display: flex; }

.sidebar-usuario-nombre {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: normal;
  word-break: break-word;
  line-height: 1.3;
}

.sidebar-usuario-menu {
  display: none;
  flex-direction: column;
  gap: var(--space-2);
  position: absolute;
  bottom: 100%;
  left: var(--space-2);
  width: 220px;
  margin-bottom: var(--space-2);
  background: var(--color-bg);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  box-shadow: 0 4px 16px rgba(255, 68, 51, 0.2);
}

.sidebar-usuario-menu.is-open { display: flex; }

.sidebar-usuario-email {
  color: var(--color-text-secondary);
  word-break: break-all;
}

.sidebar-usuario-logout {
  color: var(--color-primary);
  font-weight: 600;
  font-size: 0.85rem;
}


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

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }

.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-6); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-6); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-6); }

.col-span-2 { grid-column: span 2; }

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-primary { color: var(--color-primary); }
.text-muted { color: var(--color-text-secondary); }
.text-danger { color: var(--color-danger); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.hide-mobile { display: none; }
.hide-desktop { display: initial; }

/* ============================================================
   FICHA DE DETALLE (patron comun a todos los modulos: resumen +
   nav rapida + tablas campo->valor de solo lectura)
   ============================================================ */

.kv-table th {
  width: 200px;
  color: var(--color-text-secondary);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: none;
  letter-spacing: 0;
  vertical-align: top;
}

.kv-table td { font-size: 0.95rem; }

.quick-nav {
  position: sticky;
  top: var(--header-height);
  background: var(--color-bg-soft);
  z-index: 20;
  padding: var(--space-3) 0;
  margin-bottom: var(--space-6);
  border-bottom: 1px solid var(--color-border);
}

.quick-nav a {
  margin-right: var(--space-6);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-secondary);
}

.quick-nav a:hover { color: var(--color-primary); }

.section-anchor { scroll-margin-top: calc(var(--header-height) + 60px); }

/* ============================================================
   MODAL DE VISTA PREVIA (pestaña Archivos - Documentacion de Entrega)
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.modal-overlay.is-active { display: flex; }

.modal-box {
  background: var(--color-bg);
  border-radius: var(--radius-md);
  width: min(1400px, 96%);
  height: min(95vh, 1400px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-soft);
}

.modal-iframe {
  flex: 1;
  width: 100%;
  border: none;
}

.btn-archivo-preview {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  margin-left: var(--space-2);
  opacity: 0.7;
}

.btn-archivo-preview:hover { opacity: 1; }
