/* ============================================================
   Passport Size Photo Print — Styles
   ============================================================ */

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --secondary: #64748b;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #ca8a04;
    --bg: #f8fafc;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius: 10px;
    --transition: 0.2s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    padding: 16px;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
}

/* Header */
.app-header {
    text-align: center;
    padding: 32px 16px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 24px;
}

.app-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.app-header .tagline {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* Main layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

@media (min-width: 900px) {
    /* Only one step is visible at a time; the editor owns the two-column layout. */
    #step-editor .editor-layout {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 420px);
        gap: 24px;
        align-items: start;
    }
}

/* Panels */
.panel {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 24px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.panel h2 {
    font-size: 1.25rem;
    margin-bottom: 16px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
}

.step-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    font-size: 0.85rem;
    font-weight: 700;
    flex-shrink: 0;
}

.panel h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--text);
}

.panel h4 {
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: var(--secondary);
}

/* Upload */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: #fff;
}

.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
}

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

.upload-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    display: block;
}

#uploadPrompt {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.upload-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 10px;
    line-height: 1.5;
}

.file-input {
    display: none;
}

.image-info {
    margin-top: 16px;
    padding: 14px;
    background: #f1f5f9;
    border-radius: 8px;
    font-size: 0.85rem;
}

.info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.info-row span:first-child {
    color: var(--text-muted);
}

/* Size selector */
.size-selector {
    margin-bottom: 20px;
}

.size-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.size-btn {
    border: 2px solid var(--border);
    background: #fff;
    border-radius: 10px;
    padding: 16px 12px;
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
    font-size: 0.9rem;
}

.size-btn:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.size-btn.active {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}

.size-btn.active .size-label {
    font-weight: 700;
}

.size-label {
    display: block;
    font-weight: 600;
    margin-bottom: 2px;
}

.size-desc {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Crop editor */
.canvas-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    max-height: 520px;
    background: #0f172a;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    margin-bottom: 16px;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.canvas-wrapper.dragging {
    cursor: grabbing;
}

#editorCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

.crop-overlay {
    position: absolute;
    box-sizing: border-box;
    border: 2px dashed #fff;
    border-radius: 3px;
    pointer-events: none;
    box-shadow: 0 0 0 9999px rgb(15 23 42 / 0.42);
    background-image:
        linear-gradient(rgb(255 255 255 / 0.25) 1px, transparent 1px),
        linear-gradient(90deg, rgb(255 255 255 / 0.25) 1px, transparent 1px);
    background-size: 25% 25%;
    background-position: center;
}

.canvas-hint {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgb(15 23 42 / 0.85);
    color: #fff;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
    pointer-events: none;
    white-space: nowrap;
}

.controls-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.control-label {
    font-size: 0.85rem;
    color: var(--secondary);
    min-width: 150px;
}

.control-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    min-width: 48px;
    text-align: right;
}

.control-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-left: 8px;
}

input[type="range"] {
    flex: 1;
    min-width: 80px;
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

.crop-preview {
    margin-top: 16px;
    padding: 14px;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid var(--border);
    text-align: center;
}

.preview-physical {
    width: min(100%, 220px);
    aspect-ratio: 3 / 4;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    margin: 0 auto 8px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#cropResultImg {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: fill;
}

.preview-size-label {
    display: inline-block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-light);
    padding: 3px 10px;
    border-radius: 999px;
}

/* Layout info */
.layout-info {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 16px;
    padding: 12px;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.info-item {
    display: flex;
    flex-direction: column;
}

.info-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.info-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary);
}

/* A4 preview: real A4 dimensions, scaled only for the screen */
.a4-preview-wrapper {
    margin-top: 8px;
}

.a4-scale-shell {
    --a4-scale: 0.5;
    width: calc(210mm * var(--a4-scale));
    height: calc(297mm * var(--a4-scale));
    margin: 0 auto 8px;
    position: relative;
    overflow: hidden;
}

.a4-viewport {
    width: 210mm;
    height: 297mm;
    transform: scale(var(--a4-scale));
    transform-origin: top left;
    border: 1px solid #cbd5e1;
    background: #fff;
}

.a4-sheet {
    width: 210mm;
    height: 297mm;
    background: #fff;
    border: 1.5px solid #94a3b8;
    box-shadow: 0 8px 24px -4px rgb(0 0 0 / 0.2);
    border-radius: 2px;
    position: relative;
    overflow: hidden;
}

.a4-content {
    position: relative;
    width: 100%;
    height: 100%;
}

.a4-photo {
    position: absolute;
    background: #e2e8f0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 10px;
}

.a4-photo img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    display: block;
}

.cut-guide {
    position: absolute;
    z-index: 10;
    pointer-events: none;
}

.cut-guide.photo-guide {
    background: transparent;
    border: 1px dashed #ef4444;
}

@media (max-width: 600px) {
    .a4-scale-shell {
        --a4-scale: 0.32;
    }
    .control-label {
        min-width: 120px;
    }
    .control-hint {
        display: none;
    }
    body {
        padding: 10px;
    }
    .panel {
        padding: 16px;
    }
}

/* Output */
.output-hint {
    color: var(--text-muted);
    margin-bottom: 20px;
    text-align: center;
}

.print-note {
    margin-top: 14px;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.action-buttons {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 20px;
}

@media (min-width: 600px) {
    .action-buttons {
        grid-template-columns: 1fr 1fr 1fr;
    }
}

.btn {
    padding: 14px 18px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

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

.btn-secondary:hover:not(:disabled) {
    background: #e2e8f0;
}

.btn-print {
    background: var(--success);
    color: #fff;
    border: 2px solid #15803d;
    letter-spacing: 0.5px;
}

.btn-print:hover:not(:disabled) {
    background: #15803d;
}

.validation {
    margin-top: 20px;
    padding: 16px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    font-size: 0.85rem;
    color: #166534;
}

.validation h4 {
    margin-bottom: 6px;
    font-size: 0.9rem;
}

#validationMsg {
    font-family: ui-monospace, SFMono-Regular, monospace;
    font-size: 0.8rem;
}

/* Hidden */
[hidden] {
    display: none !important;
}

/* Screen: the print sheet is generated only when needed. */
.print-root {
    display: none;
}

/* ============================================================
   PRINT — one exact A4 sheet, no app chrome, no browser margins
   ============================================================ */
@page {
    size: A4 portrait;
    margin: 0;
}

@media print {
    html,
    body {
        width: 210mm !important;
        height: 297mm !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        overflow: hidden !important;
    }

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

    .app-container,
    .app-header,
    #step-upload,
    #step-editor,
    #step-output,
    .validation,
    .action-buttons,
    .print-note,
    .output-hint {
        display: none !important;
    }

    .print-root {
        display: block !important;
        position: absolute !important;
        inset: 0 auto auto 0 !important;
        width: 210mm !important;
        height: 297mm !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
    }

    .print-root .a4-sheet {
        width: 210mm !important;
        height: 297mm !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        transform: none !important;
        overflow: hidden !important;
        page-break-after: avoid !important;
        break-after: avoid !important;
    }

    .print-root .a4-content {
        width: 210mm !important;
        height: 297mm !important;
    }
}
