/*! =========================================================================
 *  wit-ui — sistema de diseño WITDATA
 *  Pensado para consolas de datos densas: se escanean y se operan.
 *
 *  Uso mínimo:
 *    <link rel="stylesheet" href="wit-ui.css">
 *    <html data-theme="light" data-density="comfortable">
 *
 *  Tipografía (superfamilia IBM Plex):
 *    <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Sans+Condensed:wght@600;700&family=IBM+Plex+Mono:wght@400;500&display=swap" rel="stylesheet">
 *
 *  Los tokens son --ds-*. Prefijo neutro a propósito, para no colisionar
 *  con tokens de marca preexistentes en los productos que lo adopten.
 *  ========================================================================= */

/* ==========================================================================
   1 · TOKENS
   ========================================================================== */

:root, [data-theme="light"] {
  color-scheme: light;

  /* Neutrales — derivados del navy de marca #233756 (matiz ~217°).
     No son grises puros: el sesgo frío lee como instrumento y separa
     limpio del acento verde. */
  --ds-canvas:        #F7F8FA;
  --ds-surface:       #FFFFFF;
  --ds-surface-2:     #F1F3F6;
  --ds-surface-3:     #E8EBF0;
  --ds-border-subtle: #E3E7ED;
  --ds-border:        #D3D9E2;
  --ds-border-strong: #B4BECD;
  --ds-text:          #1B2432;
  --ds-text-secondary:#45536A;
  --ds-text-muted:    #5C6B80;

  /* Acento. #359A4F es la identidad de marca, pero con blanco encima da
     3.57:1 y falla AA. Por eso se separa el uso: -solid para rellenos,
     -text para texto y links. Nunca usar --ds-accent como relleno. */
  --ds-accent:            #359A4F;
  --ds-accent-solid:      #2C8244;
  --ds-accent-solid-hover:#24763B;
  --ds-on-solid:          #FFFFFF;
  --ds-accent-text:       #227038;
  --ds-accent-soft:       #E7F3EB;
  --ds-accent-soft-hover: #D6EADD;
  --ds-accent-ring:       rgba(44,130,68,.32);

  /* Semántico — separado del acento. Los valores base son rellenos con
     texto blanco encima, todos verificados ≥4.5:1. */
  --ds-ok:        #2C8244;  --ds-ok-text:     #1F6435;  --ds-ok-soft:     #E7F3EB;
  --ds-warn:      #B45309;  --ds-warn-text:   #92400E;  --ds-warn-soft:   #FDF3E3;
  --ds-danger:    #DC2626;  --ds-danger-text: #B91C1C;  --ds-danger-soft: #FDECEC;
  --ds-info:      #336FAD;  --ds-info-text:   #2C6299;  --ds-info-soft:   #E9F1FA;

  --ds-e-raised:  0 1px 2px rgba(27,36,50,.06), 0 0 0 1px rgba(27,36,50,.04);
  --ds-e-overlay: 0 4px 12px -2px rgba(27,36,50,.12), 0 2px 4px -2px rgba(27,36,50,.08);
  --ds-e-modal:   0 24px 48px -12px rgba(27,36,50,.24), 0 8px 16px -8px rgba(27,36,50,.12);
  --ds-backdrop:  rgba(27,36,50,.44);
  --ds-code-bg:   #F1F3F6;
}

