/* =============================================================================
   SIGLO 2 · Sistema de Diseño Institucional (High-End Visual Design)
   Legislatura de Tierra del Fuego · Temas dark & light (<html data-theme>)
   ============================================================================= */

:root,
[data-theme="dark"] {
  /* superficies multinivel (GovTech Linear/Vercel) */
  --bg:               #090D10;
  --bg-deep:          #06090B;
  --bg-soft:          #0C1216;
  --surface:          #10171C;
  --surface-elevated: #141E24;
  --surface-sub:      #152027;
  --surface-hover:    #1A2831;
  --line:             rgba(226, 240, 238, 0.085);
  --line-strong:      rgba(226, 240, 238, 0.16);

  /* texto (contraste >= 7:1 principal, >= 4.5:1 secundario) */
  --text:          #F1F6F5;
  --muted:         #96ABA8;
  --subtle:        #69807D;

  /* acento institucional único (teal parlamentario, cero violeta) */
  --accent:        #47C9B2;
  --accent-strong: #34B19B;
  --accent-text:   #74E3CE;
  --accent-soft:   rgba(71, 201, 178, 0.13);
  --accent-glow:   rgba(71, 201, 178, 0.24);
  --on-accent:     #042620;

  /* estados semánticos */
  --ok-bg:      rgba(52, 211, 153, 0.13);   --ok:      #6EE7B7;
  --info-bg:    rgba(96, 165, 250, 0.14);   --info:    #93C5FD;
  --warn-bg:    rgba(251, 191, 36, 0.14);   --warn:    #FCD34D;
  --alert-bg:   rgba(248, 113, 113, 0.15);  --alert:   #FCA5A5;
  --neutral-bg: rgba(148, 163, 184, 0.13);  --neutral: #A8BAB7;

  /* escala geométrica y sombras multicapa */
  --radius-sm: 6px;
  --radius:    9px;
  --radius-lg: 14px;
  --shadow:    0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 28px rgba(0, 0, 0, 0.28);
  --shadow-elevated: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 4px 12px rgba(0, 0, 0, 0.4), 0 18px 40px rgba(0, 0, 0, 0.35);
  --shadow-pop: 0 18px 44px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--line-strong);

  /* tipografía editorial + monoespaciada */
  --font: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* motion tokens (taste-skill) */
  --ease:    cubic-bezier(.2, .8, .2, 1);
  --m-in:    150ms;
  --m-out:   120ms;
  --m-press: 90ms;
}

[data-theme="light"] {
  --bg:               #F4F7FA;
  --bg-deep:          #FFFFFF;
  --bg-soft:          #F8FAFC;
  --surface:          #FFFFFF;
  --surface-elevated: #FFFFFF;
  --surface-sub:      #F0F4F8;
  --surface-hover:    #E9F0F6;
  --line:             rgba(15, 23, 34, 0.09);
  --line-strong:      rgba(15, 23, 34, 0.17);

  --text:          #0D1621;
  --muted:         #4A5E70;
  --subtle:        #697E90;

  --accent:        #0D7A6F;
  --accent-strong: #096259;
  --accent-text:   #0B6B61;
  --accent-soft:   rgba(13, 122, 111, 0.10);
  --accent-glow:   rgba(13, 122, 111, 0.18);
  --on-accent:     #FFFFFF;

  --ok-bg:      #ECFDF5;  --ok:      #047857;
  --info-bg:    #EFF6FF;  --info:    #1D4ED8;
  --warn-bg:    #FFFBEB;  --warn:    #B45309;
  --alert-bg:   #FEF2F2;  --alert:   #B91C1C;
  --neutral-bg: #F1F5F9;  --neutral: #475569;

  --shadow:    0 1px 2px rgba(15, 23, 34, 0.04), 0 4px 14px rgba(15, 23, 34, 0.04);
  --shadow-elevated: 0 2px 4px rgba(15, 23, 34, 0.05), 0 12px 30px rgba(15, 23, 34, 0.07);
  --shadow-pop: 0 14px 36px rgba(15, 23, 34, 0.14), 0 0 0 1px var(--line-strong);
}

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent-text); text-decoration: none; transition: color var(--m-in) var(--ease); }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------------------------------------------------------------- barra superior */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 1.25rem;
  height: 62px; padding: 0 24px;
  background: color-mix(in srgb, var(--bg-deep) 82%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: .6rem;
  font-weight: 800; font-size: .98rem; letter-spacing: -.025em;
  color: var(--text); white-space: nowrap;
}
.brand:hover { text-decoration: none; color: var(--text); }
.brand-logo {
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--accent); line-height: 0; flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-sub { font-size: .68rem; font-weight: 500; color: var(--muted); letter-spacing: .01em; }

