/* ============================================
   PRE-ORDER FEATURE - PREMIUM REDESIGN v2.0
   Gaming E-commerce Style with Glassmorphism
   ============================================ */

/* === CSS Variables === */
:root {
    --preorder-primary: #f59e0b;
    --preorder-primary-dark: #d97706;
    --preorder-secondary: #8b5cf6;
    --preorder-success: #10b981;
    --preorder-bg-dark: #0f0f1a;
    --preorder-bg-card: rgba(20, 20, 35, 0.95);
    --preorder-glass: rgba(255, 255, 255, 0.03);
    --preorder-border: rgba(255, 255, 255, 0.08);
    --preorder-text: #ffffff;
    --preorder-text-muted: #9ca3af;
    --preorder-glow: 0 0 20px rgba(245, 158, 11, 0.3);
}

/* === MODAL OVERLAY === */
#preorderModal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 99999 !important;
    background: rgba(0, 0, 0, 0.85) !important;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

#preorderModal.show {
    display: flex !important;
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

#preorderModal .modal-dialog {
    max-width: 420px;
    width: 100%;
    margin: auto;
    animation: modalSlideUp 0.3s ease;
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* === MODAL CONTENT === */
.preorder-modal-content {
    background: var(--preorder-bg-card);
    border: 1px solid var(--preorder-border);
    border-radius: 20px;
    overflow: hidden;
    box-shadow:
        0 25px 50px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(245, 158, 11, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* === HEADER === */
.preorder-modal-header {
    background: linear-gradient(135deg,
            rgba(245, 158, 11, 0.15) 0%,
            rgba(139, 92, 246, 0.1) 100%);
    border-bottom: 1px solid var(--preorder-border);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

.preorder-modal-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg,
            var(--preorder-primary),
            var(--preorder-secondary));
}

.preorder-modal-header .modal-title {
    color: var(--preorder-text);
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}

.preorder-modal-header .modal-title svg {
    width: 22px;
    height: 22px;
    color: var(--preorder-primary);
}

.preorder-modal-header .btn-close {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 8px;
    opacity: 0.7;
    transition: all 0.2s ease;
}

.preorder-modal-header .btn-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
}

/* === BODY === */
.preorder-modal-body {
    padding: 1.25rem;
    max-height: 65vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Custom Scrollbar */
.preorder-modal-body::-webkit-scrollbar {
    width: 4px;
}

.preorder-modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.preorder-modal-body::-webkit-scrollbar-thumb {
    background: rgba(245, 158, 11, 0.3);
    border-radius: 4px;
}

/* === GROUP INFO - COMPACT HORIZONTAL === */
.preorder-group-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem;
    background: var(--preorder-glass);
    border: 1px solid var(--preorder-border);
    border-radius: 14px;
    margin-bottom: 1rem;
}

