/* ==========================================================================
   Sistema de Legajos IHQ — estilos de la interfaz
   Identidad: superficies oscuras escalonadas, acento dorado institucional,
   Hanken Grotesk en títulos e Inter en texto y controles (alojadas en /fonts).
   Criterios: medidas en rem, respuesta inmediata al presionar, movimiento solo
   en transform/opacity y alternativas para quien reduce movimiento,
   transparencia o pide más contraste.
   ========================================================================== */

@font-face {
  font-family: "Hanken Grotesk";
  font-style: normal;
  font-weight: 600 800;
  font-display: swap;
  src: url("/fonts/hanken-grotesk-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/fonts/inter-latin.woff2") format("woff2");
}

:root {
  color-scheme: dark;

  /* Superficies: de la más profunda a la más elevada */
  --surface-lowest: #0d0f0f;
  --bg: #121414;
  --surface-low: #1a1c1c;
  --surface: #1e2020;
  --surface-high: #282a2a;
  --surface-highest: #333535;
  --surface-bright: #3d3f3f;

  /* Acento institucional */
  --gold: #f6de59;
  --gold-hover: #e2c642;
  --gold-dim: #dec744;
  --on-gold: #211b00;
  --gold-soft: rgba(246, 222, 89, 0.12);

  /* Texto */
  --text-strong: #fff9f0;
  --text: #e2e2e2;
  --text-muted: #cdc6af;
  --text-subtle: #a39d88;
  --brass: #97917c;

  /* Bordes */
  --border: #2f3131;
  --border-strong: #4b4735;

  /* Estados */
  --danger: #ffb4ab;
  --danger-strong: #ff8a7d;
  --danger-bg: rgba(147, 0, 10, 0.32);
  --success: #a8d5a2;
  --success-bg: rgba(74, 124, 68, 0.28);
  --info: #cbc6bd;

  --font-head: "Hanken Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --radius-xs: 0.375rem;
  --radius-sm: 0.5rem;
  --radius: 0.75rem;
  --radius-lg: 1rem;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 24px 48px -20px rgba(0, 0, 0, 0.75);
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--gold);

  --sidebar-w: 17.5rem;
  --topbar-h: 4.5rem;
  --content-max: 82rem;
  --gutter: 2.5rem;

  /* Salida rápida y sin rebote */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.64, 0, 0.78, 0);
  --dur-press: 100ms;
  --dur-state: 160ms;
  --dur-enter: 280ms;
}

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

html { font-size: 100%; -webkit-text-size-adjust: 100%; }

body {
  font: 400 0.9375rem/1.55 var(--font-body);
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
::selection { background: #a89000; color: #1a1600; }

input, select, textarea, button { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }

a { color: var(--gold); text-decoration: none; }
@media (hover: hover) { a:hover { text-decoration: underline; text-underline-offset: 0.2em; } }

/* --- Iconos (sprite SVG en /img/icons.svg) --- */
.icon { display: inline-block; flex-shrink: 0; width: 1.25rem; height: 1.25rem; fill: currentColor; vertical-align: middle; }
.icon-sm { width: 1rem; height: 1rem; }
.icon-lg { width: 1.5rem; height: 1.5rem; }

/* --- Tipografía --- */
h1, h2, h3, h4 { font-family: var(--font-head); color: var(--text-strong); }
h1 { font-size: 2rem; line-height: 1.15; letter-spacing: -0.02em; font-weight: 700; }
h2 { font-size: 1.375rem; line-height: 1.25; letter-spacing: -0.012em; font-weight: 700; }
h3 { font-size: 1.0625rem; line-height: 1.3; letter-spacing: -0.006em; font-weight: 700; }
p { max-width: 75ch; }
strong { font-weight: 600; color: var(--text-strong); }
.hint { display: block; color: var(--text-subtle); font-size: 0.8125rem; line-height: 1.45; margin-top: 0.35rem; font-weight: 400; }
.hint a { font-weight: 500; }
.muted { color: var(--text-subtle); }
.mono { font-family: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, monospace; font-size: 0.8125rem; letter-spacing: 0.01em; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--gold);
}
.eyebrow-dot { width: 0.375rem; height: 0.375rem; border-radius: 50%; background: var(--gold); }
.chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.25rem 0.6rem; border-radius: var(--radius-xs);
  background: var(--surface-highest); color: var(--gold);
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.02em; white-space: nowrap;
}
.chip-solid { background: #a89000; color: #1a1600; text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.6875rem; font-weight: 700; }
.header-meta { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

/* ==========================================================================
   Estructura: barra lateral + barra superior + contenido
   ========================================================================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
}

/* --- Barra lateral --- */
.sidebar {
  grid-row: 1 / -1;
  grid-column: 1;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.5rem 1rem;
  background: var(--surface-lowest);
  border-right: 1px solid #1c1e1e;
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 0.75rem; padding: 0 0.5rem; color: inherit; text-decoration: none; border-radius: var(--radius-sm); }
@media (hover: hover) { .brand:hover { text-decoration: none; } }
.brand-mark {
  display: grid; place-items: center; flex-shrink: 0;
  width: 2.75rem; height: 2.75rem; border-radius: var(--radius-sm);
  background: var(--surface-highest); color: var(--gold);
}
.brand-mark .icon { width: 1.625rem; height: 1.625rem; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-family: var(--font-head); font-size: 1.125rem; font-weight: 700; line-height: 1.15; letter-spacing: -0.01em; color: var(--text-strong); }
.brand-sub { margin-top: 0.3rem; font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--brass); }

.sidebar-sep { height: 1px; margin: 0 0.5rem; background: rgba(51, 53, 53, 0.6); }
.nav-label { padding: 0 1rem; margin: 0.75rem 0 0.35rem; font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--brass); }
.nav-label:first-child { margin-top: 0; }

