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

:root {
    /* Dark Mode (Default) */
    --bg-dark: #1a1a1a;
    --bg-darker: #0f0f0f;
    --header-bg: #000000;
    --text-white: #ffffff;
    --text-light: #e0e0e0;
    --accent-red: #e63946;
    --accent-orange: #ff6b70;
    --nav-bg: #2a2a2a;
    --nav-active: #ff6b70;
    --card-bg: #2a2a2a;
    --card-border: #3a3a3a;
    --input-bg: #1a1a1a;
    --input-border: #3a3a3a;
    --button-bg: #ff6b70;
    --button-hover: #e63946;
}

[data-theme="light"] {
    /* Light Mode */
    --bg-dark: #f5f5f5;
    --bg-darker: #ffffff;
    --header-bg: #ffffff;
    --text-white: #1a1a1a;
    --text-light: #4a4a4a;
    --accent-red: #e63946;
    --accent-orange: #ff6b70;
    --nav-bg: #ffffff;
    --nav-active: #ff6b70;
    --card-bg: #ffffff;
    --card-border: #e0e0e0;
    --input-bg: #f5f5f5;
    --input-border: #d0d0d0;
    --button-bg: #ff6b70;
    --button-hover: #e63946;
}

html {
    /* Prevent flash of unstyled content */
    background-color: var(--bg-darker);
    transition: background-color 0.1s ease;
}

body {
    font-family: 'Noto Sans Khmer', 'Arial', sans-serif;
    background-color: var(--bg-darker);
    color: var(--text-white);
    line-height: 1.6;
    min-height: 100vh;
    padding-bottom: 80px;
    transition: background-color 0.1s ease, color 0.1s ease;
    -webkit-overflow-scrolling: touch;
    overflow-x: hidden;
    will-change: background-color, color;
}

