/* Print Page Styles for PF2E Card Maker
   US Letter layout with 2x4 grid for 8 cards
*/

/* Main print page container */
.print-page {
    width: 1650px !important; /* Half of 3300px - 11 inches at 150 DPI */
    height: 1275px !important; /* Half of 2550px - 8.5 inches at 150 DPI */
    margin: 0;
    padding: 0 !important;
    box-sizing: border-box;
    background: white !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: relative;
}

/* Print page title and controls */
.print-page-header {
    text-align: center;
    margin-bottom: 20px;
}

.print-page-title {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 10px;
    color: #333;
}

.print-page-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

/* Grid container for cards */
.print-grid {
    display: grid !important;
    grid-template-columns: repeat(4, 375px) !important; /* Half of 750px */
    grid-template-rows: repeat(2, 525px) !important; /* Half of 1050px */
    gap: 0 !important; /* No gaps - matches export */
    width: 1500px !important; /* 4 * 375px - half of original */
    height: 1050px !important; /* 2 * 525px - half of original */
    margin: 0 auto !important;
    padding: 0 !important;
    justify-content: center !important;
    position: relative;
}

/* Print preview scale adjustments */
.print-preview-viewport {
    transform-origin: top center;
}

/* When exporting, use actual print sizes */
@media print {
    .print-grid {
        grid-template-columns: repeat(4, 2.5in) !important;
        grid-template-rows: repeat(2, 3.5in) !important;
    }

    .card-slot {
        width: 2.5in !important;
        height: 3.5in !important;
    }

    .card-slot .card {
        width: 2.5in !important;
        height: 3.5in !important;
        max-width: 2.5in !important;
        max-height: 3.5in !important;
        transform: scale(1.75); /* Scale to fit print size (2.5in / 1.44in ≈ 1.74) */
    }
}

/* Individual card slots */
.card-slot {
    position: relative;
    width: 375px !important; /* Half of 750px */
    height: 525px !important; /* Half of 1050px */
    border: none !important; /* No borders - matches export */
    background: white;
    cursor: move;
    transition: all 0.2s ease;
    overflow: hidden;
}

/* Empty slot styling */
.card-slot.empty {
    border: 3px dashed #999 !important; /* Show dashed border for empty slots */
    background: #f5f5f5;
}

.card-slot.empty::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23999" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><line x1="12" y1="8" x2="12" y2="16"/><line x1="8" y1="12" x2="16" y2="12"/></svg>') center/contain no-repeat;
    opacity: 0.3;
}

/* Drag and drop states */
.card-slot.dragging {
    opacity: 0.5;
    transform: scale(1.05);
    z-index: 1000;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.card-slot.drag-over {
    background-color: rgba(0, 102, 204, 0.1);
    border-color: #0066cc;
}

/* Card within slot */
.card-slot .card {
    width: 750px !important; /* Full native width */
    height: 1050px !important; /* Full native height */
    transform: scale(0.5) !important; /* Scale to 50% */
    transform-origin: center center;
    font-size: 12pt; /* Base font size for print */
    overflow: hidden !important;
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -525px; /* Half of 1050px (before scaling) */
    margin-left: -375px; /* Half of 750px (before scaling) */
}

/* Ensure card elements maintain proper proportions when scaled */
.card-slot .card * {
    transform-origin: center;
}

/* Adjust font sizes for scaled cards */
.card-slot .feat-name-box {
    font-size: 35pt !important; /* Scale up from 14pt by 2.5x to compensate for card scale */
}

.card-slot .description-box {
    font-size: 25pt !important; /* Scale up from 10pt by 2.5x */
}

.card-slot .trait {
    font-size: 20pt !important; /* Larger for readability */
}

/* For PNG export - ensure proper scaling */
@media screen {
    #print-page-container {
        /* When exporting, we want full resolution */
    }
}