.sidebar nav { display: flex; flex-direction: column; gap: 0.25rem; }
.nav-link {
  display: flex; align-items: center; gap: 0.75rem;
  min-height: 2.75rem; padding: 0.65rem 1rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.875rem; font-weight: 600; letter-spacing: 0.01em;
  text-decoration: none;
  transition: background-color var(--dur-state) var(--ease-out), color var(--dur-state) var(--ease-out), transform var(--dur-press) ease-out;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.nav-link .icon { color: var(--brass); transition: color var(--dur-state) var(--ease-out); }
@media (hover: hover) {
  .nav-link:hover { background: var(--surface-high); color: var(--text-strong); text-decoration: none; }
  .nav-link:hover .icon { color: var(--gold); }
}
.nav-link:active { transform: scale(0.98); }
.nav-link.active { background: var(--gold); color: var(--on-gold); font-weight: 700; box-shadow: var(--shadow-sm); }
.nav-link.active .icon { color: var(--on-gold); }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 0.75rem; }
.cycle-card { padding: 0.9rem 1rem; border-radius: var(--radius); background: var(--surface-low); }
.cycle-card .eyebrow-dot { animation: pulse 2.4s ease-in-out infinite; }
.cycle-card p { margin-top: 0.35rem; font-size: 0.8125rem; color: var(--text-subtle); }
.sidebar-copy { padding: 0 0.5rem; font-size: 0.75rem; color: var(--brass); }
@keyframes pulse { 50% { opacity: 0.35; } }

/* --- Barra superior --- */
.topbar {
  grid-column: 2;
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  height: var(--topbar-h);
  padding: 0 var(--gutter);
  background: rgba(18, 20, 20, 0.86);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  backdrop-filter: saturate(160%) blur(16px);
  transition: box-shadow var(--dur-state) var(--ease-out);
}
.topbar.is-stuck { box-shadow: 0 1px 0 var(--border), 0 10px 24px -18px rgba(0, 0, 0, 0.9); }

.topbar .nav-toggle { display: none; }

.topbar-search { position: relative; flex: 1; max-width: 36rem; }
.topbar-search .icon { position: absolute; left: 0.9rem; top: 50%; transform: translateY(-50%); color: var(--text-subtle); pointer-events: none; }
.topbar-search input { padding-left: 2.75rem; background: var(--surface-low); border-color: transparent; border-radius: var(--radius); }
@media (hover: hover) { .topbar-search input:hover { border-color: var(--border-strong); } }

