/* ============================================================
   DICO · Geommag — Sistema de diseño (mejora UI, plan §11)
   Tokens derivados de la marca existente (#17658C).
   Compatible con las clases legacy: .boton, .btn_menu, .titulo_campo,
   .fuente_campo, .txt_captura, .titulo2/3/4, .title_bar, .msj_err.
   ============================================================ */

:root {
  /* Marca */
  --brand-900: #0B3547;
  --brand-700: #0F4A6B;
  --brand-600: #17658C;   /* primario existente de la marca */
  --brand-500: #1E7AA6;
  --brand-100: #E3EFF5;
  --brand-50:  #F0F6FA;

  /* Neutros (fríos, no crema) */
  --neutral-900: #1C2733;
  --neutral-700: #3D4A57;
  --neutral-500: #64748B;
  --neutral-300: #C7D1DB;
  --neutral-200: #DFE6EC;
  --neutral-100: #EDF1F5;
  --neutral-50:  #F5F7FA;
  --surface: #FFFFFF;

  /* Estados */
  --danger:  #B3261E;
  --success: #1E7A46;

  /* Escala de espacio (base 4px) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  /* Radios y sombras */
  --radius-sm: 6px;
  --radius-md: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 42, 57, .08);
  --shadow-md: 0 6px 16px rgba(16, 42, 57, .10);

  /* Escala tipográfica */
  --font-ui: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --text-13: 13px;
  --text-14: 14px;
  --text-16: 16px;
  --text-20: 20px;
  --text-28: 28px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-ui);
  font-size: var(--text-14);
  line-height: 1.55;
  color: var(--neutral-900);
  background: var(--neutral-50);
}

/* ---------- Navbar unificada (libs/header.php) ---------- */
.app-nav {
  background: var(--brand-600);
  border-bottom: 1px solid var(--brand-700);
  box-shadow: var(--shadow-sm);
}
.app-nav__inner {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.app-nav__brand {
  color: #FFFFFF;
  font-size: var(--text-16);
  font-weight: 700;
  letter-spacing: .2px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.app-nav__logo {
  height: 30px;
  width: auto;
  border-radius: var(--radius-sm);
}
.app-nav__brand small {
  font-weight: 400;
  opacity: .8;
}
.app-nav__meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.app-nav__user {
  color: #FFFFFF;
  font-size: var(--text-13);
  opacity: .92;
}
.app-nav__logout {
  color: #FFFFFF;
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .25);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-13);
  font-weight: 600;
  text-decoration: none;
  transition: background-color .15s ease;
}
.app-nav__logout:hover { background: rgba(255, 255, 255, .26); }
.app-nav__logout:focus-visible { outline: 2px solid #FFFFFF; outline-offset: 2px; }

/* ---------- Concha de página ---------- */
.app-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-6);
}
.page-title {
  font-size: var(--text-20);
  font-weight: 700;
  letter-spacing: -.2px;
  color: var(--brand-900);
  margin: 0 0 var(--space-4);
}

/* ---------- Panel (una sola tarjeta por vista, sin anidar) ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
}

/* Variante ancha para vistas densas (tablas de captura) */
.panel--wide { max-width: 1200px; margin-left: auto; margin-right: auto; }
.panel--login {
  max-width: 380px;
  margin: 10vh auto 0;
}

/* ---------- Franja de acciones / navegación de formulario ----------
   Cierre tipo "barra de diálogo": borde superior para separarla de la
   tarjeta de contenido del panel. */
.app-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--neutral-200);
}
.app-actions--end { justify-content: flex-end; }

/* Separador entre acciones principales y de salida */
.app-actions__spacer { flex: 1 1 auto; }

/* ---------- Botones de menú (compat .btn_menu) ---------- */
.menu-stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-2);
}
.btn_menu {
  display: block;
  width: 100%;
  max-width: 340px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--brand-700);
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}
.btn_menu:hover {
  border-color: var(--brand-500);
  background: var(--brand-50);
  box-shadow: var(--shadow-sm);
}
.btn_menu:focus-visible {
  outline: 2px solid var(--brand-600);
  outline-offset: 2px;
}

/* Botón primario (compat .boton) */
.boton {
  display: inline-block;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--brand-600);
  border-radius: var(--radius-sm);
  background: var(--brand-600);
  color: #FFFFFF;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .15s ease;
}
.boton:hover { background: var(--brand-700); }
.boton:focus-visible { outline: 2px solid var(--brand-900); outline-offset: 2px; }

/* ---------- Formularios ---------- */
input[type="text"], input[type="password"], select, textarea { font: inherit; }
.txt_captura, .fuente_campo,
input[type="text"], input[type="password"], select, textarea {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--neutral-900);
}
.txt_captura:focus, .fuente_campo:focus,
input[type="text"]:focus, input[type="password"]:focus,
select:focus, textarea:focus {
  border-color: var(--brand-500);
  outline: none;
  box-shadow: 0 0 0 3px rgba(23, 101, 140, .16);
}
input:disabled, .fuente_campo:disabled, .txt_captura:disabled {
  background: var(--neutral-100);
  color: var(--neutral-500);
}