.preorder-group-img {
    width: 56px !important;
    height: 56px !important;
    min-width: 56px !important;
    max-width: 56px !important;
    border-radius: 10px;
    object-fit: cover;
    border: 2px solid rgba(245, 158, 11, 0.4);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

.preorder-group-details {
    flex: 1;
    min-width: 0;
}

.preorder-group-details h6 {
    margin: 0 0 4px 0;
    color: var(--preorder-text);
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.3;
    /* Truncate long names */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.preorder-group-details p {
    margin: 0;
    font-size: 0.75rem;
    color: var(--preorder-text-muted);
    line-height: 1.4;
}

/* === PRICE DISPLAY === */
.preorder-price-display {
    background: linear-gradient(145deg,
            rgba(0, 0, 0, 0.5),
            rgba(0, 0, 0, 0.3));
    border: 1px solid var(--preorder-border);
    border-radius: 14px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.preorder-price-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    color: var(--preorder-text-muted);
    font-size: 0.9rem;
}

.preorder-price-row:not(:last-child) {
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

/* Base Price */
.base-price-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.base-price {
    font-weight: 600;
    color: var(--preorder-text);
    font-size: 1rem;
}

.base-price.discounted {
    color: var(--preorder-success) !important;
}

.original-price {
    text-decoration: line-through;
    color: #666;
    font-size: 0.85rem;
}

/* Discount */
.discount-label {
    display: flex;
    align-items: center;
    gap: 6px;
}

.discount-badge {
    background: linear-gradient(135deg, var(--preorder-success), #059669);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.discount-amount {
    color: var(--preorder-success) !important;
    font-weight: 700;
}

/* Priority Fee */
.priority-fee {
    color: var(--preorder-primary) !important;
    font-weight: 600;
}

/* Total Row */
.preorder-price-row.total-row {
    border-top: 1px dashed rgba(245, 158, 11, 0.3);
    border-bottom: none !important;
    margin-top: 0.5rem;
    padding-top: 0.75rem;
}

.preorder-price-row.total-row>span:first-child {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    color: var(--preorder-text);
}

.total-price {
    background: linear-gradient(135deg, var(--preorder-primary), #fbbf24);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 1.25rem !important;
    font-weight: 800;
}

/* === PRIORITY TOGGLE === */
.preorder-priority-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.preorder-priority-label {
    cursor: pointer;
    margin: 0;
}

.preorder-priority-label input {
    display: none;
}

.preorder-priority-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 0.875rem 0.5rem;
    background: var(--preorder-glass);
    border: 2px solid var(--preorder-border);
    border-radius: 12px;
    transition: all 0.25s ease;
    min-height: 90px;
    justify-content: center;
}

.preorder-priority-label:hover .preorder-priority-option {
    border-color: rgba(245, 158, 11, 0.3);
    background: rgba(245, 158, 11, 0.05);
}

.preorder-priority-label input:checked+.preorder-priority-option {
    border-color: var(--preorder-primary);
    background: rgba(245, 158, 11, 0.1);
    box-shadow: var(--preorder-glow);
}

.preorder-priority-option.priority {
    background: linear-gradient(135deg,
            rgba(139, 92, 246, 0.08),
            rgba(245, 158, 11, 0.08));
}

.preorder-priority-label input:checked+.preorder-priority-option.priority {
    border-color: var(--preorder-secondary);
    background: linear-gradient(135deg,
            rgba(139, 92, 246, 0.15),
            rgba(245, 158, 11, 0.1));
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.25);
}

.preorder-priority-icon {
    width: 32px;
    height: 32px;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* SVG Icons instead of emoji */
.preorder-priority-icon svg {
    width: 24px;
    height: 24px;
    color: var(--preorder-text-muted);
}

.preorder-priority-label input:checked+.preorder-priority-option .preorder-priority-icon svg {
    color: var(--preorder-primary);
}

.preorder-priority-label input:checked+.preorder-priority-option.priority .preorder-priority-icon svg {
    color: var(--preorder-secondary);
}

.preorder-priority-info {
    line-height: 1.3;
}

.preorder-priority-info strong {
    display: block;
    color: var(--preorder-text);
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.preorder-priority-info small {
    color: var(--preorder-text-muted);
    font-size: 0.7rem;
}

.preorder-priority-price {
    color: var(--preorder-primary);
    font-weight: 700;
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

.preorder-priority-option.priority .preorder-priority-price {
    color: var(--preorder-secondary);
}

/* === VOUCHER INPUT === */
.preorder-voucher-input {
    margin-bottom: 0.875rem;
}

.preorder-voucher-input label {
    display: block;
    color: var(--preorder-text-muted);
    font-size: 0.8rem;
    margin-bottom: 6px;
    font-weight: 500;
}

.preorder-voucher-input .input-group {
    display: flex;
    gap: 0;
}

.preorder-voucher-input .form-control {
    flex: 1;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--preorder-border);
    border-right: none;
    color: var(--preorder-text);
    border-radius: 10px 0 0 10px;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.preorder-voucher-input .form-control:focus {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--preorder-primary);
    outline: none;
    box-shadow: none;
}

.preorder-voucher-input .form-control::placeholder {
    color: #555;
}

.preorder-voucher-input .btn-outline-primary {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid var(--preorder-primary);
    color: var(--preorder-primary);
    border-radius: 0 10px 10px 0;
    padding: 0.625rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.preorder-voucher-input .btn-outline-primary:hover {
    background: var(--preorder-primary);
    color: #000;
}

#preorderVoucherStatus {
    margin-top: 6px;
    font-size: 0.75rem;
}

/* === NOTE INPUT === */
.preorder-note-input {
    margin-bottom: 0.875rem;
}

.preorder-note-input label {
    display: block;
    color: var(--preorder-text-muted);
    font-size: 0.8rem;
    margin-bottom: 6px;
    font-weight: 500;
}

.preorder-note-input .form-control {
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--preorder-border);
    color: var(--preorder-text);
    border-radius: 10px;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    resize: none;
    min-height: 60px;
    transition: all 0.2s ease;
}

.preorder-note-input .form-control:focus {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--preorder-primary);
    outline: none;
    box-shadow: none;
}

.preorder-note-input .form-control::placeholder {
    color: #555;
}

/* === WARNING BOX === */
.preorder-warning {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 0.75rem;
    background: linear-gradient(135deg,
            rgba(245, 158, 11, 0.08),
            rgba(245, 158, 11, 0.04));
    border: 1px solid rgba(245, 158, 11, 0.2);
    border-radius: 10px;
    font-size: 0.75rem;
    color: rgba(245, 158, 11, 0.9);
    line-height: 1.5;
}

.preorder-warning svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin-top: 1px;
}

/* === FOOTER === */
.preorder-modal-footer {
    background: rgba(0, 0, 0, 0.3);
    border-top: 1px solid var(--preorder-border);
    padding: 1rem 1.25rem;
    display: flex;
    gap: 0.75rem;
}

.preorder-modal-footer .btn-secondary {
    flex: 1;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--preorder-border);
    color: var(--preorder-text-muted);
    padding: 0.75rem 1rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.preorder-modal-footer .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--preorder-text);
}