/* Header */
.header {
    background: var(--header-bg);
    padding: 1rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

[data-theme="light"] .header {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1600px;
    margin: 0 auto;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-image,
.logo-video {
    height: 60px;
    width: auto;
    transition: transform 0.3s ease;
    object-fit: contain;
}

.logo-image:hover,
.logo-video:hover {
    transform: scale(1.05);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.theme-toggle {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    transition: transform 0.3s;
}

.theme-toggle:hover {
    transform: scale(1.1);
}

.logout-btn {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    transition: transform 0.3s, opacity 0.3s;
    opacity: 0.8;
}

.logout-btn:hover {
    transform: scale(1.1);
    opacity: 1;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-red);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: transform 0.3s;
}

.user-avatar-container {
    position: relative;
}

.user-avatar:hover {
    transform: scale(1.1);
}

/* User Menu Dropdown */

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-avatar span {
    font-size: 1.5rem;
}

/* Main Content */
.main-content {
    padding: 2rem 1.5rem;
    min-height: calc(100vh - 200px);
    max-width: 1600px;
    margin: 0 auto;
}

/* Page header */
.templates-page-header {
    margin-bottom: 1.5rem;
}
.templates-page-header .revamp-page-title {
    margin-bottom: 0.25rem;
}
.templates-page-header .revamp-page-subtitle {
    margin-bottom: 0;
    color: var(--text-light);
}

/* ========== Resume-builder layout: event top, customize left, preview right ========== */
.templates-page-inner {
    max-width: 1400px;
    margin: 0 auto;
}
.templates-main {
    display: grid;
    grid-template-columns: minmax(300px, 380px) 1fr;
    gap: 1.5rem;
    min-height: 0;
    align-items: start;
}
.templates-top-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem 1.25rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.templates-event-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}
.templates-event-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-light);
    white-space: nowrap;
}
.templates-event-select {
    min-width: 220px;
    max-width: 320px;
    padding: 0.55rem 0.85rem;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    color: #000;
    font-size: 0.9rem;
    font-family: 'Noto Sans Khmer', 'Arial', sans-serif;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.templates-event-select option {
    color: #000;
    background: #fff;
}
.templates-event-select:focus {
    outline: none;
    border-color: var(--accent-orange, var(--revamp-primary));
    box-shadow: 0 0 0 3px rgba(255, 107, 112, 0.15);
}
.templates-search-input {
    width: 160px;
    padding: 0.55rem 0.85rem;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    color: var(--text-white);
    font-size: 0.875rem;
    font-family: 'Noto Sans Khmer', 'Arial', sans-serif;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.templates-search-input:focus {
    outline: none;
    border-color: var(--accent-orange, var(--revamp-primary));
    box-shadow: 0 0 0 3px rgba(255, 107, 112, 0.15);
}
.templates-search-input::placeholder {
    color: var(--text-light);
    opacity: 0.7;
}
.templates-top-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}
.templates-btn-create,
.templates-btn-edit {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    border-radius: 8px;
    transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.templates-btn-create:hover,
.templates-btn-edit:hover {
    transform: translateY(-1px);
}
.btn-icon-sm {
    width: 1rem;
    height: 1rem;
    object-fit: contain;
}
.templates-customize-column {
    position: sticky;
    top: 1rem;
}
.templates-customize-card {
    padding: 1.35rem;
    border-radius: 14px;
    border: 1px solid var(--card-border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.templates-preview-column {
    min-width: 0;
}
.templates-preview-card {
    padding: 1rem;
    border-radius: 14px;
    border: 1px solid var(--card-border);
    min-height: 0;
    display: flex;
    flex-direction: column;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.templates-preview-card[data-preview-mode="invitation"] {
    padding: 0;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    background: #0a0a0a;
}
.templates-preview-header {
    margin-bottom: 0.75rem;
}
.template-preview-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-white);
    margin: 0;
}
.templates-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    padding: 2.5rem 2rem;
    gap: 1.25rem;
}
.templates-empty-state .empty-state-icon {
    opacity: 0.85;
    width: 4rem;
    height: 4rem;
}
.templates-empty-state .empty-message {
    text-align: center;
    margin-bottom: 0;
    font-size: 1.05rem;
    max-width: 280px;
}
.templates-empty-state .store-link {
    margin-top: 0.25rem;
}

/* Mobile tabs: Settings / Preview (shown on small viewports) */
.templates-mobile-tabs {
    display: none;
    margin-bottom: 1rem;
    padding: 4px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    gap: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.templates-mobile-tab {
    flex: 1;
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: 'Noto Sans Khmer', sans-serif;
    color: var(--text-light);
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.templates-mobile-tab:hover {
    background: var(--card-border);
    color: var(--text-white);
}
.templates-mobile-tab.active {
    background: var(--accent-red, var(--revamp-primary));
    color: #fff;
}

.templates-container {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 2rem;
    height: 100%;
    min-height: calc(100vh - 300px);
}

.header-btn-icon {
    width: 1.25rem;
    height: 1.25rem;
    object-fit: contain;
}

/* Left Panel: My Templates */
.templates-panel {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    height: fit-content;
    max-height: calc(100vh - 200px);
}

.panel-title {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-white);
    margin-bottom: 1.5rem;
}
.panel-title-icon {
    width: 1.25rem;
    height: 1.25rem;
    object-fit: contain;
    flex-shrink: 0;
}

.search-container {
    margin-bottom: 1.5rem;
}
.search-label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-light);
    margin-bottom: 0.5rem;
}
.search-label-icon {
    width: 1rem;
    height: 1rem;
    object-fit: contain;
}

.search-input {
    width: 100%;
    padding: 0.38rem 0.65rem;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 6px;
    color: var(--text-white);
    font-size: 0.8rem;
    font-family: 'Noto Sans Khmer', 'Arial', sans-serif;
    transition: all 0.3s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-orange);
    box-shadow: 0 0 0 3px rgba(255, 107, 112, 0.1);
}

.search-input::placeholder {
    color: var(--text-light);
    opacity: 0.6;
}

