/*
 * Demo A · Suite operativa B2B en marca blanca (datos inventados)
 * Reutiliza el sistema visual golden-dashboard-shell (DEC-44) sobre los tokens
 * y capas del motor ui-engine (IBM Plex Sans + Mono, breakpoints en em, contraste WCAG AA).
 * Marca blanca: acento azul pizarra #1D4E89 (sin marca ni datos reales).
 */

@layer tokens, kit, golden;

@import url("tokens.css") layer(tokens);
@import url("kit.css") layer(kit);

@layer golden {
  :root {
    /* Marca blanca: Cerámica Soler Mayorista (ficticia) */
    --ui-accent: #1D4E89;
    --ui-accent-hover: #153B69;
    --ui-on-accent: #FFFFFF;
    --ui-accent-text: #1D4E89;
    --ui-focus: #1D4E89;

    /* Superficies exactas de golden-dashboard-shell (auditadas WCAG AA) */
    --ui-bg: #F6F6F4;
    --ui-surface: #FFFFFF;
    --ui-surface-muted: #F6F6F4;
    --ui-control: #EFEEEA;
    --ui-border: #E6E5E1;
    --ui-border-subtle: #EFEEEA;
    --ui-border-field: #8F8D8A; /* 3.31:1 sobre blanco, 3.06:1 sobre canvas */
    --ui-ink: #17161B;
    --ui-ink-soft: #53525A;     /* 7.13:1 sobre canvas */
    --ui-ink-muted: #666470;    /* >5.3:1 sobre blanco y canvas */

    /* Semántica operativa (texto + borde + punto; nunca solo fondo) */
    --g-accent-soft: #E8F0FA;
    --g-ok-fg: #166534;
    --g-ok-bg: #E7F7EF;
    --g-warn-fg: #854D0E;
    --g-warn-bg: #FBF1D6;
    --g-err-fg: #991B1B;
    --g-err-bg: #FBE9E9;
    --g-info-fg: #1D4E89;
    --g-info-bg: #E8F0FA;
    --g-neutral-fg: #47464F;
    --g-neutral-bg: #EFEEEA;

    --g-radius-md: 10px;
    --g-radius-lg: 14px;
    --g-shadow-subtle: 0 1px 2px rgba(23, 22, 27, 0.04);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --ui-accent: #2C67B0;
      --ui-accent-hover: #21518D;
      --ui-on-accent: #FFFFFF;
      --ui-accent-text: #8CC0FF;
      --ui-focus: #8CC0FF;
      --ui-bg: #111214;
      --ui-surface: #181A1D;
      --ui-surface-muted: #1E2125;
      --ui-control: #25292E;
      --ui-border: #2C3137;
      --ui-border-subtle: #22262B;
      --ui-border-field: #5A626C;
      --ui-ink: #ECEEF0;
      --ui-ink-soft: #C5CBD2;
      --ui-ink-muted: #9AA2AC;
      --g-accent-soft: #1B2C42;
      --g-ok-fg: #6EE7B7;
      --g-ok-bg: #122921;
      --g-warn-fg: #FCD34D;
      --g-warn-bg: #2D2310;
      --g-err-fg: #FCA5A5;
      --g-err-bg: #321619;
      --g-info-fg: #8CC0FF;
      --g-info-bg: #1B2C42;
      --g-neutral-fg: #C5CBD2;
      --g-neutral-bg: #25292E;
    }
  }

  :root[data-theme="dark"] {
    --ui-accent: #2C67B0;
    --ui-accent-hover: #21518D;
    --ui-on-accent: #FFFFFF;
    --ui-accent-text: #8CC0FF;
    --ui-focus: #8CC0FF;
    --ui-bg: #111214;
    --ui-surface: #181A1D;
    --ui-surface-muted: #1E2125;
    --ui-control: #25292E;
    --ui-border: #2C3137;
    --ui-border-subtle: #22262B;
    --ui-border-field: #5A626C;
    --ui-ink: #ECEEF0;
    --ui-ink-soft: #C5CBD2;
    --ui-ink-muted: #9AA2AC;
    --g-accent-soft: #1B2C42;
    --g-ok-fg: #6EE7B7;
    --g-ok-bg: #122921;
    --g-warn-fg: #FCD34D;
    --g-warn-bg: #2D2310;
    --g-err-fg: #FCA5A5;
    --g-err-bg: #321619;
    --g-info-fg: #8CC0FF;
    --g-info-bg: #1B2C42;
    --g-neutral-fg: #C5CBD2;
    --g-neutral-bg: #25292E;
  }

  html {
    margin: 0;
    font-size: 100%;
    background: var(--ui-bg);
    color: var(--ui-ink);
  }

  body {
    margin: 0;
    background: var(--ui-bg);
    color: var(--ui-ink);
    font-family: var(--ui-font-sans);
    font-size: var(--ui-text-md);
    line-height: 1.45;
  }

  [hidden] {
    display: none !important;
  }

  /* ── Shell operativo (AppShell + Sidebar golden-dashboard-shell) ───────── */
  .g-shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    background: var(--ui-bg);
  }

  .g-sidebar {
    display: none;
    background: var(--ui-bg);
    border-right: 1px solid var(--ui-border);
  }

  .g-sidebar.is-open {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0;
    z-index: 40;
    max-width: min(17.5rem, 100vw);
    background: var(--ui-surface);
    border-right: 1px solid var(--ui-border);
    overflow-y: auto;
  }

  .g-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(23, 22, 27, 0.45);
  }

  .g-backdrop.is-open {
    display: block;
  }

  .g-sidebar__inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 0.875rem 0.75rem;
    gap: 0.75rem;
  }

  .g-brand-row {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0 0.25rem 0.375rem;
  }

  .g-brand-mark {
    width: 2rem;
    height: 2rem;
    border-radius: var(--g-radius-md);
    background: var(--ui-accent);
    color: var(--ui-on-accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--ui-weight-bold);
    font-size: var(--ui-text-sm);
    flex: none;
  }

  .g-brand-text {
    min-width: 0;
    flex: 1 1 auto;
  }

  .g-brand-name {
    display: block;
    font-size: var(--ui-text-sm);
    font-weight: var(--ui-weight-bold);
    color: var(--ui-ink);
    line-height: 1.2;
  }

  .g-brand-sub {
    display: block;
    font-size: var(--ui-text-xs);
    color: var(--ui-ink-muted);
  }

  .g-quick-find {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.625rem;
    border-radius: var(--g-radius-md);
    border: 1px solid var(--ui-border-field);
    background: var(--ui-surface);
    color: var(--ui-ink-muted);
    font-size: var(--ui-text-xs);
    text-decoration: none;
  }

  .g-quick-find kbd {
    margin-left: auto;
    font-family: var(--ui-font-mono);
    font-size: var(--ui-text-2xs);
    padding: 0.05rem 0.35rem;
    border-radius: 4px;
    border: 1px solid var(--ui-border);
    background: var(--ui-bg);
    color: var(--ui-ink-muted);
  }

  .g-nav {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    flex: 1 1 auto;
  }

  .g-nav__section {
    padding: 0.875rem 0.625rem 0.25rem;
    font-size: var(--ui-text-2xs);
    font-weight: var(--ui-weight-medium);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ui-ink-muted);
  }

  .g-nav__link {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-height: 2.375rem;
    padding: 0.45rem 0.625rem;
    border-radius: var(--g-radius-md);
    color: var(--ui-ink-soft);
    text-decoration: none;
    font-size: var(--ui-text-sm);
    transition: background var(--ui-duration) var(--ui-ease), color var(--ui-duration) var(--ui-ease);
  }

  .g-nav__link svg {
    width: 1.0625rem;
    height: 1.0625rem;
    flex: none;
  }

  .g-nav__badge {
    margin-left: auto;
    font-family: var(--ui-font-mono);
    font-size: var(--ui-text-2xs);
    font-weight: var(--ui-weight-medium);
    padding: 0.1rem 0.42rem;
    border-radius: 999px;
    background: var(--g-accent-soft);
    color: var(--ui-accent-text);
  }

  @media (hover: hover) and (pointer: fine) {
    .g-nav__link:hover {
      background: color-mix(in srgb, var(--ui-surface) 75%, transparent);
      color: var(--ui-ink);
    }
  }

  .g-nav__link[aria-current="page"] {
    background: var(--ui-surface);
    color: var(--ui-ink);
    font-weight: var(--ui-weight-medium);
    box-shadow: var(--g-shadow-subtle);
  }

  .g-nav__link[aria-current="page"] svg {
    color: var(--ui-accent-text);
  }

  .g-sidebar__foot {
    border-top: 1px solid var(--ui-border);
    padding-top: 0.625rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: var(--ui-text-xs);
    color: var(--ui-ink-muted);
  }

  .g-sidebar__foot strong {
    color: var(--ui-ink);
    font-weight: var(--ui-weight-medium);
  }

  /* Barra móvil superior */
  .g-mobile-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem 0.5rem;
    min-height: 3.5rem;
    padding: 0.5rem 0.875rem;
    background: var(--ui-surface);
    border-bottom: 1px solid var(--ui-border);
  }

  .g-mobile-bar__left {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-width: 0;
  }

  .g-main-col {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
  }

  .g-demo-ribbon {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem 1rem;
    padding: 0.375rem 1rem;
    background: var(--ui-surface);
    border-bottom: 1px solid var(--ui-border);
    font-size: var(--ui-text-xs);
    color: var(--ui-ink-muted);
    overflow-wrap: anywhere;
  }

  .g-demo-ribbon__tag {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--ui-font-mono);
    font-size: var(--ui-text-2xs);
    font-weight: var(--ui-weight-bold);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ui-ink);
  }

  .g-demo-ribbon__dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 2px;
    background: var(--g-warn-fg);
    flex: none;
  }

  .g-content {
    flex: 1 1 auto;
    width: 100%;
    max-width: 82rem;
    margin: 0 auto;
    padding: 1rem 1rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
  }

  @media (min-width: 64em) {
    .g-shell {
      flex-direction: row;
    }

    .g-sidebar {
      display: flex;
      flex-direction: column;
      flex: none;
      width: 14.5rem;
      position: sticky;
      top: 0;
      height: 100dvh;
      overflow-y: auto;
    }

    .g-mobile-bar,
    .g-sidebar__close {
      display: none;
    }

    .g-demo-ribbon {
      padding: 0.375rem 1.75rem;
    }

    .g-content {
      padding: 1.125rem 1.75rem 2rem;
    }
  }

  /* ── Cabecera de página (PageHeader) ───────────────────────────────────── */
  .g-page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.625rem 1rem;
  }

  .g-page-head__title {
    margin: 0;
    font-size: 1.375rem;
    font-weight: var(--ui-weight-bold);
    line-height: 1.25;
    color: var(--ui-ink);
    overflow-wrap: anywhere;
  }

  .g-page-head__sub {
    margin: 0.15rem 0 0;
    font-size: var(--ui-text-sm);
    color: var(--ui-ink-soft);
    overflow-wrap: anywhere;
  }

  .g-page-head__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    max-width: 100%;
  }

  /* ── Controles y botones (Golden) ──────────────────────────────────────── */
  .g-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 2.25rem;
    padding: 0.375rem 0.875rem;
    border-radius: var(--g-radius-md);
    border: 1px solid var(--ui-border-field);
    background: var(--ui-surface);
    color: var(--ui-ink);
    font: inherit;
    font-size: var(--ui-text-sm);
    font-weight: var(--ui-weight-medium);
    text-decoration: none;
    cursor: pointer;
    max-width: 100%;
    white-space: normal;
    text-align: center;
    transition: background var(--ui-duration) var(--ui-ease), color var(--ui-duration) var(--ui-ease), border-color var(--ui-duration) var(--ui-ease);
  }

  .g-btn svg {
    width: 0.95rem;
    height: 0.95rem;
    flex: none;
  }

  @media (hover: hover) and (pointer: fine) {
    .g-btn:hover {
      background: var(--ui-bg);
    }
  }

  .g-btn--primary {
    background: var(--ui-accent);
    border-color: var(--ui-accent);
    color: var(--ui-on-accent);
  }

  @media (hover: hover) and (pointer: fine) {
    .g-btn--primary:hover {
      background: var(--ui-accent-hover);
      border-color: var(--ui-accent-hover);
    }
  }

  .g-btn--soft {
    background: var(--g-accent-soft);
    border-color: color-mix(in srgb, var(--ui-accent-text) 35%, transparent);
    color: var(--ui-accent-text);
    min-height: 2rem;
    padding: 0.25rem 0.625rem;
    font-size: var(--ui-text-xs);
    white-space: nowrap;
  }

  @media (hover: hover) and (pointer: fine) {
    .g-btn--soft:hover {
      background: var(--ui-accent);
      border-color: var(--ui-accent);
      color: var(--ui-on-accent);
    }
  }

  .g-btn:disabled,
  .g-btn[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .g-seg-group {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 2px;
    border-radius: var(--g-radius-md);
    border: 1px solid var(--ui-border-field);
    background: var(--ui-surface);
    gap: 2px;
    max-width: 100%;
  }

  .g-panel .g-seg-group {
    border: 0;
    background: var(--ui-control);
    border-radius: 6px;
  }

  .g-seg-btn {
    border: 0;
    border-radius: 7px;
    padding: 0.3rem 0.65rem;
    min-height: 2rem;
    background: transparent;
    color: var(--ui-ink-soft);
    font: inherit;
    font-size: var(--ui-text-xs);
    font-weight: var(--ui-weight-medium);
    cursor: pointer;
    white-space: normal;
  }

  .g-seg-btn[aria-pressed="true"] {
    background: var(--ui-ink);
    color: var(--ui-surface);
  }

  .g-seg-btn--soft[aria-pressed="true"] {
    background: var(--g-accent-soft);
    color: var(--ui-accent-text);
  }

  /* ── Paneles Golden (sin tarjetas anidadas) ────────────────────────────── */
  .g-panel {
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: var(--g-radius-lg);
    overflow: hidden;
  }

  .g-panel__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.375rem 0.75rem;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--ui-border);
  }

  .g-panel__title {
    margin: 0;
    font-size: var(--ui-text-sm);
    font-weight: var(--ui-weight-bold);
    color: var(--ui-ink);
    overflow-wrap: anywhere;
  }

  .g-panel__meta {
    font-size: var(--ui-text-xs);
    color: var(--ui-ink-muted);
    overflow-wrap: anywhere;
  }

  .g-panel__body {
    padding: 0.875rem 1rem;
  }

  /* ── Banda de pendientes actuales (Overview) ───────────────────────────── */
  .g-alerts-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  @media (min-width: 44em) {
    .g-alerts-grid {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }

  .g-alert-cell {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: inherit;
    border-top: 1px solid var(--ui-border);
    transition: background var(--ui-duration) var(--ui-ease);
  }

  .g-alert-cell:first-child {
    border-top: 0;
  }

  @media (min-width: 44em) {
    .g-alert-cell {
      border-top: 0;
      border-left: 1px solid var(--ui-border);
    }
    .g-alert-cell:first-child {
      border-left: 0;
    }
  }

  @media (hover: hover) and (pointer: fine) {
    .g-alert-cell:hover {
      background: var(--ui-bg);
    }
  }

  .g-alert-cell__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: var(--ui-text-xs);
    color: var(--ui-ink-soft);
  }

  .g-alert-cell__val {
    font-family: var(--ui-font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 1.5rem;
    font-weight: var(--ui-weight-bold);
    line-height: 1.2;
    color: var(--ui-ink);
  }

  .g-alert-cell__sub {
    font-size: var(--ui-text-xs);
    color: var(--ui-ink-muted);
  }

  /* ── Grids operativos ──────────────────────────────────────────────────── */
  .g-overview-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.875rem;
  }

  @media (min-width: 58em) {
    .g-overview-grid {
      grid-template-columns: 22rem minmax(0, 1fr);
    }
  }

  .g-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
    gap: 0.75rem;
  }

  .g-kpi {
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: var(--g-radius-lg);
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 0;
  }

  .g-kpi__label {
    font-size: var(--ui-text-xs);
    color: var(--ui-ink-soft);
  }

  .g-kpi__row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.5rem;
  }

  .g-kpi__val {
    font-family: var(--ui-font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 1.375rem;
    font-weight: var(--ui-weight-bold);
    color: var(--ui-ink);
    overflow-wrap: anywhere;
  }

  .g-kpi__delta {
    font-family: var(--ui-font-mono);
    font-size: var(--ui-text-xs);
    font-weight: var(--ui-weight-medium);
  }

  .g-kpi__delta--up { color: var(--g-ok-fg); }
  .g-kpi__delta--down { color: var(--g-err-fg); }
  .g-kpi__sub { font-size: var(--ui-text-xs); color: var(--ui-ink-muted); }

  /* Flujo comercial (plano sin tarjetas anidadas con borde) */
  .g-flow-pair {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr));
    gap: 0.5rem;
  }

  .g-flow-node {
    background: var(--ui-bg);
    border-radius: var(--g-radius-md);
    padding: 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
  }

  .g-flow-node--row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
  }

  .g-flow-node__label {
    font-size: var(--ui-text-xs);
    color: var(--ui-ink-soft);
  }

  .g-flow-node__val {
    font-family: var(--ui-font-mono);
    font-size: 1.0625rem;
    font-weight: var(--ui-weight-bold);
    color: var(--ui-ink);
  }

  .g-flow-connector {
    height: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ui-ink-muted);
    font-size: var(--ui-text-xs);
  }

  /* DotChart SVG / grid */
  .g-dotchart {
    display: grid;
    grid-template-columns: repeat(24, minmax(0, 1fr));
    gap: 3px;
    align-items: end;
    height: 6.5rem;
    padding-top: 0.5rem;
  }

  .g-dotchart__col {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 3px;
  }

  .g-dot {
    width: 5px;
    height: 5px;
    border-radius: 999px;
    background: var(--ui-border);
  }

  .g-dot--on {
    background: var(--ui-accent);
  }

  .g-chart-meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.375rem 1rem;
    margin-top: 0.625rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--ui-border-subtle);
    font-size: var(--ui-text-xs);
    color: var(--ui-ink-muted);
  }

  /* ── Pestañas de etapa con subrayado de acento (Operations.tsx) ────────── */
  .g-tabs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    border-bottom: 1px solid var(--ui-border);
  }

  .g-tab {
    position: relative;
    border: 0;
    background: transparent;
    padding: 0.6rem 0.75rem;
    min-height: 2.5rem;
    color: var(--ui-ink-soft);
    font: inherit;
    font-size: var(--ui-text-sm);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
  }

  .g-tab__count {
    font-family: var(--ui-font-mono);
    font-size: var(--ui-text-xs);
    color: var(--ui-ink-muted);
  }

  .g-tab[aria-pressed="true"] {
    color: var(--ui-ink);
    font-weight: var(--ui-weight-bold);
  }

  .g-tab[aria-pressed="true"]::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    background: var(--ui-accent);
  }

  /* ── Barra de filtros con etiqueta visible estable (WCAG Operations.tsx) ─ */
  .g-filterbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.625rem;
  }

  .g-search-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1 1 min(100%, 16rem);
    max-width: 24rem;
    min-width: 0;
  }

  .g-search-field label {
    font-size: var(--ui-text-xs);
    font-weight: var(--ui-weight-medium);
    color: var(--ui-ink-soft);
  }

  .g-search-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.375rem;
    padding: 0 0.65rem;
    border-radius: var(--g-radius-md);
    border: 1px solid var(--ui-border-field);
    background: var(--ui-surface);
    color: var(--ui-ink-muted);
  }

  .g-search-box:focus-within {
    border-color: var(--ui-focus);
    box-shadow: 0 0 0 1px var(--ui-focus);
  }

  .g-search-box input {
    width: 100%;
    min-width: 0;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--ui-ink);
    font: inherit;
    font-size: var(--ui-text-sm);
  }

  /* ── Badges semánticos Recognition-First (borde + punto + texto) ───────── */
  .g-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: var(--ui-text-xs);
    font-weight: var(--ui-weight-medium);
    line-height: 1.3;
    border: 1px solid color-mix(in srgb, currentColor 28%, transparent);
    max-width: 100%;
    white-space: nowrap;
  }

  .g-badge::before {
    content: "";
    width: 0.42rem;
    height: 0.42rem;
    border-radius: 2px;
    background: currentColor;
    flex: none;
  }

  .g-badge--ok { color: var(--g-ok-fg); background: var(--g-ok-bg); }
  .g-badge--warn { color: var(--g-warn-fg); background: var(--g-warn-bg); }
  .g-badge--err { color: var(--g-err-fg); background: var(--g-err-bg); }
  .g-badge--info { color: var(--g-info-fg); background: var(--g-info-bg); }
  .g-badge--neutral { color: var(--g-neutral-fg); background: var(--g-neutral-bg); }

  /* ── Tabla operativa densa en escritorio + apilado limpio en móvil ─────── */
  .g-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .g-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--ui-text-sm);
  }

  .g-table th,
  .g-table td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--ui-border-subtle);
    vertical-align: middle;
  }

  .g-table th:first-child,
  .g-table td:first-child { padding-left: 1rem; }
  .g-table th:last-child,
  .g-table td:last-child { padding-right: 1rem; }

  .g-table thead th {
    font-size: var(--ui-text-xs);
    font-weight: var(--ui-weight-medium);
    color: var(--ui-ink-muted);
    border-bottom: 1px solid var(--ui-border);
    white-space: nowrap;
  }

  .g-table tbody tr:last-child td { border-bottom: 0; }
  .g-table .ui-end { text-align: right; }

  @media (hover: hover) and (pointer: fine) {
    .g-table tbody tr:hover {
      background: color-mix(in srgb, var(--ui-bg) 65%, transparent);
    }
  }

  .g-link-strong {
    color: var(--ui-ink);
    font-weight: var(--ui-weight-bold);
    text-decoration: none;
  }

  .g-link-strong:hover {
    color: var(--ui-accent-text);
    text-decoration: underline;
  }

  .g-sub {
    display: block;
    font-size: var(--ui-text-xs);
    color: var(--ui-ink-muted);
    margin-top: 0.1rem;
    overflow-wrap: anywhere;
  }

  /* Reflow por debajo de 56em para tablas densas (nunca comprime 11 columnas) */
  @media (max-width: 56em) {
    .g-table--responsive thead {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip: rect(0 0 0 0);
      white-space: nowrap;
    }

    .g-table--responsive,
    .g-table--responsive tbody,
    .g-table--responsive tr,
    .g-table--responsive td {
      display: block;
      width: 100%;
    }

    .g-table--responsive tr {
      padding: 0.75rem 1rem;
      border-bottom: 1px solid var(--ui-border);
    }

    .g-table--responsive tr:last-child { border-bottom: 0; }

    .g-table--responsive td,
    .g-table--responsive td:first-child,
    .g-table--responsive td:last-child {
      padding: 0.2rem 0;
      border-bottom: 0;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      align-items: center;
      gap: 0.25rem 0.75rem;
      text-align: left;
      overflow-wrap: anywhere;
    }

    .g-table--responsive td::before {
      content: attr(data-label);
      font-size: var(--ui-text-xs);
      color: var(--ui-ink-muted);
    }

    .g-table--responsive td[data-primary="true"] {
      display: block;
      padding-bottom: 0.35rem;
    }

    .g-table--responsive td[data-primary="true"]::before {
      display: none;
    }
  }

  /* ── Split y ficha de detalle ──────────────────────────────────────────── */
  .g-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.875rem;
    align-items: start;
  }

  @media (min-width: 58em) {
    .g-split {
      grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
    }
  }

  .g-split--even {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.875rem;
    align-items: start;
  }

  @media (min-width: 52em) {
    .g-split--even {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  .g-dl {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 11.5rem), 1fr));
    margin: 0;
  }

  .g-dl__item {
    min-width: 0;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--ui-border-subtle);
  }

  .g-dl__item dt {
    font-size: var(--ui-text-xs);
    color: var(--ui-ink-muted);
    margin-bottom: 0.15rem;
  }

  .g-dl__item dd {
    margin: 0;
    font-size: var(--ui-text-sm);
    font-weight: var(--ui-weight-medium);
    color: var(--ui-ink);
    overflow-wrap: anywhere;
  }

  /* Actos humanos separados / puertas fail-closed */
  .g-gates {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
    gap: 0.75rem;
  }

  .g-gate {
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: var(--g-radius-lg);
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
  }

  .g-gate--blocked {
    border-color: color-mix(in srgb, var(--g-err-fg) 38%, var(--ui-border));
  }

  .g-gate--pending {
    border-color: color-mix(in srgb, var(--g-warn-fg) 38%, var(--ui-border));
  }

  .g-gate__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem;
  }

  .g-gate__title {
    margin: 0;
    font-size: var(--ui-text-sm);
    font-weight: var(--ui-weight-bold);
    color: var(--ui-ink);
  }

  .g-gate__text {
    margin: 0;
    font-size: var(--ui-text-xs);
    color: var(--ui-ink-soft);
    overflow-wrap: anywhere;
  }

  /* Totales y stepper */
  .g-stepper {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.5rem;
    padding: 0.55rem 0.875rem;
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: var(--g-radius-lg);
    list-style: none;
    margin: 0;
    font-size: var(--ui-text-xs);
  }

  .g-stepper li {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    max-width: 100%;
  }

  .g-stepper li + li::before {
    content: "/";
    color: var(--ui-border-field);
  }

  .g-stepper a {
    color: var(--ui-ink-muted);
    text-decoration: none;
    padding: 0.2rem 0.45rem;
    border-radius: 6px;
    overflow-wrap: anywhere;
  }

  .g-stepper a[aria-current="step"] {
    background: var(--g-accent-soft);
    color: var(--ui-accent-text);
    font-weight: var(--ui-weight-bold);
  }

  .g-totals {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.875rem 1rem;
    background: var(--ui-surface-muted);
    border-top: 1px solid var(--ui-border);
  }

  .g-totals__row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.25rem 0.75rem;
    font-size: var(--ui-text-sm);
    color: var(--ui-ink-soft);
  }

  .g-totals__row--grand {
    border-top: 1px solid var(--ui-border);
    padding-top: 0.5rem;
    margin-top: 0.2rem;
    font-weight: var(--ui-weight-bold);
    color: var(--ui-ink);
  }

  .g-totals__row--grand .ui-num {
    font-size: 1.1875rem;
  }

  /* Bloque de etiqueta térmica y código de barras sintético */
  .g-label-sheet {
    padding: 0.875rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
  }

  .g-label-sheet__head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.35rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--ui-border);
    font-size: var(--ui-text-xs);
    font-weight: var(--ui-weight-bold);
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .g-barcode {
    border-top: 1px solid var(--ui-border);
    padding-top: 0.625rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }

  .g-barcode svg {
    width: 100%;
    max-width: 16rem;
    height: 2.4rem;
    color: var(--ui-ink);
  }

  .g-notice {
    padding: 0.65rem 0.875rem;
    border-radius: var(--g-radius-md);
    border: 1px solid var(--ui-border);
    background: var(--ui-surface);
    font-size: var(--ui-text-sm);
    color: var(--ui-ink-soft);
    overflow-wrap: anywhere;
  }

  .g-notice--err { border-color: color-mix(in srgb, var(--g-err-fg) 40%, var(--ui-border)); }
  .g-notice--ok { border-color: color-mix(in srgb, var(--g-ok-fg) 40%, var(--ui-border)); }
  .g-notice strong { color: var(--ui-ink); }

  .g-feedback { display: none; }
  .g-feedback.is-visible { display: block; }

  .g-timeline {
    list-style: none;
    margin: 0;
    padding: 0;
  }

  .g-timeline li {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.25rem 0.75rem;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--ui-border-subtle);
    font-size: var(--ui-text-sm);
  }

  .g-timeline li:last-child { border-bottom: 0; }

  .g-timeline__time {
    font-family: var(--ui-font-mono);
    font-size: var(--ui-text-xs);
    color: var(--ui-ink-muted);
  }

  /* Estados de vista opcionales (?view=empty|error|loading) */
  [data-view="list"] .v-empty,
  [data-view="list"] .v-error,
  [data-view="list"] .v-loading,
  [data-view="empty"] .v-list,
  [data-view="empty"] .v-error,
  [data-view="empty"] .v-loading,
  [data-view="error"] .v-list,
  [data-view="error"] .v-empty,
  [data-view="error"] .v-loading,
  [data-view="loading"] .v-list,
  [data-view="loading"] .v-empty,
  [data-view="loading"] .v-error {
    display: none;
  }

  /* Enlace de salto para teclado */
  .g-skip {
    position: absolute;
    left: -9999px;
    top: 0.5rem;
    z-index: 60;
    padding: 0.5rem 0.875rem;
    background: var(--ui-accent);
    color: var(--ui-on-accent);
    border-radius: var(--g-radius-md);
    text-decoration: none;
    font-weight: var(--ui-weight-bold);
  }

  .g-skip:focus { left: 0.5rem; }

  /* Anchos extremos (320 px al 200 % = 160 px CSS) */
  @media (max-width: 24em) {
    .g-mobile-bar .g-brand-mark { display: none; }
    .g-mobile-bar__left { flex: 1 1 100%; min-width: 0; }
    .g-mobile-bar .g-brand-name { overflow-wrap: anywhere; }
    .g-badge,
    .g-btn--soft {
      white-space: normal;
      overflow-wrap: anywhere;
    }
    .g-content { padding: 0.625rem 0.625rem 1.5rem; }
    .g-panel__head,
    .g-panel__body,
    .g-dl__item,
    .g-alert-cell,
    .g-kpi,
    .g-gate,
    .g-label-sheet,
    .g-totals,
    .g-timeline li,
    .g-table--responsive tr {
      padding-left: 0.625rem;
      padding-right: 0.625rem;
    }
    .g-page-head__title { font-size: 1.125rem; }
    .g-dotchart { grid-template-columns: repeat(12, minmax(0, 1fr)); }
    .g-dotchart__col:nth-child(n+13) { display: none; }
  }
}


