/* ============================================================
   4DataFlow — Design tokens (basados en 4DataSuite)
   ------------------------------------------------------------
   Modo claro/oscuro: el tema se aplica con `data-theme="light|dark"`
   en <html>. El default (sin atributo) es dark, y `[data-theme="light"]`
   más abajo redefine los tokens visuales sin cambiar nombres — toda la
   UI sigue refiriéndose a las mismas variables (`--dark-card`,
   `--text-primary`, etc.) y resuelve a colores claros u oscuros según
   el atributo. Los tokens *brand* (teal/cyan) son comunes a ambos modos.
   ============================================================ */

:root {
    /* Brand (compartido entre temas) */
    --brand-teal: #009E8E;
    --brand-teal-light: #00C4B0;
    --brand-cyan: #00E5FF;
    --brand-slate: #516180;

    --gradient-brand: linear-gradient(135deg, #009E8E 0%, #00E5FF 100%);
    --gradient-brand-btn: linear-gradient(135deg, #00665C 0%, #0098B0 100%);
    --shadow-teal: 0 0 40px rgba(0, 158, 142, 0.30);

    --navbar-height: 64px;
    --sidemenu-width: 240px;

    /* ── Tokens dark (default) ──────────────────────────── */
    --dark-900: #060A10;
    --dark-800: #0B1120;
    --dark-700: #101827;
    --dark-card: #111827;
    --dark-card-2: #1A2540;

    --border: rgba(0, 158, 142, 0.18);
    --border-subtle: rgba(255, 255, 255, 0.06);

    --text-primary: #F0F6FF;
    --text-secondary: #94A3B8;
    --text-muted: #4B5A6E;

    --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.40);

    /* Superficies "elevadas" sobre cards. En dark se logran con
       overlays blancos translúcidos; en light con grises sutiles. */
    --surface-soft: rgba(255, 255, 255, 0.025);
    --surface-soft-strong: rgba(255, 255, 255, 0.04);
    --surface-raised: rgba(255, 255, 255, 0.06);
    --surface-hover: rgba(255, 255, 255, 0.05);

    /* Inputs / selects / textareas */
    --input-bg: var(--dark-card-2);
    --input-bg-soft: rgba(255, 255, 255, 0.04);
    --input-border: rgba(255, 255, 255, 0.18);

    /* Fondo del dropdown nativo de un <select> al desplegar.
       Los browsers pintan las <option> con su fondo nativo si no se setea. */
    --option-bg: #1A2030;

    /* Fondos para <code>/keytags/inline blocks */
    --code-bg: rgba(255, 255, 255, 0.06);
    --code-bg-strong: rgba(0, 0, 0, 0.30);
    --code-text: #7dd3fc;
    --err-code-text: #fecaca;
    --sql-preview-text: #c8e6c9;

    /* Tokens semánticos para banners y mensajes de estado.
       En dark, texto claro sobre fondo translúcido; en light, texto oscuro. */
    --banner-text-ok:    #86efac;
    --banner-text-err:   #fca5a5;
    --banner-text-warn:  #fde68a;
    --banner-text-info:  #7dd3fc;
    --banner-text-muted: #cbd5e1;
    --banner-icon-ok:    #4ade80;
    --banner-icon-err:   #f87171;
    --banner-icon-warn:  #facc15;
    --banner-icon-info:  #7dd3fc;
    --banner-strong:     var(--text-primary);
    --badge-admin-text:  #d8b4fe;

    /* Backdrop overlay (modal scrim) — el mismo en ambos modos */
    --backdrop: rgba(0, 0, 0, 0.55);

    /* Botón secundario "ghost" (border + transparente).
       En dark el border era rgba(255,255,255,0.18), en light necesita ser oscuro. */
    --ghost-border: rgba(255, 255, 255, 0.18);
    --ghost-border-hover: var(--brand-teal);

    /* Esquema de color del browser para inputs/scrollbars nativos */
    color-scheme: dark;
}

/* ── Tokens light ──────────────────────────────────────── */
:root[data-theme="light"] {
    --dark-900: #F1F5F9;
    --dark-800: #E2E8F0;
    --dark-700: #CBD5E1;
    --dark-card: #FFFFFF;
    --dark-card-2: #F8FAFC;

    --border: rgba(0, 158, 142, 0.32);
    --border-subtle: rgba(15, 23, 42, 0.10);

    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-muted: #64748B;

    --shadow-card: 0 8px 24px rgba(15, 23, 42, 0.08);

    --surface-soft: rgba(15, 23, 42, 0.025);
    --surface-soft-strong: rgba(15, 23, 42, 0.05);
    --surface-raised: rgba(15, 23, 42, 0.07);
    --surface-hover: rgba(15, 23, 42, 0.04);

    --input-bg: #FFFFFF;
    --input-bg-soft: rgba(15, 23, 42, 0.03);
    --input-border: rgba(15, 23, 42, 0.18);

    --option-bg: #FFFFFF;

    --code-bg: rgba(15, 23, 42, 0.06);
    --code-bg-strong: rgba(15, 23, 42, 0.08);
    --code-text: #0369A1;
    --err-code-text: #991B1B;
    --sql-preview-text: #166534;

    --banner-text-ok:    #14532D;
    --banner-text-err:   #7F1D1D;
    --banner-text-warn:  #78350F;
    --banner-text-info:  #075985;
    --banner-text-muted: #475569;
    --banner-icon-ok:    #16A34A;
    --banner-icon-err:   #DC2626;
    --banner-icon-warn:  #D97706;
    --banner-icon-info:  #0284C7;
    --badge-admin-text:  #6B21A8;

    --backdrop: rgba(15, 23, 42, 0.45);

    --ghost-border: rgba(15, 23, 42, 0.20);

    color-scheme: light;
}

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

html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--dark-900);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    line-height: 1.55;
}