[data-theme="dark"] {
  color-scheme: dark;

  /* Misma familia tonal que el claro: fondo y superficies comparten matiz.
     Mezclar un fondo cálido con superficies frías es lo que hace ver una
     interfaz "sucia" en oscuro. */
  --ds-canvas:        #0F141C;
  --ds-surface:       #161D28;
  --ds-surface-2:     #1E2733;
  --ds-surface-3:     #27323F;
  --ds-border-subtle: #232C3A;
  --ds-border:        #2E3947;
  --ds-border-strong: #405063;
  --ds-text:          #E8EDF4;
  --ds-text-secondary:#A8B5C6;
  --ds-text-muted:    #8494A8;

  /* Los rellenos sólidos NO cambian entre temas: son superficies con texto
     blanco encima, no texto sobre el canvas. Si en oscuro se aclaran, el
     blanco deja de pasar AA. Lo que sí cambia es -text y -soft. */
  --ds-accent:            #359A4F;
  --ds-accent-solid:      #2C8244;
  --ds-accent-solid-hover:#35995A;
  --ds-on-solid:          #FFFFFF;
  --ds-accent-text:       #6FD188;
  --ds-accent-soft:       #14301F;
  --ds-accent-soft-hover: #1B3F29;
  --ds-accent-ring:       rgba(79,184,106,.36);

  --ds-ok:        #2C8244;  --ds-ok-text:     #6FD188;  --ds-ok-soft:     #14301F;
  --ds-warn:      #B45309;  --ds-warn-text:   #FBBF24;  --ds-warn-soft:   #33240D;
  --ds-danger:    #DC2626;  --ds-danger-text: #FCA5A5;  --ds-danger-soft: #3A1A1A;
  --ds-info:      #336FAD;  --ds-info-text:   #93C0EE;  --ds-info-soft:   #14293D;

  --ds-e-raised:  0 1px 2px rgba(0,0,0,.4), 0 0 0 1px rgba(255,255,255,.04);
  --ds-e-overlay: 0 4px 12px -2px rgba(0,0,0,.5), 0 2px 4px -2px rgba(0,0,0,.4);
  --ds-e-modal:   0 24px 48px -12px rgba(0,0,0,.7), 0 8px 16px -8px rgba(0,0,0,.5);
  --ds-backdrop:  rgba(9,13,19,.68);
  --ds-code-bg:   #10161F;
}

:root {
  /* Tipografía */
  --ds-font-ui:      "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --ds-font-display: "IBM Plex Sans Condensed", "IBM Plex Sans", system-ui, sans-serif;
  --ds-font-data:    "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;

  /* Radios */
  --ds-r-control: 6px;
  --ds-r-card:    8px;
  --ds-r-modal:   10px;

  /* Densidad (comfortable). Unidad base 4px. */
  --ds-h-sm:   28px;
  --ds-h-md:   32px;
  --ds-h-lg:   40px;
  --ds-row-h:  36px;
  --ds-pad-x:  12px;
  --ds-cell-y: 9px;
  --ds-card-p: 20px;
  --ds-gap:    16px;

  /* Motion */
  --ds-t-fast: 120ms;
  --ds-t-slow: 160ms;
  --ds-ease:   cubic-bezier(.4,0,.2,1);
}

[data-density="compact"] {
  --ds-h-sm:   24px;
  --ds-h-md:   28px;
  --ds-h-lg:   34px;
  --ds-row-h:  32px;
  --ds-pad-x:  10px;
  --ds-cell-y: 6px;
  --ds-card-p: 14px;
  --ds-gap:    12px;
}

/* ==========================================================================
   2 · BASE
   ========================================================================== */

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

/* Cualquier `display` explícito pisa el default del atributo [hidden].
   Sin esto, un elemento con display:flex sigue viéndose aunque esté hidden. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--ds-canvas);
  color: var(--ds-text);
  font-family: var(--ds-font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-family: var(--ds-font-display); font-weight: 600; letter-spacing: -.005em; }
p { margin: 0; }
a { color: var(--ds-accent-text); }

:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--ds-accent-solid);
  outline-offset: 2px;
  border-radius: var(--ds-r-control);
}

code, kbd, .ds-data { font-family: var(--ds-font-data); font-variant-numeric: tabular-nums; }
.ds-num { font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ==========================================================================
   3 · TIPOGRAFÍA
   ========================================================================== */