.templates-list {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 1rem;
    min-height: 200px;
}

.templates-list::-webkit-scrollbar {
    width: 6px;
}

.templates-list::-webkit-scrollbar-track {
    background: var(--input-bg);
    border-radius: 3px;
}

.templates-list::-webkit-scrollbar-thumb {
    background: var(--input-border);
    border-radius: 3px;
}

.templates-list::-webkit-scrollbar-thumb:hover {
    background: var(--accent-orange);
}

.template-item {
    padding: 1rem;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.template-item:hover {
    background: var(--input-border);
    transform: translateX(4px);
}

.template-item.selected {
    background: rgba(255, 107, 112, 0.1);
    border-color: var(--accent-orange);
}

.template-item-name {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-white);
    margin-bottom: 0.25rem;
}

.template-item-preview {
    font-size: 0.85rem;
    color: var(--text-light);
}

.empty-templates {
    text-align: center;
    padding: 2rem;
    color: var(--text-light);
    font-size: 0.95rem;
}

.item-count {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-light);
    text-align: center;
    padding-top: 1rem;
    border-top: 1px solid var(--card-border);
}
.item-count-icon {
    width: 1rem;
    height: 1rem;
    object-fit: contain;
    opacity: 0.8;
}

/* Right Panel: Display */
.display-panel {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 200px);
}

.display-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.display-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn-view-template,
.btn-save {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    background: var(--card-bg);
    color: var(--text-white);
    font-size: 0.8rem;
    font-weight: 500;
    font-family: 'Noto Sans Khmer', 'Arial', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.btn-view-template:hover {
    background: var(--input-bg);
    border-color: var(--accent-orange);
}

.btn-save {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--button-bg);
    border-color: var(--button-bg);
    color: #ffffff;
}
.btn-save-icon {
    width: 1.1rem;
    height: 1.1rem;
    object-fit: contain;
    flex-shrink: 0;
}

.btn-save:hover {
    background: var(--button-hover);
    border-color: var(--button-hover);
}

.btn-icon {
    font-size: 0.9rem;
}

.btn-text {
    font-size: 0.8rem;
}

.display-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    position: relative;
}

.display-content:has(.template-preview--invitation) {
    align-items: stretch;
    justify-content: stretch;
    min-height: 0;
    background: #0a0a0a;
}

/* Mobile view: center the phone mockup — override the stretch from invitation rule */
.display-content:has(.template-preview--device-mobile) {
    align-items: center !important;
    justify-content: center !important;
}

.empty-state {
    text-align: center;
    padding: 2.5rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}
.empty-state-icon {
    width: 3.5rem;
    height: 3.5rem;
    object-fit: contain;
    opacity: 0.7;
}
.empty-message {
    font-size: 1rem;
    color: var(--text-light);
    line-height: 1.6;
    margin: 0;
}

.store-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    color: var(--accent-orange);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    border-radius: 8px;
    border: 1px solid var(--accent-orange);
    background: transparent;
    transition: background 0.2s, color 0.2s;
}
.store-link:hover {
    background: rgba(255, 107, 112, 0.1);
    color: var(--accent-orange);
    text-decoration: none;
}
.store-link-icon {
    width: 1.1rem;
    height: 1.1rem;
    object-fit: contain;
    flex-shrink: 0;
}

.template-preview {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.template-preview-content {
    width: 100%;
    max-width: 600px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
}

.template-preview-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-white);
    margin-bottom: 1rem;
}

.template-preview-image {
    width: 100%;
    max-width: 500px;
    height: auto;
    border-radius: 8px;
    margin: 1rem 0;
}

/* Invitation page preview wrapper */
.template-preview--invitation {
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 0;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
}

/* Desktop device frame: full-width so the video bg fills the entire preview */
.template-preview--invitation .template-preview-device-frame:not(.template-preview-device-frame--mobile) {
    width: 100%;
    height: 120%;
    display: flex;
    align-items: stretch;
}

