/* =========================================================================
   Paleta corporativa
   -------------------------------------------------------------------------
   El amarillo de marca (#E5D504) tiene 1.52:1 contra blanco, así que NO es
   un color de texto en modo claro. Por eso la marca se reparte en tres
   papeles y no en un único token de acento:

     --brand       relleno de superficies >=24px, SIEMPRE con --on-brand encima
     --brand-deep  bordes, foco y elementos pequeños (3.98:1 -> UI, no texto)
     --brand-ink   texto, enlaces y estados activos (5.23:1 sobre --bg)

   Regla: un elemento amarillo pequeño sobre fondo claro desaparece. Puntos,
   iconos finos y texto van en --brand-ink o --brand-deep, nunca en --brand.

   En oscuro esto se invierte: #E5D504 rinde 12.31:1 sobre el fondo, así que
   --brand y --brand-ink pasan a valer lo mismo.

   El amarillo es exclusivo de identidad y no participa en la rampa de
   estados: "pendiente" usa pizarra y "aviso" usa naranja, para que el color
   corporativo nunca se lea como un estado del sistema.
   ========================================================================= */
/* Bordes en tres niveles. Un único tono de borde obliga a elegir entre
   controles legibles y contenedores discretos; separándolos se consigue lo
   uno y lo otro:
     --line2        1.37:1  separadores internos (filas de tabla)
     --line         1.72:1  contorno de contenedores (card, tabla, panel)
     --line-strong  3.44:1  contorno de CONTROLES (input, select, botón, chip)
                            -> WCAG 1.4.11 exige 3:1 aquí, en el resto no
     --line-hover   5.30:1  control apuntado */
:root {
  --bg: #F7F6EE; --surface: #FFFFFF; --surface2: #F2F0E4;
  --ink: #17170F; --muted: #5A5A4C; --faint: #6F6E5C;
  --line: #C9C6B0; --line2: #DFDDCC;
  --line-strong: #8F8B74; --line-hover: #6F6C58;
  --brand: #E5D504; --brand-deep: #89821A; --brand-ink: #6F6912;
  --brand-soft: #F2EFD2; --on-brand: #191703;
  --slate: #4F5A63; --slate-soft: #E9ECEF;
  --warn: #A8541B; --warn-soft: #F7EADF;
  --blue: #1F5C93; --blue-soft: #E4EDF6;
  --green: #2C6B45; --green-soft: #E3F0E8;
  --red: #A33527; --red-soft: #F7E6E3; --on-red: #FFFFFF;
  --shadow: 0 1px 2px rgba(23,23,15,.05), 0 8px 24px rgba(23,23,15,.05);
  --radius: 10px;
}