.t-display-lg { font-family: var(--ds-font-display); font-size: 24px; line-height: 1.2;  font-weight: 600; letter-spacing: -.01em; }
.t-display    { font-family: var(--ds-font-display); font-size: 20px; line-height: 1.25; font-weight: 600; letter-spacing: -.008em; }
.t-title      { font-size: 16px; line-height: 1.35; font-weight: 600; }
.t-body       { font-size: 14px; line-height: 1.5; }
.t-body-sm    { font-size: 13px; line-height: 1.45; }
.t-label      { font-size: 12px; line-height: 1.3; font-weight: 500; }
.t-micro      { font-size: 11px; line-height: 1.25; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.t-data       { font-family: var(--ds-font-data); font-size: 13px; font-variant-numeric: tabular-nums; }
.muted        { color: var(--ds-text-muted); }
.secondary    { color: var(--ds-text-secondary); }

/* ==========================================================================
   4 · BOTONES
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--ds-h-md); padding: 0 var(--ds-pad-x);
  border: 1px solid transparent; border-radius: var(--ds-r-control);
  font-family: inherit; font-size: 13px; font-weight: 500; line-height: 1;
  white-space: nowrap; cursor: pointer;
  transition: background var(--ds-t-fast) var(--ds-ease),
              border-color var(--ds-t-fast) var(--ds-ease),
              color var(--ds-t-fast) var(--ds-ease);
}
.btn:disabled { cursor: not-allowed; opacity: .45; }
.btn-sm { height: var(--ds-h-sm); font-size: 12px; padding: 0 10px; }
.btn-lg { height: var(--ds-h-lg); font-size: 14px; padding: 0 18px; }

.btn-primary   { background: var(--ds-accent-solid); color: var(--ds-on-solid); }
.btn-primary:hover:not(:disabled) { background: var(--ds-accent-solid-hover); }

.btn-secondary { background: var(--ds-surface); color: var(--ds-text); border-color: var(--ds-border); }
.btn-secondary:hover:not(:disabled) { background: var(--ds-surface-2); border-color: var(--ds-border-strong); }

.btn-ghost     { background: transparent; color: var(--ds-text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--ds-surface-2); color: var(--ds-text); }

.btn-danger    { background: var(--ds-danger); color: var(--ds-on-solid); }
.btn-danger:hover:not(:disabled) { filter: brightness(.92); }

.btn[data-loading="true"] { pointer-events: none; opacity: .7; }
.btn[data-loading="true"]::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: ds-spin .6s linear infinite;
}
@keyframes ds-spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--ds-h-md); height: var(--ds-h-md); flex: none;
  border: 1px solid transparent; border-radius: var(--ds-r-control);
  background: transparent; color: var(--ds-text-secondary); cursor: pointer;
  transition: background var(--ds-t-fast) var(--ds-ease), color var(--ds-t-fast) var(--ds-ease);
}
.icon-btn:hover:not(:disabled) { background: var(--ds-surface-2); color: var(--ds-text); }
.icon-btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn-bordered { border-color: var(--ds-border); background: var(--ds-surface); }
.icon-btn-danger:hover:not(:disabled) { background: var(--ds-danger-soft); color: var(--ds-danger-text); }
.icon-btn svg { width: 16px; height: 16px; }

/* ==========================================================================
   5 · CAMPOS
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 12px; font-weight: 500; color: var(--ds-text-secondary); }
.field-hint  { font-size: 12px; color: var(--ds-text-muted); }
.field-error { font-size: 12px; color: var(--ds-danger-text); display: flex; align-items: center; gap: 5px; }

.input, .select, .textarea {
  width: 100%; height: var(--ds-h-md); padding: 0 10px;
  background: var(--ds-surface); color: var(--ds-text);
  border: 1px solid var(--ds-border); border-radius: var(--ds-r-control);
  font-family: inherit; font-size: 13px;
  transition: border-color var(--ds-t-fast) var(--ds-ease), box-shadow var(--ds-t-fast) var(--ds-ease);
}
.textarea { height: auto; min-height: 72px; padding: 8px 10px; line-height: 1.5; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--ds-text-muted); }
.input:hover:not(:disabled), .select:hover:not(:disabled), .textarea:hover:not(:disabled) { border-color: var(--ds-border-strong); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--ds-accent-solid);
  box-shadow: 0 0 0 3px var(--ds-accent-ring);
}
.input:disabled, .select:disabled, .textarea:disabled { background: var(--ds-surface-2); color: var(--ds-text-muted); cursor: not-allowed; }
.input[aria-invalid="true"] { border-color: var(--ds-danger); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px rgba(220,38,38,.22); }
.select { appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%235C6B80' stroke-width='1.6'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 16px; }
[data-theme="dark"] .select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%238494A8' stroke-width='1.6'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E"); }

.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-left: 32px; }
.input-group > svg { position: absolute; left: 9px; width: 15px; height: 15px; color: var(--ds-text-muted); pointer-events: none; }
.input-group kbd { position: absolute; right: 8px; }

kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 4px;
  border: 1px solid var(--ds-border); border-bottom-width: 2px; border-radius: 4px;
  background: var(--ds-surface-2); color: var(--ds-text-muted);
  font-size: 10px; font-weight: 500;
}

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.check input { accent-color: var(--ds-accent-solid); width: 15px; height: 15px; margin: 0; cursor: pointer; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 34px; height: 20px; flex: none; border-radius: 999px;
  background: var(--ds-border-strong); position: relative;
  transition: background var(--ds-t-fast) var(--ds-ease);
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: #fff;
  transition: transform var(--ds-t-fast) var(--ds-ease);
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.switch input:checked + .switch-track { background: var(--ds-accent-solid); }
.switch input:checked + .switch-track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--ds-accent-solid); outline-offset: 2px; }

/* ==========================================================================
   6 · ESTADO
   El estado se codifica también en la forma (punto relleno vs hueco), no
   solo por matiz: funciona con daltonismo y en escala de grises.
   ========================================================================== */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 20px; padding: 0 8px 0 6px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .01em; white-space: nowrap;
}
.pill::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex: none; }
.pill-ok      { background: var(--ds-ok-soft);     color: var(--ds-ok-text); }
.pill-warn    { background: var(--ds-warn-soft);   color: var(--ds-warn-text); }
.pill-danger  { background: var(--ds-danger-soft); color: var(--ds-danger-text); }
.pill-info    { background: var(--ds-info-soft);   color: var(--ds-info-text); }
.pill-neutral { background: var(--ds-surface-3);   color: var(--ds-text-muted); }
.pill-muted   { background: transparent; color: var(--ds-text-muted); box-shadow: inset 0 0 0 1px var(--ds-border); }
.pill-muted::before { background: transparent; box-shadow: inset 0 0 0 1.5px currentColor; }