/* Iframe: full-width so the fixed video background fills the preview panel */
.template-preview-iframe {
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 0;
    border-radius: 0;
    background: #0a0a0a;
}

/* ── Mobile device frame: phone mockup ──────────────────────────────────── */

/* When mobile device is active, center the phone mockup instead of stretching */
.template-preview--device-mobile,
.template-preview--invitation.template-preview--device-mobile {
    position: relative;
    align-items: center !important;
    justify-content: center !important;
    background: #0a0a0a;
    padding: 2rem 1.5rem !important;
    box-sizing: border-box;
}

/* Mobile device frame: now handled by React IphoneMockup component */
/* This class is no longer used for mobile — kept as stub for safety */
.template-preview-device-frame--mobile {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--nav-bg);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0.75rem 0.5rem;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

[data-theme="light"] .bottom-nav {
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.bottom-nav::-webkit-scrollbar {
    display: none;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    text-decoration: none;
    color: var(--text-light);
    border-radius: 12px;
    transition: all 0.3s ease;
    min-width: 70px;
    flex-shrink: 0;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-white);
}

.nav-item.active {
    background: var(--nav-active);
    color: var(--text-white);
    box-shadow: 0 4px 15px rgba(255, 107, 112, 0.3);
}

.nav-icon {
    width: 24px;
    height: 24px;
    display: block;
    object-fit: contain;
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0.8;
}

.nav-item:hover .nav-icon {
    transform: scale(1.1);
    opacity: 1;
}

.nav-item.active .nav-icon {
    opacity: 1;
    filter: brightness(1.2);
}

.nav-text {
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ═══════════════════════════════════════════════════════════════════ */

/* ── ≤ 1024px  Tablet / collapsed two-panel ──────────────────────── */
@media (max-width: 1024px) {
    /* Show tab switcher */
    .templates-mobile-tabs {
        display: flex;
    }

    /* Single-column stacked layout */
    .templates-main {
        grid-template-columns: 1fr;
        min-height: unset;
        gap: 1rem;
    }

    /* Tab-driven panel visibility */
    .templates-main[data-active-tab="settings"] .templates-preview-column {
        display: none;
    }
    .templates-main[data-active-tab="preview"] .templates-customize-column {
        display: none;
    }

    /* Unstick the left column */
    .templates-customize-column {
        position: static;
    }

    /* Top bar: stack vertically */
    .templates-top-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        padding: 0.85rem 1rem;
    }
    .templates-event-row {
        flex-direction: column;
        align-items: stretch;
    }
    .templates-event-select {
        min-width: 0;
        max-width: none;
        width: 100%;
    }
    .templates-search-input {
        width: 100%;
    }
    .templates-top-actions {
        width: 100%;
    }
    .templates-btn-create,
    .templates-btn-edit {
        flex: 1;
        justify-content: center;
    }

    /* Preview panel: reasonable height on tablet — override ALL 70vh values */
    .templates-preview-card {
        min-height: 55vh;
    }
    .display-content {
        min-height: 280px;
    }
    .display-content:has(.template-preview--invitation) {
        min-height: 55vh;
    }
    .template-preview--invitation {
        min-height: 55vh;
    }
    .template-preview-iframe {
        min-height: 55vh;
    }

    /* Legacy grid */
    .templates-container {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    .templates-panel {
        max-height: 400px;
    }
    .display-panel {
        min-height: 500px;
    }

    /* User menu: never wider than viewport */
    .user-menu {
        min-width: min(320px, calc(100vw - 2rem));
        max-width: calc(100vw - 2rem);
    }
}

/* ── ≤ 768px  Mobile ─────────────────────────────────────────────── */
@media (max-width: 768px) {
    /* Header */
    .header {
        padding: 0.6rem 1rem;
    }
    .logo-image,
    .logo-video {
        height: 44px;
    }
    .user-avatar {
        width: 34px;
        height: 34px;
    }

    /* Page padding */
    .main-content {
        padding: 1rem 0.875rem;
    }

    /* Top bar */
    .templates-top-bar {
        padding: 0.75rem 0.875rem;
        gap: 0.6rem;
        margin-bottom: 1rem;
    }

    /* Customize card */
    .templates-customize-card {
        padding: 1rem;
    }

    /* Preview panel: cap height on mobile, override ALL 70vh values */
    .templates-preview-card {
        min-height: 50vh;
    }
    .templates-preview-card[data-preview-mode="invitation"] {
        min-height: 50vh;
    }
    .display-content:has(.template-preview--invitation) {
        min-height: 50vh;
    }
    .template-preview--invitation {
        min-height: 50vh;
    }
    .template-preview-iframe {
        min-height: 50vh;
    }

    /* iPhone mockup: width-based shrink */
    .iphone-mockup {
        width: 220px;
    }

    /* Cover templates grid: 2 columns on mobile */
    .cover-templates-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 0.6rem;
    }

    /* Couple photo picker: always 2 cols */
    .couple-photo-style-grid--3col {
        grid-template-columns: 1fr 1fr;
    }
    .couple-photo-style-icon {
        width: 32px;
        height: 32px;
    }

    /* Legacy panels */
    .templates-panel,
    .display-panel {
        padding: 1rem;
    }
    .panel-title {
        font-size: 1.2rem;
    }

    /* User menu: full-width dropdown edge-to-edge on phones */
    .user-menu {
        right: -0.5rem;
        min-width: min(300px, calc(100vw - 1rem));
    }

    .bottom-nav {
        padding: 0.75rem 0.25rem;
    }
    .nav-item {
        min-width: 56px;
        padding: 0.5rem 0.4rem;
    }
    .nav-icon {
        width: 22px;
        height: 22px;
    }
    .nav-text {
        font-size: 0.68rem;
    }
}

