/* ============================================
   Photo Arranger — Styles
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
    --color-bg: #0a0a0f;
    --color-surface: #13131a;
    --color-surface-2: #1a1a24;
    --color-surface-3: #22222e;
    --color-border: rgba(255, 255, 255, 0.06);
    --color-border-hover: rgba(255, 255, 255, 0.12);
    --color-text: #e8e8f0;
    --color-text-secondary: #8888a0;
    --color-text-muted: #555568;
    --color-primary: #6366f1;
    --color-primary-hover: #818cf8;
    --color-primary-glow: rgba(99, 102, 241, 0.25);
    --color-accent: #a78bfa;
    --color-danger: #f87171;
    --color-danger-hover: #fca5a5;
    --color-success: #34d399;
    --color-paper: #ffffff;
    --color-paper-shadow: rgba(0, 0, 0, 0.4);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 20px var(--color-primary-glow);
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms cubic-bezier(0.16, 1, 0.3, 1);
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --header-height: 64px;
    --panel-width: 320px;
}

/* ---------- Reset ---------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* ---------- Background Decoration ---------- */
.bg-decoration {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.15;
}

.blob-1 {
    width: 600px;
    height: 600px;
    background: var(--color-primary);
    top: -200px;
    right: -100px;
    animation: float 20s ease-in-out infinite;
}

.blob-2 {
    width: 500px;
    height: 500px;
    background: var(--color-accent);
    bottom: -100px;
    left: -150px;
    animation: float 25s ease-in-out infinite reverse;
}

.blob-3 {
    width: 400px;
    height: 400px;
    background: #ec4899;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: float 18s ease-in-out infinite 5s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -40px) scale(1.05); }
    50% { transform: translate(-20px, 20px) scale(0.95); }
    75% { transform: translate(40px, 30px) scale(1.02); }
}

/* ---------- Header ---------- */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    z-index: 100;
    background: rgba(10, 10, 15, 0.75);
    backdrop-filter: blur(24px) saturate(1.4);
    border-bottom: 1px solid var(--color-border);
}

.header-inner {
    max-width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: var(--shadow-glow);
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--color-text), var(--color-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.header-actions {
    display: flex;
    gap: 8px;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    border: none;
    font-family: var(--font-family);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8125rem;
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.btn-ghost:hover {
    background: var(--color-surface-2);
    color: var(--color-text);
    border-color: var(--color-border-hover);
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    color: white;
    border: none;
    box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
    filter: brightness(1.15);
    box-shadow: 0 0 30px var(--color-primary-glow);
    transform: translateY(-1px);
}

.btn-danger {
    background: transparent;
    color: var(--color-danger);
    border: 1px solid rgba(248, 113, 113, 0.2);
}

.btn-danger:hover {
    background: rgba(248, 113, 113, 0.1);
    border-color: rgba(248, 113, 113, 0.4);
}

/* ---------- Main Layout ---------- */
.main-content {
    display: flex;
    padding-top: var(--header-height);
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

/* ---------- Controls Panel ---------- */
.controls-panel {
    width: var(--panel-width);
    min-width: var(--panel-width);
    height: calc(100vh - var(--header-height));
    overflow-y: auto;
    background: rgba(19, 19, 26, 0.85);
    backdrop-filter: blur(16px);
    border-right: 1px solid var(--color-border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    position: sticky;
    top: var(--header-height);
}

.controls-panel::-webkit-scrollbar {
    width: 4px;
}

.controls-panel::-webkit-scrollbar-track {
    background: transparent;
}

.controls-panel::-webkit-scrollbar-thumb {
    background: var(--color-surface-3);
    border-radius: 2px;
}

/* ---------- Panel Sections ---------- */
.panel-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.section-title svg {
    opacity: 0.6;
}

/* ---------- Paper Size Buttons ---------- */
.paper-sizes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.paper-size-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 8px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    font-family: var(--font-family);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.paper-size-btn:hover {
    border-color: var(--color-border-hover);
    background: var(--color-surface-2);
    color: var(--color-text);
}

.paper-size-btn.active {
    border-color: var(--color-primary);
    background: rgba(99, 102, 241, 0.08);
    color: var(--color-primary-hover);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.15);
}

.paper-name {
    font-size: 0.875rem;
    font-weight: 600;
}

.paper-dim {
    font-size: 0.6875rem;
    opacity: 0.7;
}

/* ---------- Settings ---------- */
.setting-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.setting-label {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    font-weight: 500;
}

/* Orientation Toggle */
.orientation-toggle, .fill-mode-toggle {
    display: flex;
    gap: 6px;
}

.orientation-btn, .fill-mode-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    font-family: var(--font-family);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.orientation-btn:hover, .fill-mode-btn:hover {
    border-color: var(--color-border-hover);
    color: var(--color-text);
}

.orientation-btn.active, .fill-mode-btn.active {
    border-color: var(--color-primary);
    background: rgba(99, 102, 241, 0.08);
    color: var(--color-primary-hover);
}

/* Number Input */
.number-input-group {
    display: flex;
    align-items: center;
    gap: 0;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    overflow: hidden;
    background: var(--color-surface);
}

.num-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    font-family: var(--font-family);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.num-btn:hover {
    background: var(--color-surface-2);
    color: var(--color-text);
}

.num-input {
    flex: 1;
    height: 36px;
    border: none;
    border-left: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
    background: transparent;
    color: var(--color-text);
    font-family: var(--font-family);
    font-size: 0.875rem;
    font-weight: 600;
    text-align: center;
    outline: none;
    -moz-appearance: textfield;
}

.num-input::-webkit-outer-spin-button,
.num-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

/* ---------- Photo List ---------- */
.photo-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 300px;
    overflow-y: auto;
}

.photo-list::-webkit-scrollbar {
    width: 3px;
}

.photo-list::-webkit-scrollbar-thumb {
    background: var(--color-surface-3);
    border-radius: 2px;
}

.photo-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    transition: all var(--transition-fast);
    animation: slideIn 0.3s var(--transition-slow);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.photo-item:hover {
    border-color: var(--color-border-hover);
}

.photo-item-thumb {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    flex-shrink: 0;
}

.photo-item-info {
    flex: 1;
    min-width: 0;
}

.photo-item-name {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.photo-item-size {
    font-size: 0.6875rem;
    color: var(--color-text-muted);
}

.photo-item-remove {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.photo-item-remove:hover {
    background: rgba(248, 113, 113, 0.15);
    color: var(--color-danger);
}

/* Orientation Badge */
.photo-orient-badge {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    vertical-align: middle;
    margin-left: 4px;
}

.photo-orient-badge.landscape {
    background: rgba(99, 102, 241, 0.15);
    color: var(--color-primary-hover);
    border: 1px solid rgba(99, 102, 241, 0.25);
}

.photo-orient-badge.portrait {
    background: rgba(167, 139, 250, 0.12);
    color: var(--color-accent);
    border: 1px solid rgba(167, 139, 250, 0.2);
}

/* ---------- Preview Area ---------- */
.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    min-height: calc(100vh - var(--header-height));
}

/* ---------- Upload Zone ---------- */
.upload-zone {
    width: 100%;
    max-width: 600px;
    cursor: pointer;
}

.upload-zone-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 64px 40px;
    border-radius: var(--radius-xl);
    border: 2px dashed var(--color-border-hover);
    background: rgba(19, 19, 26, 0.5);
    backdrop-filter: blur(12px);
    transition: all var(--transition-base);
    text-align: center;
}

.upload-zone:hover .upload-zone-inner,
.upload-zone.drag-over .upload-zone-inner {
    border-color: var(--color-primary);
    background: rgba(99, 102, 241, 0.04);
    box-shadow: var(--shadow-glow);
}

.upload-zone.drag-over .upload-zone-inner {
    transform: scale(1.02);
}

.upload-icon {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(167, 139, 250, 0.1));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-primary-hover);
    animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.2); }
    50% { box-shadow: 0 0 30px 10px rgba(99, 102, 241, 0.1); }
}