.nav { display: flex; align-items: center; gap: 3px; flex: 1; overflow-x: auto; scrollbar-width: none; height: 100%; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  position: relative;
  display: inline-flex; align-items: center; gap: .38rem;
  color: var(--muted); padding: .42rem .75rem; border-radius: var(--radius-sm);
  font-size: .86rem; font-weight: 500; white-space: nowrap;
  transition: color var(--m-in) var(--ease), background var(--m-in) var(--ease);
}
.nav a:hover { color: var(--text); background: var(--surface-hover); text-decoration: none; }
.nav a[aria-current="page"] {
  color: var(--accent-text); background: var(--accent-soft); font-weight: 600;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 28%, transparent);
}
.nav a[aria-current="page"]::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: -11px; height: 2px;
  border-radius: 2px; background: var(--accent);
}
.nav .count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--alert-bg); color: var(--alert);
  border: 1px solid color-mix(in srgb, var(--alert) 32%, transparent);
  font-family: var(--mono); font-size: .68rem; font-weight: 600; font-variant-numeric: tabular-nums;
}
.userbox {
  display: flex; align-items: center; gap: .55rem;
  color: var(--muted); font-size: .84rem; white-space: nowrap;
}
.user-chip {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: 3px 10px 3px 4px; border-radius: 999px;
  background: var(--surface-sub); border: 1px solid var(--line);
}
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 28px; height: 28px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-text);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  font-family: var(--mono); font-size: .72rem; font-weight: 600; letter-spacing: .02em;
}
.avatar-sm {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 22px; height: 22px; border-radius: 999px;
  background: var(--surface-sub); color: var(--accent-text);
  border: 1px solid var(--line-strong);
  font-family: var(--mono); font-size: .65rem; font-weight: 600;
}
.userbox .name { font-weight: 600; color: var(--text); max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.menu-btn, .btn.menu-btn { display: none; }
.mobile-quick-badges { display: none; }
.mobile-badge-link {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  min-width: 40px; min-height: 40px; padding: 0 8px; border-radius: var(--radius);
  color: var(--muted); background: var(--surface-sub); border: 1px solid var(--line);
}
.mobile-badge-link:hover { color: var(--text); background: var(--surface-hover); text-decoration: none; }
.mobile-badge-link .count {
  position: absolute; top: -4px; right: -4px;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--alert-bg); color: var(--alert);
  border: 1px solid color-mix(in srgb, var(--alert) 40%, transparent);
  font-size: .68rem; font-weight: 700; font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- drawer móvil */
body.drawer-open { overflow: hidden; }
.mobile-drawer-backdrop {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0, 0, 0, 0.56);
  opacity: 0; transition: opacity 180ms var(--ease);
}
.mobile-drawer-backdrop.is-open { opacity: 1; }
.mobile-drawer-backdrop[hidden] { display: none; }

.mobile-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 90;
  width: min(330px, 88vw); max-width: 100vw;
  background: var(--bg-deep); border-left: 1px solid var(--line-strong);
  box-shadow: var(--shadow-pop);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 200ms var(--ease);
}
.mobile-drawer.is-open { transform: translateX(0); }
.mobile-drawer[hidden] { display: none; }

.mobile-drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.mobile-drawer-close { min-width: 44px; min-height: 44px; font-size: 1rem; }