/* ── ≤ 480px  Small phones ───────────────────────────────────────── */
@media (max-width: 480px) {
    /* Page padding */
    .main-content {
        padding: 0.75rem;
    }

    /* Top bar: tighter */
    .templates-top-bar {
        padding: 0.65rem 0.75rem;
        border-radius: 10px;
        gap: 0.5rem;
        margin-bottom: 0.75rem;
    }
    .templates-event-label {
        font-size: 0.82rem;
    }
    .templates-event-select,
    .templates-search-input {
        font-size: 0.82rem;
        padding: 0.45rem 0.7rem;
    }
    .templates-btn-create,
    .templates-btn-edit {
        padding: 0.45rem 0.75rem;
        font-size: 0.8rem;
    }

    /* Mobile tab pills */
    .templates-mobile-tabs {
        gap: 0.25rem;
        padding: 3px;
    }
    .templates-mobile-tab {
        font-size: 0.8rem;
        padding: 0.45rem 0.85rem;
    }

    /* Customize card */
    .templates-customize-card {
        padding: 0.875rem;
    }
    .template-customize-title {
        font-size: 1.05rem;
    }
    .template-customize-desc {
        font-size: 0.8rem;
        margin-bottom: 1.1rem;
    }
    .template-customize-section {
        margin-bottom: 1rem;
    }
    .template-font-section-group {
        padding: 0.75rem;
    }

    /* Font / select dropdowns */
    .template-font-section-group select {
        font-size: 0.8rem;
        padding: 0.4rem 0.6rem;
    }

    /* Cover templates: 3 equal cols on narrow phones */
    .cover-templates-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }
    .cover-template-card .cover-template-name {
        font-size: 0.65rem;
    }

    /* Couple photo picker: 2 cols */
    .couple-photo-style-grid,
    .couple-photo-style-grid--3col {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }
    .couple-photo-style-btn {
        padding: 0.65rem 0.4rem;
        gap: 0.35rem;
    }
    .couple-photo-style-icon {
        width: 28px;
        height: 28px;
    }
    .couple-photo-style-name {
        font-size: 0.72rem;
    }

    /* Preview panel: further reduce on tiny phones, override ALL 70vh values */
    .templates-preview-card {
        min-height: 45vh;
        border-radius: 10px;
    }
    .templates-preview-card[data-preview-mode="invitation"] {
        min-height: 45vh;
    }
    .display-content:has(.template-preview--invitation) {
        min-height: 45vh;
    }
    .template-preview--invitation {
        min-height: 45vh;
    }
    .template-preview-iframe {
        min-height: 45vh;
    }
    .iphone-mockup {
        width: 200px;
    }

    /* Save button */
    .template-save-btn {
        font-size: 0.85rem;
        padding: 0.6rem 1.25rem;
    }

    /* Empty state */
    .templates-empty-state {
        min-height: 280px;
        padding: 1.5rem 1rem;
        gap: 1rem;
    }
    .templates-empty-state .empty-state-icon {
        width: 3rem;
        height: 3rem;
    }
    .templates-empty-state .empty-message {
        font-size: 0.875rem;
    }

    /* Legacy panels */
    .templates-panel,
    .display-panel {
        padding: 0.75rem;
    }
    .panel-title {
        font-size: 1.05rem;
        margin-bottom: 0.875rem;
    }

    /* Bottom nav */
    .bottom-nav {
        padding: 0.5rem 0.25rem;
    }
    .nav-item {
        min-width: 48px;
        padding: 0.4rem 0.35rem;
    }
    .nav-text {
        font-size: 0.62rem;
    }
}

