/* ══════════════════════════════════════════════
   Passport Photo Tool — Design System
   Aligned with HoChieuGap Landing Page
   ══════════════════════════════════════════════ */

/* ── CSS Variables (synced with main site) ── */
:root {
    /* Colors */
    --c-primary: #1B4F72;
    --c-primary-dark: #143D59;
    --c-primary-light: #2E86C1;
    --c-accent: #E74C3C;
    --c-accent-dark: #C0392B;
    --c-accent-glow: rgba(231, 76, 60, 0.3);
    --c-success: #27AE60;
    --c-success-light: #2ECC71;
    --c-warning: #F39C12;
    --c-danger: #C0392B;
    --c-bg: #F8F9FA;
    --c-bg-alt: #FFFFFF;
    --c-text: #2C3E50;
    --c-text-muted: #6C757D;
    --c-text-light: #ADB5BD;
    --c-border: #DEE2E6;
    --c-border-light: #E9ECEF;

    /* Gradients */
    --g-primary: linear-gradient(135deg, #1B4F72, #2E86C1);
    --g-accent: linear-gradient(135deg, #E74C3C, #F39C12);

    /* Typography */
    --f-heading: 'Be Vietnam Pro', sans-serif;
    --f-body: 'Inter', 'Be Vietnam Pro', sans-serif;

    /* Spacing */
    --s-xs: 4px;
    --s-sm: 8px;
    --s-md: 16px;
    --s-lg: 24px;
    --s-xl: 32px;

    /* Border Radius */
    --r-sm: 6px;
    --r-md: 12px;
    --r-lg: 20px;
    --r-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
    --shadow-accent: 0 8px 30px rgba(231, 76, 60, 0.3);

    /* Transitions */
    --t-fast: 0.15s ease;
    --t-normal: 0.3s ease;
}

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

body {
    font-family: var(--f-body);
    background-color: var(--c-bg);
    color: var(--c-text);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

#app-container {
    width: 100%;
    max-width: 420px;
    height: 100vh;
    height: 100dvh;
    background: var(--c-bg-alt);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    margin: 0 auto;
}

@media (min-width: 421px) {
    #app-container {
        height: 800px;
        border-radius: var(--r-lg);
    }
}

.view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 1;
    visibility: visible;
    transition: opacity var(--t-normal), visibility var(--t-normal);
    background: var(--c-bg-alt);
}

.view.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: -1;
}

/* =========================================
   ONBOARDING VIEW
   ========================================= */
.onboarding-content,
.preview-content {
    padding: var(--s-lg);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.header {
    text-align: left;
    margin-top: var(--s-lg);
    margin-bottom: var(--s-xl);
}

.header h2 {
    font-family: var(--f-heading);
    font-size: 24px;
    font-weight: 700;
    color: var(--c-primary);
    margin-bottom: var(--s-sm);
}

.header p {
    font-size: 15px;
    color: var(--c-text-muted);
    line-height: 1.5;
}

.guidelines {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--s-md);
}

.guide-item {
    display: flex;
    align-items: flex-start;
    gap: var(--s-md);
    padding: var(--s-md);
    border-radius: var(--r-md);
    background: var(--c-bg);
    border: 1px solid var(--c-border-light);
    transition: all var(--t-fast);
}

.guide-item:hover {
    border-color: var(--c-primary-light);
    box-shadow: var(--shadow-sm);
}

.guide-item .icon {
    font-size: 28px;
    flex-shrink: 0;
}

.guide-item .text {
    display: flex;
    flex-direction: column;
    gap: var(--s-xs);
}

.guide-item .text strong {
    font-size: 15px;
    font-weight: 600;
    color: var(--c-text);
}

.guide-item .text span {
    font-size: 13px;
    color: var(--c-text-muted);
    line-height: 1.4;
}

/* =========================================
   CAMERA VIEW
   ========================================= */
.camera-wrapper {
    position: relative;
    flex: 1;
    background: #000;
    overflow: hidden;
}

#videoElement {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