input[type="file"] {
  font: inherit;
  max-width: 100%;
  padding: var(--space-2);
  border: 1px dashed var(--neutral-300);
  border-radius: var(--radius-sm);
  background: var(--neutral-50);
  cursor: pointer;
}

/* Texto de ayuda bajo un campo */
.form-hint {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--text-13);
  color: var(--neutral-500);
}

/* ---------- Avisos / mensajes de error ---------- */
.alert {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--neutral-200);
  border-left: 4px solid var(--brand-600);
  border-radius: var(--radius-sm);
  background: var(--brand-50);
  color: var(--neutral-900);
  margin-bottom: var(--space-4);
}
.alert-danger,
.msj_err {
  border-color: #E7B8B4;
  border-left-color: var(--danger);
  background: #FDF0EF;
  color: var(--danger);
}
.alert-success {
  border-color: #B7DCC5;
  border-left-color: var(--success);
  background: #F0F8F3;
  color: var(--success);
}

/* ---------- Textos compat ---------- */
.titulo_campo { font-weight: 600; color: var(--neutral-700); }
.titulo2 { font-size: var(--text-16); font-weight: 700; color: var(--brand-900); }
.titulo3 { font-weight: 600; color: var(--neutral-700); }
.titulo4 { font-weight: 600; color: var(--neutral-500); font-size: var(--text-13); }
.title_bar { font-size: var(--text-16); font-weight: 700; color: #FFFFFF; }
.msj_err { color: var(--danger); font-size: var(--text-13); font-weight: 600; }

/* ---------- Enlaces ---------- */
a { color: var(--brand-600); }
a:hover { color: var(--brand-700); }

/* ---------- Filtros de búsqueda (fila de campos) ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
}
.filters .field { flex: 1 1 180px; }

/* ---------- Pistas / instrucciones ---------- */
.panel-hint {
  margin: 0 0 var(--space-4);
  color: var(--neutral-700);
  font-size: var(--text-14);
}

/* ---------- Cuadrícula de campos de formulario (tablas legacy) ---------- */
.form-grid {
  width: 100%;
  border-collapse: collapse;
}
.form-grid > tbody > tr > td,
.form-grid > tr > td {
  padding: var(--space-2) 0;
  vertical-align: middle;
}
.form-grid > tbody > tr > td:first-child,
.form-grid > tr > td:first-child {
  padding-right: var(--space-4);
  white-space: nowrap;
}

/* Lista de casillas (selección múltiple) */
.checkbox-list {
  max-height: 320px;
  overflow-y: auto;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-sm);
  background: var(--neutral-50);
}
.checkbox-list label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) 0;
  font-size: var(--text-13);
  cursor: pointer;
}

/* ---------- Tablas de datos ---------- */
.table-wrap {
  margin-top: var(--space-5);
  overflow-x: auto;
}
.tabla-datos {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-13);
}
.tabla-datos th {
  text-align: left;
  white-space: nowrap;
  padding: var(--space-2) var(--space-3);
  background: var(--brand-50);
  color: var(--brand-900);
  border-bottom: 2px solid var(--brand-600);
}
.tabla-datos td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--neutral-200);
  vertical-align: middle;
}
.tabla-datos tbody tr:nth-child(even) td { background: var(--neutral-50); }
.tabla-datos tbody tr:hover td { background: var(--brand-50); }
.tabla-datos .sin-datos { color: var(--neutral-500); }