.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }
.topbar-divider { width: 1px; height: 2rem; background: rgba(51, 53, 53, 0.7); }
.user-meta { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; min-width: 0; }
.user-name { font-size: 0.875rem; font-weight: 700; color: var(--text-strong); max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { margin-top: 0.15rem; font-size: 0.75rem; font-weight: 500; color: var(--gold); }
.avatar {
  display: grid; place-items: center; flex-shrink: 0;
  width: 2.25rem; height: 2.25rem; border-radius: 50%;
  background: var(--surface-highest); color: var(--gold);
  font-family: var(--font-head); font-weight: 700; font-size: 0.875rem; text-transform: uppercase;
}

.icon-btn {
  display: inline-grid; place-items: center; flex-shrink: 0;
  width: 2.5rem; height: 2.5rem;
  border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted);
  cursor: pointer;
  transition: background-color var(--dur-state) var(--ease-out), color var(--dur-state) var(--ease-out), transform var(--dur-press) ease-out;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
@media (hover: hover) { .icon-btn:hover { background: var(--surface-high); color: var(--text-strong); } }
.icon-btn:active { transform: scale(0.94); }
.logout-form { display: contents; }

/* --- Contenido --- */
.content {
  grid-column: 2;
  min-width: 0;
  width: 100%;
  max-width: calc(var(--content-max) + 2 * var(--gutter));
  padding: 1.75rem var(--gutter) 4rem;
}

/* Encabezado de cada página: título, contexto y acciones principales */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1.25rem 2rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}
.header-text { display: flex; flex-direction: column; gap: 0.6rem; min-width: 0; max-width: 48rem; }
.header p { color: var(--text-muted); font-size: 1rem; }
.header h1 .badge { margin-left: 0.5rem; vertical-align: 0.35em; }

/* --- Ruta de ubicación --- */
.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; font-size: 0.8125rem; color: var(--text-subtle); margin-bottom: 1rem; }
.breadcrumbs a { color: var(--text-muted); border-radius: 4px; }
@media (hover: hover) { .breadcrumbs a:hover { color: var(--gold); } }
.breadcrumbs [aria-current="page"] { color: var(--text-strong); font-weight: 500; }
.breadcrumbs-sep { color: var(--brass); }

/* ==========================================================================
   Tarjetas e indicadores
   ========================================================================== */
.card, .form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-sm);
}
.form-card { max-width: 60rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.card-head h2, .card-head h3 { display: flex; align-items: center; gap: 0.6rem; }
.card-head > h2 > .icon, .card-head > h3 > .icon { color: var(--gold); }
.section { margin-bottom: 1.5rem; }
.section-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.kpi-card {
  position: relative;
  overflow: hidden;
  display: flex; flex-direction: column; gap: 0.75rem;
  padding: 1.25rem 1.35rem;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.kpi-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.kpi-card h3 { font-family: var(--font-body); font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--brass); }
.kpi-icon { display: grid; place-items: center; flex-shrink: 0; width: 2.25rem; height: 2.25rem; border-radius: var(--radius-sm); background: var(--surface-highest); color: var(--gold); }
.kpi-card .number { font-family: var(--font-head); font-size: 2.25rem; line-height: 1; letter-spacing: -0.02em; font-weight: 800; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.kpi-card .number.number-sm { font-size: 1.25rem; line-height: 1.3; letter-spacing: -0.01em; font-weight: 700; }
.kpi-card .number.is-accent { color: var(--gold); }
.kpi-foot { font-size: 0.8125rem; color: var(--text-subtle); }
.kpi-watermark { position: absolute; right: -1rem; bottom: -1.25rem; width: 7rem; height: 7rem; color: var(--text-strong); opacity: 0.035; pointer-events: none; }
.meter { height: 0.375rem; border-radius: 999px; background: var(--surface-lowest); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--gold); }

/* Accesos rápidos del panel */
.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 0.75rem; }
.quick-link {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--surface-low);
  border: 1px solid transparent;
  color: var(--text);
  text-decoration: none;
  transition: background-color var(--dur-state) var(--ease-out), border-color var(--dur-state) var(--ease-out), transform var(--dur-press) ease-out;
}
.quick-link strong { display: block; font-size: 0.9375rem; }
.quick-link .hint { margin-top: 0.15rem; }
.quick-link > .icon:last-child { margin-left: auto; color: var(--brass); }
@media (hover: hover) {
  .quick-link:hover { background: var(--surface-high); border-color: var(--border-strong); text-decoration: none; }
  .quick-link:hover > .icon:last-child { color: var(--gold); }
}
.quick-link:active { transform: scale(0.99); }