a {
    color: var(--brand-teal-light);
    text-decoration: none;
    transition: color 0.15s ease;
}
a:hover {
    color: var(--brand-cyan);
}

h1, h2, h3, h4 {
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-primary);
}

.gradient-text {
    background: var(--gradient-brand);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ── Botones ────────────────────────────────────────────── */

.btn-primary,
.btn-primary-custom {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--gradient-brand-btn);
    color: white;
    padding: 12px 28px;
    border: none;
    border-radius: 50px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}
.btn-primary:hover,
.btn-primary-custom:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-teal);
    color: white;
}

.btn-secondary-custom {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    color: var(--text-primary);
    padding: 12px 28px;
    border-radius: 50px;
    font-weight: 600;
    font-size: 0.9rem;
    border: 1px solid var(--ghost-border);
    transition: all 0.2s ease;
    cursor: pointer;
}
.btn-secondary-custom:hover {
    border-color: var(--brand-teal);
    color: var(--brand-teal-light);
    background: rgba(0, 158, 142, 0.06);
}

.btn-danger-custom {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    color: var(--banner-text-err);
    padding: 12px 28px;
    border-radius: 50px;
    font-weight: 600;
    font-size: 0.9rem;
    border: 1px solid rgba(220, 38, 38, 0.45);
    transition: all 0.2s ease;
    cursor: pointer;
}
.btn-danger-custom:hover:not(:disabled) {
    background: rgba(220, 38, 38, 0.12);
    border-color: rgba(220, 38, 38, 0.7);
    color: var(--banner-text-err);
}
.btn-danger-custom:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ── Modal genérico (confirmaciones, prompts) ────────────── */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--backdrop);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1050;
    padding: 1rem;
}
.modal-card {
    background: var(--dark-card);
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    width: min(520px, 100%);
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
}
.modal-card__header {
    padding: 1.25rem 1.5rem 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
}
.modal-card__title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
}
.modal-card__title i {
    color: var(--banner-icon-warn);
}
.modal-card__body {
    padding: 1.25rem 1.5rem;
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.5;
}
.modal-card__body p {
    margin: 0 0 0.75rem;
}
.modal-card__body p:last-child {
    margin-bottom: 0;
}
.modal-card__hint {
    color: var(--text-secondary, #94a3b8);
    font-size: 0.85rem;
}
.modal-card__footer {
    padding: 0.75rem 1.5rem 1.25rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    flex-wrap: wrap;
}

/* ── Página "Mi cuenta" / cambiar contraseña ──────────────── */

.account-page {
    max-width: 520px;
    margin: 2.5rem auto;
    padding: 0 1rem;
    color: var(--text-primary);
}
.account-page__header {
    margin-bottom: 1.5rem;
}
.account-page__title {
    margin: 0.4rem 0 0.3rem;
    font-size: 1.6rem;
    font-weight: 600;
}
.account-page__subtitle {
    margin: 0;
    color: var(--text-secondary, #94a3b8);
    font-size: 0.95rem;
}
.account-page__error,
.account-page__ok {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.7rem 0.9rem;
    border-radius: 10px;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}
.account-page__error {
    background: rgba(220, 38, 38, 0.12);
    border: 1px solid rgba(220, 38, 38, 0.4);
    color: var(--banner-text-err);
}
.account-page__ok {
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.40);
    color: var(--banner-text-ok);
}
.account-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: var(--dark-card);
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    padding: 1.5rem;
}
.account-form__field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.account-form__label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary, #94a3b8);
}
.account-form__actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

/* ── Error boundary global ────────────────────────────────── */

.error-boundary {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 3rem 1rem;
    min-height: 60vh;
}
.error-boundary__card {
    max-width: 560px;
    width: 100%;
    background: var(--dark-card);
    border: 1px solid rgba(220, 38, 38, 0.40);
    border-radius: 14px;
    padding: 2rem 2rem 1.5rem;
    text-align: center;
}
.error-boundary__icon {
    font-size: 2.5rem;
    color: var(--banner-icon-err);
    margin-bottom: 0.75rem;
    display: block;
}
.error-boundary__title {
    margin: 0 0 0.6rem;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text-primary);
}
.error-boundary__message {
    margin: 0 0 1rem;
    color: var(--text-secondary, #94a3b8);
    line-height: 1.5;
}
.error-boundary__code {
    margin: 0 0 1.25rem;
    font-size: 0.85rem;
    color: var(--text-secondary, #94a3b8);
}
.error-boundary__code code {
    background: rgba(220, 38, 38, 0.12);
    color: var(--banner-text-err);
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    font-size: 0.85rem;
}
.error-boundary__details {
    text-align: left;
    margin: 0 0 1.25rem;
    padding: 0.75rem 1rem;
    background: var(--surface-soft-strong);
    border: 1px dashed var(--border-subtle);
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary, #94a3b8);
}
.error-boundary__details summary {
    cursor: pointer;
    font-weight: 600;
}
.error-boundary__exc-type {
    margin: 0.5rem 0 0.4rem;
    color: var(--banner-text-err);
    word-break: break-word;
}
.error-boundary__pre {
    margin: 0;
    padding: 0.6rem 0.75rem;
    background: var(--code-bg-strong);
    border-radius: 6px;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow: auto;
    font-size: 0.78rem;
}
.error-boundary__actions {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ── Páginas de ayuda (manuales) ──────────────────────────── */

.help-page {
    max-width: 880px;
    margin: 0 auto;
    color: var(--text-primary);
    line-height: 1.65;
}
.help-page__header {
    margin-bottom: 2rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
}
.help-page__title {
    margin: 0.4rem 0 0.5rem;
    font-size: 1.9rem;
    font-weight: 700;
}
.help-page__subtitle {
    margin: 0;
    color: var(--text-secondary, #94a3b8);
    font-size: 1rem;
}

.help-toc {
    background: rgba(0, 158, 142, 0.06);
    border: 1px solid rgba(0, 158, 142, 0.20);
    border-radius: 12px;
    padding: 1rem 1.25rem 1.25rem;
    margin-bottom: 2.5rem;
}
.help-toc strong {
    display: block;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--brand-teal-light);
    margin-bottom: 0.6rem;
}
.help-toc ul {
    margin: 0;
    padding-left: 1.25rem;
    columns: 2;
    column-gap: 1.5rem;
}
.help-toc li {
    margin-bottom: 0.35rem;
    break-inside: avoid;
}
.help-toc a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
}
.help-toc a:hover {
    color: var(--brand-teal-light);
    text-decoration: underline;
}

.help-section {
    margin: 2rem 0 2.5rem;
    scroll-margin-top: calc(var(--navbar-height) + 1rem);
}
.help-section h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0 0 0.9rem;
    color: var(--text-primary);
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border-subtle);
}
.help-section h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 1.5rem 0 0.6rem;
    color: var(--text-primary);
}
.help-section p,
.help-section ol,
.help-section ul {
    margin: 0 0 0.85rem;
    color: var(--text-primary);
}
.help-section ol,
.help-section ul {
    padding-left: 1.5rem;
}
.help-section li {
    margin-bottom: 0.35rem;
}
.help-section code {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 0.05rem 0.4rem;
    border-radius: 4px;
    font-size: 0.88em;
}
.help-section em {
    color: var(--text-primary);
    font-style: normal;
    font-weight: 600;
}