/* Aplica en modo "system" cuando el navegador prefiere oscuro (sin toggle explícito).
   Debe ser idéntico al bloque [data-theme="dark"] de abajo. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12130E; --surface: #1A1C15; --surface2: #212318;
    --ink: #ECEBE0; --muted: #9C9C8D; --faint: #6F7063;
    --line: #2C2E22; --line2: #24261B;
    --line-strong: #6E7157; --line-hover: #8A8D72;
    --brand: #E5D504; --brand-deep: #B5AC2A; --brand-ink: #E5D504;
    --brand-soft: #2B2809; --on-brand: #191703;
    --slate: #A6B2BC; --slate-soft: #242A2F;
    --warn: #E0A06A; --warn-soft: #2E2015;
    --blue: #6FA8DC; --blue-soft: #1A2430;
    --green: #6FBF8E; --green-soft: #16241C;
    --red: #E08272; --red-soft: #2C1B18; --on-red: #2C1B18;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.28);
  }
}

/* Toggle explícito (persistido en localStorage por static/js/theme.js) */
:root[data-theme="dark"] {
  --bg: #12130E; --surface: #1A1C15; --surface2: #212318;
  --ink: #ECEBE0; --muted: #9C9C8D; --faint: #6F7063;
  --line: #2C2E22; --line2: #24261B;
  --line-strong: #6E7157; --line-hover: #8A8D72;
  --brand: #E5D504; --brand-deep: #B5AC2A; --brand-ink: #E5D504;
  --brand-soft: #2B2809; --on-brand: #191703;
  --slate: #A6B2BC; --slate-soft: #242A2F;
  --warn: #E0A06A; --warn-soft: #2E2015;
  --blue: #6FA8DC; --blue-soft: #1A2430;
  --green: #6FBF8E; --green-soft: #16241C;
  --red: #E08272; --red-soft: #2C1B18; --on-red: #2C1B18;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body.scroll-locked { overflow: hidden; }
/* Utilidad global de visibilidad -- !important a propósito: debe ganar
   siempre sin importar el display propio del componente (ver el patrón de
   apertura/cierre en files/static/files/js/quick_create_modals.js y el
   drawer móvil de /archivos/ más abajo). */
.hidden { display: none !important; }
/* El ATRIBUTO hidden necesita el mismo refuerzo: la regla del user-agent
   ([hidden]{display:none}) pierde contra CUALQUIER display de autor -- un
   elemento con class .btn (display:inline-flex) o .preview-empty
   (display:flex) ignoraba el atributo por completo, dejando visible lo que
   el JS creía haber ocultado (el.hidden = true). Nota: esta regla anula
   hidden="until-found"; si algún día se necesita, excluirlo aquí. */
[hidden] { display: none !important; }
/* Oculto a la vista pero SIN display:none, que es la diferencia que importa:
   el elemento sigue siendo ENFOCABLE. Lo necesita el <select> nativo que
   envuelve .hf-combo (ver files/static/files/js/hf_searchable_select.js): con
   display:none, un navegador que corra su validación nativa se encuentra un
   control required imposible de enfocar, se niega a enviar el formulario y
   solo lo loguea en consola -- botón Guardar muerto sin ningún mensaje. */
.hf-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
/* .form-field select (0,1,1) le gana en especificidad a .hf-sr-only (0,1,0) y
   le devolvía los 40px de alto. De ahí el selector con el tipo delante. */
select.hf-sr-only { height: 1px; min-height: 0; }
body {
  color: var(--ink);
  font-family: "Instrument Sans", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: "IBM Plex Mono", monospace; }
a { color: var(--brand-ink); text-decoration: none; }
a:hover { color: var(--ink); text-decoration: underline; }
input, button, select, textarea { font-family: inherit; }
input::placeholder, textarea::placeholder { color: var(--faint); }

@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pulseDot { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* =========================================================================
   App shell (sidebar + main) -- ver templates/app_base.html
   ========================================================================= */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 236px 1fr; background: var(--bg); }

.app-sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.app-logo { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; }
.app-logo-mark { width: 24px; height: 24px; border-radius: 50%; flex: none; display: block; }
.app-logo-text { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.app-logo-text .muted { color: var(--muted); font-weight: 400; }

.app-nav { display: flex; flex-direction: column; gap: 2px; }
.app-nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: none; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 13.5px; font-weight: 500; text-align: left;
  cursor: pointer; text-decoration: none;
}
.app-nav-item:hover { background: var(--surface2); color: var(--muted); text-decoration: none; }
/* El estado activo se marca con un asta amarilla que sangra el alto completo
   del item, igual que las astas de la H del logo sangran hasta que las recorta
   el círculo. Es el único elemento llamativo de la interfaz. */
.app-nav-item.active { position: relative; color: var(--brand-ink); font-weight: 600; }
.app-nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--brand);
}
.app-nav-item.active:hover { background: transparent; color: var(--brand-ink); }
.app-nav-item svg { flex: none; }

.app-storage { margin-top: 26px; padding: 0 8px 8px; }
.app-storage-label {
  font-size: 11px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--faint); margin-bottom: 8px;
}
.app-storage-value { margin-top: 8px; font-size: 12px; color: var(--muted); }

.app-sidebar-footer { margin-top: auto; padding-top: 18px; border-top: 1px solid var(--line2); }
.app-theme-toggle {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 8px;
  border: none; border-radius: 8px; background: transparent; color: var(--muted);
  font-size: 13px; cursor: pointer; text-align: left;
}
.app-theme-toggle:hover { background: var(--surface2); color: var(--ink); }