/* ── max-height: 800px  Short viewports (landscape phone etc.) ───── */
@media (max-height: 800px) {
    .iphone-mockup {
        width: 210px !important;
    }
}
.user-avatar-container {
    position: relative;
}

.user-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 0 1px rgba(0, 0, 0, 0.1);
    min-width: 320px;
    max-width: 400px;
    z-index: 1000;
    display: none;
    overflow: hidden;
    animation: fadeIn 0.2s ease;
}

.user-menu.active {
    display: block;
}

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

.user-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e5e5;
}

.user-menu-title {
    font-size: 14px;
    font-weight: 600;
    color: #1a1a1a;
}

.user-menu-signout {
    font-size: 14px;
    color: #0066cc;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.2s;
}

.user-menu-signout:hover {
    color: #0052a3;
    text-decoration: underline;
}

.user-menu-content {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
}

.user-menu-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #e5e5e5;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.user-menu-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-menu-avatar span {
    font-size: 24px;
    font-weight: 600;
    color: #666666;
}

.user-menu-info {
    flex: 1;
    min-width: 0;
}

.user-menu-name {
    font-size: 16px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 4px;
    word-wrap: break-word;
}

.user-menu-email {
    font-size: 14px;
    color: #666666;
    word-wrap: break-word;
}

.user-menu-footer {
    padding: 12px 16px;
    border-top: 1px solid #e5e5e5;
}

.user-menu-link {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #0066cc;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.2s;
}

.user-menu-link:hover {
    color: #0052a3;
    text-decoration: underline;
}

.user-menu-link::before {
    content: '👤';
    font-size: 16px;
}

/* Dark mode styles */
[data-theme="dark"] .user-menu {
    background: #2d2d2d;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), 0 0 1px rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .user-menu-header {
    border-bottom-color: #404040;
}

[data-theme="dark"] .user-menu-title {
    color: #ffffff;
}

[data-theme="dark"] .user-menu-signout {
    color: #4a9eff;
}

[data-theme="dark"] .user-menu-signout:hover {
    color: #6bb3ff;
}

[data-theme="dark"] .user-menu-avatar {
    background: #404040;
}

[data-theme="dark"] .user-menu-avatar span {
    color: #cccccc;
}

[data-theme="dark"] .user-menu-name {
    color: #ffffff;
}

[data-theme="dark"] .user-menu-email {
    color: #b3b3b3;
}

[data-theme="dark"] .user-menu-footer {
    border-top-color: #404040;
}

[data-theme="dark"] .user-menu-link {
    color: #4a9eff;
}