.btn-preorder-submit {
    flex: 2;
    background: linear-gradient(135deg, var(--preorder-primary), var(--preorder-primary-dark));
    color: #000;
    font-weight: 700;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.25s ease;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.btn-preorder-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
}

.btn-preorder-submit:active {
    transform: translateY(0);
}

.btn-preorder-submit:disabled {
    opacity: 0.6;
    transform: none;
    cursor: not-allowed;
}

.btn-preorder-submit svg {
    width: 18px;
    height: 18px;
}

/* === ANIMATIONS === */
@keyframes pricePulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.03);
    }

    100% {
        transform: scale(1);
    }
}

/* === PRE-ORDER BUTTON (on product card) === */
.btn-preorder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: linear-gradient(135deg, var(--preorder-primary), var(--preorder-primary-dark));
    color: #000;
    font-weight: 600;
    border: none;
    padding: 0.625rem 1.25rem;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.25s ease;
    font-size: 0.875rem;
    width: 100%;
    box-shadow: 0 3px 10px rgba(245, 158, 11, 0.25);
}

.btn-preorder:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(245, 158, 11, 0.35);
}

.btn-preorder svg {
    width: 18px;
    height: 18px;
}

/* === STATUS BADGES === */
.badge-out-of-stock {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
}

.preorder-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.preorder-status.pending {
    background: rgba(245, 158, 11, 0.12);
    color: var(--preorder-primary);
    border: 1px solid rgba(245, 158, 11, 0.25);
}

.preorder-status.processing {
    background: rgba(59, 130, 246, 0.12);
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.25);
}

.preorder-status.completed {
    background: rgba(34, 197, 94, 0.12);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.25);
}

.preorder-status.refunded {
    background: rgba(139, 92, 246, 0.12);
    color: #8b5cf6;
    border: 1px solid rgba(139, 92, 246, 0.25);
}

.preorder-status.cancelled {
    background: rgba(107, 114, 128, 0.12);
    color: #6b7280;
    border: 1px solid rgba(107, 114, 128, 0.25);
}

/* ============================================
   RESPONSIVE - MOBILE FIRST
   ============================================ */