.badge {
  display: inline-flex; align-items: center; height: 18px; padding: 0 6px;
  border-radius: 4px; font-size: 11px; font-weight: 500;
  background: var(--ds-surface-3); color: var(--ds-text-secondary);
}
.badge-accent { background: var(--ds-accent-soft); color: var(--ds-accent-text); }

/* ==========================================================================
   7 · SUPERFICIES
   ========================================================================== */
.card {
  background: var(--ds-surface); border: 1px solid var(--ds-border-subtle);
  border-radius: var(--ds-r-card); box-shadow: var(--ds-e-raised);
}
.card-p { padding: var(--ds-card-p); }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px var(--ds-card-p); border-bottom: 1px solid var(--ds-border-subtle);
}

/* ==========================================================================
   8 · TABLA
   ========================================================================== */
.table-wrap { overflow-x: auto; border-radius: var(--ds-r-card); }
table.ds { width: 100%; border-collapse: collapse; font-size: 13px; }
table.ds th {
  position: sticky; top: 0; z-index: 1; text-align: left;
  padding: 7px 12px; background: var(--ds-surface-2);
  border-bottom: 1px solid var(--ds-border);
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ds-text-muted); white-space: nowrap;
}
table.ds th[aria-sort] { cursor: pointer; user-select: none; }
table.ds th[aria-sort]:hover { color: var(--ds-text); }
table.ds th .sort-ind { opacity: .35; margin-left: 3px; }
table.ds th[aria-sort="ascending"] .sort-ind,
table.ds th[aria-sort="descending"] .sort-ind { opacity: 1; }
table.ds td {
  padding: var(--ds-cell-y) 12px; height: var(--ds-row-h);
  border-bottom: 1px solid var(--ds-border-subtle); vertical-align: middle;
}
table.ds tbody tr { transition: background var(--ds-t-fast) var(--ds-ease); }
table.ds tbody tr:hover { background: var(--ds-surface-2); }
table.ds tbody tr[aria-selected="true"] { background: var(--ds-accent-soft); }
table.ds tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; opacity: 0; transition: opacity var(--ds-t-fast) var(--ds-ease); }
tr:hover .row-actions, tr:focus-within .row-actions { opacity: 1; }

