/* ============================================
   CRYSTAL RECEIPT MODAL - AETHER DESIGN
   Design baseado no Modelo5TicketCrystal.jsx
   ============================================ */

/* Fonte SF Pro Display */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* === VARIÁVEIS DO TEMA CRYSTAL === */
:root {
    --crystal-font-primary: 'SF Pro Display', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --crystal-accent: #D4AF37;

    /* Light Mode */
    --crystal-light-bg: transparent;
    --crystal-light-text-primary: #1D1D1F;
    --crystal-light-text-secondary: #86868B;
    --crystal-light-card-bg: #FFFFFF;
    --crystal-light-separator: rgba(0, 0, 0, 0.08);
    --crystal-light-filter: drop-shadow(0 0 0.75px #000000) drop-shadow(0 20px 40px rgba(0, 0, 0, 0.10));

    /* Dark Mode */
    --crystal-dark-bg: transparent;
    --crystal-dark-text-primary: #F5F5F7;
    --crystal-dark-text-secondary: #A1A1AA;
    --crystal-dark-card-bg: rgba(20, 20, 25, 0.7);
    --crystal-dark-separator: rgba(255, 255, 255, 0.08);
    --crystal-dark-filter: drop-shadow(0 0 1px rgba(255,255,255,0.15)) drop-shadow(0 20px 40px rgba(0, 0, 0, 0.7));
}

/* === MODAL OVERLAY === */
.crystal-receipt-overlay {
    position: fixed;
    inset: 0;
    z-index: 10200;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 500ms cubic-bezier(0.22, 1, 0.36, 1);
}

.crystal-receipt-overlay.active {
    opacity: 1;
    pointer-events: all;
}

/* === WRAPPER PRINCIPAL === */
.crystal-receipt-wrapper {
    position: relative;
    width: 100%;
    max-width: 28rem;
    z-index: 10;
    transform: translateY(3rem) scale(0.95);
    opacity: 0;
    transition: all 1000ms cubic-bezier(0.22, 1, 0.36, 1);
}

.crystal-receipt-overlay.active .crystal-receipt-wrapper {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* Light Mode */
.crystal-receipt-wrapper {
    filter: var(--crystal-light-filter);
}

/* Dark Mode */
.dark .crystal-receipt-wrapper,
body.dark-mode .crystal-receipt-wrapper {
    filter: var(--crystal-dark-filter);
}

/* === TICKET MASK (Semi-círculos laterais) === */
.crystal-ticket {
    border-radius: 24px;
    overflow: hidden;
    position: relative;
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    background: var(--crystal-light-card-bg);
    transition: background 500ms ease;

    /* Máscara para criar os semi-círculos */
    -webkit-mask-image:
        radial-gradient(circle at 0 160px, transparent 10px, black 10.5px),
        radial-gradient(circle at 100% 160px, transparent 10px, black 10.5px);
    mask-image:
        radial-gradient(circle at 0 160px, transparent 10px, black 10.5px),
        radial-gradient(circle at 100% 160px, transparent 10px, black 10.5px);
    -webkit-mask-composite: source-in;
    mask-composite: intersect;
}

.dark .crystal-ticket,
body.dark-mode .crystal-ticket {
    background: var(--crystal-dark-card-bg);
}

/* === LINHA TRACEJADA === */
.crystal-dashed-line {
    position: absolute;
    left: 0.75rem;
    right: 0.75rem;
    height: 1px;
    top: 160px;
    z-index: 20;
    opacity: 0.5;
    background-image: linear-gradient(to right, #d1d1d6 50%, transparent 50%);
    background-position: bottom;
    background-size: 10px 1px;
    background-repeat: repeat-x;
}

.dark .crystal-dashed-line,
body.dark-mode .crystal-dashed-line {
    background-image: linear-gradient(to right, #333 50%, transparent 50%);
}

/* === HEADER DO RECIBO === */
.crystal-header {
    height: 160px;
    position: relative;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all 500ms ease;
}

.crystal-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 66.666%;
    height: 0.25rem;
    background: linear-gradient(to right, transparent, rgba(0, 0, 0, 0.05), transparent);
    filter: blur(2px);
}

.dark .crystal-header::before,
body.dark-mode .crystal-header::before {
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.1), transparent);
}

/* Icon Box */
.crystal-icon-box {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.75rem;
    border: 1px solid rgba(0, 0, 0, 0.05);
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: all 300ms ease;
}

.dark .crystal-icon-box,
body.dark-mode .crystal-icon-box {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

/* Status Badge */
.crystal-status-badge {
    padding: 0.375rem 0.75rem;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    border: 1px solid rgba(212, 175, 55, 0.2);
    background: rgba(212, 175, 55, 0.05);
    color: var(--crystal-accent);
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.dark .crystal-status-badge,
body.dark-mode .crystal-status-badge {
    background: rgba(212, 175, 55, 0.1);
}

/* === LISTA DE ITENS === */
.crystal-items-container {
    padding: 2rem 1.5rem 1rem;
    transition: all 500ms ease;
}

.crystal-item-row {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 1rem;
    opacity: 0;
    transform: translateY(1rem);
    animation: fadeInItem 700ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes fadeInItem {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.crystal-qty-box {
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: #f9fafb;
    color: #6b7280;
    flex-shrink: 0;
    transition: all 300ms ease;
}

.dark .crystal-qty-box,
body.dark-mode .crystal-qty-box {
    border-color: rgba(255, 255, 255, 0.1);
    background: #1A1A1C;
    color: #86868B;
}

.crystal-qty-box.discount {
    border-color: rgba(212, 175, 55, 0.3);
    background: rgba(212, 175, 55, 0.05);
    color: var(--crystal-accent);
}

.dark .crystal-qty-box.discount,
body.dark-mode .crystal-qty-box.discount {
    background: rgba(212, 175, 55, 0.1);
}

/* Expandir itens ocultos */
.crystal-hidden-items {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: all 1000ms cubic-bezier(0.22, 1, 0.36, 1);
}

.crystal-hidden-items.expanded {
    max-height: 350px;
    opacity: 1;
    overflow-y: auto;
    margin-top: 1rem;
}

/* Botão "Ver mais" */
.crystal-expand-btn {
    width: 100%;
    padding: 0.75rem;
    margin-top: 1.5rem;
    border-top: 1px dashed #a0a0a0;
    background: transparent;
    border-left: none;
    border-right: none;
    border-bottom: none;
    border-radius: 0 0 0.75rem 0.75rem;
    cursor: pointer;
    transition: all 300ms ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--crystal-light-text-secondary);
}

.dark .crystal-expand-btn,
body.dark-mode .crystal-expand-btn {
    border-color: #333;
    color: var(--crystal-dark-text-secondary);
}

.crystal-expand-btn:hover {
    background: rgba(0, 0, 0, 0.02);
}

.dark .crystal-expand-btn:hover,
body.dark-mode .crystal-expand-btn:hover {
    background: rgba(255, 255, 255, 0.02);
}

.crystal-expand-icon {
    transition: transform 500ms cubic-bezier(0.22, 1, 0.36, 1);
}

.crystal-expand-btn.expanded .crystal-expand-icon {
    transform: rotate(180deg);
}

/* === FOOTER === */
.crystal-footer {
    padding: 1.5rem;
    padding-top: 0.5rem;
    transition: all 500ms ease;
}

.crystal-footer-box {
    border-radius: 20px;
    padding: 1.5rem;
    border: 1px solid rgba(0, 0, 0, 0.06);
    background: #F9FAFB;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.02);
    transition: all 500ms ease;
}

.dark .crystal-footer-box,
body.dark-mode .crystal-footer-box {
    background: #131315;
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: none;
}

/* Arquivo Escaneado */
.crystal-file-box {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 0.75rem;
    border: 1px dashed rgba(0, 0, 0, 0.08);
    background: #FFFFFF;
    margin-bottom: 0.75rem;
    transition: all 300ms ease;
}

.dark .crystal-file-box,
body.dark-mode .crystal-file-box {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.1);
}

.crystal-file-icon {
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    background: #E3F2FD;
    color: #007AFF;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.dark .crystal-file-icon,
body.dark-mode .crystal-file-icon {
    background: rgba(0, 122, 255, 0.15);
}

/* Total Pago */
.crystal-total-row {
    display: flex;
    justify-content: space-between;
    align-items: end;
    padding-top: 0.75rem;
    border-top: 1px solid var(--crystal-light-separator);
}

.dark .crystal-total-row,
body.dark-mode .crystal-total-row {
    border-color: var(--crystal-dark-separator);
}

.crystal-total-value {
    font-size: 1.875rem;
    font-weight: 700;
    letter-spacing: -0.05em;
    color: var(--crystal-light-text-primary);
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
    transition: color 500ms ease;
}

.dark .crystal-total-value,
body.dark-mode .crystal-total-value {
    color: var(--crystal-dark-text-primary);
}

/* === BOTÕES DE AÇÃO === */
.crystal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 2fr;
    gap: 0.5rem;
    margin-top: 1.5rem;
    position: relative;
    z-index: 10;
}

.crystal-btn {
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border-radius: 0.75rem;
    border: 1px solid;
    cursor: pointer;
    transition: all 300ms cubic-bezier(0.22, 1, 0.36, 1);
    font-weight: 700;
    font-size: 0.75rem;
}

.crystal-btn:hover {
    transform: scale(1.05);
}

.crystal-btn:active {
    transform: scale(0.95);
}

.crystal-btn-secondary {
    background: white;
    border-color: rgba(0, 0, 0, 0.08);
    color: var(--crystal-light-text-secondary);
}

.dark .crystal-btn-secondary,
body.dark-mode .crystal-btn-secondary {
    background: #1A1A1C;
    border-color: var(--crystal-dark-separator);
    color: var(--crystal-dark-text-secondary);
}

.crystal-btn-primary {
    background: #1D1D1F;
    border-color: transparent;
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.crystal-btn-primary:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    transform: scale(1.05) translateY(-2px);
}

.dark .crystal-btn-primary,
body.dark-mode .crystal-btn-primary {
    background: var(--crystal-accent);
    color: black;
}

/* === REFLEXO DECORATIVO === */
.crystal-reflection {
    position: absolute;
    inset: 0;
    border-radius: 24px;
    pointer-events: none;
    z-index: 30;
    mix-blend-mode: overlay;
    background: linear-gradient(135deg, rgba(255,255,255,0.2) 0%, rgba(255,255,255,0) 100%);

    /* Aplicar a mesma máscara do ticket */
    -webkit-mask-image:
        radial-gradient(circle at 0 160px, transparent 10px, black 10.5px),
        radial-gradient(circle at 100% 160px, transparent 10px, black 10.5px);
    mask-image:
        radial-gradient(circle at 0 160px, transparent 10px, black 10.5px),
        radial-gradient(circle at 100% 160px, transparent 10px, black 10.5px);
    -webkit-mask-composite: source-in;
    mask-composite: intersect;
}

.dark .crystal-reflection,
body.dark-mode .crystal-reflection {
    background: linear-gradient(135deg, rgba(255,255,255,0.05) 0%, rgba(255,255,255,0) 100%);
}

/* === UTILITÁRIOS === */
.crystal-text-primary {
    color: var(--crystal-light-text-primary);
    transition: color 500ms ease;
}

.dark .crystal-text-primary,
body.dark-mode .crystal-text-primary {
    color: var(--crystal-dark-text-primary);
}

.crystal-text-secondary {
    color: var(--crystal-light-text-secondary);
    transition: color 500ms ease;
}

.dark .crystal-text-secondary,
body.dark-mode .crystal-text-secondary {
    color: var(--crystal-dark-text-secondary);
}

.crystal-text-accent {
    color: var(--crystal-accent);
}

/* === SCROLLBAR === */
.crystal-hidden-items::-webkit-scrollbar {
    width: 0px;
    background: transparent;
    display: none;
}

.crystal-hidden-items {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* === RESPONSIVO === */
@media (max-width: 480px) {
    .crystal-receipt-wrapper {
        max-width: 100%;
    }

    .crystal-actions {
        grid-template-columns: 1fr 1fr;
    }

    .crystal-btn-primary {
        grid-column: span 2;
    }
}

/* === ANIMAÇÕES === */
@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* Botão de fechar (X) */
.crystal-close-btn {
    position: absolute;
    top: -3rem;
    right: 0;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 300ms ease;
    z-index: 100;
}

.crystal-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* ============================================
   PRINT STYLES - Simple Receipt Layout
   Mostra apenas o elemento temporário de impressão
   ============================================ */

@media print {
    /* ========================================
       PRIORIDADE MÁXIMA: Sobrescrever font-system.css e z-index-system.css
       ======================================== */

    /* ESCONDER ABSOLUTAMENTE TUDO PRIMEIRO */
    html *,
    body *,
    body > *,
    * {
        visibility: hidden !important;
        display: none !important;
        opacity: 0 !important;
        max-height: 0 !important;
        overflow: hidden !important;
        position: absolute !important;
        left: -9999px !important;
    }

    /* Reset html e body para visível */
    html,
    body,
    body.crystal-printing {
        display: block !important;
        visibility: visible !important;
        background: white !important;
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        opacity: 1 !important;
        max-height: none !important;
        position: static !important;
        left: 0 !important;
    }

    /* Mostrar APENAS o container de impressão */
    #crystal-print-container {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        position: static !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        height: auto !important;
        max-height: none !important;
        margin: 0 !important;
        padding: 0 !important;
        background: white !important;
        overflow: visible !important;
    }

    /* Mostrar todos os elementos DENTRO do container */
    #crystal-print-container,
    #crystal-print-container *,
    #crystal-print-container > *,
    #crystal-print-container div,
    #crystal-print-container span,
    #crystal-print-container p,
    #crystal-print-container h1,
    #crystal-print-container h2,
    #crystal-print-container h3,
    #crystal-print-container strong {
        visibility: visible !important;
        display: block !important;
        opacity: 1 !important;
        max-height: none !important;
        position: static !important;
        left: auto !important;
        overflow: visible !important;
    }

    /* Esconder elementos comuns de UI/Dashboard */
    header,
    footer,
    nav,
    aside,
    .header,
    .footer,
    .navbar,
    .sidebar,
    .menu,
    button:not(#crystal-print-container button),
    .btn,
    .button,
    input,
    select,
    textarea,
    form,
    [class*="modal"]:not(#crystal-print-container),
    [id*="modal"]:not(#crystal-print-container),
    [class*="popup"],
    [class*="dialog"],
    [class*="overlay"]:not(#crystal-print-container),
    script,
    style,
    noscript {
        display: none !important;
        visibility: hidden !important;
    }

    /* Remove animações e transições */
    * {
        animation: none !important;
        transition: none !important;
    }

    /* Prevenir quebras de página */
    #crystal-print-container,
    #crystal-print-container > div {
        page-break-inside: avoid !important;
    }

    /* Garantir que spans e divs dentro do container sejam exibidos */
    #crystal-print-container div,
    #crystal-print-container span,
    #crystal-print-container p,
    #crystal-print-container h1,
    #crystal-print-container h2,
    #crystal-print-container h3,
    #crystal-print-container strong {
        display: block !important;
        visibility: visible !important;
    }

    /* Elementos inline devem permanecer inline */
    #crystal-print-container span,
    #crystal-print-container strong {
        display: inline !important;
    }

    /* Flexbox para elementos que precisam */
    #crystal-print-container [style*="display: flex"],
    #crystal-print-container [style*="display:flex"] {
        display: flex !important;
    }
}

/* Esconder o container de impressão na tela (só visível na impressão) */
#crystal-print-container {
    display: none;
}

body.crystal-printing #crystal-print-container {
    display: none; /* Ainda invisível na tela mesmo em modo printing */
}

@media screen {
    #crystal-print-container {
        display: none !important;
    }
}