/* --- Overlay System --- */
.overlay-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* --- Passport Guide Frame (4:6 ratio) --- */
.guide-frame {
    position: absolute;
    width: 82%;
    aspect-ratio: 4 / 6;
    top: 48%;
    left: 50%;
    transform: translate(-50%, -54%);
    border: 2.5px solid rgba(255, 255, 255, 0.5);
    border-radius: 4px;
    transition: border-color var(--t-normal), box-shadow var(--t-normal);
    overflow: visible;
}

.guide-frame::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    pointer-events: none;
}

.guide-frame::after {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    bottom: -1px;
    border-radius: 4px;
}

/* --- Head Oval Silhouette --- */
.guide-oval {
    position: absolute;
    width: 62%;
    aspect-ratio: 3 / 4;
    top: 3%;
    left: 50%;
    transform: translateX(-50%);
    border: 2px dashed rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    transition: border-color var(--t-normal), box-shadow var(--t-normal);
}

/* --- Guide Lines --- */
.guide-line {
    position: absolute;
    left: 0;
    width: 100%;
    border-top: 1px dashed rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.guide-line-top { top: 3%; }
.guide-line-eye { top: 40%; }
.guide-line-chin { top: 62%; }

.guide-label {
    font-size: 9px;
    color: rgba(255, 255, 255, 0.55);
    background: rgba(0, 0, 0, 0.45);
    padding: 2px 5px;
    border-radius: 3px;
    position: absolute;
    right: 4px;
    white-space: nowrap;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    font-weight: 500;
}

/* --- Shoulder Hint --- */
.guide-shoulders {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    height: 28%;
    border-top: 2px dashed rgba(255, 255, 255, 0.12);
    border-top-left-radius: 50% 100%;
    border-top-right-radius: 50% 100%;
}

/* --- Guide States --- */
.guide-frame.state-default { border-color: rgba(255, 255, 255, 0.5); }
.guide-oval.state-default { border-color: rgba(255, 255, 255, 0.4); }

.guide-frame.state-error { border-color: var(--c-accent); }
.guide-oval.state-error { border-color: rgba(231, 76, 60, 0.5); }

.guide-frame.state-warning { border-color: var(--c-warning); }
.guide-oval.state-warning { border-color: rgba(243, 156, 18, 0.5); }

.guide-frame.state-success {
    border-color: var(--c-success);
    box-shadow: 0 0 25px rgba(39, 174, 96, 0.3), inset 0 0 25px rgba(39, 174, 96, 0.08);
}

.guide-oval.state-success {
    border-color: var(--c-success);
    border-style: solid;
    box-shadow: 0 0 18px rgba(39, 174, 96, 0.4);
}

/* --- Countdown Overlay --- */
.countdown-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--t-normal), visibility var(--t-normal);
    z-index: 20;
}

.countdown-overlay.active {
    opacity: 1;
    visibility: visible;
}

.countdown-number {
    font-family: var(--f-heading);
    font-size: 120px;
    font-weight: 800;
    color: white;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    animation: countPopIn 0.4s ease-out;
}

.countdown-number.pulse {
    animation: countPopIn 0.3s ease-out;
}

@keyframes countPopIn {
    from { transform: scale(1.8); opacity: 0.3; }
    to { transform: scale(1); opacity: 1; }
}

/* --- Status Indicator --- */
.status-indicator {
    position: absolute;
    bottom: 16px;
    left: 0;
    width: 100%;
    text-align: center;
    color: white;
    font-weight: 500;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s-sm);
    z-index: 10;
}

.status-indicator p {
    background: rgba(0, 0, 0, 0.65);
    padding: var(--s-sm) 18px;
    border-radius: var(--r-full);
    font-size: 14px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: background var(--t-normal);
}

/* --- Camera Controls --- */
.camera-controls {
    height: 130px;
    background: var(--c-bg-alt);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--s-md);
    border-top: 1px solid var(--c-border-light);
}