.upload-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
}

.upload-desc {
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
}

.upload-formats {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    padding: 6px 14px;
    background: var(--color-surface-2);
    border-radius: 20px;
}

/* ---------- Paper Preview ---------- */
.paper-wrapper {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.paper-toolbar {
    width: 100%;
    max-width: 800px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(19, 19, 26, 0.7);
    backdrop-filter: blur(12px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
}

.paper-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

.paper-info span:first-child {
    font-weight: 600;
    color: var(--color-text);
}

.page-indicator {
    padding: 3px 10px;
    background: var(--color-surface-2);
    border-radius: 20px;
    font-size: 0.75rem;
}

.paper-actions {
    display: flex;
    gap: 8px;
}

/* ---------- Pages Container ---------- */
.pages-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 8px 0;
    width: 100%;
}

.paper-page {
    background: var(--color-paper);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0,0,0,0.1);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
    transition: box-shadow var(--transition-base);
}

.paper-page:hover {
    box-shadow: var(--shadow-lg), 0 0 40px rgba(99, 102, 241, 0.08), 0 0 0 1px rgba(0,0,0,0.1);
}

.paper-page-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
}

.photo-cell {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f5;
}

.photo-cell img {
    display: block;
    max-width: 100%;
    max-height: 100%;
}

.photo-cell img.cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-cell img.fit {
    object-fit: contain;
}

/* ---------- Page Navigation ---------- */
.page-navigation {
    display: flex;
    align-items: center;
    gap: 16px;
}

.page-nav-info {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    font-weight: 600;
}

/* ---------- Print Styles ---------- */
.print-container {
    display: none;
}

@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    html, body {
        background: white !important;
        margin: 0 !important;
        padding: 0 !important;
        width: auto !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
    }

    /* Hide everything except print container */
    body > *:not(.print-container) {
        display: none !important;
        width: 0 !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
    }

    .header,
    .main-content,
    .controls-panel,
    .preview-area,
    .bg-decoration,
    .toast {
        display: none !important;
        width: 0 !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
        position: absolute !important;
    }

    .print-container {
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
        position: static !important;
    }

    .print-page {
        page-break-after: always;
        page-break-inside: avoid;
        position: relative;
        overflow: hidden;
        margin: 0;
        padding: 0;
    }

    .print-page:last-child {
        page-break-after: auto;
    }

    .print-page .photo-cell {
        position: absolute;
        overflow: hidden;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .print-page .photo-cell img {
        display: block;
    }

    .print-page .photo-cell img.cover {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .print-page .photo-cell img.fit {
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
    }

    @page {
        margin: 0;
        size: auto;
    }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .main-content {
        flex-direction: column;
    }

    .controls-panel {
        width: 100%;
        min-width: unset;
        height: auto;
        max-height: none;
        position: static;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }

    .preview-area {
        min-height: 60vh;
    }

    .paper-toolbar {
        flex-direction: column;
        gap: 12px;
    }
}

/* ---------- Scrollbar (global) ---------- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-surface-3);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}

/* ---------- Toast Notification ---------- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    color: var(--color-text);
    font-size: 0.875rem;
    font-weight: 500;
    z-index: 1000;
    backdrop-filter: blur(16px);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.toast-error {
    border-color: rgba(248, 113, 113, 0.3);
    color: var(--color-danger);
}

.toast.toast-success {
    border-color: rgba(52, 211, 153, 0.3);
    color: var(--color-success);
}