.bulk-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; background: var(--ds-accent-soft);
  border-bottom: 1px solid var(--ds-border);
  font-size: 13px;
}

/* ==========================================================================
   9 · ALERTAS · TOASTS
   Regla: toast para el resultado de una acción, alerta inline para el
   estado de algo que está en pantalla. Nunca los dos para lo mismo.
   ========================================================================== */
.alert {
  display: flex; gap: 10px; padding: 10px 12px;
  border-radius: var(--ds-r-control); border: 1px solid transparent;
  font-size: 13px; line-height: 1.45;
}
.alert > svg { width: 16px; height: 16px; flex: none; margin-top: 1px; }
.alert-title { font-weight: 600; }
.alert-ok     { background: var(--ds-ok-soft);     border-color: color-mix(in srgb, var(--ds-ok) 26%, transparent);     color: var(--ds-ok-text); }
.alert-warn   { background: var(--ds-warn-soft);   border-color: color-mix(in srgb, var(--ds-warn) 26%, transparent);   color: var(--ds-warn-text); }
.alert-danger { background: var(--ds-danger-soft); border-color: color-mix(in srgb, var(--ds-danger) 26%, transparent); color: var(--ds-danger-text); }
.alert-info   { background: var(--ds-info-soft);   border-color: color-mix(in srgb, var(--ds-info) 26%, transparent);   color: var(--ds-info-text); }
.alert p { color: inherit; }

.toast-region {
  position: fixed; bottom: 16px; right: 16px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 9px; min-width: 280px; max-width: 380px;
  padding: 10px 12px; pointer-events: auto;
  background: var(--ds-surface); color: var(--ds-text);
  border: 1px solid var(--ds-border); border-left: 3px solid var(--ds-text-muted);
  border-radius: var(--ds-r-control); box-shadow: var(--ds-e-overlay);
  font-size: 13px;
  animation: ds-toast-in var(--ds-t-slow) var(--ds-ease);
}
@keyframes ds-toast-in { from { opacity: 0; transform: translateY(6px); } }
.toast > svg { width: 16px; height: 16px; flex: none; margin-top: 1px; }
.toast-ok     { border-left-color: var(--ds-ok); }     .toast-ok > svg     { color: var(--ds-ok-text); }
.toast-warn   { border-left-color: var(--ds-warn); }   .toast-warn > svg   { color: var(--ds-warn-text); }
.toast-danger { border-left-color: var(--ds-danger); } .toast-danger > svg { color: var(--ds-danger-text); }
.toast-info   { border-left-color: var(--ds-info); }   .toast-info > svg   { color: var(--ds-info-text); }
.toast-close { margin-left: auto; }

/* ==========================================================================
   10 · OVERLAYS
   ========================================================================== */
dialog.ds-modal {
  padding: 0; border: 1px solid var(--ds-border); border-radius: var(--ds-r-modal);
  background: var(--ds-surface); color: var(--ds-text);
  box-shadow: var(--ds-e-modal); width: min(440px, calc(100vw - 32px));
}
dialog.ds-modal::backdrop { background: var(--ds-backdrop); backdrop-filter: blur(2px); }
.modal-head { padding: 16px 18px 0; }
.modal-body { padding: 8px 18px 16px; color: var(--ds-text-secondary); font-size: 13px; line-height: 1.5; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px;
  border-top: 1px solid var(--ds-border-subtle); background: var(--ds-surface-2);
  border-radius: 0 0 var(--ds-r-modal) var(--ds-r-modal);
}

.menu {
  min-width: 190px; padding: 4px; background: var(--ds-surface);
  border: 1px solid var(--ds-border); border-radius: var(--ds-r-card);
  box-shadow: var(--ds-e-overlay);
}
.menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 6px 8px; border: 0; border-radius: 5px; background: transparent;
  color: var(--ds-text); font-family: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.menu-item:hover { background: var(--ds-surface-2); }
.menu-item-danger { color: var(--ds-danger-text); }
.menu-item-danger:hover { background: var(--ds-danger-soft); }
.menu-sep { height: 1px; margin: 4px 0; background: var(--ds-border-subtle); }
.menu-item kbd { margin-left: auto; }