/* --- Mode Toggle --- */
.mode-toggle {
    display: flex;
    flex-direction: column;
    gap: var(--s-sm);
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: var(--s-xs);
    padding: var(--s-sm) 10px;
    border: 1.5px solid var(--c-border);
    border-radius: var(--r-sm);
    background: transparent;
    cursor: pointer;
    transition: all var(--t-fast);
    font-family: var(--f-body);
}

.mode-btn .mode-icon { font-size: 16px; }

.mode-btn .mode-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--c-text-muted);
}

.mode-btn.active {
    border-color: var(--c-primary);
    background: rgba(27, 79, 114, 0.08);
}

.mode-btn.active .mode-label {
    color: var(--c-primary);
    font-weight: 600;
}

/* --- Capture Zone --- */
.capture-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s-sm);
}

.btn-shutter {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: transparent;
    border: 4px solid var(--c-border);
    padding: 4px;
    cursor: pointer;
    transition: all var(--t-fast);
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn-shutter .shutter-inner {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--c-border);
    transition: all var(--t-fast);
}

.btn-shutter:not(:disabled):hover .shutter-inner {
    background: var(--c-primary-dark);
}

.btn-shutter:not(:disabled) {
    border-color: var(--c-accent);
}

.btn-shutter:not(:disabled) .shutter-inner {
    background: var(--c-accent);
}

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

.btn-shutter.shutter-auto-taking .shutter-inner {
    background: var(--c-success);
    animation: shutterPulse 0.8s infinite alternate;
}

@keyframes shutterPulse {
    from { transform: scale(1); }
    to { transform: scale(0.88); }
}

.auto-capture-hint {
    font-size: 10px;
    color: var(--c-text-muted);
    text-align: center;
    max-width: 120px;
    line-height: 1.3;
}

/* --- Back Button (Camera View) --- */
.btn-back-cam {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1.5px solid var(--c-border);
    background: transparent;
    color: var(--c-text-muted);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all var(--t-fast);
    font-family: var(--f-body);
}

.btn-back-cam:hover {
    background: var(--c-bg);
    color: var(--c-text);
    border-color: var(--c-primary-light);
}

/* =========================================
   PREVIEW VIEW
   ========================================= */
.preview-content h2 {
    font-family: var(--f-heading);
    text-align: center;
    color: var(--c-primary);
    margin-bottom: var(--s-lg);
    margin-top: var(--s-lg);
}

.image-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--c-bg);
    border-radius: var(--r-md);
    border: 1px dashed var(--c-border);
    overflow: hidden;
    padding: var(--s-md);
}

#preview-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--s-xs);
    box-shadow: var(--shadow-md);
}

/* =========================================
   GENERAL BUTTONS
   ========================================= */
.action-footer {
    display: flex;
    gap: 10px;
    margin-top: var(--s-lg);
}

.btn {
    appearance: none;
    border: none;
    padding: 14px var(--s-md);
    border-radius: var(--r-md);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    flex: 1;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    transition: all var(--t-normal);
    font-family: var(--f-body);
    gap: var(--s-sm);
}

.btn:active {
    transform: scale(0.98);
}

/* UX: Primary CTA uses accent gradient matching landing page */
.btn.primary {
    background: var(--g-accent);
    color: white;
    box-shadow: var(--shadow-accent);
}

.btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(231, 76, 60, 0.4);
}

.btn.primary:active {
    transform: translateY(0) scale(0.98);
}

.btn.secondary {
    background: var(--c-bg);
    color: var(--c-text);
}

.btn.secondary.outline {
    background: transparent;
    border: 2px solid var(--c-primary);
    color: var(--c-primary);
}

.btn.secondary:hover {
    background: var(--c-border-light);
}

.btn.secondary.outline:hover {
    background: var(--c-primary);
    color: white;
}

/* Enhanced back-link — use primary-light */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: var(--s-xs);
    color: var(--c-primary-light);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: var(--s-md);
    padding: var(--s-xs) var(--s-sm);
    border-radius: var(--r-sm);
    transition: background var(--t-fast), color var(--t-fast);
}