/* ── Guía editorial interactiva (Attio-inspired · claro, hairlines, cero neón) ── */
body.has-ed-guide .g-demo-ribbon { display: none; }

.ed-guide {
  position: sticky;
  top: 0;
  z-index: 30;
  background: #F3F3EF;
  color: #17161B;
  border-bottom: 1px solid #D5D4CC;
  font-family: var(--ui-font-sans);
}

.ed-guide__inner {
  max-width: 82rem;
  margin: 0 auto;
  padding: 0.5rem 1.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

.ed-guide__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.65rem;
  min-width: 0;
}

.ed-guide__back {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #47464F;
  text-decoration: none;
  padding: 0.25rem 0;
  min-height: 2rem;
}

.ed-guide__back:hover { color: #17161B; text-decoration: underline; text-underline-offset: 2px; }
.ed-guide__back svg { width: 0.9rem; height: 0.9rem; flex: none; }

.ed-guide__sep {
  width: 1px;
  height: 1rem;
  background: #CECDC5;
  flex: none;
}

.ed-guide__step {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  min-width: 0;
  flex-wrap: wrap;
}

.ed-guide__index {
  font-family: var(--ui-font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: #17161B;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.ed-guide__title {
  font-size: 0.8125rem;
  font-weight: 500;
  color: #47464F;
}

.ed-guide__demo-note {
  font-family: var(--ui-font-mono);
  font-size: 0.6875rem;
  color: #53525A;
  padding: 0.12rem 0.45rem;
  border: 1px solid #D5D4CC;
  border-radius: 5px;
  background: #FAFAF7;
  white-space: nowrap;
}

.ed-switch {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, auto));
  gap: 2px;
  padding: 3px;
  background: #E5E4DE;
  border: 1px solid #D5D4CC;
  border-radius: 8px;
  max-width: 100%;
}