.dash-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.info-list { display: flex; flex-direction: column; gap: 0.5rem; }
.info-item { display: flex; align-items: flex-start; gap: 0.75rem; padding: 0.75rem; border-radius: var(--radius-sm); background: var(--surface-low); font-size: 0.8125rem; color: var(--text-subtle); }
.info-item > .icon { color: var(--gold); margin-top: 0.1rem; }
.info-item strong { display: block; font-size: 0.875rem; }

/* ==========================================================================
   Formularios
   ========================================================================== */
.form-stack { display: flex; flex-direction: column; gap: 1.25rem; max-width: 60rem; }
.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.form-section-head {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 1.1rem 1.5rem;
  background: var(--surface-high);
  border-bottom: 1px solid var(--border);
}
.form-section-head h2 { font-size: 1.0625rem; }
.form-section-head p { margin-top: 0.15rem; font-size: 0.8125rem; color: var(--text-subtle); }
.step-num { font-family: var(--font-head); color: var(--gold); margin-right: 0.35rem; }
.form-section-body { padding: 1.5rem; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem 1.5rem; }
.form-grid > h3 { padding-top: 0.5rem; }
.full-width { grid-column: 1 / -1; }
.field-row { display: flex; gap: 0.5rem; }
.field-row > * { min-width: 0; }
.field-row .w-sm { flex: 0 0 34%; }
.field-row .w-md { flex: 0 0 42%; }
.field-row .grow { flex: 1; }

label { display: block; margin-bottom: 0.45rem; font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.01em; color: var(--text-muted); }
.req { color: var(--gold); margin-left: 0.15rem; font-weight: 700; }
.form-legend { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8125rem; color: var(--text-subtle); }

input, select, textarea {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-low);
  color: var(--text-strong);
  font-size: 0.9375rem;
  line-height: 1.4;
  transition: border-color var(--dur-state) var(--ease-out), box-shadow var(--dur-state) var(--ease-out), background-color var(--dur-state) var(--ease-out);
}
textarea { min-height: 6rem; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--brass); opacity: 1; }
@media (hover: hover) {
  input:hover, select:hover, textarea:hover { border-color: #6a6450; }
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--gold);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(246, 222, 89, 0.18);
}
input[readonly] { background: var(--surface-lowest); color: var(--text-subtle); border-style: dashed; }

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2.5rem;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 -960 960 960' fill='%23cdc6af'%3E%3Cpath d='M480-345 240-585l43-43 197 198 197-197 43 43-240 239Z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 1.25rem;
}
select option { background: var(--surface); color: var(--text); }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.85) sepia(0.3); cursor: pointer; }
input[type="number"] { font-variant-numeric: tabular-nums; }

/* Casilla de verificación como fila completa clicable */
input[type="checkbox"] { width: 1.125rem; height: 1.125rem; min-height: 0; margin: 0; padding: 0; flex-shrink: 0; accent-color: var(--gold); cursor: pointer; }
.check-row {
  display: flex; align-items: flex-start; gap: 0.75rem;
  margin: 0; padding: 0.9rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface-low);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.875rem; font-weight: 500; line-height: 1.45;
  cursor: pointer;
}
.check-row input { margin-top: 0.1rem; }

/* Carga de archivos: zona punteada con botón propio */
input[type="file"] {
  min-height: 3.25rem;
  padding: 0.55rem;
  border: 1px dashed var(--border-strong);
  background: var(--surface-low);
  color: var(--text-subtle);
  font-size: 0.8125rem;
  cursor: pointer;
}
input[type="file"]::file-selector-button {
  margin-right: 0.85rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--surface-highest);
  color: var(--text-strong);
  font: 600 0.8125rem/1.2 var(--font-body);
  cursor: pointer;
  transition: background-color var(--dur-state) var(--ease-out), color var(--dur-state) var(--ease-out);
}
@media (hover: hover) {
  input[type="file"]:hover { border-color: var(--gold-dim); }
  input[type="file"]:hover::file-selector-button { background: var(--gold); color: var(--on-gold); border-color: var(--gold); }
}
.file-field { padding: 1rem; border-radius: var(--radius); background: var(--surface-low); border: 1px solid var(--border); }
.file-field label { display: flex; align-items: center; gap: 0.5rem; color: var(--text-strong); }
.file-field label .icon { color: var(--gold); }
.file-field input[type="file"] { background: var(--surface); }
.file-list { list-style: none; display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.6rem; }
.file-list li { display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.6rem; border-radius: var(--radius-xs); background: var(--surface-high); font-size: 0.8125rem; color: var(--text); }
.file-list li .icon { color: var(--gold); }
.file-list .file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .file-size { color: var(--text-subtle); font-variant-numeric: tabular-nums; }
.file-list li.is-invalid { background: var(--danger-bg); color: var(--danger); }
.file-list li.is-invalid .icon, .file-list li.is-invalid .file-size { color: var(--danger); }
.notice {
  display: flex; align-items: flex-start; gap: 0.75rem;
  max-width: none;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--gold-soft);
  border: 1px solid rgba(246, 222, 89, 0.22);
  color: var(--text);
  font-size: 0.8125rem; line-height: 1.5;
}
.notice > .icon { color: var(--gold); margin-top: 0.05rem; }