.app-user { display: flex; align-items: center; gap: 10px; padding: 9px 8px; margin-top: 2px; }
.app-user-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--brand-soft);
  color: var(--brand-ink); display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; flex: none;
}
.app-user-info { min-width: 0; }
.app-user-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-user-role { font-size: 11px; color: var(--faint); }
.app-user-logout {
  margin-left: auto; border: none; background: transparent; color: var(--faint);
  cursor: pointer; padding: 4px; display: flex;
}
.app-user-logout:hover { color: var(--ink); }

.app-main { min-width: 0; }
.app-main-inner { padding: 34px 40px 56px; animation: fadeUp .28s ease both; }

/* =========================================================================
   Componentes generales
   ========================================================================= */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.page-header h1 { margin: 0 0 6px; font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.page-header p { margin: 0; font-size: 14px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: 9px;
  background: var(--surface); color: var(--ink);
  font-size: 13px; font-weight: 500; cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface2); border-color: var(--line-hover); text-decoration: none; }
/* Deshabilitado explícito: con opacity el texto caía por debajo de 3:1. */
.btn:disabled, .btn[aria-disabled="true"] {
  background: var(--surface2); border-color: var(--line); color: var(--faint);
  cursor: not-allowed;
}
.btn-sm { height: 30px; padding: 0 12px; font-size: 12.5px; }
.btn-primary { border: none; background: var(--brand); color: var(--on-brand); font-weight: 600; }
.btn-primary:hover { opacity: .88; background: var(--brand); }
/* --on-red, no #fff: en oscuro --red es un salmón claro y el blanco no contrastaba. */
.btn-danger { border: none; background: var(--red); color: var(--on-red); font-weight: 600; }
.btn-danger:hover { opacity: .88; background: var(--red); }
.btn-link { border: none; background: none; color: var(--muted); text-decoration: underline; padding: 0; height: auto; }

.card { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); padding: 22px 24px; }

/* Tabla en formato "grid-row" (encabezado + filas con el mismo grid-template-columns) */
.grid-table { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.grid-row {
  display: grid; gap: 16px; align-items: center; padding: 14px 20px;
  border-bottom: 1px solid var(--line2);
}
.grid-row:last-child { border-bottom: none; }
.grid-head {
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--surface2);
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--faint);
}
.grid-row-empty { padding: 20px; color: var(--muted); font-size: 13.5px; }
.file-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.file-ext {
  width: 30px; height: 30px; border-radius: 8px; background: var(--surface2);
  border: 1px solid var(--line); display: flex; align-items: center; justify-content: center;
  font-family: "IBM Plex Mono", monospace; font-size: 9px; font-weight: 500; color: var(--muted); flex: none;
}
.file-name { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-ref { font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--faint); }
.row-actions { display: flex; justify-content: flex-end; }

/* Menú "..." por fila (details/summary nativo, sin JS) */
.row-menu { position: relative; }
.row-menu summary {
  list-style: none; cursor: pointer; color: var(--faint); display: flex;
  width: 28px; height: 28px; align-items: center; justify-content: center; border-radius: 6px;
}
.row-menu summary::-webkit-details-marker { display: none; }
.row-menu summary:hover { background: var(--surface2); color: var(--ink); }
.row-menu[open] summary { background: var(--surface2); }
.row-menu-content {
  position: absolute; right: 0; top: 32px; z-index: 5; min-width: 140px;
  border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface);
  box-shadow: var(--shadow); padding: 4px; display: flex; flex-direction: column;
}
.row-menu-content a {
  padding: 8px 10px; border-radius: 6px; font-size: 13px; color: var(--ink); text-decoration: none;
}
.row-menu-content a:hover { background: var(--surface2); text-decoration: none; }
.row-menu-content a.danger { color: var(--red); }

/* =========================================================================
   Vista master-detail de Archivos (ver files/templates/files/filearchive_list.html
   y files/static/files/js/filearchive_split.js)
   ========================================================================= */
.split-view { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr); gap: 16px; align-items: start; }
.split-view .grid-table { max-height: calc(100vh - 260px); overflow-y: auto; }

