/* ========================================================================== 
   Digitalia v342.5.0 · Fase Visual 6
   Modales, alertas, confirmaciones y feedback unificados.
   Capa visual final; no altera la logica funcional ni los eventos existentes.
   POS y Nueva Venta quedan fuera deliberadamente.
   ========================================================================== */

:root {
    --v342-dialog-radius: 16px;
    --v342-dialog-border: color-mix(in srgb, var(--ui-primary, #351078) 9%, var(--ui-line, #e4e9f1));
    --v342-dialog-shadow: 0 28px 70px rgba(15, 23, 42, .20), 0 6px 18px rgba(15, 23, 42, .07);
    --v342-dialog-soft: color-mix(in srgb, var(--ui-primary, #351078) 3%, var(--ui-surface, #fff));
    --v342-dialog-muted: var(--ui-copy, #667085);
    --v342-feedback-radius: 12px;
    --v342-feedback-shadow: 0 14px 34px rgba(15, 23, 42, .09);
}

/* --------------------------------------------------------------------------
   Backdrop y superficie modal común
   -------------------------------------------------------------------------- */
body.app-layout:not(.pos-mode):not(.terminal-pos-mode) dialog::backdrop {
    background: rgba(15, 23, 42, .50);
    backdrop-filter: blur(3px) saturate(.9);
    -webkit-backdrop-filter: blur(3px) saturate(.9);
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(
    .app-modal,
    .detail-view-dialog,
    .quick-actions-dialog,
    .ux-confirm-dialog
) {
    border-radius: var(--v342-dialog-radius) !important;
    box-shadow: var(--v342-dialog-shadow) !important;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(
    .app-modal-panel,
    .entity-modal-panel,
    .product-modal-panel,
    .address-book-panel,
    .detail-view-panel,
    .quick-actions-panel,
    .ux-confirm-panel
) {
    border-color: var(--v342-dialog-border) !important;
    background: var(--ui-surface, #fff);
}

/* Header común: más compacto, mejor jerarquía y cierre consistente. */
body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(
    .app-modal-header,
    .modal-header,
    .detail-view-header,
    .quick-actions-head
) {
    min-height: 64px;
    padding: 14px 18px !important;
    gap: 14px;
    border-bottom: 1px solid var(--v342-dialog-border) !important;
    background: linear-gradient(180deg, var(--ui-surface, #fff), var(--v342-dialog-soft)) !important;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(
    .app-modal-header,
    .modal-header,
    .detail-view-header,
    .quick-actions-head
) h2,
body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(
    .app-modal-header,
    .modal-header,
    .detail-view-header,
    .quick-actions-head
) h3 {
    margin: 2px 0 3px;
    color: var(--ui-ink, #172033);
    font-size: 1.04rem !important;
    line-height: 1.3 !important;
    font-weight: 750 !important;
    letter-spacing: -.012em;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(
    .app-modal-header,
    .modal-header,
    .detail-view-header,
    .quick-actions-head
) p {
    margin: 0;
    color: var(--v342-dialog-muted);
    font-size: .75rem !important;
    line-height: 1.45 !important;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .modal-eyebrow {
    margin-bottom: 2px;
    color: var(--ui-primary, #351078) !important;
    font-size: .62rem !important;
    font-weight: 800 !important;
    letter-spacing: .085em;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(.modal-close, .detail-view-close, .quick-actions-close) {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px;
    min-height: 32px;
    display: inline-grid;
    place-items: center;
    padding: 0 !important;
    border: 1px solid var(--v342-dialog-border) !important;
    border-radius: 9px !important;
    background: var(--ui-surface, #fff) !important;
    color: var(--ui-copy, #667085) !important;
    font-size: 1.15rem !important;
    line-height: 1 !important;
    box-shadow: 0 1px 2px rgba(15,23,42,.03);
    transition: background .15s ease, color .15s ease, border-color .15s ease, transform .15s ease;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(.modal-close, .detail-view-close, .quick-actions-close):hover {
    background: color-mix(in srgb, var(--ui-primary, #351078) 6%, var(--ui-surface, #fff)) !important;
    border-color: color-mix(in srgb, var(--ui-primary, #351078) 20%, var(--v342-dialog-border)) !important;
    color: var(--ui-primary, #351078) !important;
    transform: translateY(-1px);
}

/* Cuerpo / footer de modales CRUD. */
body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-modal-grid {
    padding: 15px 18px !important;
    gap: 10px 12px !important;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(.app-modal-footer, .detail-view-footer) {
    min-height: 58px;
    padding: 10px 18px !important;
    gap: 8px;
    border-top: 1px solid var(--v342-dialog-border) !important;
    background: var(--v342-dialog-soft) !important;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-modal-footer .button,
body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .detail-view-footer .button {
    min-height: 36px !important;
    padding: 7px 13px !important;
    border-radius: 8px !important;
    font-size: .76rem !important;
}

/* Tabs de modal. */
body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .modal-tabs {
    padding: 0 18px !important;
    gap: 2px !important;
    border-bottom-color: var(--v342-dialog-border) !important;
    background: var(--ui-surface, #fff) !important;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .modal-tab {
    min-height: 38px !important;
    padding: 9px 12px 8px !important;
    border-radius: 7px 7px 0 0 !important;
    color: var(--ui-copy, #667085) !important;
    font-size: .73rem !important;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .modal-tab.is-active {
    color: var(--ui-primary, #351078) !important;
    border-bottom-color: var(--ui-primary, #351078) !important;
    background: color-mix(in srgb, var(--ui-primary, #351078) 5%, var(--ui-surface, #fff)) !important;
}

/* --------------------------------------------------------------------------
   Confirmación global existente: aspecto de confirmación de ERP moderno
   -------------------------------------------------------------------------- */
body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .ux-confirm-dialog {
    width: min(440px, calc(100vw - 28px));
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .ux-confirm-panel {
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 13px;
    padding: 18px;
    border-radius: var(--v342-dialog-radius) !important;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .ux-confirm-icon {
    width: 40px;
    height: 40px;
    border-radius: 11px;
    font-size: .95rem;
    box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 12%, transparent);
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .ux-confirm-copy h2 {
    margin: 1px 0 5px;
    font-size: .98rem;
    font-weight: 760;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .ux-confirm-copy p {
    font-size: .76rem;
    line-height: 1.5;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .ux-confirm-actions {
    margin-top: 3px;
    padding-top: 13px;
    border-top-color: var(--v342-dialog-border);
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .ux-confirm-actions .button {
    min-height: 36px !important;
    padding: 7px 14px !important;
    border-radius: 8px !important;
    font-size: .75rem !important;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .ux-confirm-dialog[data-tone="danger"] [data-ux-confirm-accept] {
    background: #dc2626 !important;
    border-color: #dc2626 !important;
    box-shadow: 0 5px 14px rgba(220,38,38,.16);
}

/* --------------------------------------------------------------------------
   Alertas inline de módulos: mismo lenguaje visual, sin convertirlas en toast
   -------------------------------------------------------------------------- */
body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-content .alert:not(.app-feedback) {
    position: relative;
    margin-block: 10px;
    padding: 10px 12px !important;
    border-width: 1px !important;
    border-style: solid !important;
    border-radius: 10px !important;
    box-shadow: 0 3px 10px rgba(15,23,42,.035);
    font-size: .76rem !important;
    line-height: 1.5 !important;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-content .alert:not(.app-feedback) strong {
    font-weight: 760;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-content .alert:not(.app-feedback) a {
    font-weight: 700;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-content :where(.alert-success, .alert.success) {
    background: color-mix(in srgb, #16a34a 7%, var(--ui-surface, #fff)) !important;
    border-color: color-mix(in srgb, #16a34a 24%, transparent) !important;
    color: #166534 !important;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-content :where(.alert-warning, .alert.warning) {
    background: color-mix(in srgb, #d97706 7%, var(--ui-surface, #fff)) !important;
    border-color: color-mix(in srgb, #d97706 25%, transparent) !important;
    color: #92400e !important;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-content :where(.alert-error, .alert.error) {
    background: color-mix(in srgb, #dc2626 6%, var(--ui-surface, #fff)) !important;
    border-color: color-mix(in srgb, #dc2626 23%, transparent) !important;
    color: #991b1b !important;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-content :where(.alert-info, .alert.info) {
    background: color-mix(in srgb, #2563eb 6%, var(--ui-surface, #fff)) !important;
    border-color: color-mix(in srgb, #2563eb 22%, transparent) !important;
    color: #1e40af !important;
}

/* --------------------------------------------------------------------------
   Flash global: comportamiento visual de toast flotante en administración.
   No cambia el JS ni el tiempo de vida; solo presentación.
   -------------------------------------------------------------------------- */
body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-content .app-flash-stack {
    position: fixed;
    top: 76px;
    right: 18px;
    z-index: 7000;
    width: min(420px, calc(100vw - 36px));
    margin: 0;
    gap: 8px;
    pointer-events: none;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-content .app-feedback {
    grid-template-columns: 32px minmax(0,1fr) 28px;
    gap: 10px;
    min-height: 54px;
    padding: 10px 10px !important;
    border-radius: var(--v342-feedback-radius) !important;
    box-shadow: var(--v342-feedback-shadow) !important;
    background-clip: padding-box;
    pointer-events: auto;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-feedback__icon {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    font-size: .82rem;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-feedback__copy {
    gap: 1px;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-feedback__copy strong {
    font-size: .75rem;
    font-weight: 780;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-feedback__copy span {
    font-size: .72rem;
    line-height: 1.42;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-feedback__close {
    width: 28px;
    height: 28px;
    border-radius: 8px;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-feedback.is-leaving {
    transform: translateX(12px) scale(.985);
}

/* Toasts internos de guardado AJAX (clientes, proveedores, etc.). */
body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-toast {
    right: 18px;
    bottom: 18px;
    max-width: min(400px, calc(100vw - 36px));
    padding: 11px 13px;
    border-radius: 11px;
    box-shadow: var(--v342-feedback-shadow);
    font-size: .75rem;
    font-weight: 700;
    line-height: 1.45;
}

/* Detalle asíncrono. */
body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .detail-view-dialog {
    width: min(980px, calc(100vw - 36px));
    max-height: min(90vh, 820px);
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .detail-view-body {
    padding: 16px 18px !important;
    scrollbar-gutter: stable;
}

body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .detail-view-loading {
    padding: 22px 18px;
    color: var(--ui-copy, #667085);
    font-size: .76rem;
}

/* Quick actions: mismo lenguaje del resto de diálogos. */
body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .quick-actions-panel {
    border-radius: var(--v342-dialog-radius) !important;
}

/* Focus consistente. */
body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(
    .app-modal,
    .detail-view-dialog,
    .quick-actions-dialog,
    .ux-confirm-dialog
) :where(button, a[href], input, select, textarea):focus-visible {
    outline: 3px solid color-mix(in srgb, var(--ui-primary, #351078) 24%, transparent) !important;
    outline-offset: 2px !important;
}

/* Dark mode: conservar contraste sin forzar blancos. */
html[data-theme="dark"] body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(
    .app-modal-panel,
    .entity-modal-panel,
    .product-modal-panel,
    .address-book-panel,
    .detail-view-panel,
    .quick-actions-panel,
    .ux-confirm-panel
) {
    background: var(--ui-surface, #171a23) !important;
}

html[data-theme="dark"] body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-content :where(.alert-success, .alert.success) { color: #86efac !important; }
html[data-theme="dark"] body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-content :where(.alert-warning, .alert.warning) { color: #fcd34d !important; }
html[data-theme="dark"] body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-content :where(.alert-error, .alert.error) { color: #fca5a5 !important; }
html[data-theme="dark"] body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-content :where(.alert-info, .alert.info) { color: #93c5fd !important; }

/* Responsive. */
@media (max-width: 760px) {
    body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-content .app-flash-stack {
        top: 68px;
        left: 10px;
        right: 10px;
        width: auto;
    }

    body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(.app-modal, .detail-view-dialog, .quick-actions-dialog) {
        width: calc(100vw - 14px) !important;
        max-width: none !important;
        max-height: calc(100dvh - 14px) !important;
        border-radius: 13px !important;
    }

    body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(.app-modal-panel, .detail-view-panel, .quick-actions-panel) {
        max-height: calc(100dvh - 14px) !important;
    }

    body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(.app-modal-header, .modal-header, .detail-view-header, .quick-actions-head) {
        min-height: 58px;
        padding: 12px 14px !important;
    }

    body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-modal-grid,
    body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .detail-view-body {
        padding: 13px 14px !important;
    }

    body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(.app-modal-footer, .detail-view-footer) {
        padding: 10px 14px !important;
    }

    body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .ux-confirm-panel {
        grid-template-columns: 36px minmax(0,1fr);
        padding: 15px;
    }

    body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .ux-confirm-icon {
        width: 34px;
        height: 34px;
    }

    body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .ux-confirm-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    body.app-layout:not(.pos-mode):not(.terminal-pos-mode) .app-toast {
        left: 10px;
        right: 10px;
        bottom: 10px;
        max-width: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    body.app-layout:not(.pos-mode):not(.terminal-pos-mode) :where(.app-feedback, .app-modal[open], .app-toast) {
        animation: none !important;
        transition-duration: .01ms !important;
    }
}