/* Errores de validación junto al campo */
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger-strong); }
input[aria-invalid="true"]:focus-visible, select[aria-invalid="true"]:focus-visible, textarea[aria-invalid="true"]:focus-visible { box-shadow: 0 0 0 3px rgba(255, 138, 125, 0.25); }
.field-error { display: flex; align-items: center; gap: 0.35rem; color: var(--danger); font-size: 0.8125rem; line-height: 1.35; margin-top: 0.4rem; font-weight: 500; animation: field-error-in var(--dur-enter) var(--ease-out); }
.field-error::before { content: "!"; display: inline-grid; place-items: center; flex-shrink: 0; width: 1rem; height: 1rem; border-radius: 50%; background: var(--danger-strong); color: #2b0000; font-size: 0.6875rem; font-weight: 800; }
.field-error[hidden] { display: none; }
@keyframes field-error-in { from { opacity: 0; transform: translateY(-3px); } }

/* Barra de acciones del formulario */
.form-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 1.1rem 1.5rem;
  border-radius: var(--radius-lg);
  background: var(--surface-high);
  border: 1px solid var(--border);
}
.form-actions .actions { margin-left: auto; gap: 0.75rem; }
.form-card .form-actions { margin-top: 0.5rem; padding: 1.1rem 0 0; background: none; border: none; border-top: 1px solid var(--border); border-radius: 0; }

/* ==========================================================================
   Botones
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.625rem 1.2rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--gold);
  color: var(--on-gold);
  font: 700 0.875rem/1.2 var(--font-body);
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 6px 16px -8px rgba(246, 222, 89, 0.45);
  transition: transform var(--dur-press) ease-out, background-color var(--dur-state) var(--ease-out), border-color var(--dur-state) var(--ease-out), color var(--dur-state) var(--ease-out), opacity var(--dur-state) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn-secondary { background: var(--surface-highest); color: var(--text-strong); border-color: #3f4141; box-shadow: none; }
.btn-secondary .icon { color: var(--gold); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border-strong); box-shadow: none; }
.btn-danger { background: transparent; color: var(--danger); border-color: rgba(255, 180, 171, 0.45); box-shadow: none; }
@media (hover: hover) {
  .btn:hover { background: var(--gold-hover); text-decoration: none; }
  .btn-secondary:hover { background: var(--surface-bright); border-color: #4f5151; }
  .btn-ghost:hover { background: var(--surface-high); color: var(--text-strong); }
  .btn-danger:hover { background: var(--danger-bg); color: #ffd7d1; border-color: var(--danger); }
}
.btn-sm { min-height: 2.125rem; padding: 0.4rem 0.75rem; font-size: 0.8125rem; gap: 0.35rem; }
.btn-sm .icon { width: 1rem; height: 1rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }
.btn[aria-busy="true"] { cursor: progress; opacity: 0.85; }
.btn[aria-busy="true"]::before {
  content: "";
  width: 0.9rem; height: 0.9rem;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

a:focus-visible, button:focus-visible, summary:focus-visible { outline: none; box-shadow: var(--focus-ring); }
input[type="checkbox"]:focus-visible, input[type="file"]:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.actions form { display: inline-flex; }
.inline-form { display: flex; gap: 0.5rem; align-items: center; }

/* ==========================================================================
   Etiquetas de estado
   ========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: var(--surface-highest);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.06em; line-height: 1.3;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge::before { content: ""; width: 0.375rem; height: 0.375rem; border-radius: 50%; background: currentColor; }
.badge-activo, .badge-active { color: var(--gold); }
.badge-inactivo { color: var(--brass); background: var(--surface-high); }
.badge-egresado { color: var(--info); }
.badge-licencia { color: var(--gold-hover); background: rgba(168, 144, 0, 0.22); }
.badge-role-admin { background: #a89000; color: #1a1600; }
.badge-role-admin::before { background: #1a1600; }
.badge-role-docente { color: var(--text-strong); }

/* ==========================================================================
   Avisos en página y flotantes
   ========================================================================== */