.back-link:hover {
    text-decoration: none;
    background: rgba(46, 134, 193, 0.08);
    color: var(--c-primary);
}

.back-to-home {
    text-align: center;
    padding-top: var(--s-md);
}

/* Loader */
.loader {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    display: none;
}

.loader.active { display: block; }

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

canvas.hidden { display: none; }

/* =========================================
   CONFIRMATION VIEW
   ========================================= */
.confirmation-content {
    padding: var(--s-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    text-align: center;
    overflow-y: auto;
}

.confirmation-icon {
    font-size: 56px;
    margin-top: var(--s-lg);
    margin-bottom: var(--s-sm);
    animation: confirmBounce 0.6s ease-out;
}

@keyframes confirmBounce {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.15); }
    70% { transform: scale(0.95); }
    100% { transform: scale(1); opacity: 1; }
}

.confirmation-content h2 {
    font-family: var(--f-heading);
    font-size: 22px;
    font-weight: 700;
    margin-bottom: var(--s-sm);
    color: var(--c-primary);
}

.confirmation-desc {
    font-size: 14px;
    color: var(--c-text-muted);
    line-height: 1.5;
    max-width: 320px;
    margin-bottom: var(--s-md);
}

.confirmation-preview {
    width: 140px;
    height: 210px;
    border-radius: var(--r-md);
    overflow: hidden;
    border: 2px solid var(--c-success);
    box-shadow: 0 4px 16px rgba(39, 174, 96, 0.2);
    margin-bottom: 20px;
    flex-shrink: 0;
}

.confirmation-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.confirmation-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 320px;
}

.confirmation-actions .btn {
    text-decoration: none;
    justify-content: center;
}

.btn.ghost {
    background: transparent;
    color: var(--c-text-muted);
    border: none;
    font-size: 14px;
    font-weight: 500;
    padding: 10px var(--s-md);
}

.btn.ghost:hover {
    color: var(--c-primary);
    background: rgba(27, 79, 114, 0.06);
}

.btn.btn-lg {
    padding: 16px 20px;
    font-size: 16px;
}

.btn.btn-block {
    width: 100%;
}

.confirmation-tip {
    display: flex;
    align-items: flex-start;
    gap: var(--s-sm);
    margin-top: 20px;
    padding: var(--s-md);
    background: rgba(243, 156, 18, 0.08);
    border: 1px solid rgba(243, 156, 18, 0.2);
    border-radius: var(--r-md);
    max-width: 320px;
    text-align: left;
}

.confirmation-tip .tip-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.confirmation-tip span:last-child {
    font-size: 12px;
    color: var(--c-text-muted);
    line-height: 1.4;
}

/* =========================================================================
   REGISTER VIEW (BƯỚC 5 & BƯỚC 6) - UX OPTIMIZED
   ========================================================================= */

#register-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: var(--c-bg);
    justify-content: flex-start;
}

.register-header {
    display: flex;
    align-items: center;
    padding: 1rem;
    background-color: var(--c-bg-alt);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 10;
}

.btn-back-icon {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--c-text);
    cursor: pointer;
    padding: 0.5rem;
    margin-right: 1rem;
    transition: color var(--t-fast);
}

.btn-back-icon:hover {
    color: var(--c-primary);
}

.register-header h2 {
    margin: 0;
    font-family: var(--f-heading);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--c-primary);
}

.register-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 1rem 8rem 1rem;
}

.register-subtitle {
    font-size: 0.9rem;
    color: var(--c-text-muted);
    margin-bottom: 1.5rem;
    text-align: center;
}