.mobile-drawer-user {
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  display: grid; gap: 6px;
}
.mobile-drawer-user-name { font-weight: 700; font-size: .94rem; color: var(--text); }
.mobile-drawer-user-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .78rem; color: var(--muted); }

.mobile-drawer-nav {
  flex: 1; overflow-y: auto; padding: 10px 12px;
  display: grid; gap: 4px; align-content: start;
}
.mobile-drawer-link {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 44px; padding: 0 12px; border-radius: var(--radius);
  color: var(--text); font-size: .94rem; font-weight: 500;
  transition: background var(--m-in) var(--ease);
}
.mobile-drawer-link:hover { background: var(--surface-hover); text-decoration: none; }
.mobile-drawer-link[aria-current="page"] {
  background: var(--accent-soft); color: var(--accent-text); font-weight: 700;
}
.mobile-drawer-link .count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
  background: var(--alert-bg); color: var(--alert);
  font-size: .74rem; font-weight: 700; font-variant-numeric: tabular-nums;
}

.mobile-drawer-foot {
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--surface);
  display: grid; gap: 8px;
}
.mobile-drawer-foot-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mobile-drawer-foot-row .btn { width: 100%; min-height: 44px; }
.mobile-drawer-foot .btn-block { min-height: 44px; }

/* ---------------------------------------------------------------- layout */
.page {
  max-width: 1380px; margin: 0 auto; padding: 24px;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px;
}
.page > * { min-width: 0; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 2px 2px 4px;
}
.page-head .eyebrow {
  display: block; font-size: .7rem; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--accent-text); margin-bottom: 4px;
}
.page-head h1 {
  margin: 0; font-size: 1.55rem; font-weight: 800; letter-spacing: -.025em; line-height: 1.18;
}
.page-head p { margin: .25rem 0 0; color: var(--muted); font-size: .88rem; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  min-width: 0;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.card-head h2 { margin: 0; font-size: 1.02rem; font-weight: 700; letter-spacing: -.015em; }
.card-head p { margin: .18rem 0 0; color: var(--muted); font-size: .84rem; }
.card-body { padding: 18px 20px; min-width: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-side { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.grid-side > *, .grid-2 > *, .entity-head > * { min-width: 0; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }

/* encabezado de entidad */
.entity-head {
  display: grid; grid-template-columns: minmax(280px, 1fr) 2fr; gap: 1.5rem;
  padding: 20px; align-items: center;
}
.entity-title { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.entity-title h1 { margin: 0; font-size: 1.35rem; font-weight: 800; letter-spacing: -.02em; }
.entity-meta { color: var(--muted); font-size: .86rem; margin-top: .25rem; }

/* pestañas */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; align-content: flex-start; }
.tabs a {
  color: var(--muted); padding: .45rem .8rem; border-radius: var(--radius);
  font-size: .875rem; font-weight: 500;
  transition: color var(--m-in) var(--ease), background var(--m-in) var(--ease);
}
.tabs a:hover { color: var(--text); background: var(--surface-hover); text-decoration: none; }
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }

/* ---------------------------------------------------------------- pastillas */
.pill {
  display: inline-flex; align-items: center; gap: .38rem;
  height: 23px; padding: 0 .6rem; border-radius: 999px;
  font-size: .7rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  background: var(--neutral-bg); color: var(--neutral);
  border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
  white-space: nowrap;
}
.pill.ok::before, .pill.info::before, .pill.warn::before, .pill.alert::before, .pill.err::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0;
}
.pill.ok    { background: var(--ok-bg);     color: var(--ok); }
.pill.info  { background: var(--info-bg);   color: var(--info); }
.pill.warn  { background: var(--warn-bg);   color: var(--warn); }
.pill.alert, .pill.err { background: var(--alert-bg); color: var(--alert); }
.pill.code  {
  background: var(--accent-soft); color: var(--accent-text);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius-sm); font-family: var(--mono); font-weight: 600; letter-spacing: .01em;
}
.pill.ia    { background: var(--accent-soft); color: var(--accent-text); }