.tooltip { position: relative; display: inline-flex; }
.tooltip::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%); padding: 4px 8px; border-radius: 5px;
  background: var(--ds-text); color: var(--ds-canvas);
  font-size: 11px; white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity var(--ds-t-fast) var(--ds-ease);
}
.tooltip:hover::after, .tooltip:focus-within::after { opacity: 1; }

/* ==========================================================================
   11 · NAVEGACIÓN
   ========================================================================== */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--ds-border); }
.tab {
  padding: 7px 12px; border: 0; background: transparent; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  color: var(--ds-text-muted); font-family: inherit; font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
  transition: color var(--ds-t-fast) var(--ds-ease), border-color var(--ds-t-fast) var(--ds-ease);
}
.tab:hover { color: var(--ds-text); }
.tab[aria-selected="true"] { color: var(--ds-text); border-bottom-color: var(--ds-accent-solid); }
.tab .badge { background: var(--ds-surface-3); }
.tab[aria-selected="true"] .badge { background: var(--ds-accent-soft); color: var(--ds-accent-text); }

.crumbs { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ds-text-muted); }
.crumbs a { color: var(--ds-text-muted); text-decoration: none; }
.crumbs a:hover { color: var(--ds-text); text-decoration: underline; }
.crumbs [aria-current] { color: var(--ds-text); }

/* Chips de filtro: son botones que aplican el filtro y muestran el conteo
   del subconjunto, no etiquetas decorativas. */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--ds-border); background: var(--ds-surface);
  color: var(--ds-text-secondary); font-family: inherit; font-size: 12px; cursor: pointer;
  transition: background var(--ds-t-fast) var(--ds-ease), border-color var(--ds-t-fast) var(--ds-ease), color var(--ds-t-fast) var(--ds-ease);
}
.chip:hover { border-color: var(--ds-border-strong); background: var(--ds-surface-2); }
.chip[aria-pressed="true"] { background: var(--ds-accent-soft); border-color: var(--ds-accent-solid); color: var(--ds-accent-text); font-weight: 500; }
.chip .n { font-variant-numeric: tabular-nums; font-weight: 600; }

.seg { display: inline-flex; padding: 2px; gap: 2px; background: var(--ds-surface-2); border: 1px solid var(--ds-border-subtle); border-radius: var(--ds-r-control); }
.seg button {
  padding: 4px 10px; border: 0; border-radius: 4px; background: transparent;
  color: var(--ds-text-muted); font-family: inherit; font-size: 12px; font-weight: 500; cursor: pointer;
  transition: background var(--ds-t-fast) var(--ds-ease), color var(--ds-t-fast) var(--ds-ease);
}
.seg button[aria-pressed="true"] { background: var(--ds-surface); color: var(--ds-text); box-shadow: var(--ds-e-raised); }

.nav-link {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 6px 8px; border: 0; border-radius: 5px; background: transparent;
  color: var(--ds-text-secondary); font-family: inherit; font-size: 13px; text-align: left; cursor: pointer;
  transition: background var(--ds-t-fast) var(--ds-ease), color var(--ds-t-fast) var(--ds-ease);
}
.nav-link:hover { background: var(--ds-surface-2); color: var(--ds-text); }
.nav-link[aria-current="true"], .nav-link[aria-current="page"] { background: var(--ds-accent-soft); color: var(--ds-accent-text); font-weight: 500; }
.nav-link .n { margin-left: auto; font-size: 11px; color: var(--ds-text-muted); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   12 · ESTADOS
   Carga, vacío, sin resultados y error son cuatro estados distintos y
   necesitan cuatro tratamientos. Nunca mostrar el vacío mientras carga.
   ========================================================================== */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 40px 24px; border: 1px dashed var(--ds-border); border-radius: var(--ds-r-card);
  background: var(--ds-surface);
}
.empty-icon {
  display: grid; place-items: center; width: 40px; height: 40px; margin-bottom: 12px;
  border-radius: 50%; background: var(--ds-surface-2); color: var(--ds-text-muted);
}
.empty-icon svg { width: 20px; height: 20px; }
.empty-danger { border-style: solid; border-color: color-mix(in srgb, var(--ds-danger) 30%, transparent); }
.empty-danger .empty-icon { background: var(--ds-danger-soft); color: var(--ds-danger-text); }