.optim-form .form-section {
    background: var(--c-bg-alt);
    border: none;
    border-radius: var(--r-md);
    padding: 1.5rem 1rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.optim-form legend {
    font-family: var(--f-heading);
    font-weight: 700;
    color: var(--c-primary);
    font-size: 1.1rem;
    margin-bottom: 1rem;
    padding: 0 0.5rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-row.dual {
    display: flex;
    gap: 1rem;
}

.form-row.dual .form-group {
    flex: 1;
}

.optim-form label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
    color: var(--c-text);
}

.req {
    color: var(--c-accent);
}

/* Fitts's Law: Touch targets ≥ 48px */
.touch-target {
    min-height: 48px;
    width: 100%;
    border: 2px solid var(--c-border);
    border-radius: var(--r-md);
    padding: 0 1rem;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
    background-color: var(--c-bg);
}

.touch-target:focus {
    outline: none;
    border-color: var(--c-primary-light);
    background-color: var(--c-bg-alt);
    box-shadow: 0 0 0 4px rgba(46, 134, 193, 0.15);
}

.text-uppercase {
    text-transform: uppercase;
}

.error-msg {
    color: var(--c-accent);
    font-size: 0.8rem;
    margin-top: 0.5rem;
    display: none;
}

/* Validation states */
.form-group.has-error .touch-target {
    border-color: var(--c-accent);
    background-color: rgba(231, 76, 60, 0.04);
}

.form-group.has-error .error-msg {
    display: block;
}

/* Sticky Action Bar — Thumb Zone (Fitts's Law) */
.sticky-action-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--c-bg-alt);
    padding: 1rem;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
    z-index: 20;
}

.secure-badge {
    text-align: center;
    font-size: 0.75rem;
    color: var(--c-text-muted);
    margin-top: 0.75rem;
}

/* Success View */
.success-full {
    background: var(--c-bg-alt);
    border-radius: var(--r-lg);
    padding: 2.5rem 1.5rem;
    box-shadow: var(--shadow-md);
}

.confirmation-icon.bounce {
    animation: bounceIn 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

@keyframes bounceIn {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.success-ticket {
    background: var(--c-bg);
    border: 1px dashed var(--c-border);
    border-radius: var(--r-md);
    padding: 1rem;
    margin: 1.5rem 0;
    text-align: left;
}

.ticket-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.ticket-row:last-child {
    margin-bottom: 0;
}

.ticket-row .label {
    color: var(--c-text-muted);
}

.color-success {
    color: var(--c-success);
}

.margin-bottom-sm {
    margin-bottom: 0.75rem;
}

/* =========================================
   CONTACT ESCAPE HATCH
   UX: Give lazy/hesitant users an easy exit
   ========================================= */
.contact-escape {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-md);
    padding: var(--s-md);
    margin-bottom: 1.5rem;
    background: linear-gradient(135deg, rgba(27, 79, 114, 0.06), rgba(46, 134, 193, 0.08));
    border: 1px solid rgba(46, 134, 193, 0.2);
    border-radius: var(--r-md);
}

.contact-escape__label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--c-text);
    white-space: nowrap;
}

.contact-escape__actions {
    display: flex;
    gap: var(--s-sm);
}

.contact-escape__btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: var(--s-sm) 14px;
    border-radius: var(--r-full);
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    transition: all var(--t-fast);
    white-space: nowrap;
    /* UX: Fitts's Law — min touch target */
    min-height: 44px;
}

.contact-escape__btn--zalo {
    background: #0068FF;
    color: #fff;
}

.contact-escape__btn--zalo:hover {
    background: #0054cc;
    transform: translateY(-1px);
}

.contact-escape__btn--phone {
    background: var(--c-success);
    color: #fff;
}

.contact-escape__btn--phone:hover {
    background: #219a52;
    transform: translateY(-1px);
}

/* =========================================
   EXPANDABLE SECTION (Progressive Disclosure)
   UX: Hick's Law — hide advanced fields
   ========================================= */
.expand-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-sm);
    width: 100%;
    padding: 14px var(--s-md);
    margin-bottom: 1rem;
    background: var(--c-bg);
    border: 2px dashed var(--c-border);
    border-radius: var(--r-md);
    cursor: pointer;
    font-family: var(--f-body);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--c-primary);
    transition: all var(--t-normal);
    /* UX: Fitts's Law */
    min-height: 48px;
}

.expand-toggle:hover {
    border-color: var(--c-primary-light);
    background: rgba(46, 134, 193, 0.06);
}