/* ---------------------------------------------------------------- botones homogéneos */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  height: 36px; padding: 0 14px; width: auto; max-width: 100%;
  border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: var(--surface-sub); color: var(--text);
  font: 600 .86rem/1 var(--font); cursor: pointer; white-space: nowrap;
  text-decoration: none; justify-self: start;
  transition: background var(--m-in) var(--ease), border-color var(--m-in) var(--ease),
              color var(--m-in) var(--ease), transform var(--m-in) var(--ease);
}
.btn:hover { background: var(--surface-hover); border-color: var(--muted); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }

.btn.primary, .btn.btn-primary {
  background: var(--accent); border-color: var(--accent); color: var(--on-accent);
}
.btn.primary:hover, .btn.btn-primary:hover {
  background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent);
}
.btn.secondary, .btn.btn-secondary {
  background: var(--surface-sub); border-color: var(--line-strong); color: var(--text);
}
.btn.ghost, .btn.btn-ghost {
  border-color: transparent; background: transparent; color: var(--muted);
}
.btn.ghost:hover, .btn.btn-ghost:hover {
  background: var(--surface-hover); color: var(--text); border-color: transparent;
}
.btn.danger, .btn.btn-danger {
  background: var(--alert-bg); border-color: color-mix(in srgb, var(--alert) 35%, transparent);
  color: var(--alert);
}
.btn.danger:hover, .btn.btn-danger:hover {
  background: color-mix(in srgb, var(--alert) 24%, transparent);
}
.btn.ok {
  background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 35%, transparent);
  color: var(--ok);
}
.btn.ok:hover { background: color-mix(in srgb, var(--ok) 22%, transparent); }

.btn.sm, .btn.btn-sm {
  height: 30px; padding: 0 10px; font-size: .79rem; border-radius: var(--radius-sm);
}
.btn.btn-block { width: 100%; justify-self: stretch; }

@media (hover: hover) and (pointer: fine) {
  .btn:hover { transform: translateY(-1px); }
  .btn:active { transform: translateY(1px) scale(.985); transition-duration: var(--m-press); }
}

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------------- avisos / banners */
.banner, .notice {
  padding: .75rem 1rem; border-radius: var(--radius);
  background: var(--warn-bg); color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  font-size: .88rem; line-height: 1.5;
}
.notice.ia {
  background: var(--accent-soft); color: var(--accent-text);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

/* ---------------------------------------------------------------- barra de filtros APEX */
.apex-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 20px; border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}
.apex-search-wrap {
  position: relative; flex: 1 1 240px; max-width: 440px; min-width: 180px;
}
.apex-search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--subtle); pointer-events: none; display: inline-flex;
}
.apex-search-input {
  width: 100%; height: 34px; padding: 0 10px 0 32px;
  border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text);
  font: 400 .875rem var(--font);
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
.apex-search-input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.apex-filters-wrap { position: relative; }
.apex-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--accent); color: var(--on-accent);
  font-size: .7rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.apex-badge:empty, .apex-badge[data-count="0"] { display: none; }