/* Columnas: Nombre / Cliente / Clase de archivo / Vencimiento / Estado / acciones */
.grid-row--files { grid-template-columns: 2fr 1.2fr 1fr .9fr .9fr 40px; }
.grid-row--files[tabindex] { cursor: pointer; user-select: none; }
.grid-row--files[tabindex]:focus-visible { outline: 2px solid var(--brand-deep); outline-offset: -2px; }
.grid-row--files[aria-current="true"] { background: var(--brand-soft); }

.preview-panel {
  position: sticky; top: 20px; max-height: calc(100vh - 260px);
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  display: flex; flex-direction: column; overflow: hidden;
}
.preview-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 40px 24px; color: var(--faint); text-align: center;
}
.preview-empty svg { color: var(--faint); }
.preview-empty p { margin: 0; font-size: 13.5px; }
.preview-content { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.preview-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line2); flex: none;
}
.preview-header-info { min-width: 0; }
.preview-header-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-header-meta { margin-top: 4px; font-size: 12px; color: var(--muted); }
.preview-header-actions { display: flex; gap: 6px; flex: none; align-items: center; }
.preview-drawer-close { display: none; }
.preview-body { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.preview-body iframe { flex: 1; width: 100%; border: none; }
/* flex:none + max-constraints + margin:auto: no puede colapsar (el sizing
   anterior con flex:1/height:100% era circular -- el panel desktop solo
   tiene max-height, altura indefinida) y centra en ambos ejes dentro del
   flex column, igual que .preview-fallback-card. */
.preview-body img {
  flex: none; display: block; max-width: 100%; max-height: 100%;
  margin: auto; background: var(--surface2);
}
/* Páginas PDF renderizadas por PDF.js: flex items en columna con
   overflow:auto -- sin flex:none, las 5 páginas se aplastarían para caber
   en el viewport en vez de scrollear. */
.preview-body canvas.preview-pdf-page { flex: none; display: block; width: 100%; height: auto; }
.preview-body canvas.preview-pdf-page + canvas.preview-pdf-page { margin-top: 8px; }
.preview-fallback-card { margin: auto; padding: 24px; text-align: center; max-width: 300px; }
.preview-fallback-card .file-ext { margin: 0 auto 14px; width: 46px; height: 46px; font-size: 13px; }
.preview-fallback-card p { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }
.preview-fallback-card .preview-fallback-meta { margin-top: 6px; font-size: 12px; color: var(--faint); }
.preview-open-new { display: block; margin-top: 12px; text-align: center; font-size: 12.5px; }
.preview-truncated-notice { flex: none; padding: 8px 14px; background: var(--warn-soft); color: var(--warn); font-size: 12px; text-align: center; }
.preview-loading { flex: 1; display: flex; align-items: center; justify-content: center; padding: 40px 24px; color: var(--faint); font-size: 13px; }
.preview-text {
  flex: 1; margin: 0; padding: 16px 18px; overflow: auto;
  white-space: pre-wrap; word-break: break-word;
  font-family: "IBM Plex Mono", monospace; font-size: 12px; line-height: 1.55; color: var(--ink);
}

/* Backdrop del drawer móvil -- ver templates/base.html::body_end */
.drawer-backdrop { position: fixed; inset: 0; z-index: 890; background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .22s ease; }
.drawer-backdrop.is-open { opacity: 1; pointer-events: auto; }

/* Búsqueda + chips de filtro */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.search-field { position: relative; flex: 1; max-width: 340px; }
.search-field svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search-field input {
  width: 100%; height: 38px; padding: 0 14px 0 36px; border: 1px solid var(--line-strong);
  border-radius: 9px; background: var(--surface); color: var(--ink); font-size: 13px; outline: none;
}
.search-field input:hover { border-color: var(--line-hover); }
.search-field input:focus { border-color: var(--brand-deep); box-shadow: 0 0 0 3px var(--brand-soft); }
/* Filtro por rango de fechas (apertura/vencimiento), a un costado del
   chip-group de estado -- mismo <form> (ver filearchive_list.html), así que
   ningún filtro pisa a los demás al enviarse. */
.date-filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-left: auto; }
.date-filter-field { display: flex; align-items: center; gap: 6px; }
.date-filter-field label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.date-range-inputs { display: flex; align-items: center; gap: 4px; }
.date-range-inputs input[type="date"] {
  height: 32px; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: 7px;
  background: var(--surface); color: var(--ink); font-size: 12.5px; outline: none;
}
.date-range-inputs input[type="date"]:hover { border-color: var(--line-hover); }
.date-range-inputs input[type="date"]:focus { border-color: var(--brand-deep); box-shadow: 0 0 0 3px var(--brand-soft); }
.date-range-sep { color: var(--faint); font-size: 12px; }