.help-callout {
    display: flex;
    gap: 0.7rem;
    padding: 0.85rem 1rem;
    border-radius: 10px;
    margin: 1rem 0;
    align-items: flex-start;
}
.help-callout i {
    font-size: 1.15rem;
    margin-top: 0.1rem;
    flex-shrink: 0;
}
.help-callout--info {
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid rgba(56, 189, 248, 0.25);
    color: var(--banner-text-info);
}
.help-callout--info i { color: var(--banner-icon-info); }
.help-callout--warn {
    background: rgba(245, 158, 11, 0.10);
    border: 1px solid rgba(245, 158, 11, 0.30);
    color: var(--banner-text-warn);
}
.help-callout--warn i { color: var(--banner-icon-warn); }

.help-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0 1.25rem;
}
.help-table th,
.help-table td {
    text-align: left;
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: top;
}
.help-table th {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 600;
}

@media (max-width: 640px) {
    .help-toc ul {
        columns: 1;
    }
}

/* ── Banner de factura cancelada ──────────────────────────── */

.cancel-banner {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0.75rem 0;
    padding: 0.7rem 0.9rem;
    background: rgba(100, 116, 139, 0.12);
    border: 1px solid rgba(100, 116, 139, 0.35);
    border-radius: 10px;
    color: var(--banner-text-muted);
    font-size: 0.9rem;
}
.cancel-banner i {
    color: var(--text-secondary);
    font-size: 1.1rem;
}
.cancel-banner__body strong {
    color: var(--text-primary);
}

/* ── Banner del envío al endpoint del cliente (ok / error) ──────────────────── */

.send-banner {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    margin: 0.75rem 0;
    padding: 0.7rem 0.9rem;
    border-radius: 10px;
    font-size: 0.9rem;
}
.send-banner i {
    font-size: 1.1rem;
    margin-top: 0.1rem;
}
.send-banner__body strong {
    color: var(--text-primary);
}
.send-banner__detail {
    margin-top: 0.35rem;
    font-size: 0.82rem;
    word-break: break-word;
}
.send-banner--ok {
    background: rgba(34, 197, 94, 0.10);
    border: 1px solid rgba(34, 197, 94, 0.35);
    color: var(--banner-text-ok);
}
.send-banner--ok i { color: var(--banner-icon-ok); }
/* El `code` por defecto se renderea en rojo/rosa de Bootstrap, da aspecto de error
   dentro del banner de éxito. Forzamos a heredar color del banner + un fondo sutil. */
.send-banner--ok code,
.send-banner--err code,
.send-banner--info code,
.send-banner--review code {
    color: inherit;
    background: var(--code-bg);
    padding: 0.05rem 0.35rem;
    border-radius: 4px;
    font-size: 0.85em;
}
.send-banner--err {
    background: rgba(220, 38, 38, 0.10);
    border: 1px solid rgba(220, 38, 38, 0.40);
    color: var(--banner-text-err);
}
.send-banner--err i { color: var(--banner-icon-err); }

/* Info banner — usado para SendPending (factura en cola, retry automático en curso). */
.send-banner--info {
    background: rgba(234, 179, 8, 0.10);
    border: 1px solid rgba(234, 179, 8, 0.35);
    color: var(--banner-text-warn);
}
.send-banner--info i { color: var(--banner-icon-warn); }

/* Review banner — "hay datos para revisar antes de aprobar". Es un WARNING, no un error:
   caja + ícono amarillos (warning) y textos en azul para no leerse como falla. */
.send-banner--review {
    background: rgba(234, 179, 8, 0.10);
    border: 1px solid rgba(234, 179, 8, 0.35);
    color: var(--banner-text-info);
}
.send-banner--review i { color: var(--banner-icon-warn); }

/* ── Bootstrap overrides (theme-aware) ──────────────────── */

.form-control,
.form-select {
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-primary);
}
.form-control:focus,
.form-select:focus {
    background-color: var(--input-bg);
    color: var(--text-primary);
    border-color: var(--brand-teal);
    box-shadow: 0 0 0 0.2rem rgba(0, 158, 142, 0.20);
}
.form-control::placeholder {
    color: var(--text-muted);
}

.btn:focus,
.btn:active:focus,
.form-control:focus {
    box-shadow: 0 0 0 0.2rem rgba(0, 158, 142, 0.25);
}

/* ── Validación ─────────────────────────────────────────── */

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}
.invalid {
    outline: 1px solid #e50000;
}
.validation-message {
    color: #ff6b6b;
}

/* ── Error boundary y reconnect ─────────────────────────── */