.apex-popover {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 50;
  width: min(560px, calc(100vw - 32px));
  padding: 16px; border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-pop);
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px;
}
.apex-popover[hidden] { display: none; }
.apex-popover-head {
  grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center;
  padding-bottom: 8px; border-bottom: 1px solid var(--line);
  font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
}
.apex-meta {
  margin-left: auto; color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- combo buscable */
.siglo-select { position: relative; width: 100%; min-width: 0; max-width: 100%; }
.siglo-select-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; max-width: 100%; min-width: 0; min-height: 36px; padding: 6px 10px;
  border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: var(--surface-sub); color: var(--text);
  font: 400 .88rem var(--font); text-align: left; cursor: pointer;
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
.siglo-select-trigger:hover { border-color: var(--muted); }
.siglo-select-trigger[aria-expanded="true"] {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.siglo-select-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.siglo-select-chevron { color: var(--subtle); font-size: .75rem; flex-shrink: 0; }
.siglo-select-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 60;
  min-width: 220px; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.siglo-select-dropdown[hidden] { display: none; }
.siglo-select-search {
  width: 100%; height: 34px; padding: 0 10px;
  border: 0; border-bottom: 1px solid var(--line);
  background: var(--surface-sub); color: var(--text);
  font: 400 .85rem var(--font);
}
.siglo-select-search:focus { outline: none; background: var(--surface); }
.siglo-select-list {
  list-style: none; margin: 0; padding: 4px;
  max-height: 220px; overflow-y: auto;
}
.siglo-select-option {
  padding: 7px 10px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: .86rem; color: var(--text);
  transition: background 100ms var(--ease);
}
.siglo-select-option:hover, .siglo-select-option.is-active {
  background: var(--surface-hover);
}
.siglo-select-option.is-selected {
  background: var(--accent-soft); color: var(--accent-text); font-weight: 600;
}
.siglo-select-empty {
  padding: 10px; text-align: center; color: var(--muted); font-size: .82rem;
}

/* ---------------------------------------------------------------- tablas */
.table-wrap { overflow-x: auto; }
table.data, table.tabla { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data th, table.tabla th {
  text-align: left; padding: .78rem 1rem; background: var(--surface-sub);
  color: var(--muted); font-size: .7rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.data td, table.tabla td {
  padding: .88rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle;
}
table.data tbody tr:last-child td, table.tabla tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr, table.tabla tbody tr { transition: background 120ms var(--ease); }
table.data tbody tr:hover td, table.tabla tbody tr:hover td { background: var(--surface-hover); }
table.data tbody tr.row-link, table.tabla tbody tr.row-link { cursor: pointer; }
table.data td.n, table.tabla td.n { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }
table.data td.num, table.tabla td.num { font-family: var(--mono); font-size: .82rem; }
.cell-sub { display: block; color: var(--muted); font-size: .8rem; margin-top: 2px; }
.strong-accent { color: var(--accent-text); font-weight: 700; }

/* ---------------------------------------------------------------- KPIs */
.kpi {
  position: relative; overflow: hidden;
  padding: 16px 18px; border-radius: var(--radius);
  background: var(--surface-elevated); border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.kpi::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent 85%);
}
.kpi-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--accent-text);
}
.kpi .label {
  color: var(--muted); font-size: .71rem; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase;
}
.kpi .value {
  font-size: 2rem; font-weight: 800; letter-spacing: -.03em;
  margin-top: .35rem; font-variant-numeric: tabular-nums; line-height: 1.1;
}
.kpi .delta { color: var(--muted); font-size: .8rem; margin-top: .3rem; }

.bar { height: 7px; border-radius: 999px; background: var(--surface-sub); overflow: hidden; margin-top: 4px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ---------------------------------------------------------------- formularios */
.field { display: grid; gap: .35rem; align-content: start; min-width: 0; }
.field label {
  color: var(--muted); font-size: .74rem; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase;
}
.field > .btn { justify-self: start; align-self: end; }
.input, select.input, textarea.input {
  width: 100%; max-width: 100%; min-width: 0; min-height: 36px; padding: .48rem .72rem; border-radius: var(--radius);
  background: var(--surface-sub); border: 1px solid var(--line-strong); color: var(--text);
  font: 400 .9rem var(--font);
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
textarea.input { min-height: 84px; line-height: 1.5; }
.input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input:disabled { opacity: .65; cursor: not-allowed; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }

/* ---------------------------------------------------------------- línea de tiempo */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative; padding: 0 0 1rem 1.35rem;
  border-left: 1.5px solid var(--line-strong); margin-left: .4rem;
}
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; left: -6px; top: .3rem; width: 10px; height: 10px;
  border-radius: 50%; background: var(--surface); border: 2px solid var(--accent);
}
.timeline li.done::before { background: var(--accent); }
.timeline .when { color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- caja IA */
.ia-box {
  border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 1rem 1.1rem;
  background: linear-gradient(135deg, var(--accent-soft), color-mix(in srgb, var(--surface-elevated) 90%, transparent));
  box-shadow: var(--shadow);
}
.ia-box .ia-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: .5rem; flex-wrap: wrap; margin-bottom: .55rem;
}
.ia-badge {
  font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--accent-text);
}
.ia-meta { font-size: .76rem; color: var(--muted); font-family: var(--mono); font-variant-numeric: tabular-nums; }
.conf { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent-text); font-size: .84rem; }
.ia-conf-bar {
  height: 5px; border-radius: 999px; background: var(--surface-sub); overflow: hidden;
  margin: .45rem 0 .65rem;
}
.ia-conf-bar > span {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent-text));
}