/* Formularios */
.form-field { margin-bottom: 16px; display: flex; flex-direction: column; gap: 7px; }
.form-field label { font-size: 12px; font-weight: 500; color: var(--muted); }
.form-field input, .form-field select, .form-field textarea {
  height: 40px; padding: 0 13px; border: 1px solid var(--line-strong); border-radius: 9px;
  background: var(--surface2); color: var(--ink); font-size: 13.5px; outline: none;
}
.form-field textarea { height: auto; padding: 11px 13px; resize: vertical; }
.form-field input:hover, .form-field select:hover, .form-field textarea:hover {
  border-color: var(--line-hover);
}
/* El foco se marca con color de borde Y anillo: el color solo no basta para
   quien no distingue el olivo del gris. */
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  border-color: var(--brand-deep); background: var(--surface);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.form-field input:disabled, .form-field select:disabled, .form-field textarea:disabled {
  border-color: var(--line); background: var(--surface2);
  color: var(--faint); cursor: not-allowed;
}
.form-help { color: var(--faint); font-size: 11px; }
/* .errorlist es lo que renderiza {{ field.errors }} de Django. Sin ella, los
   errores de servidor salían como viñetas negras del navegador: el proyecto
   solo estilaba las clases que emite su propio JS. */
.form-error, .hf-form-errors, .errorlist { color: var(--red); font-size: 13px; }
.form-actions { display: flex; gap: 9px; margin-top: 20px; }

/* --- Campos obligatorios -------------------------------------------------
   El asterisco es un refuerzo VISUAL de required/aria-required (de ahí el
   aria-hidden en las plantillas): el color por sí solo no puede portar el
   significado, y el lector de pantalla ya anuncia la obligatoriedad por el
   atributo del control. En las plantillas se DERIVA de field.field.required,
   nunca escrito a mano -- a mano mentiría en cuanto cambie un blank= en
   files/models.py. */
.form-required { color: var(--red); font-weight: 600; margin-left: 3px; }
.form-legend { margin: 0 0 14px; font-size: 11.5px; color: var(--faint); }

/* Tarjetas de estadística (dashboard) */
.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 32px; }
.stat-card { padding: 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.stat-card .stat-label { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.stat-card .stat-value { font-family: "IBM Plex Mono", monospace; font-size: 30px; font-weight: 500; letter-spacing: -0.02em; }
.stat-card .stat-sub { margin-top: 8px; font-size: 12px; color: var(--muted); }
.stat-value.color-blue { color: var(--blue); }
.stat-value.color-red { color: var(--red); }

.dash-panels { display: grid; grid-template-columns: 1.5fr 1fr; gap: 14px; }
.dash-panel-title { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 24px; }
.dash-panel-title h2 { margin: 0; font-size: 15px; font-weight: 600; }
.dash-panel-title span { font-size: 12px; color: var(--faint); }

.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 168px; }
.bar-chart .bar { flex: 1; background: var(--brand-soft); border-radius: 4px 4px 2px 2px; min-height: 2px; }
.bar-chart .bar.is-today { background: var(--brand); }
.bar-chart-labels { display: flex; justify-content: space-between; margin-top: 12px; font-size: 11px; color: var(--faint); font-family: "IBM Plex Mono", monospace; }

.queue-row { margin-bottom: 18px; }
.queue-row-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 7px; }
.queue-row-head .mono { color: var(--muted); }

/* Mensajes flash */
.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.message { padding: 10px 14px; border-radius: 9px; margin-bottom: 8px; font-size: 13.5px; }
.message-success { background: var(--green-soft); color: var(--green); }
.message-error { background: var(--red-soft); color: var(--red); }
.message-warning { background: var(--warn-soft); color: var(--warn); }
.message-info { background: var(--blue-soft); color: var(--blue); }

