/* PDFomator - Custom styles for Pico CSS Red Theme */

/* CSS Variables for red theme overrides */
:root {
    --fab-size: 56px;
    --border-radius: 8px;
    --border-radius-small: 4px;
    --shadow-overlay: 0 4px 20px rgba(0,0,0,0.2);
    --shadow-fab: 0 4px 12px rgba(0, 0, 0, 0.2);
    --shadow-fab-hover: 0 6px 16px rgba(0, 0, 0, 0.3);
    --backdrop-blur: blur(4px);
    
    /* Red theme colors - using Pico's red palette */
    --custom-red: #dc2626;
    --custom-red-hover: #b91c1c;
    --custom-red-dark: #991b1b;
}

/* Reset and base layout */
* { box-sizing: border-box; }

/* Force light theme - override Pico CSS auto theme detection */
:root:not([data-theme="dark"]) {
    --pico-color-scheme: light;
}

[data-theme="light"] {
    --pico-color-scheme: light !important;
}

body {
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
    background: var(--pico-background-color);
    font-family: var(--pico-font-family);
}

/* App container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
}

/* Header */
.header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.5rem 1rem;
    background: var(--custom-red);
    border-bottom: 1px solid var(--custom-red-dark);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 10;
    position: relative;
    flex-shrink: 0;
}

.header h1 {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 600;
    color: white;
    letter-spacing: -0.02em;
    text-align: center;
}

.version {
    font-size: 0.7rem;
    opacity: 0.8;
    font-weight: 400;
    margin-left: 0.3rem;
}

/* Main content */
.main-content {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    overflow: auto;
}

/* FAB section */
.fab-section {
    flex-shrink: 0;
    padding: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Sheet container */
.sheet {
    background: white;
    border: 1px solid #ddd;
    border-radius: var(--border-radius-small);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin: 0 auto;
    max-width: 95vw;
    max-height: 75vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Paper size classes */
.sheet.a4-portrait {
    width: min(95vw, 75vh * 210 / 297);
    height: min(75vh, 95vw * 297 / 210);
}

.sheet.a4-landscape {
    width: min(95vw, 75vh * 297 / 210);
    height: min(75vh, 95vw * 210 / 297);
}

.sheet.a3-portrait {
    width: min(95vw, 75vh * 297 / 420);
    height: min(75vh, 95vw * 420 / 297);
}

.sheet.a3-landscape {
    width: min(95vw, 75vh * 420 / 297);
    height: min(75vh, 95vw * 297 / 420);
}

/* FAB buttons */
.fab {
    width: var(--fab-size);
    height: var(--fab-size);
    border-radius: 50%;
    border: none;
    background: var(--custom-red);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-fab);
    transition: all 0.2s ease;
    position: relative;
    z-index: 20;
}

.fab:hover {
    background: var(--custom-red-hover);
    transform: scale(1.1);
    box-shadow: var(--shadow-fab-hover);
}

.fab:active { 
    transform: scale(0.95); 
    background: var(--custom-red-dark);
}

.fab-container {
    display: flex;
    gap: 1rem;
    z-index: 20;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    padding: 0.75rem;
    border-radius: calc(var(--fab-size) / 2 + 0.75rem);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

/* Overlay base styles */
.grid-overlay, .size-overlay, .file-type-overlay, .page-selector-overlay, .export-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: var(--backdrop-blur);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

/* Picker containers */
.grid-picker, .size-picker, .file-type-picker, .page-selector, .overlay-content {
    background: white;
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-overlay);
    text-align: center;
    min-width: 300px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
}

/* Grid picker */
.grid-matrix {
    display: grid;
    grid-template-columns: repeat(5, 40px);
    grid-template-rows: repeat(5, 40px);
    gap: 4px;
    justify-content: center;
    margin: 1rem 0;
    /* Touch-friendly improvements */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    touch-action: none; /* Prevent scrolling during touch interactions */
}

.grid-cell {
    background: white;
    border: 2px solid var(--pico-muted-border-color);
    border-radius: var(--border-radius);
    padding: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    /* Touch-friendly improvements */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none; /* Disable iOS callout */
    -webkit-tap-highlight-color: transparent; /* Disable tap highlight */
}

.grid-cell:hover, .grid-cell.highlighted {
    background: #fee2e2;
    border-color: var(--pico-primary);
}

.grid-info {
    font-weight: bold;
    color: var(--pico-primary);
}

/* Size picker */
.size-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin: 1rem 0;
}

.size-option {
    text-align: left;
}

.size-option.selected {
    background: #fee2e2;
    border-color: var(--pico-primary);
}

.size-preview {
    width: 60px;
    height: 60px;
    background: white;
    border: 2px solid var(--pico-muted-border-color);
    border-radius: var(--border-radius-small);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-bottom: 0.75rem;
    position: relative;
}

.size-preview.a4-portrait, .size-preview.a3-portrait {
    width: 42px;
    height: 60px;
}

.size-preview.a4-landscape, .size-preview.a3-landscape {
    width: 60px;
    height: 42px;
}

/* File type picker */
.file-type-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 1rem 0;
}

.file-type-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1rem;
    color: inherit;
    padding: 0.75rem;
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
    cursor: pointer;
    background: white;
    border: 2px solid var(--pico-muted-border-color);
}

.file-type-btn:hover {
    background: #fee2e2;
    border-color: var(--pico-primary);
}

.file-type-icon {
    font-size: 1.5rem;
}

/* Page selector */
.page-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin: 1rem 0;
    max-height: 60vh;
    overflow-y: auto;
}