/* Export mode - full size for PNG export */
.export-mode {
    /* Container for export - US Letter landscape at 300 DPI */
    width: 3300px !important; /* 11 inches at 300 DPI */
    height: 2550px !important; /* 8.5 inches at 300 DPI */
    background: white !important;
    padding: 0 !important;
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.export-mode .print-page {
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: white !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.export-mode .print-grid {
    grid-template-columns: repeat(4, 750px) !important; /* Cards at full 750px width */
    grid-template-rows: repeat(2, 1050px) !important; /* Cards at full 1050px height */
    gap: 0 !important; /* No gaps for clean export */
    width: 3000px !important; /* 4 * 750px */
    height: 2100px !important; /* 2 * 1050px */
    margin: 0 !important;
    padding: 0 !important;
}

.export-mode .card-slot {
    width: 750px !important; /* Full card width */
    height: 1050px !important; /* Full card height */
    border: none !important; /* No borders for clean export */
    padding: 0 !important;
    margin: 0 !important;
    box-sizing: border-box !important;
}

.export-mode .card-slot .card {
    transform: scale(1) !important; /* No scaling - cards at native 750x1050px */
    width: 750px !important; /* Native card size */
    height: 1050px !important; /* Native card size */
    transform-origin: center;
}


/* Remove button for individual cards */
.card-slot .remove-card {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(255, 0, 0, 0.8);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.card-slot:hover .remove-card {
    opacity: 1;
}

.card-preview-image {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    display: block !important;
}

/* Print-specific styles */
@media print {
    .print-page {
        margin: 0;
        padding: 0;
        width: 8.5in;
        height: 11in;
    }

    .print-page-header,
    .print-page-controls,
    .remove-card {
        display: none !important;
    }

    .print-grid {
        margin: 0;
    }

    .card-slot {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .card-slot.empty {
        display: none;
    }
}

/* Button styles for print page controls */
.btn-print-page {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.2s ease;
}

.btn-print-page.btn-primary {
    background: #0066cc;
    color: white;
}

.btn-print-page.btn-primary:hover {
    background: #0052a3;
}

.btn-print-page.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-print-page.btn-secondary:hover {
    background: #5a6268;
}

.btn-print-page.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-print-page.btn-danger:hover {
    background: #c82333;
}

.btn-print-page.btn-success {
    background: #28a745;
    color: white;
}

.btn-print-page.btn-success:hover {
    background: #218838;
}

/* Loading state */
.export-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.export-loading::after {
    content: "";
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive adjustments for screen preview */
@media screen and (max-width: 1200px) {
    .print-page {
        transform: scale(0.8);
        transform-origin: center top;
        margin-bottom: 50px;
    }
}

@media screen and (max-width: 900px) {
    .print-page {
        transform: scale(0.6);
    }
}

/* Tooltip for drag instructions */
.drag-tooltip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 100;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.card-slot:hover .drag-tooltip {
    opacity: 1;
}

/* Card count indicator */
.card-count {
    text-align: center;
    margin-top: 10px;
    font-size: 14px;
    color: #666;
}

.card-count strong {
    color: #333;
}

/* Print preview viewport - creates a scrollable area */
.print-preview-viewport {
    overflow: auto;
    max-height: 600px;
    background: #f0f0f0;
    border-radius: 4px;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
    min-height: 400px;
    margin-top: 20px;
    position: relative;
}

/* Center the scaled print page */
.print-preview-viewport::before {
    content: '';
    display: inline-block;
    height: 100%;
    vertical-align: top;
}

/* Print preview wrapper */
.print-preview-wrapper {
    background: #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

/* Preview controls */
.print-preview-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding: 10px;
    background: white;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.print-preview-controls label {
    font-weight: bold;
    color: #333;
}

.print-preview-controls select {
    padding: 5px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
}

.print-preview-controls .btn-print-page {
    padding: 5px 15px;
    font-size: 13px;
}

/* Preview viewport - creates a scrollable area */
.print-preview-viewport {
    overflow: auto;
    max-height: 600px;
    background: #f0f0f0;
    border-radius: 4px;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
    min-height: 400px;
}

/* Container for the print page preview */
#print-page-container {
    background: white;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: transform 0.3s ease;
    transform-origin: top center;
    padding: 0;
    display: inline-block; /* Changed from flex to allow proper scaling */
    transform-origin: top center;
}

/* Ensure print grid is visible - already defined above with exact dimensions */
/* No duplicate rules needed */

/* Hide only card preview when print page tab is active */
body.print-page-active .preview-section {
    display: none;
}