.pagination { display: flex; align-items: center; justify-content: space-between; padding: 13px 20px; font-size: 12.5px; color: var(--muted); }
.pagination-links { display: flex; gap: 6px; }

/* =========================================================================
   Login (split screen, sin sidebar -- ver authentication/templates/authentication/login.html)
   ========================================================================= */
.login-shell { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; background: var(--bg); }
.login-panel {
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 56px 64px; background: var(--surface); border-right: 1px solid var(--line);
}
.login-brand { display: flex; align-items: center; gap: 10px; }
.login-logo-mark { width: 28px; height: 28px; }
.login-brand .app-logo-text { font-size: 15px; }
.login-form-wrap { max-width: 380px; width: 100%; }
.login-form-wrap h1 { margin: 0 0 8px; font-size: 30px; font-weight: 600; letter-spacing: -0.02em; }
.login-form-wrap > p { margin: 0 0 32px; font-size: 14px; line-height: 1.55; color: var(--muted); }
.login-footer { font-size: 12px; color: var(--faint); }
.login-note {
  margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line2);
  display: flex; align-items: flex-start; gap: 9px;
}
.login-note-dot {
  /* 6px sobre superficie clara: --brand desaparecería, va en --brand-deep. */
  width: 6px; height: 6px; border-radius: 50%; background: var(--brand-deep);
  margin-top: 6px; flex: none; animation: pulseDot 2.4s ease-in-out infinite;
}
.login-note p { margin: 0; font-size: 12px; line-height: 1.5; color: var(--faint); }

.login-side {
  position: relative; display: flex; flex-direction: column; justify-content: center;
  padding: 64px; background: var(--surface2); overflow: hidden;
}
.login-side-grid {
  position: absolute; inset: 0;
  background-image: linear-gradient(var(--line2) 1px, transparent 1px), linear-gradient(90deg, var(--line2) 1px, transparent 1px);
  background-size: 56px 56px; opacity: .8;
}
.login-side-content { position: relative; max-width: 420px; }
.login-side-kicker {
  font-family: "IBM Plex Mono", monospace; font-size: 11px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--brand-ink); margin-bottom: 18px;
}
.login-side-lead { margin: 0 0 36px; font-size: 22px; line-height: 1.45; font-weight: 500; letter-spacing: -0.01em; }
.login-steps { display: flex; flex-direction: column; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.login-step { display: flex; align-items: center; gap: 14px; padding: 16px 18px; background: var(--surface); }
.login-step-num { font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--faint); width: 20px; flex: none; }
.login-step-text { font-size: 14px; }

/* =========================================================================
   Dropzone de subida (files/static/files/css/upload_page.css complementa esto)
   ========================================================================= */