.page-thumbnail {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.page-thumbnail:hover {
    background: #fee2e2;
    border-color: var(--pico-primary);
}

.page-thumbnail canvas {
    max-width: 100%;
    max-height: 120px;
    border-radius: var(--border-radius-small);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.page-thumbnail .page-label {
    font-size: 0.9rem;
    font-weight: bold;
}

/* Interactive elements */
.interactive-card {
    background: white;
    border: 2px solid var(--pico-muted-border-color);
    border-radius: var(--border-radius);
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.interactive-card:hover {
    background: #fee2e2;
    border-color: var(--pico-primary);
}

.btn-cancel {
    margin-top: 1rem;
    background: #6b7280;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-small);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.btn-cancel:hover {
    background: #4b5563;
}

/* Export overlay specific styles */
.export-options {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 1.5rem 0;
}

.export-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    color: inherit;
    padding: 1rem;
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
    cursor: pointer;
    background: white;
    border: 2px solid var(--pico-muted-border-color);
    text-align: center;
}

.export-btn:hover {
    background: #fee2e2;
    border-color: var(--pico-primary);
}

.export-btn strong {
    font-size: 1.1rem;
    color: var(--pico-primary);
}

.export-btn small {
    color: var(--pico-muted-color);
    font-size: 0.85rem;
}

.cancel-btn {
    margin-top: 1rem;
    background: #6b7280;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-small);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.cancel-btn:hover {
    background: #4b5563;
}

/* Loading indicator */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
    color: white;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Utility classes */
.hidden { display: none !important; }

/* Mobile responsive */
@media (max-width: 768px) {
    .header {
        padding: 0.75rem;
    }
    
    .header h1 {
        font-size: 1.3rem;
    }
    
    .main-content {
        padding: 0.5rem;
    }
    
    .fab-container {
        bottom: 1rem;
        gap: 0.75rem;
    }
    
    .fab {
        width: 48px;
        height: 48px;
        font-size: 1rem;
    }
    
    .grid-picker, .size-picker, .file-type-picker, .page-selector {
        padding: 1.5rem;
        margin: 1rem;
        min-width: auto;
    }
    
    .size-options {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .size-preview {
        width: 50px !important;
        height: 50px !important;
        margin-bottom: 0.5rem;
    }
    
    .size-preview.a4-portrait, .size-preview.a3-portrait {
        width: 35px !important;
        height: 50px !important;
    }

    .size-preview.a4-landscape, .size-preview.a3-landscape {
        width: 50px !important;
        height: 35px !important;
    }
    
    .page-grid {
        grid-template-columns: 1fr;
    }
}

/* Update Notification */
.update-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    animation: slideDown 0.3s ease-out;
}

.update-content {
    background: var(--custom-red);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    font-weight: 500;
}

.update-btn {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.update-btn:hover {
    background: rgba(255,255,255,0.3);
}

.dismiss-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

.dismiss-btn:hover {
    opacity: 1;
}

@keyframes slideDown {
    from {
        transform: translateX(-50%) translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

/* Landscape orientation styles */
@media screen and (orientation: landscape) and (max-height: 500px) {
    /* Hide header in landscape mode to maximize sheet space */
    .header {
        display: none;
    }
    
    /* Adjust app container for landscape layout */
    .app-container {
        flex-direction: row;
    }
    
    /* Main content takes most of the space */
    .main-content {
        flex: 1;
        padding: 0.5rem;
        padding-right: calc(var(--fab-size) + 2rem); /* Leave space for FABs */
    }
    
    /* FAB section moves to right side */
    .fab-section {
        position: fixed;
        right: 1rem;
        top: 50%;
        transform: translateY(-50%);
        height: auto;
        width: auto;
        padding: 0;
        z-index: 20;
    }
    
    /* FAB container stacks vertically like macOS dock on side */
    .fab-container {
        flex-direction: column;
        gap: 0.75rem;
        background: rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(10px);
        padding: 0.75rem;
        border-radius: calc(var(--fab-size) / 2 + 0.75rem);
        border: 1px solid rgba(255, 255, 255, 0.2);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    }
    
    /* Adjust sheet sizing for landscape */
    .sheet {
        max-width: calc(100vw - var(--fab-size) - 3rem);
        max-height: 95vh;
    }
    
    /* Paper size adjustments for landscape mode */
    .sheet.a4-portrait {
        width: min(calc(100vw - var(--fab-size) - 3rem), 95vh * 210 / 297);
        height: min(95vh, calc(100vw - var(--fab-size) - 3rem) * 297 / 210);
    }

    .sheet.a4-landscape {
        width: min(calc(100vw - var(--fab-size) - 3rem), 95vh * 297 / 210);
        height: min(95vh, calc(100vw - var(--fab-size) - 3rem) * 210 / 297);
    }

    .sheet.a3-portrait {
        width: min(calc(100vw - var(--fab-size) - 3rem), 95vh * 297 / 420);
        height: min(95vh, calc(100vw - var(--fab-size) - 3rem) * 420 / 297);
    }

    .sheet.a3-landscape {
        width: min(calc(100vw - var(--fab-size) - 3rem), 95vh * 420 / 297);
        height: min(95vh, calc(100vw - var(--fab-size) - 3rem) * 297 / 420);
    }
    
    /* Adjust overlays for landscape mode */
    .grid-picker, .size-picker, .file-type-picker, .page-selector {
        max-width: calc(100vw - var(--fab-size) - 4rem);
        margin-right: calc(var(--fab-size) + 2rem);
    }
}