/* ---------------------------------------------------------------- login dividido / auth */
.auth-shell {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(circle at 50% 0%, var(--accent-soft), transparent 55%), var(--bg);
}
.auth-card { width: 100%; max-width: 420px; box-shadow: var(--shadow-elevated); }

.auth-split {
  min-height: 100vh; display: grid; grid-template-columns: 1fr 1.05fr;
  background: var(--bg);
}
.auth-brand-pane {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between; gap: 2rem;
  padding: 48px 52px;
  background:
    radial-gradient(circle at 18% 15%, var(--accent-glow), transparent 52%),
    linear-gradient(155deg, #071316 0%, #0A1D21 55%, #071014 100%);
  color: #EFF6F5;
  border-right: 1px solid var(--line);
}
.auth-brand-pane::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .28;
  background-image:
    linear-gradient(rgba(71, 201, 178, 0.14) 1px, transparent 1px),
    linear-gradient(90deg, rgba(71, 201, 178, 0.14) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: radial-gradient(circle at 30% 30%, #000 20%, transparent 78%);
}
.auth-brand-pane > * { position: relative; z-index: 1; }
.auth-hero-mark { display: inline-flex; align-items: center; gap: 12px; color: #5CE0C8; }
.auth-hero-mark svg { width: 48px; height: 48px; }
.auth-brand-title {
  margin: 1.5rem 0 .65rem; font-size: clamp(1.75rem, 2.4vw, 2.35rem);
  font-weight: 800; letter-spacing: -.03em; line-height: 1.15; color: #F5FAF9;
}
.auth-brand-lead { margin: 0; color: #A6BFBC; font-size: .96rem; line-height: 1.6; max-width: 48ch; }
.auth-feature-list { display: grid; gap: 12px; margin-top: 2rem; }
.auth-feature-item {
  padding: 14px 16px; border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.045); border: 1px solid rgba(255, 255, 255, 0.09);
  display: flex; align-items: flex-start; gap: 12px;
}
.auth-feature-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #47C9B2; margin-top: 7px; flex-shrink: 0;
}
.auth-feature-item strong { display: block; font-size: .88rem; color: #F1F6F5; }
.auth-feature-item span { display: block; font-size: .8rem; color: #9CB4B1; margin-top: 2px; }
.auth-brand-foot { font-size: .78rem; color: #7F9A97; font-family: var(--mono); }

.auth-form-pane {
  position: relative; display: grid; place-items: center; padding: 36px 24px;
  background: var(--bg);
}
.auth-theme-float { position: absolute; top: 20px; right: 24px; }
.auth-form-card {
  width: 100%; max-width: 420px; padding: 32px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-elevated);
}
.auth-form-card h2 { margin: 0; font-size: 1.38rem; font-weight: 800; letter-spacing: -.025em; }
.auth-form-card .auth-sub { margin: .3rem 0 1.4rem; color: var(--muted); font-size: .88rem; }

/* ---------------------------------------------------------------- marca de agua Q7 */
.q7-watermark {
  position: fixed; inset: 0; pointer-events: none; z-index: 9999; opacity: .045;
  display: grid; grid-template-columns: repeat(2, 1fr); align-content: space-around; justify-items: center;
}
.q7-watermark span {
  transform: rotate(-28deg); font-weight: 800; letter-spacing: .14em;
  text-transform: uppercase; color: currentColor;
}

/* ---------------------------------------------------------------- móvil (<= 900px y <= 768px / 390×844) */
@media (max-width: 900px) {
  .auth-split { grid-template-columns: minmax(0, 1fr); }
  .auth-brand-pane { padding: 28px 20px; border-right: 0; border-bottom: 1px solid var(--line); }
  .auth-feature-list { display: none; }
  .auth-form-pane { padding: 24px 16px 36px; }
  .auth-form-card { padding: 24px 20px; }
  .auth-theme-float { top: 14px; right: 14px; }
  .topbar { padding: 0 12px; gap: .6rem; height: 56px; justify-content: space-between; }
  .nav, .userbox .name, .desktop-only { display: none !important; }
  .mobile-quick-badges { display: flex; align-items: center; gap: 6px; }
  .menu-btn, .btn.menu-btn {
    display: inline-flex; min-width: 44px; min-height: 44px; padding: 0; font-size: 1.15rem;
  }
  .page { padding: 12px; gap: 14px; }
  .card-head { padding: 14px 16px; }
  .card-body { padding: 14px 16px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid-2, .grid-side, .entity-head, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .entity-head { padding: 16px; gap: .9rem; }
  .entity-title h1 { font-size: 1.18rem; }
  .span-2 { grid-column: auto; }
  .kpi { padding: 12px 13px; }
  .kpi .value { font-size: 1.45rem; }

  /* pestañas desplazables horizontalmente sin cortar */
  .tabs {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; max-width: 100%; padding-bottom: 2px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { flex-shrink: 0; min-height: 40px; display: inline-flex; align-items: center; white-space: nowrap; }
}

@media (max-width: 768px) {
  /* barra APEX apilada ergonómicamente */
  .apex-bar { padding: 10px 12px; gap: 8px; }
  .apex-search-wrap { flex: 1 1 100%; max-width: 100%; min-width: 0; }
  .apex-search-input { height: 44px; font-size: 16px; }
  .apex-filters-wrap { flex: 1 1 auto; }
  .apex-filters-wrap > .btn { width: 100%; min-height: 44px; }
  .apex-bar [data-apex-clear] { min-height: 44px; padding: 0 14px; }
  .apex-meta { width: 100%; margin-left: 0; }
  .apex-popover {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    width: 100%; max-width: 100%; max-height: 82vh; overflow-y: auto;
    border-radius: 16px 16px 0 0;
    padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
    z-index: 75; grid-template-columns: minmax(0, 1fr);
  }

  /* formularios táctiles sin zoom automático de iOS Safari */
  .input, select.input, textarea.input, .siglo-select-trigger, .siglo-select-search {
    font-size: 16px; min-height: 44px;
  }
  .btn { min-height: 44px; }
  .btn.sm, .btn.btn-sm { min-height: 36px; }

  /* tabla -> tarjetas limpias y tocables */
  .table-wrap { overflow-x: visible; }
  table.data.stack, table.data.stack tbody { display: block; width: 100%; }
  table.data.stack thead { display: none; }
  table.data.stack tbody {
    display: grid; gap: 10px; padding: 10px 12px; background: var(--bg-soft);
  }
  table.data.stack tr {
    display: block; padding: 12px 14px;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
  }
  table.data.stack tbody tr:last-child td { border-bottom: 0; }
  table.data.stack td { display: block; border: 0; padding: .22rem 0; text-align: left; }
  table.data.stack td[data-label] {
    display: grid; grid-template-columns: 78px minmax(0, 1fr); gap: .5rem; align-items: baseline;
  }
  table.data.stack td[data-label]::before {
    content: attr(data-label); color: var(--muted);
    font-size: .7rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  }
  table.data.stack td[data-label] > .cell, table.data.stack td.n {
    text-align: left; min-width: 0; max-width: 100%; overflow-wrap: anywhere;
  }
  table.data.stack .pill {
    white-space: normal; height: auto; min-height: 22px; padding: 2px 8px; line-height: 1.25; max-width: 100%;
  }
  table.data.stack td:last-child:not([data-label]) {
    margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--line);
  }
  table.data.stack td.drag { display: none; }
  table.data.stack tr:hover td { background: transparent; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
  .btn:hover, .btn:active { transform: none !important; }
}

@media print {
  .topbar, .btn, .tabs, .apex-bar { display: none !important; }
  body { background: #fff; color: #0F1722; }
}