.blazor-error-boundary {
    background: #2a1418;
    color: #ffb4b4;
    padding: 1rem 1rem 1rem 3.7rem;
    border-radius: 8px;
}
.blazor-error-boundary::after {
    content: "Ocurrió un error.";
}

#blazor-error-ui {
    background: #1a0d0d;
    color: #ffb4b4;
    border-top: 1px solid rgba(255, 107, 107, 0.3);
    bottom: 0;
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.75rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
    color: #ffb4b4;
}
#blazor-error-ui .reload {
    color: var(--brand-cyan);
    margin-left: 0.5rem;
}

/* ── Status badges ──────────────────────────────────────── */

.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.65rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
}
.badge-status i {
    font-size: 0.85rem;
}
.badge-status--done {
    background: rgba(148, 163, 184, 0.12);
    border: 1px solid rgba(148, 163, 184, 0.30);
    color: var(--banner-text-muted);
}
.badge-status--pending {
    background: rgba(245, 158, 11, 0.14);
    border: 1px solid rgba(245, 158, 11, 0.40);
    color: var(--banner-text-warn);
}
.badge-status--sent {
    background: rgba(34, 197, 94, 0.14);
    border: 1px solid rgba(34, 197, 94, 0.40);
    color: var(--banner-text-ok);
}
.badge-status--incomplete {
    background: rgba(239, 68, 68, 0.14);
    border: 1px solid rgba(239, 68, 68, 0.45);
    color: var(--banner-text-err);
}
.badge-status--invalid {
    background: rgba(220, 38, 38, 0.18);
    border: 1px solid rgba(220, 38, 38, 0.55);
    color: var(--banner-text-err);
}
.badge-status--cancelled {
    background: rgba(100, 116, 139, 0.18);
    border: 1px solid rgba(100, 116, 139, 0.45);
    color: var(--text-secondary);
    text-decoration: line-through;
    text-decoration-color: rgba(148, 163, 184, 0.5);
}
.badge-errors {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: 0.4rem;
    padding: 0.1rem 0.5rem;
    background: rgba(220, 38, 38, 0.15);
    border: 1px solid rgba(220, 38, 38, 0.45);
    color: var(--banner-text-err);
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: help;
}
.badge-errors i { font-size: 0.78em; }

/* ── Scrollbar (theme-aware vía tokens) ─────────────────── */

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: var(--dark-900);
}
::-webkit-scrollbar-thumb {
    background: var(--dark-card-2);
    border-radius: 5px;
}
:root[data-theme="light"] ::-webkit-scrollbar-thumb {
    background: var(--dark-700);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--brand-slate);
}

/* ── Toggle de tema (light/dark) ────────────────────────── */
/* Botón con dos iconos; CSS muestra el icono que representa el modo
   al que se va a saltar. */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
    flex-shrink: 0;
    line-height: 1;
}
.theme-toggle:hover {
    color: var(--brand-teal-light);
    border-color: var(--brand-teal);
    background: var(--surface-hover);
}
.theme-toggle i {
    font-size: 1rem;
    line-height: 1;
}
/* Mostrar siempre el icono "destino" — en dark se ve el sol (saltar a light) */
.theme-toggle .theme-toggle__icon-light { display: inline-flex; }
.theme-toggle .theme-toggle__icon-dark  { display: none; }
:root[data-theme="light"] .theme-toggle .theme-toggle__icon-light { display: none; }
:root[data-theme="light"] .theme-toggle .theme-toggle__icon-dark  { display: inline-flex; }

/* Variante flotante (login / pantallas sin topbar) */
.theme-toggle--floating {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 50;
    width: 38px;
    height: 38px;
    background: var(--dark-card);
    border-color: var(--border);
    box-shadow: var(--shadow-card);
}

/* ============================================================
   Dashboards (User / ClientAdmin / M4 Admin)
   Usa los mismos tokens (--dark-card, --text-*, --brand-teal, etc.)
   para respetar light/dark sin reglas duplicadas.
   ============================================================ */
.dashboard-page {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.5rem;
}

.dashboard-page__hint {
    color: var(--text-secondary);
    font-style: italic;
}

.dashboard-page__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
}

.dashboard-page__title {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0.25rem 0 0;
    color: var(--text-primary);
}

.dashboard-page__subtitle {
    color: var(--text-secondary);
    margin: 0.25rem 0 0;
}

.dashboard-page__actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Chips de filtro de período arriba de los KPIs (Mes actual / 3 meses / Año / Todos). */
.dashboard-period-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0 0 1rem 0;
}
.dashboard-period-chip {
    appearance: none;
    background: var(--card-bg, rgba(255, 255, 255, 0.04));
    color: var(--text-secondary);
    border: 1px solid var(--card-border, rgba(255, 255, 255, 0.1));
    border-radius: 999px;
    padding: 0.35rem 0.95rem;
    font-size: 0.85em;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.dashboard-period-chip:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}