.ed-switch__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.125rem;
  padding: 0.3rem 0.7rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #44434B;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  white-space: normal;
  transition: background 120ms ease, color 120ms ease;
}

.ed-switch__btn:hover { color: #17161B; }

.ed-switch__dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.45;
  flex: none;
}

.ed-switch__btn[aria-pressed="true"] {
  background: #FFFFFF;
  color: #17161B;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(23, 22, 27, 0.08);
}

.ed-switch__btn[aria-pressed="true"] .ed-switch__dot { opacity: 1; }
.ed-switch__btn[data-ed-mode="tool"][aria-pressed="true"] .ed-switch__dot { background: #1D4E89; }
.ed-switch__btn[data-ed-mode="legacy"][aria-pressed="true"] { color: #7C4308; }
.ed-switch__btn[data-ed-mode="legacy"][aria-pressed="true"] .ed-switch__dot { background: #9A5B13; }

.ed-guide__nav {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.ed-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 2.125rem;
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  border: 1px solid #C8C7BF;
  background: #FFFFFF;
  color: #17161B;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  max-width: 100%;
  white-space: normal;
  text-align: center;
  transition: background 120ms ease, border-color 120ms ease;
}

.ed-btn:hover { background: #F8F8F5; border-color: #A8A79F; }

.ed-btn--primary {
  background: #1D4E89;
  border-color: #1D4E89;
  color: #FFFFFF;
  font-weight: 600;
}

.ed-btn--primary:hover { background: #153B69; border-color: #153B69; color: #FFFFFF; }

.ed-btn--quiet {
  background: transparent;
  border-color: #D5D4CC;
  color: #3E3D45;
}

.ed-btn--quiet:hover { background: #FFFFFF; color: #17161B; }

/* Ficha editorial de misión inline (dentro de <main>, no sticky) */
.ed-cue {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem 1rem;
  padding: 0.75rem 1rem;
  background: #FFFFFF;
  border: 1px solid #E2E1DC;
  border-left: 3px solid #1D4E89;
  border-radius: 10px;
}

.ed-cue--legacy {
  background: #FBF8F1;
  border-color: #E3D4B7;
  border-left-color: #9A5B13;
}

.ed-cue--done {
  background: #F3F9F5;
  border-color: #C5DFCD;
  border-left-color: #166534;
}

.ed-cue__body {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  flex: 1 1 20rem;
}

.ed-cue__eyebrow {
  font-family: var(--ui-font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #1D4E89;
}

.ed-cue--legacy .ed-cue__eyebrow { color: #7C4308; }
.ed-cue--done .ed-cue__eyebrow { color: #166534; }

.ed-cue__text {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.45;
  color: #17161B;
  overflow-wrap: anywhere;
}

.ed-cue--legacy .ed-cue__text { color: #2E2418; }
.ed-cue--done .ed-cue__text { color: #15291D; }

.ed-kbd {
  display: inline-block;
  padding: 0.05rem 0.42rem;
  margin: 0 0.1rem;
  border-radius: 5px;
  border: 1px solid #C9D7EA;
  background: #EEF4FC;
  color: #153B69;
  font-family: var(--ui-font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}

.ed-cue__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Señalización serena del botón objetivo (sin halo pulsante neón) */
.ed-target {
  outline: 2px solid #1D4E89;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(29, 78, 137, 0.13);
}

/* Emulación real in-place «Hoy, sin panel» dentro del bloque objetivo */
.ed-legacy-panel {
  padding: 1rem;
  background: #FBF8F1;
  border-top: 1px solid #E3D4B7;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ed-legacy-panel--standalone {
  border: 1px solid #E3D4B7;
  border-left: 3px solid #9A5B13;
  border-radius: 12px;
}

.ed-legacy-panel__tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  align-self: flex-start;
  font-family: var(--ui-font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #7C4308;
  background: #F5EAD4;
  border: 1px solid #DFC89F;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
}

.ed-legacy-panel__error {
  padding: 0.75rem 0.875rem;
  background: #FBE9E9;
  border: 1px solid #E7B8B8;
  border-radius: 8px;
  color: #8B1A1A;
  font-size: 0.875rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.ed-legacy-panel__error strong { display: block; margin-bottom: 0.2rem; color: #741212; }

.ed-legacy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
  gap: 0.625rem;
  margin: 0;
}

.ed-legacy-cell {
  background: #FFFFFF;
  border: 1px solid #E6DEC9;
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
}

.ed-legacy-cell dt {
  font-size: 0.75rem;
  font-weight: 600;
  color: #6B5B44;
  margin-bottom: 0.2rem;
}

.ed-legacy-cell dd {
  margin: 0;
  font-size: 0.84375rem;
  color: #2E2418;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.ed-legacy-panel__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  padding-top: 0.25rem;
}

.ed-legacy-panel__note {
  font-size: 0.8125rem;
  color: #5C4E3A;
}

.ed-legacy-hidden { display: none !important; }

@media (max-width: 63.99em) {
  .ed-guide { position: static; }
  .ed-guide__inner { padding: 0.625rem 0.875rem; gap: 0.55rem; }
  .ed-guide__meta { width: 100%; justify-content: space-between; }
  .ed-guide__sep, .ed-guide__demo-note { display: none; }
  .ed-switch { width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ed-guide__nav { width: 100%; }
  .ed-guide__nav .ed-btn { flex: 1 1 auto; }
}

@media (max-width: 24em) {
  .ed-guide__inner { padding: 0.5rem 0.625rem; }
  .ed-switch { grid-template-columns: minmax(0, 1fr); }
  .ed-cue { padding: 0.625rem; }
  .ed-kbd { white-space: normal; }
  .ed-legacy-panel { padding: 0.625rem; }
}