/* ---------- Movimiento ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ── Catálogos: panel izquierdo (listado) + panel derecho (formulario) ── */
.catalog-wrap {
  display: flex;
  gap: var(--space-4);
  align-items: flex-start;
  max-width: 1100px;
  margin: 0 auto;
}
.catalog-list {
  flex: 0 0 300px;
  background: var(--surface);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
}
.catalog-list h2 {
  margin: 0 0 var(--space-3);
  font-size: var(--text-16);
  color: var(--brand-900);
}
.catalog-search {
  position: relative;
  margin-bottom: var(--space-3);
}
.catalog-search input {
  width: 100%;
  padding: 8px 8px 8px 30px;
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-sm);
  font: inherit;
}
.catalog-search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--neutral-500);
  pointer-events: none;
}
.catalog-items {
  overflow-y: auto;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-sm);
  background: var(--neutral-50);
  margin-bottom: var(--space-3);
  min-height: 0;
  /* ≈25 filas visibles; scroll para el resto */
  max-height: min(850px, 62vh);
}
.catalog-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px 12px;
  font-size: var(--text-13);
  color: var(--neutral-900);
  text-decoration: none;
  border-bottom: 1px solid var(--neutral-200);
  cursor: pointer;
  transition: background-color .12s ease;
}
.catalog-item:hover { background: var(--brand-50); }
.catalog-item.selected {
  background: var(--brand-100);
  font-weight: 600;
  color: var(--brand-900);
}
.catalog-item .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex: none;
}
.catalog-item .dot.inactive { background: var(--neutral-300); }
.catalog-count {
  font-size: var(--text-13);
  color: var(--neutral-500);
  margin-bottom: var(--space-3);
  text-align: right;
}
.catalog-form {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  overflow-y: auto;
}
.catalog-form h2 {
  margin: 0 0 var(--space-4);
  font-size: var(--text-20);
  color: var(--brand-900);
  padding-bottom: var(--space-3);
  border-bottom: 2px solid var(--brand-600);
}
.catalog-form fieldset {
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  margin: 0 0 var(--space-4);
}
.catalog-form legend {
  padding: 0 var(--space-2);
  font-weight: 700;
  color: var(--brand-700);
  font-size: var(--text-14);
}
@media (max-width: 900px) {
  .catalog-wrap { flex-direction: column; }
  .catalog-list { flex: none; min-height: 0; max-height: 40vh; }
}

/* ── Variantes de botón ── */
.boton--danger {
  background: var(--danger);
  border-color: var(--danger);
}
.boton--danger:hover { background: #8F1D14; }
.boton--ghost {
  background: var(--surface);
  color: var(--brand-700);
  border-color: var(--neutral-300);
}
.boton--ghost:hover { background: var(--neutral-100); }

/* ── Campo de fecha con calendario ── */
.date-field { display: inline-flex; gap: 6px; align-items: center; }
.date-field input { width: 120px; }
.cal-btn { padding: 8px 10px; display: inline-flex; align-items: center; }
.calendar {
  position: absolute;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: var(--space-3);
  width: 224px;
  margin-top: 4px;
}
.hidden { display: none !important; }
.calendar.hidden { display: none; }
.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: var(--text-13);
  color: var(--brand-900);
}
.calendar-header button {
  border: none;
  background: none;
  cursor: pointer;
  font-size: var(--text-16);
  color: var(--brand-700);
  padding: 0 6px;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  text-align: center;
  font-size: var(--text-13);
}
.calendar-grid .dow { color: var(--neutral-500); font-weight: 600; padding: 2px 0; }
.calendar-grid .day { padding: 5px 0; cursor: pointer; border-radius: 4px; color: var(--neutral-900); }
.calendar-grid .day:hover { background: var(--brand-50); }
.calendar-grid .day.today { box-shadow: inset 0 0 0 1px var(--brand-600); }
.calendar-grid .day.empty { cursor: default; }

/* ── Combo con búsqueda al teclear (libs/combobox.js) ── */
.combo-search { position: relative; display: inline-block; }
.combo-search select { display: none; }
.combo-search-input {
  width: 100%;
  padding: 8px 26px 8px 10px;
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--surface);
  cursor: pointer;
}
.combo-search::after {
  content: '\25BE';
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--neutral-500);
  pointer-events: none;
  font-size: var(--text-13);
}
.combo-search-input:focus {
  border-color: var(--brand-500);
  outline: none;
  box-shadow: 0 0 0 3px rgba(23, 101, 140, .18);
}
.combo-search-input.disabled {
  background: var(--neutral-100);
  color: var(--neutral-500);
}
.combo-search-list {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  z-index: 60;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}
.combo-search-item {
  padding: 7px 10px;
  font-size: var(--text-13);
  cursor: pointer;
}
.combo-search-item:hover { background: var(--brand-50); }
.combo-search-empty { padding: 8px 10px; color: var(--neutral-500); font-size: var(--text-13); }
.msj_aviso {
  background: #FFF4E0;
  border: 1px solid #E8A23D;
  color: #7A4A0B;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: var(--text-13);
}
.switch { position: relative; display: inline-block; width: 52px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; cursor: pointer; inset: 0; background: var(--neutral-300); border-radius: 28px; transition: .2s; }
.switch .slider:before { content: ""; position: absolute; height: 22px; width: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: #2E9E5B; }
.switch input:checked + .slider:before { transform: translateX(24px); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .app-shell { padding: var(--space-4) var(--space-3) var(--space-5); }
  .app-nav__inner { flex-wrap: wrap; gap: var(--space-2); }
  .panel { padding: var(--space-4); }

  /* En móvil las acciones se apilan y ocupan el ancho completo */
  .app-actions { flex-direction: column; align-items: stretch; }
  .app-actions > .boton,
  .app-actions > .btn_menu { width: 100%; max-width: none; text-align: center; }
  .app-actions__spacer { display: none; }
}