.expand-toggle.active {
    border-color: var(--c-primary-light);
    background: rgba(46, 134, 193, 0.06);
    border-style: solid;
}

.expand-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.expandable-section {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.3s ease,
                margin 0.3s ease;
    margin-bottom: 0;
}

.expandable-section.expanded {
    max-height: 1200px;
    opacity: 1;
    margin-bottom: 1rem;
}

/* =========================================
   TEXTAREA TOUCH TARGET
   ========================================= */
textarea.touch-target {
    min-height: 72px;
    padding: 12px 1rem;
    resize: vertical;
    line-height: 1.5;
}

/* =========================================
   TOAST NOTIFICATION SYSTEM
   ========================================= */
.form-toast-container {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: calc(100% - 32px);
    max-width: 440px;
    pointer-events: none;
}

.form-toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px 20px;
    border-radius: var(--r-md);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.1);
    animation: toastSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    opacity: 0;
    transform: translateY(20px);
    font-size: 14px;
    line-height: 1.5;
}

.form-toast.hiding {
    animation: toastSlideDown 0.25s ease-in forwards;
}

.form-toast--success {
    background: #ECFDF5;
    border: 1px solid #A7F3D0;
    color: #065F46;
}

.form-toast--error {
    background: #FEF2F2;
    border: 1px solid #FECACA;
    color: #991B1B;
}

.form-toast--retrying {
    background: #FFFBEB;
    border: 1px solid #FDE68A;
    color: #92400E;
}

.form-toast-icon {
    font-size: 20px;
    flex-shrink: 0;
    line-height: 1;
    margin-top: 1px;
}

.form-toast-body {
    flex: 1;
    min-width: 0;
}

.form-toast-title {
    font-weight: 700;
    margin-bottom: 2px;
}

.form-toast-msg {
    opacity: 0.85;
}

.form-toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    opacity: 0.5;
    padding: 4px;
    color: inherit;
    transition: opacity var(--t-fast);
}

.form-toast-close:hover {
    opacity: 1;
}

.form-toast-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.form-toast-zalo {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: #0068FF;
    color: #fff !important;
    border-radius: var(--r-full);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: background var(--t-fast), transform var(--t-fast);
    min-height: 44px;
}

.form-toast-zalo:hover {
    background: #0054cc;
    transform: translateY(-1px);
}

.form-toast-call {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--c-success);
    color: #fff !important;
    border-radius: var(--r-full);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: background var(--t-fast), transform var(--t-fast);
    min-height: 44px;
}

.form-toast-call:hover {
    background: #219a52;
    transform: translateY(-1px);
}

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

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

/* =========================================
   MOBILE RESPONSIVE — COMPREHENSIVE
   All screens ≤ 768px (tablets + phones)
   ========================================= */
@media (max-width: 768px) {
    body {
        align-items: stretch;
    }

    #app-container {
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        box-shadow: none;
    }

    /* Toast container */
    .form-toast-container {
        bottom: 80px;
        width: calc(100% - 24px);
    }

    /* Contact escape: stack on narrow */
    .contact-escape {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .contact-escape__actions {
        justify-content: center;
    }

    /* Confirmation: remove max-width constraints */
    .confirmation-desc,
    .confirmation-actions,
    .confirmation-tip {
        max-width: 100%;
    }

    /* Preview action footer: column layout */
    .action-footer {
        flex-direction: column;
        gap: 8px;
    }

    .action-footer .btn {
        width: 100%;
        justify-content: center;
    }
}

/* =========================================
   MOBILE PHONES (≤ 480px)
   Target: All modern phones
   ========================================= */