/* Tablets */
@media (max-width: 768px) {
    #preorderModal {
        padding: 0.75rem;
        align-items: flex-start;
        padding-top: 2rem;
    }

    #preorderModal .modal-dialog {
        max-width: 100%;
        max-height: calc(100vh - 3rem);
    }

    .preorder-modal-content {
        max-height: calc(100vh - 3rem);
        display: flex;
        flex-direction: column;
        border-radius: 16px;
    }

    .preorder-modal-header {
        flex-shrink: 0;
        padding: 0.875rem 1rem;
    }

    .preorder-modal-body {
        flex: 1 1 auto;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding: 1rem;
        max-height: calc(100vh - 160px) !important;
        min-height: 200px;
    }

    .preorder-modal-footer {
        flex-shrink: 0;
        padding: 0.875rem 1rem;
        background: rgba(15, 15, 26, 0.98);
        backdrop-filter: blur(10px);
    }

    /* Compact product info */
    .preorder-group-info {
        padding: 0.75rem;
        gap: 0.875rem;
    }

    .preorder-group-img {
        width: 48px !important;
        height: 48px !important;
        min-width: 48px !important;
        max-width: 48px !important;
    }

    .preorder-group-details h6 {
        font-size: 0.9rem;
    }

    /* Stack priority options on very small */
    .preorder-priority-toggle {
        gap: 0.625rem;
    }

    .preorder-priority-option {
        padding: 0.75rem 0.375rem;
        min-height: 85px;
    }

    .preorder-priority-icon {
        width: 28px;
        height: 28px;
        margin-bottom: 0.375rem;
    }

    .preorder-priority-icon svg {
        width: 20px;
        height: 20px;
    }

    .preorder-priority-info strong {
        font-size: 0.8rem;
    }

    .preorder-priority-info small {
        font-size: 0.65rem;
    }

    .preorder-priority-price {
        font-size: 0.8rem;
    }

    /* Inputs */
    .preorder-voucher-input .form-control,
    .preorder-note-input .form-control {
        font-size: 16px;
        /* Prevent zoom on iOS */
    }

    .preorder-note-input .form-control {
        min-height: 50px;
    }

    /* Footer buttons */
    .preorder-modal-footer .btn-secondary {
        flex: none;
        width: auto;
        padding: 0.75rem 1rem;
    }

    .btn-preorder-submit {
        flex: 1;
        padding: 0.75rem;
    }
}

/* Small phones */
@media (max-width: 400px) {
    #preorderModal {
        padding: 0.5rem;
        padding-top: 1rem;
    }

    .preorder-modal-header {
        padding: 0.75rem;
    }

    .preorder-modal-header .modal-title {
        font-size: 1rem;
    }

    .preorder-modal-body {
        padding: 0.875rem;
    }

    .preorder-price-display {
        padding: 0.875rem;
    }

    .preorder-price-row {
        font-size: 0.85rem;
    }

    .total-price {
        font-size: 1.1rem !important;
    }

    .preorder-warning {
        font-size: 0.7rem;
        padding: 0.625rem;
    }

    .preorder-modal-footer {
        padding: 0.75rem;
        flex-direction: column-reverse;
        gap: 0.5rem;
    }

    .preorder-modal-footer .btn-secondary,
    .btn-preorder-submit {
        width: 100%;
        flex: none;
    }
}

/* Landscape phones */
@media (max-height: 500px) and (orientation: landscape) {
    #preorderModal {
        padding: 0.5rem;
        align-items: flex-start;
    }

    .preorder-modal-body {
        max-height: calc(100vh - 130px);
    }

    .preorder-group-info {
        flex-direction: row;
        text-align: left;
    }
}

/* Desktop enhancements */
@media (min-width: 769px) {
    .preorder-modal-content {
        transition: transform 0.3s ease, box-shadow 0.3s ease;
    }

    .preorder-modal-content:hover {
        box-shadow:
            0 30px 60px rgba(0, 0, 0, 0.6),
            0 0 0 1px rgba(245, 158, 11, 0.15);
    }

    .preorder-priority-option:hover {
        transform: translateY(-2px);
    }
}

/* === HIDDEN INPUTS === */
#preorderGroupId,
#preorderEstimatedPrice {
    display: none;
}