.skel { background: var(--ds-surface-2); border-radius: 5px; position: relative; overflow: hidden; }
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--ds-surface-3) 70%, transparent), transparent);
  animation: ds-shimmer 1.4s infinite;
}
@keyframes ds-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

.progress { height: 5px; border-radius: 999px; background: var(--ds-surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 999px; background: var(--ds-accent-solid); transition: width var(--ds-t-slow) var(--ds-ease); }

/* ==========================================================================
   13 · PATRONES COMPUESTOS
   ========================================================================== */

/* Árbol colapsable — para jerarquías largas que no deben renderizarse
   enteras de una. */
.tree-node { border-bottom: 1px solid var(--ds-border-subtle); }
.tree-node:last-child { border-bottom: 0; }
.tree-head {
  display: flex; align-items: center; gap: 9px; width: 100%; padding: 9px 12px;
  border: 0; background: transparent; color: var(--ds-text); font-family: inherit; font-size: 13px;
  text-align: left; cursor: pointer;
}
.tree-head:hover { background: var(--ds-surface-2); }
.tree-caret { width: 14px; flex: none; color: var(--ds-text-muted); transition: transform var(--ds-t-fast) var(--ds-ease); }
.tree-node[data-open] .tree-caret { transform: rotate(90deg); }
.tree-kids { display: none; }
.tree-node[data-open] .tree-kids { display: block; }
.tree-leaf {
  display: flex; align-items: center; gap: 9px; padding: 7px 12px 7px 34px;
  border-top: 1px solid var(--ds-border-subtle); font-size: 13px;
}
.tree-leaf:hover { background: var(--ds-surface-2); }
.tree-leaf[data-out] { opacity: .45; }
.tree-leaf .ctx { flex: 1; min-width: 0; color: var(--ds-text-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-leaf .ctx[data-empty] { color: var(--ds-warn-text); }

/* Command palette */
.cmdk-wrap { position: fixed; inset: 0; z-index: 400; display: none; padding-top: 12vh; justify-content: center; background: var(--ds-backdrop); }
.cmdk-wrap[data-open] { display: flex; }
.cmdk {
  width: min(540px, calc(100vw - 32px)); height: fit-content; max-height: 60vh; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--ds-surface); border: 1px solid var(--ds-border);
  border-radius: var(--ds-r-modal); box-shadow: var(--ds-e-modal);
}
.cmdk input {
  height: 46px; padding: 0 14px; border: 0; border-bottom: 1px solid var(--ds-border-subtle);
  background: transparent; color: var(--ds-text); font-family: inherit; font-size: 14px; outline: none;
}
.cmdk-list { overflow-y: auto; padding: 6px; }
.cmdk-group { padding: 8px 8px 4px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--ds-text-muted); }
.cmdk-item { display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 5px; font-size: 13px; cursor: pointer; }
.cmdk-item[data-sel] { background: var(--ds-accent-soft); color: var(--ds-accent-text); }
.cmdk-item kbd { margin-left: auto; }

/* Conversación */
.bubble { max-width: 78%; padding: 9px 12px; border-radius: 10px; font-size: 13px; line-height: 1.5; }
.bubble-user { margin-left: auto; background: var(--ds-accent-solid); color: var(--ds-on-solid); border-bottom-right-radius: 3px; }
.bubble-bot  { background: var(--ds-surface-2); color: var(--ds-text); border-bottom-left-radius: 3px; }
.msg-actions { display: flex; gap: 1px; margin-top: 5px; opacity: 0; transition: opacity var(--ds-t-fast) var(--ds-ease); }
.msg-row:hover .msg-actions, .msg-row:focus-within .msg-actions { opacity: 1; }

/* ==========================================================================
   14 · UTILIDADES
   ========================================================================== */
.stack  { display: flex; flex-direction: column; gap: var(--ds-gap); }
.row    { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--ds-gap); }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.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; }