@media (max-width: 480px) {
    /* ── Onboarding ── */
    .onboarding-content,
    .preview-content {
        padding: var(--s-md);
    }

    .header {
        margin-top: var(--s-md);
        margin-bottom: var(--s-lg);
    }

    .header h2 {
        font-size: 21px;
    }

    .header p {
        font-size: 14px;
    }

    .guide-item {
        padding: 12px;
        gap: 12px;
    }

    .guide-item .icon {
        font-size: 24px;
    }

    .guide-item .text strong {
        font-size: 14px;
    }

    .guide-item .text span {
        font-size: 12px;
    }

    /* ── Camera Controls ── */
    .camera-controls {
        height: 110px;
        padding: 0 12px;
    }

    .btn-shutter {
        width: 60px;
        height: 60px;
    }

    .auto-capture-hint {
        font-size: 9px;
        max-width: 110px;
    }

    .mode-btn {
        padding: 6px 10px;
    }

    .mode-btn .mode-icon {
        font-size: 14px;
    }

    .mode-btn .mode-label {
        font-size: 10px;
    }

    /* ── Preview ── */
    .preview-content h2 {
        font-size: 18px;
        margin-top: var(--s-md);
        margin-bottom: var(--s-md);
    }

    .action-footer .btn {
        font-size: 14px;
        padding: 12px var(--s-md);
    }

    /* ── Confirmation ── */
    .confirmation-content {
        padding: var(--s-md);
    }

    .confirmation-icon {
        font-size: 44px;
        margin-top: var(--s-md);
    }

    .confirmation-content h2 {
        font-size: 19px;
    }

    .confirmation-preview {
        width: 120px;
        height: 180px;
        margin-bottom: 16px;
    }

    /* ── Register: stack dual rows ── */
    .register-content {
        padding: 1rem 0.75rem 6rem 0.75rem;
    }

    .optim-form .form-section {
        padding: 1rem 0.75rem;
    }

    .form-row.dual {
        flex-direction: column;
        gap: 0;
    }

    .form-row.dual .form-group {
        flex: none;
        width: 100%;
    }

    /* ── Sticky bar ── */
    .sticky-action-bar {
        padding: 0.75rem;
    }

    .btn.btn-lg {
        padding: 14px 16px;
        font-size: 15px;
    }

    /* ── Success ── */
    .success-full {
        padding: 1.5rem 1rem;
        border-radius: 0;
    }

    .success-ticket {
        margin: 1rem 0;
    }

    .ticket-row {
        font-size: 0.85rem;
    }

    /* ── Contact Escape ── */
    .contact-escape {
        padding: 12px;
    }

    .contact-escape__label {
        font-size: 0.85rem;
    }

    .contact-escape__btn {
        padding: 6px 12px;
        font-size: 0.75rem;
        min-height: 44px;
    }
}

/* =========================================
   SMALL PHONES (≤ 375px)
   Target: iPhone SE, Galaxy S5, older phones
   ========================================= */
@media (max-width: 375px) {
    .header h2 {
        font-size: 19px;
    }

    .guidelines {
        gap: 10px;
    }

    .guide-item {
        padding: 10px;
        gap: 10px;
    }

    .guide-item .icon {
        font-size: 20px;
    }

    /* Camera controls compact */
    .camera-controls {
        height: 100px;
    }

    .btn-shutter {
        width: 54px;
        height: 54px;
        border-width: 3px;
        padding: 3px;
    }

    .mode-toggle {
        gap: 4px;
    }

    /* Guide frame slightly smaller */
    .guide-frame {
        width: 78%;
    }

    /* Register form tighter */
    .register-content {
        padding: 0.75rem 0.5rem 5.5rem 0.5rem;
    }

    .optim-form .form-section {
        padding: 0.75rem 0.5rem;
        margin-bottom: 1rem;
    }

    .optim-form legend {
        font-size: 1rem;
    }

    .touch-target {
        min-height: 44px;
        font-size: 0.9rem;
    }

    .expand-toggle {
        padding: 12px;
        font-size: 0.8rem;
        min-height: 44px;
    }

    .confirmation-preview {
        width: 100px;
        height: 150px;
    }

    .btn.btn-lg {
        padding: 12px 14px;
        font-size: 14px;
    }

    .status-indicator p {
        font-size: 12px;
        padding: var(--s-xs) 12px;
    }

    .countdown-number {
        font-size: 90px;
    }
}