.dashboard-period-chip--active {
    background: var(--brand-teal, #14b8a6);
    color: #fff;
    border-color: var(--brand-teal, #14b8a6);
    font-weight: 600;
}
.dashboard-period-chip--active:hover:not(:disabled) {
    background: var(--brand-teal, #14b8a6);
    color: #fff;
}
.dashboard-period-chip:disabled {
    opacity: 0.6;
    cursor: wait;
}

.dashboard-empty {
    border: 1px solid var(--border);
    background: var(--dark-card);
    padding: 2rem;
    border-radius: 0.75rem;
    text-align: center;
    color: var(--text-primary);
}

.dashboard-empty i {
    font-size: 2rem;
    color: var(--brand-teal);
    margin-bottom: 0.5rem;
    display: block;
}

.dashboard-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

/* Layout del top del dashboard ClientAdmin: KPIs apilados a la izquierda (columna fija ~280px)
   y dos donas a la derecha. En mobile colapsa a una sola columna. */
.dashboard-overview {
    display: grid;
    grid-template-columns: minmax(240px, 320px) 1fr;
    gap: 1rem;
    align-items: stretch;
}

.dashboard-overview__kpis {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.dashboard-overview__charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 992px) {
    .dashboard-overview { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .dashboard-overview__charts { grid-template-columns: 1fr; }
}

.dashboard-kpi {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    background: var(--dark-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
}

.dashboard-kpi__icon {
    width: 40px;
    height: 40px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.dashboard-kpi__icon--blue { background: rgba(56, 189, 248, 0.15); color: #38bdf8; }
.dashboard-kpi__icon--purple { background: rgba(168, 139, 250, 0.15); color: #a78bfa; }
.dashboard-kpi__icon--cyan { background: rgba(34, 211, 238, 0.15); color: #22d3ee; }
.dashboard-kpi__icon--indigo { background: rgba(129, 140, 248, 0.15); color: #818cf8; }

.dashboard-kpi__label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.dashboard-kpi__value {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0.15rem 0 0;
    color: var(--text-primary);
}

.dashboard-kpi__hint {
    color: var(--text-secondary);
    font-size: 0.7rem;
}

.dashboard-kpi__bar {
    margin-top: 0.4rem;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.dashboard-kpi__bar-fill {
    height: 100%;
    background: var(--brand-teal);
    transition: width 200ms ease;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem;
}

.dashboard-chart-card {
    background: var(--dark-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
}

.dashboard-chart-card--span-2 {
    grid-column: span 2;
}

@media (max-width: 768px) {
    .dashboard-chart-card--span-2 { grid-column: auto; }
}

.dashboard-chart-card__title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 0.75rem;
    color: var(--text-primary);
}

.dashboard-chart-card__body {
    height: 280px;
    position: relative;
}

.dashboard-system {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.dashboard-system li {
    display: flex;
    justify-content: space-between;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.dashboard-system li strong {
    color: var(--text-primary);
}

/* Lista compacta de consumos de cuota — un row por cliente con ambas métricas
   (facturas y pedidos) en línea. Ordenada por % desc del mayor entre las dos. */
.dashboard-quota {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.dashboard-quota__row {
    display: grid;
    /* Nombre + 3 métricas (Facturas, Pedidos, Chat). */
    grid-template-columns: minmax(120px, 1fr) minmax(170px, 1fr) minmax(170px, 1fr) minmax(170px, 1fr);
    align-items: center;
    gap: 1.25rem;
    font-size: 0.85rem;
}

.dashboard-quota__metric {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.6rem;
}

.dashboard-quota__name {
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dashboard-quota__tag {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    padding: 0.1rem 0.45rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    white-space: nowrap;
}

.dashboard-quota__tag--empty {
    opacity: 0.4;
}

.dashboard-quota__bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.dashboard-quota__bar-fill {
    height: 100%;
    background: var(--brand-teal);
    transition: width 200ms ease;
}

/* Indicador visual cuando el cliente está al borde / por encima del límite. El umbral
   se aplica en el code-behind, acá solo proveemos las variantes de color. */
.dashboard-quota__bar-fill--warn { background: #f59e0b; }
.dashboard-quota__bar-fill--over { background: #ef4444; }

.dashboard-quota__pct {
    text-align: right;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.dashboard-quota__pct--empty {
    opacity: 0.4;
    text-align: left;
}

@media (max-width: 992px) {
    .dashboard-quota__row {
        grid-template-columns: 1fr;
        gap: 0.4rem;
    }
}

.dashboard-recent {
    background: var(--dark-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    overflow: hidden;
}

.dashboard-recent__header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.dashboard-recent__header h2 {
    font-size: 1rem;
    margin: 0;
    color: var(--text-primary);
}

.dashboard-recent__hint {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.dashboard-recent__empty {
    padding: 1.25rem;
    color: var(--text-secondary);
    margin: 0;
}

.dashboard-recent__table {
    width: 100%;
    border-collapse: collapse;
}

.dashboard-recent__table th,
.dashboard-recent__table td {
    text-align: left;
    padding: 0.6rem 1.25rem;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}

.dashboard-recent__table th {
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.7rem;
    color: var(--text-secondary);
    background: var(--bg-elevated, transparent);
}

.dashboard-recent__table tbody tr:last-child td {
    border-bottom: 0;
}

.dashboard-recent__table code {
    color: var(--brand-teal);
}

/* ============================================================
   New order page (`/pedido/nuevo`) — placeholder con tabs
   ============================================================ */
.neworder-tabs {
    display: flex;
    gap: 0.5rem;
    background: var(--dark-card);
    padding: 0.25rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    width: fit-content;
    margin-bottom: 1rem;
}

.neworder-tab {
    background: transparent;
    border: 0;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 0.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    transition: all 150ms ease;
}

.neworder-tab.is-active {
    background: var(--brand-teal);
    color: #fff;
}

.neworder-tab:hover:not(.is-active) {
    color: var(--text-primary);
}

.neworder-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 720px;
}

.neworder-voice {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 2rem 1rem;
    background: var(--dark-card);
    border: 1px dashed var(--border);
    border-radius: 0.75rem;
}

.neworder-voice__record {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--brand-teal);
    color: #fff;
    border: 0;
    font-size: 1.75rem;
    cursor: not-allowed;
    opacity: 0.7;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 0.25rem;
}

.neworder-voice__record span {
    font-size: 0.75rem;
}

.neworder-voice__hint {
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-align: center;
    margin: 0;
}

/* Botón de grabar habilitado: que se vea clickeable cuando NO está disabled. */
.neworder-voice__record:not(:disabled) {
    opacity: 1;
    cursor: pointer;
}

.neworder-voice--recording {
    border-style: solid;
    border-color: rgba(248, 113, 113, 0.4);
    background: rgba(248, 113, 113, 0.04);
}

.neworder-voice__pulse {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.55);
    animation: neworder-pulse 1.4s infinite;
}

@keyframes neworder-pulse {
    0%   { box-shadow: 0 0 0 0    rgba(239, 68, 68, 0.6); }
    70%  { box-shadow: 0 0 0 14px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0    rgba(239, 68, 68, 0); }
}

.neworder-voice__status {
    color: var(--text-primary);
    font-weight: 500;
    margin: 0;
    font-variant-numeric: tabular-nums;
}

.neworder-voice__actions {
    display: flex;
    gap: 0.5rem;
}

.neworder-voice--recorded {
    align-items: stretch;
}

.neworder-voice__player {
    width: 100%;
    max-width: 480px;
}

.neworder-voice__meta {
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-align: center;
    margin: 0;
}

/* Panel de resultado del POST. Mostramos el JSON estructurado pretty-printed para que
   el dev pueda inspeccionar lo que devolvió el LLM. */
.neworder-result {
    background: var(--dark-card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--brand-teal);
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.neworder-result__header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    color: var(--text-primary);
    font-weight: 500;
}

.neworder-result__header > i.bi-check-circle-fill {
    color: var(--brand-teal);
}

.neworder-result__id {
    background: var(--input-bg-soft);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

.neworder-result__reset {
    margin-left: auto;
}

.neworder-result__json {
    background: var(--bg-elevated, rgba(0, 0, 0, 0.2));
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.75rem;
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-primary);
    overflow-x: auto;
    max-height: 320px;
    overflow-y: auto;
}

/* ============================================================
   OrderAnalysis (`/pedido/{id}`) — layout 2 cols con texto a la
   izquierda y datos estructurados a la derecha. Reusa estilos
   genéricos `.analysis-page__*` y `.analysis-layout__*`.
   ============================================================ */

/* Variante del layout cuando es un pedido (sin viewer de PDF) — primera columna pasa
   a ser un panel de texto que respeta el alto del contenedor. */
.analysis-layout--order {
    align-items: stretch;
}

.order-source-panel {
    background: var(--dark-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 320px;
}

.order-source-panel__header {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.order-source-panel__audio-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.order-source-panel__audio-meta i {
    margin-right: 0.25rem;
}

.order-source-panel__text {
    background: var(--bg-elevated, rgba(0, 0, 0, 0.15));
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.85rem 1rem;
    margin: 0;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-y: auto;
    flex: 1;
}

.order-source-panel__empty {
    color: var(--text-secondary);
    font-style: italic;
    margin: 0;
}

.order-data__tree {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.order-data__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.order-data__table--root {
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    overflow: hidden;
}

.order-data__table th,
.order-data__table td {
    text-align: left;
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.order-data__table tr:last-child > th,
.order-data__table tr:last-child > td {
    border-bottom: 0;
}

.order-data__table th {
    color: var(--text-secondary);
    font-weight: 500;
    width: 35%;
    background: rgba(255, 255, 255, 0.02);
}

.order-data__value {
    color: var(--text-primary);
    word-break: break-word;
}

.order-data__value--num {
    font-variant-numeric: tabular-nums;
}

.order-data__empty-value {
    color: var(--text-muted, var(--text-secondary));
    font-style: italic;
}

.order-data__array {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.order-data__array-item {
    border: 1px solid var(--border);
    border-radius: 0.4rem;
    padding: 0.4rem 0.6rem;
    background: rgba(255, 255, 255, 0.02);
}

.order-data__array-item > summary {
    cursor: pointer;
    color: var(--brand-teal);
    font-weight: 500;
    margin-bottom: 0.3rem;
}

.order-data__validation-list {
    margin: 0.3rem 0 0;
    padding-left: 1.2rem;
    color: var(--text-primary);
}

.order-data__raw {
    margin-top: 0.75rem;
}

.order-data__raw > summary {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.8rem;
    padding: 0.3rem 0;
}

.order-data__raw > pre {
    background: var(--bg-elevated, rgba(0, 0, 0, 0.2));
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.6rem;
    margin: 0.4rem 0 0;
    font-size: 0.78rem;
    color: var(--text-primary);
    overflow-x: auto;
    max-height: 280px;
    overflow-y: auto;
}

.analysis-data__empty {
    color: var(--text-secondary);
    font-style: italic;
    margin: 0.5rem 0;
}

/* Truncado del source-text preview en /pedidos para que la columna no pierda el line-height
   y no salte el alto de la row con textos largos. */
.orders-list__text {
    max-width: 380px;
    color: var(--text-secondary);
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* OrderAnalysis: acciones del header (Editar / Cancelar / Volver) y banner de feedback. */
.analysis-page__actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: flex-start;
}

.analysis-data__actions {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
}

.order-action-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    margin: 0.75rem 0;
    color: var(--text-primary);
}

.order-action-banner--ok {
    border-color: rgba(0, 158, 142, 0.4);
    background: rgba(0, 158, 142, 0.08);
}

.order-action-banner--ok > i { color: var(--brand-teal); }

.order-action-banner--err {
    border-color: rgba(239, 68, 68, 0.4);
    background: rgba(239, 68, 68, 0.08);
}

.order-action-banner--err > i { color: #ef4444; }

/* Modo edición del panel de datos: hint + textarea con JSON. */
.order-data__edit-hint {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0 0 0.5rem;
}

.order-data__edit-textarea {
    width: 100%;
    min-height: 360px;
    background: var(--bg-elevated, rgba(0, 0, 0, 0.2));
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.6rem 0.75rem;
    color: var(--text-primary);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.85rem;
    line-height: 1.45;
    resize: vertical;
}

.order-data__edit-textarea:focus {
    outline: none;
    border-color: var(--brand-teal);
    box-shadow: 0 0 0 3px rgba(0, 158, 142, 0.20);
}

.order-data__edit-textarea:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.neworder-text {
    width: 100%;
    background: var(--dark-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.75rem;
    font: inherit;
    resize: vertical;
}

.neworder-text:focus {
    outline: 2px solid var(--brand-teal);
    outline-offset: 1px;
}

.neworder-comingsoon {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0;
}

.neworder-comingsoon i {
    color: var(--brand-teal);
    margin-right: 0.4rem;
}

/* ============================================================
   Voice tab — layout 2 columnas: grabación a la izquierda, transcripción
   editable + botón Procesar a la derecha. Mobile: apila vertical.
   ============================================================ */
.neworder-voice-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-items: start;
}

@media (max-width: 768px) {
    .neworder-voice-layout {
        grid-template-columns: 1fr;
    }
}

.neworder-voice-col {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.neworder-voice-col--transcript {
    min-height: 100%;
}

.neworder-transcript {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: var(--dark-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    height: 100%;
    box-sizing: border-box;
}

.neworder-transcript__hint {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0;
}

.neworder-transcript__loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    padding: 1rem 0;
}

.neworder-transcript__textarea {
    width: 100%;
    background: var(--input-bg-soft);
    color: var(--text-primary);
    border: 1px solid var(--input-border);
    border-radius: 0.5rem;
    padding: 0.75rem;
    font: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    resize: vertical;
    min-height: 140px;
}

.neworder-transcript__textarea:focus {
    outline: none;
    border-color: var(--brand-cyan);
    background: rgba(0, 229, 255, 0.06);
}

.neworder-transcript__textarea:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* ============================================================
   Analysis layout — copiadas desde Analysis.razor.css (scoped a
   facturas) para que OrderAnalysis use el mismo look-and-feel
   sin duplicar reglas en cada componente. Las versiones scoped
   de Analysis.razor.css ganan dentro del scope (más específicas)
   pero estas globales aplican a OrderAnalysis (sin scope CSS).
   ============================================================ */
.analysis-page {
    max-width: 1400px;
    margin: 0 auto;
}

.analysis-page__loading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-secondary);
    padding: 4rem 0;
    justify-content: center;
}

.analysis-page__not-found {
    text-align: center;
    padding: 4rem 1.5rem;
    background: var(--dark-card);
    border: 1px solid var(--border-subtle, var(--border));
    border-radius: 12px;
}
.analysis-page__not-found h2 { margin-bottom: 0.5rem; }
.analysis-page__not-found p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}
.analysis-page__not-found code {
    color: var(--brand-cyan);
    background: rgba(0, 229, 255, 0.08);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}

.analysis-page__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.analysis-page__title {
    margin: 0.25rem 0 0.5rem 0;
    font-size: 1.5rem;
    word-break: break-all;
}

.analysis-page__id {
    background: var(--code-bg, rgba(0, 0, 0, 0.2));
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    user-select: all;
}

.analysis-page__meta {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.analysis-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: stretch;
    height: calc(100vh - var(--navbar-height, 64px) - 12rem);
    min-height: 60vh;
    max-height: calc(100vh - 200px);
}

@media (max-width: 768px) {
    .analysis-layout {
        grid-template-columns: 1fr;
        height: auto;
        max-height: none;
    }
}

.analysis-layout__viewer-wrapper {
    position: relative;
    background: var(--dark-card);
    border: 1px solid var(--border-subtle, var(--border));
    border-radius: 12px;
    box-shadow: var(--shadow-card, none);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.analysis-layout__viewer {
    flex: 1;
    padding: 1rem;
    overflow: auto;
    min-height: 0;
}

.analysis-layout__data {
    background: var(--dark-card);
    border: 1px solid var(--border-subtle, var(--border));
    border-radius: 12px;
    padding: 1.5rem;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
}

.analysis-data__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.analysis-data__sections {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.structured__section {
    background: var(--surface-soft, rgba(255, 255, 255, 0.02));
    border: 1px solid var(--border-subtle, var(--border));
    border-radius: 10px;
    padding: 1rem 1.1rem;
}

.structured__section-title {
    margin: 0 0 0.75rem 0;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--brand-teal-light);
}

/* Título clickeable para colapsar/expandir la sección. Hereda el look del título
   (uppercase, teal, tracking) y agrega un chevron al inicio. */
.structured__section-toggle {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
    padding: 0;
    background: none;
    border: none;
    font: inherit;
    color: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    text-align: left;
    cursor: pointer;
}
.structured__section-chevron {
    font-size: 0.9em;
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: color 0.15s ease;
}
.structured__section-toggle:hover .structured__section-chevron {
    color: var(--brand-teal-light);
}
/* Sin sección visible: el margen inferior del título sobra. */
.structured__section--collapsed .structured__section-title {
    margin-bottom: 0;
}

.structured__fields {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin: 0;
    padding: 0;
    font-size: 0.9rem;
}

.structured__field {
    display: grid;
    grid-template-columns: minmax(160px, 0.6fr) 1fr;
    gap: 0.5rem 1rem;
    padding: 0.35rem 0.55rem;
    margin: 0 -0.55rem;
    border-radius: 6px;
    border: 1px solid transparent;
}

.structured__field-label {
    color: var(--text-secondary);
    font-weight: 500;
    margin: 0;
}

.structured__field-value {
    margin: 0;
    color: var(--text-primary);
    font-weight: 600;
    word-break: break-word;
    font-variant-numeric: tabular-nums;
}

/* Feature 2: nombre por el que resolvió el lookup, junto al valor bajado (ej. "P004 — Panadería"). */
.structured__resolved-by {
    margin-left: 0.4rem;
    color: var(--text-secondary);
    font-weight: 400;
    font-size: 0.85em;
}

/* "Lupa" para browsear los valores posibles de un lookup, junto a la label del campo. */
.structured__lookup-btn {
    margin-left: 0.4rem;
    padding: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.85em;
    cursor: pointer;
    transition: color 0.15s;
    vertical-align: baseline;
}
.structured__lookup-btn:hover {
    color: var(--brand-teal-light);
}

/* Check "recordar match" por campo (modo edición): default tildado = aprender el override. */
.structured__remember {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.35rem;
    font-size: 0.78rem;
    font-weight: 400;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}
.structured__remember input {
    cursor: pointer;
    accent-color: var(--brand-teal);
}

/* Botón "Agregar ítem" para sumar filas a un array (productos, impuestos, etc.) en edición. */
.structured__add-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.6rem;
    padding: 0.4rem 0.85rem;
    background: var(--dark-card-2);
    border: 1px dashed var(--border-subtle);
    border-radius: 8px;
    color: var(--brand-teal-light);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.structured__add-item:hover {
    border-color: var(--brand-teal);
    color: var(--brand-teal);
}

.structured__items {
    list-style: none;
    counter-reset: item;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.structured__item {
    counter-increment: item;
    background: var(--surface-soft, rgba(255, 255, 255, 0.02));
    border: 1px solid var(--border-subtle, var(--border));
    border-radius: 8px;
    padding: 0.75rem 0.9rem;
    position: relative;
}

.structured__item::before {
    content: "#" counter(item);
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    font-size: 0.7rem;
    color: var(--text-muted, var(--text-secondary));
    font-weight: 700;
}

.structured__item .structured__field {
    grid-template-columns: minmax(110px, 0.4fr) 1fr;
    font-size: 0.85rem;
}

.structured__empty {
    margin: 0;
    color: var(--text-muted, var(--text-secondary));
    font-size: 0.9rem;
    font-style: italic;
}

/* Panel izquierdo de OrderAnalysis: en lugar del viewer de PDF, mostramos el texto
   fuente (transcripción o texto recibido) ocupando el alto completo del wrapper. */
.order-text-viewer {
    flex: 1;
    padding: 1.25rem 1.5rem;
    overflow: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.order-text-viewer__eyebrow {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-secondary);
    font-weight: 700;
}

.order-text-viewer__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0;
}

.order-text-viewer__text {
    background: var(--bg-elevated, rgba(0, 0, 0, 0.15));
    border: 1px solid var(--border-subtle, var(--border));
    border-radius: 8px;
    padding: 1rem 1.15rem;
    margin: 0;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

/* Editor inline de un field (modo edición) — input con el mismo styling que en
   Analysis.razor scoped, replicado a global para que aplique a OrderAnalysis. */
.structured__field-input {
    width: 100%;
    padding: 4px 8px;
    background: var(--input-bg-soft);
    border: 1px solid var(--input-border);
    border-radius: 4px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.structured__field-input:focus {
    outline: none;
    border-color: var(--brand-cyan);
    background: rgba(0, 229, 255, 0.06);
}

/* Marcado de fields con problemas — mismo set de modificadores que Analysis.razor.
   `is-invalid` (validación fallida o required-empty) gana sobre los `is-lookup-*`. */
.structured__field.is-invalid {
    position: relative;
    padding-left: 0.5rem;
    border-left: 2px solid #ef4444;
    cursor: help;
}
.structured__field.is-invalid .structured__field-label,
.structured__field.is-invalid .structured__field-value {
    color: var(--banner-text-err, #fca5a5);
}
.structured__field.is-invalid::after {
    content: "\F33A"; /* bi bi-exclamation-circle-fill */
    font-family: "bootstrap-icons";
    color: var(--banner-icon-err, #ef4444);
    font-size: 0.75rem;
    margin-left: 0.4rem;
    vertical-align: middle;
}

.structured__field.is-lookup-failed:not(.is-invalid) {
    padding-left: 0.5rem;
    border-left: 2px solid #ef4444;
    cursor: help;
}
.structured__field.is-lookup-failed:not(.is-invalid)::after {
    content: "\F33A";
    font-family: "bootstrap-icons";
    color: #ef4444;
    font-size: 0.75rem;
    margin-left: 0.4rem;
    vertical-align: middle;
}

.structured__field.is-lookup-ambiguous:not(.is-invalid) {
    padding-left: 0.5rem;
    border-left: 2px solid #f59e0b;
    cursor: help;
}
.structured__field.is-lookup-ambiguous:not(.is-invalid)::after {
    content: "\F33B";
    font-family: "bootstrap-icons";
    color: #f59e0b;
    font-size: 0.75rem;
    margin-left: 0.4rem;
    vertical-align: middle;
}

.structured__field.is-lookup-skipped:not(.is-invalid) {
    padding-left: 0.5rem;
    border-left: 2px solid #6b7280;
    cursor: help;
}
.structured__field.is-lookup-skipped:not(.is-invalid)::after {
    content: "\F431";
    font-family: "bootstrap-icons";
    color: #6b7280;
    font-size: 0.75rem;
    margin-left: 0.4rem;
    vertical-align: middle;
}

.structured__field.is-lookup-learned:not(.is-invalid) {
    padding-left: 0.5rem;
    border-left: 2px solid #22c55e;
}
.structured__field.is-lookup-overridden:not(.is-invalid) {
    padding-left: 0.5rem;
    border-left: 2px solid #60a5fa;
}

/* ============================================================
   Schema/translation pickers (compartidos por upload de factura
   y nuevo pedido). Globales para evitar problemas de scope con
   los .razor.css y mantener una sola fuente de verdad.
   ============================================================ */
.upload-page__schema-picker {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.upload-page__schema-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.upload-page__schema-select {
    background: var(--input-bg-soft);
    border: 1px solid var(--input-border);
    border-radius: 4px;
    color: var(--text-primary);
    padding: 0.5rem 0.7rem;
    font-family: inherit;
    font-size: 0.9rem;
}

.upload-page__schema-select:focus {
    outline: none;
    border-color: var(--brand-cyan);
    background: rgba(0, 229, 255, 0.06);
}

.upload-page__schema-select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.upload-page__schema-select option {
    background-color: var(--option-bg);
    color: var(--text-primary);
}

.upload-page__schema-hint {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-style: italic;
}