.alert {
  display: flex; align-items: flex-start; gap: 0.6rem;
  max-width: 60rem;
  margin-bottom: 1.25rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem; font-weight: 500;
}
.alert::before { flex-shrink: 0; display: grid; place-items: center; width: 1.25rem; height: 1.25rem; border-radius: 50%; font-size: 0.75rem; font-weight: 800; }
.alert-error { background: var(--danger-bg); color: #ffdad6; border: 1px solid rgba(255, 138, 125, 0.45); }
.alert-error::before { content: "!"; background: var(--danger-strong); color: #2b0000; }
.alert-success { background: var(--success-bg); color: #dcf3d8; border: 1px solid rgba(168, 213, 162, 0.4); }
.alert-success::before { content: "✓"; background: var(--success); color: #0e2a0b; }

.toast-region { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 100; display: flex; flex-direction: column; gap: 0.5rem; pointer-events: none; }
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 0.75rem;
  max-width: 24rem;
  padding: 0.85rem 0.85rem 0.85rem 1rem;
  border-radius: var(--radius);
  background: rgba(40, 42, 42, 0.92);
  border: 1px solid #3f4141;
  color: var(--text-strong);
  -webkit-backdrop-filter: saturate(160%) blur(20px);
  backdrop-filter: saturate(160%) blur(20px);
  box-shadow: var(--shadow-lg);
  transform-origin: bottom right;
  animation: toast-in var(--dur-enter) var(--ease-out) both;
}
.toast.is-leaving { animation: toast-out 200ms var(--ease-in) both; }
.toast-error { background: rgba(80, 10, 10, 0.94); border-color: rgba(255, 138, 125, 0.5); }
.toast-icon { flex-shrink: 0; display: grid; place-items: center; width: 1.375rem; height: 1.375rem; border-radius: 50%; background: var(--gold); color: var(--on-gold); font-size: 0.8125rem; font-weight: 800; }
.toast-error .toast-icon { background: var(--danger-strong); color: #2b0000; }
.toast-message { font-size: 0.875rem; font-weight: 500; line-height: 1.45; padding-top: 0.05rem; }
.toast-close { flex-shrink: 0; margin-left: auto; width: 1.75rem; height: 1.75rem; border: none; border-radius: 50%; background: rgba(255, 255, 255, 0.08); color: var(--text-strong); cursor: pointer; font-size: 1.1rem; line-height: 1; transition: background-color var(--dur-state), transform var(--dur-press) ease-out; touch-action: manipulation; }
.toast-close:active { transform: scale(0.92); }
@media (hover: hover) { .toast-close:hover { background: rgba(255, 255, 255, 0.18); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(0.75rem) scale(0.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(0.75rem) scale(0.98); } }

/* ==========================================================================
   Tablas
   ========================================================================== */
.table-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}
.table-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 1rem 1.5rem;
  background: var(--surface-high);
}
.table-head h2 { font-size: 1.125rem; display: flex; align-items: center; gap: 0.6rem; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 0.875rem; }
th, td { padding: 0.85rem 1rem; vertical-align: middle; }
th:first-child, td:first-child { padding-left: 1.5rem; }
th:last-child, td:last-child { padding-right: 1.5rem; }
th {
  background: rgba(51, 53, 53, 0.55);
  color: var(--text-muted);
  font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  white-space: nowrap;
}
.align-end { text-align: right; }
td.align-end .actions { justify-content: flex-end; }
td { border-top: 1px solid var(--border); color: var(--text); }
tbody tr { transition: background-color var(--dur-state) var(--ease-out); }
@media (hover: hover) { tbody tr:hover { background: rgba(40, 42, 42, 0.6); } }
.cell-main { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.cell-main strong { font-size: 0.9375rem; }
.cell-sub { font-size: 0.75rem; color: var(--text-subtle); }
.cell-code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.8125rem; color: var(--gold); white-space: nowrap; }
.person { display: flex; align-items: center; gap: 0.75rem; min-width: 12rem; }
.person .avatar { width: 2.5rem; height: 2.5rem; }
td.empty-state { padding: 3rem 1.5rem; text-align: center; }
.empty-state > .icon { width: 2.5rem; height: 2.5rem; margin: 0 auto 0.75rem; color: var(--brass); }
.empty-state strong { display: block; margin-bottom: 0.25rem; }
.empty-state p { margin: 0 auto; color: var(--text-subtle); }
.table-foot { padding: 0.85rem 1.5rem; background: var(--surface-low); border-top: 1px solid var(--border); font-size: 0.8125rem; color: var(--text-subtle); }
.card .table-container { box-shadow: none; }

/* --- Barra de filtros --- */
.filter-bar {
  margin-bottom: 1.5rem;
  padding: 1rem;
  border-radius: var(--radius-lg);
  background: var(--surface-low);
  border: 1px solid var(--border);
}
.filter-grid { display: grid; grid-template-columns: minmax(0, 2fr) repeat(2, minmax(0, 1fr)) auto; gap: 0.75rem; align-items: end; }
.filter-grid label { font-size: 0.75rem; }
.filter-grid input, .filter-grid select { background: var(--surface); }
.search-field { position: relative; }
.search-field .icon { position: absolute; left: 0.85rem; bottom: 0.75rem; color: var(--text-subtle); pointer-events: none; }
.search-field input { padding-left: 2.6rem; }

/* ==========================================================================
   Ficha del estudiante
   ========================================================================== */
.data-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; font-size: 0.9375rem; }
.data-grid > div { padding: 0.85rem 1rem; border-radius: var(--radius-sm); background: var(--surface-low); min-width: 0; }
.data-grid > .full-width { grid-column: 1 / -1; }
.data-grid dt { font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--brass); margin-bottom: 0.3rem; }
.data-grid dd { color: var(--text-strong); overflow-wrap: anywhere; }
.data-grid dd .muted { font-size: 0.8125rem; }
.upload-form {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, 1.6fr) auto; gap: 0.75rem; align-items: end;
  margin-top: 1.25rem; padding: 1.25rem; border-radius: var(--radius); background: var(--surface-low); border: 1px dashed var(--border-strong);
}
.upload-form input, .upload-form select { background: var(--surface); }
.report-content { white-space: pre-wrap; margin-top: 0.5rem; padding: 0.75rem; border-radius: var(--radius-sm); background: var(--surface-low); font-size: 0.8125rem; color: var(--text); }
details summary { cursor: pointer; display: inline-block; border-radius: 4px; }
details summary.hint { color: var(--gold); }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.5rem; align-items: start; }