.upload-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 14px; align-items: start; }
.upload-back {
  display: flex; align-items: center; gap: 6px; margin-bottom: 14px; border: none;
  background: transparent; padding: 0; color: var(--muted); font-size: 13px; cursor: pointer; text-decoration: none;
}
.upload-back:hover { color: var(--ink); text-decoration: none; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar { position: relative; height: auto; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .dash-panels, .upload-grid, .login-shell { grid-template-columns: 1fr; }
  .login-side { display: none; }
}

/* Vista master-detail de Archivos: el panel de preview se colapsa a un
   drawer de pantalla completa (ver files/static/files/js/filearchive_split.js). */
@media (max-width: 768px) {
  .split-view { grid-template-columns: 1fr; }
  .split-view .grid-table { max-height: none; overflow: visible; }

  .preview-panel {
    position: fixed; inset: auto 0 0 0; top: auto;
    height: 100vh; height: 100dvh; max-height: none;
    z-index: 900; border-radius: 16px 16px 0 0;
    transform: translateY(100%); transition: transform .22s ease;
  }
  .preview-panel.is-open { transform: translateY(0); }
  .preview-drawer-close { display: inline-flex; }
}

@media (prefers-reduced-motion: reduce) {
  .preview-panel, .drawer-backdrop { transition: none; }
}

/* =========================================================================
   Modal de alta rápida -- componente COMPARTIDO: lo usan /archivos/subir/
   (cliente y clase de archivo) y el formulario de cliente (clase de cliente
   y tipo de actividad). Vivía en upload_page.css, que solo carga la página
   de subida; al usarse en dos sitios pasa aquí. Lo maneja
   files/static/files/js/quick_create_modals.js
   ========================================================================= */
/* --- Select + botón "+ Nuevo" en la misma fila --- */
.field-with-action {
    display: flex;
    align-items: center;
    gap: 8px;
}

.field-with-action select,
.field-with-action .hf-combo {
    flex: 1;
    min-width: 0;
}

.field-with-action .btn-sm {
    flex-shrink: 0;
    white-space: nowrap;
}

/* --- Modal genérico (alta rápida de Cliente / Clase de archivo) ---
   .hidden es la fuente de verdad del estado oculto (display:none). Cuando
   se abre, se quita .hidden y en el frame SIGUIENTE se agrega .is-open --
   ese segundo paso es lo que dispara la transición de opacity/transform en
   vez de aparecer de golpe (ver openModal() en quick_create_modals.js). */
.modal-overlay {
    position: fixed;
    inset: 0;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
    background: rgba(0, 0, 0, .5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    transition: opacity .16s ease;
}

.modal-overlay.hidden {
    display: none;
}

.modal-overlay.is-open {
    opacity: 1;
}

/* --- Modales apilados ---------------------------------------------------
   data-stack-depth lo escribe openModal() según la posición en su pila. Sin
   esto, todos los overlays valían z-index:1000 y quién quedaba encima
   dependía del orden de los {% include %} en la plantilla.

   Solo hay dos niveles definidos a propósito: el dominio tiene exactamente
   dos (catálogo dentro de cliente dentro de la página). openModal() TOPA el
   atributo en el máximo definido aquí en vez de emitir un ="3", que caería al
   1000 base y volvería a pintar por orden del DOM. */
.modal-overlay[data-stack-depth="1"] { z-index: 1010; }
.modal-overlay[data-stack-depth="2"] { z-index: 1020; }

/* Dos velos al 50% superpuestos componen ~75% de negro y el modal de abajo
   queda casi invisible. rgba() en crudo y no un token: es un velo, no un
   color del tema (mismo criterio que el .modal-overlay de arriba). */
.modal-overlay[data-stack-depth="1"],
.modal-overlay[data-stack-depth="2"] {
    background: rgba(0, 0, 0, .32);
}

.modal-content {
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transform: translateY(10px) scale(.97);
    transition: transform .16s ease;
}

.modal-overlay.is-open .modal-content {
    transform: translateY(0) scale(1);
}

@media (prefers-reduced-motion: reduce) {
    .modal-overlay, .modal-content {
        transition: none;
    }
}

.hf-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--line);
}

.hf-modal-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
}

.hf-modal-close {
    border: none;
    background: none;
    color: var(--muted);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
}

.hf-modal-close:hover {
    color: var(--ink);
}

.hf-modal-body {
    padding: 20px 22px 22px;
}

.hf-modal-errors:not([hidden]) {
    margin: 0 0 14px;
    padding-left: 18px;
}

/* Enlace "Gestionar catálogos" del pie del modal. Abre en pestaña nueva a
   propósito (ver el partial): se pulsa con el formulario padre a medio
   llenar, y navegar en la misma pestaña lo perdería. */
.hf-modal-footer {
    margin: 16px 0 0;
    padding-top: 14px;
    border-top: 1px solid var(--line2);
    font-size: 12px;
}

.hf-modal-footer a { color: var(--brand-ink); }

/* =========================================================================
   Escala de z-index -- toda junta a propósito: repartida por componentes ya
   se dio el caso de dos overlays con el mismo valor donde quién quedaba
   encima dependía del orden del {% include %}.

     890   .drawer-backdrop        (drawer móvil de /archivos/)
     900   .preview-panel          (drawer móvil de /archivos/)
    1000   .modal-overlay          (base)
    1010   .modal-overlay[data-stack-depth="1"]   modal abierto DESDE otro
    1020   .modal-overlay[data-stack-depth="2"]
    1050   .hf-combo-list          (lista del select con búsqueda: es hija de
                                   <body> porque .modal-content la recortaría
                                   -- overflow-y + transform)
    1100   .hf-toasts              (siempre visible, incluso sobre un modal)
   ========================================================================= */