[data-theme="dark"] .user-menu-link:hover {
    color: #6bb3ff;
}

.revamp-app .bottom-nav {
    display: none !important;
}

/* Revamp app: remove the bottom-nav padding reserved for the hidden nav bar */
.revamp-app body,
body.revamp-body {
    padding-bottom: 0 !important;
}

/* Revamp: page header and panels */
.revamp-app .templates-page-header .revamp-page-subtitle {
    color: var(--revamp-text-muted);
}
.revamp-app .templates-panel.revamp-card,
.revamp-app .display-panel.revamp-card {
    background: var(--revamp-card-bg);
    border-color: var(--revamp-card-border);
}
.revamp-app .panel-title {
    color: var(--revamp-text);
}
.revamp-app .search-label {
    color: var(--revamp-text-muted);
}
.revamp-app .empty-message {
    color: var(--revamp-text-muted);
}
.revamp-app .store-link {
    color: var(--revamp-primary);
    border-color: var(--revamp-primary);
}
.revamp-app .store-link:hover {
    background: var(--revamp-primary-light);
    color: var(--revamp-primary);
}
.revamp-app .item-count {
    color: var(--revamp-text-muted);
    border-top-color: var(--revamp-border);
}
.revamp-app .item-count strong {
    color: var(--revamp-text);
}
.revamp-app .templates-top-bar {
    background: var(--revamp-card-bg);
    border-color: var(--revamp-card-border);
    box-shadow: var(--revamp-shadow);
}
.revamp-app .templates-event-label {
    color: var(--revamp-text-muted);
}
.revamp-app .templates-event-select {
    color: #000;
}
.revamp-app .templates-event-select:focus,
.revamp-app .templates-search-input:focus {
    border-color: var(--revamp-primary);
    box-shadow: 0 0 0 3px var(--revamp-primary-light);
}
.revamp-app .templates-customize-card,
.revamp-app .templates-preview-card {
    background: var(--revamp-card-bg);
    border-color: var(--revamp-card-border);
    box-shadow: var(--revamp-shadow);
}
.revamp-app .templates-mobile-tab.active {
    background: var(--revamp-primary);
    color: #fff;
}
.revamp-app .template-preview-title {
    color: var(--revamp-text);
}
.revamp-app .display-content {
    flex: 1;
    min-height: 0;
}
.revamp-app .display-content:has(.template-preview--invitation) {
    display: flex;
    flex-direction: column;
    min-height: 65vh;
}
.revamp-app .cover-template-card.selected {
    border-color: var(--revamp-primary);
    box-shadow: 0 0 0 2px var(--revamp-primary);
}
.revamp-app .template-save-btn {
    background: var(--revamp-primary);
    border-color: var(--revamp-primary);
}
.revamp-app .template-save-btn:hover:not(:disabled) {
    background: var(--revamp-primary-hover);
    border-color: var(--revamp-primary-hover);
}

/* Template customize panel (left column, resume-builder style) */
.template-customize-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--revamp-text);
    margin: 0 0 0.4rem 0;
    letter-spacing: -0.02em;
}
.template-customize-desc {
    font-size: 0.85rem;
    color: var(--revamp-text-muted);
    margin: 0 0 1.5rem 0;
    line-height: 1.55;
}
.template-customize-section {
    margin-bottom: 1.25rem;
}
.template-customize-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--revamp-text-muted);
    margin-bottom: 0.4rem;
}
.cover-templates-section .template-customize-label {
    margin-bottom: 0.6rem;
}
.cover-templates-grid-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.cover-templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.85rem;
}
.cover-templates-grid-wrapper:not(.expanded) .cover-template-card--more {
    display: none;
}
.cover-templates-see-more {
    align-self: flex-start;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: 'Noto Sans Khmer', Arial, sans-serif;
    color: var(--accent-red, var(--revamp-primary));
    background: transparent;
    border: 1px solid var(--revamp-border);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}