/* --- Firma: el recuadro es un papel claro para que el trazo se vea como en la versión impresa --- */
.signature-container {
  padding: 1.25rem;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-low);
  text-align: center;
  transition: border-color var(--dur-state) var(--ease-out), background-color var(--dur-state) var(--ease-out);
}
.signature-container.is-signing { border-color: var(--gold); background: var(--gold-soft); }
.signature-container > label { text-align: left; }
#signatureCanvas {
  display: block;
  margin: 0 auto;
  width: 100%;
  max-width: 31.25rem;
  height: auto;
  aspect-ratio: 500 / 160;
  background: #fbfaf6;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: crosshair;
  touch-action: none;
}
.signature-actions { display: flex; gap: 0.5rem; justify-content: center; margin-top: 0.75rem; }
.signature-preview { max-width: 16.25rem; max-height: 5.6rem; padding: 0.25rem; background: #fbfaf6; border-radius: var(--radius-xs); }
.signature-current { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; margin-bottom: 1rem; }
.signature-current .hint { text-align: center; }

/* ==========================================================================
   Acceso y página de error (sin barra lateral)
   ========================================================================== */
.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1.5rem 1rem;
  background:
    radial-gradient(60rem 30rem at 85% -10%, rgba(246, 222, 89, 0.08), transparent 60%),
    radial-gradient(40rem 30rem at -10% 110%, rgba(168, 144, 0, 0.08), transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 27rem;
  padding: 2.25rem 2rem;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}
.auth-card .brand { justify-content: center; padding: 0; margin-bottom: 1.75rem; }
.auth-card h1 { font-size: 1.5rem; text-align: center; }
.auth-card .subtitle { text-align: center; color: var(--text-subtle); margin: 0.4rem auto 1.75rem; font-size: 0.9375rem; }
.auth-card .field { margin-bottom: 1.1rem; }
.auth-card .btn { width: 100%; margin-top: 0.5rem; }
.auth-card .alert { margin-bottom: 1.25rem; }
.auth-foot { margin-top: 1.5rem; text-align: center; font-size: 0.75rem; color: var(--brass); max-width: none; }
.error-card { text-align: center; }
.error-card .kpi-icon { width: 3.5rem; height: 3.5rem; margin: 0 auto 1.25rem; color: var(--danger); }
.error-card .kpi-icon .icon { width: 2rem; height: 2rem; }
.error-card p { margin: 0.75rem auto 1.75rem; color: var(--text-muted); }

/* ==========================================================================
   Adaptación a pantallas
   ========================================================================== */
@media (max-width: 75rem) {
  .dash-grid, .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .upload-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

@media (max-width: 64rem) {
  :root { --gutter: 1.25rem; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .topbar, .content { grid-column: 1; }
  .topbar .nav-toggle { display: inline-grid; margin-left: -0.5rem; }
  .user-meta { display: none; }

  /* Con JavaScript la barra lateral es un panel deslizable */
  .js .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(var(--sidebar-w), 86vw);
    transform: translateX(-100%);
    visibility: hidden;
    box-shadow: var(--shadow-lg);
    transition: transform var(--dur-enter) var(--ease-out), visibility 0s linear var(--dur-enter);
  }
  .js .nav-open .sidebar { transform: none; visibility: visible; transition: transform var(--dur-enter) var(--ease-out); }
  .nav-backdrop { position: fixed; inset: 0; z-index: 45; border: none; background: rgba(0, 0, 0, 0.55); opacity: 0; pointer-events: none; transition: opacity var(--dur-enter) var(--ease-out); }
  .nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  .nav-open { overflow: hidden; }

  /* Sin JavaScript la navegación queda arriba, siempre visible */
  html:not(.js) .sidebar { position: static; grid-row: auto; height: auto; }
  html:not(.js) .topbar .nav-toggle { display: none; }
}
@media (min-width: 64.0625rem) { .nav-backdrop { display: none; } }

@media (max-width: 48rem) {
  h1 { font-size: 1.625rem; }
  .content { padding-top: 1.25rem; }
  .header { align-items: flex-start; }
  .header > .actions, .header > .btn { width: 100%; }
  .header > .actions .btn { flex: 1 1 auto; }
  .card, .form-card { padding: 1.25rem; }
  .form-section-head, .form-section-body { padding-left: 1.1rem; padding-right: 1.1rem; }
  .form-grid, .upload-form, .data-grid, .filter-grid { grid-template-columns: minmax(0, 1fr); }
  .form-actions { flex-direction: column-reverse; align-items: stretch; padding-left: 1.1rem; padding-right: 1.1rem; }
  .form-actions .actions { margin-left: 0; flex-direction: column-reverse; align-items: stretch; }
  .form-actions .btn { width: 100%; }
  .topbar-search input { font-size: 1rem; }
  .toast-region { left: 1rem; right: 1rem; bottom: 1rem; }
  .toast { max-width: none; }
}

@media (max-width: 30rem) {
  .field-row { flex-wrap: wrap; }
  .field-row .w-sm, .field-row .w-md { flex: 1 1 100%; }
  .topbar-divider { display: none; }
}

/* Objetivos táctiles de al menos 44px */
@media (pointer: coarse) {
  .btn-sm { min-height: 2.5rem; }
}

/* --- Preferencias de accesibilidad del sistema operativo --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
  .btn[aria-busy="true"]::before { animation: none; border-right-color: currentColor; opacity: 0.6; }
}

@media (prefers-reduced-transparency: reduce) {
  .topbar { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .toast { background: var(--surface-high); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .toast-error { background: #4a0a0a; }
}

@media (prefers-contrast: more) {
  :root { --border: #6a6450; --border-strong: #97917c; --text-muted: #ebe5cf; --text-subtle: #d6cfb8; --brass: #c9c2a8; }
  .nav-link { color: var(--text-strong); }
  .topbar { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; box-shadow: 0 1px 0 var(--border-strong); }
}

@media print {
  .sidebar, .topbar, .toast-region, .nav-backdrop { display: none !important; }
  .app { display: block; }
  body { background: #fff; color: #000; }
}