/* =========================================================================
   Select con búsqueda (combobox) -- files/static/files/js/hf_searchable_select.js
   El <select> nativo NO se elimina ni se oculta con display:none: se queda
   con .hf-sr-only como fuente de verdad del valor (los POST no cambian y la
   página degrada sin JS). Ver la nota de .hf-sr-only más arriba.
   ========================================================================= */
.hf-combo { position: relative; display: flex; }

/* El input hereda borde, alto y anillo de foco de .form-field input. Solo
   hace falta hueco a la derecha para que el texto no pase bajo el caret. */
.form-field .hf-combo-input { width: 100%; padding-right: 30px; }

/* Caret en CSS y no un SVG inyectado: construir SVG exige createElementNS y
   en este proyecto innerHTML no se usa. */
.hf-combo::after {
    content: "";
    position: absolute;
    right: 13px;
    top: 50%;
    width: 7px;
    height: 7px;
    margin-top: -5px;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    transform: rotate(45deg);
    pointer-events: none;
    transition: transform .12s ease;
}

.hf-combo[data-expanded="true"]::after {
    margin-top: -2px;
    transform: rotate(225deg);
}

/* Hija de <body> y position:fixed por obligación, no por gusto:
   .modal-content tiene overflow-y:auto (la recortaría) Y transform en estado
   abierto, y un transform distinto de none convierte al elemento en
   containing block de sus descendientes position:fixed. Dentro de un modal
   no hay otra opción que funcione, y fuera se comporta igual. */
.hf-combo-list {
    position: fixed;
    z-index: 1050;
    margin: 0;
    padding: 4px;
    list-style: none;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    box-shadow: var(--shadow);
    font-size: 13.5px;
    color: var(--ink);
}

/* Sin transición a propósito: abre y cierra al instante, lo que ahorra a este
   componente todo el trabajo de transitionend y prefers-reduced-motion. */
.hf-combo-option {
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* El foco NUNCA entra en la lista (eso es lo que compra aria-activedescendant),
   así que la opción "activa" se marca con una clase, no con :focus. */
.hf-combo-option.is-active { background: var(--brand-soft); color: var(--brand-ink); }
.hf-combo-option[aria-selected="true"] { font-weight: 600; }
.hf-combo-option.is-active[aria-selected="true"] { color: var(--brand-ink); }
.hf-combo-empty { padding: 8px 10px; color: var(--faint); }

/* =========================================================================
   Toasts -- files/static/files/js/hf_toast.js
   Misma paleta que los flash messages del servidor (.message-*, más arriba)
   para que un aviso de cliente y uno de servidor se lean como el mismo
   objeto. La división: `messages` es el canal del servidor tras una
   navegación; HFToast, el del cliente cuando no la hubo.
   ========================================================================= */
.hf-toasts {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 380px;
    /* El contenedor vacío no debe comerse los clics de la página que hay
       debajo; cada toast reactiva los suyos. */
    pointer-events: none;
}

.hf-toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 13px;
    line-height: 1.45;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .16s ease, transform .16s ease;
}

.hf-toast.is-open { opacity: 1; transform: translateY(0); }

.hf-toast-success { background: var(--green-soft); color: var(--green); }
.hf-toast-error   { background: var(--red-soft);   color: var(--red); }
.hf-toast-warning { background: var(--warn-soft);  color: var(--warn); }
.hf-toast-info    { background: var(--blue-soft);  color: var(--blue); }

.hf-toast-message { flex: 1; min-width: 0; }

.hf-toast-close {
    flex-shrink: 0;
    border: none;
    background: none;
    color: inherit;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    opacity: .7;
}

.hf-toast-close:hover { opacity: 1; }

@media (max-width: 600px) {
    .hf-toasts { left: 16px; right: 16px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
    .hf-toast { transition: none; }
    .hf-combo::after { transition: none; }
}