.cover-templates-see-more:hover {
    background: var(--revamp-input-bg);
    border-color: var(--revamp-text-muted);
}
.cover-template-card {
    cursor: pointer;
    border: 2px solid var(--revamp-border);
    border-radius: 12px;
    overflow: hidden;
    padding: 0.3rem;
    background: var(--revamp-input-bg);
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}
.cover-template-card:hover {
    border-color: var(--revamp-text-muted);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}
.cover-template-card.selected {
    border-color: var(--accent-red, var(--revamp-primary));
    box-shadow: 0 0 0 2px var(--accent-red, var(--revamp-primary));
}
.cover-template-card .cover-template-thumb {
    width: 100%;
    aspect-ratio: 1;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    background-color: var(--revamp-bg, #2a2a2a);
    border-radius: 8px;
}
.cover-template-card .cover-template-name {
    font-size: 0.72rem;
    font-weight: 500;
    text-align: center;
    padding: 0.4rem 0.25rem 0;
    color: var(--revamp-text-muted);
    line-height: 1.25;
}
.template-font-section-group {
    padding: 1rem 1.1rem;
    border: 1px solid var(--revamp-border);
    border-radius: 12px;
    margin-bottom: 1.15rem;
    background: var(--revamp-input-bg);
}
.template-font-section-group-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--revamp-text);
    margin-bottom: 0.5rem;
}
.template-font-section-hint {
    font-size: 0.75rem;
    color: var(--revamp-text-muted);
    margin-bottom: 0.65rem;
}
.template-font-section-fields {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.template-font-section-row {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.template-font-section-label {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--revamp-text-muted);
}
.template-customize-select {
    width: 100%;
    padding: 0.55rem 0.75rem;
    background: var(--revamp-surface);
    border: 1px solid var(--revamp-border);
    border-radius: 8px;
    color: var(--revamp-text);
    font-size: 0.875rem;
    font-family: 'Noto Sans Khmer', 'Arial', sans-serif;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.template-customize-select:focus {
    outline: none;
    border-color: var(--revamp-primary);
    box-shadow: 0 0 0 3px var(--revamp-primary-light);
}
.template-customize-upload-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}
.template-customize-file-input {
    font-size: 0.8rem;
    max-width: 100%;
}
.template-customize-upload-hint {
    font-size: 0.8rem;
    color: var(--revamp-text-muted);
}
.template-customize-actions {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--revamp-border);
}
.template-save-hint {
    font-size: 0.8rem;
    color: var(--revamp-text-muted);
    margin: 0 0 0.6rem 0;
}
.template-save-btn {
    width: 100%;
    justify-content: center;
    padding: 0.75rem 1.25rem;
    font-weight: 600;
    font-size: 0.95rem;
    border-radius: 10px;
    transition: background 0.2s, transform 0.15s;
}
.template-save-btn:hover:not(:disabled) {
    transform: translateY(-1px);
}
.template-save-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.template-customize-card {
    position: relative;
}

/* ========== Couple Photo Style Picker ========== */
.couple-photo-style-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.625rem;
    margin-top: 0.5rem;
}

.couple-photo-style-grid--3col {
    grid-template-columns: 1fr 1fr 1fr;
}

.couple-photo-style-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 0.5rem;
    border-radius: 10px;
    border: 2px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    color: var(--revamp-text-muted);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, color 0.2s;
    outline: none;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

.couple-photo-style-btn:hover {
    border-color: rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.08);
    color: var(--revamp-text);
}

.couple-photo-style-btn.active {
    border-color: var(--revamp-primary);
    background: color-mix(in oklab, var(--revamp-primary) 15%, transparent);
    color: var(--revamp-primary);
}

.couple-photo-style-icon {
    width: 40px;
    height: 40px;
}

.couple-photo-style-name {
    font-size: 0.8rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.3;
}

.template-customize-hint {
    font-size: 0.775rem;
    color: var(--revamp-text-muted);
    margin-top: 0.5rem;
    line-height: 1.4;
}

