/* ─── Variables ─────────────────────────────────────────────── */
:root {
    --primary: #7c3aed;
    --primary-hover: #6d28d9;
    --primary-light: #ede9fe;
    --primary-light-hover: #ddd6fe;
    --secondary: #64748b;
    --secondary-hover: #475569;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --success: #16a34a;
    --success-bg: #dcfce7;
    --info-bg: #eff6ff;
    --info-text: #1e40af;
    --error-bg: #fef2f2;
    --error-text: #991b1b;
    --bg: #f5f3ff;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.06);
    --shadow-lg: 0 4px 6px rgba(0,0,0,.07), 0 10px 30px rgba(0,0,0,.12);
    /* Badge / chip colours */
    --claimed-border: #cbd5e1;
    --badge-available-bg: #ecfdf5;
    --badge-available-text: #065f46;
    --badge-claimed-bg: #f1f5f9;
    --badge-claimed-text: #475569;
    --badge-category-bg: #f0f9ff;
    --badge-category-text: #0369a1;
    --badge-category-border: #bae6fd;
    --chip-bg: rgba(124,58,237,0.12);
    --chip-border: rgba(124,58,237,0.25);
    --cookie-link: #c4b5fd;
}

/* ─── Utility ───────────────────────────────────────────────── */
.print-only { display: none; }

/* ─── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Header ────────────────────────────────────────────────── */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.header-inner {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.logo {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
    cursor: pointer;
    border-radius: 6px;
    padding: 2px 6px;
    margin-left: -6px;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background-color 0.15s ease, opacity 0.15s ease;
}
.logo:hover {
    background-color: color-mix(in srgb, var(--primary) 10%, transparent);
    opacity: 0.85;
}

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.15s, transform 0.1s, opacity 0.15s;
    white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none !important; }
.btn:not(:disabled):active { transform: scale(0.97); }

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

.btn-secondary { background: var(--surface); color: var(--secondary); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-alt); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-outline-danger { background: transparent; color: var(--danger); border: 1.5px solid var(--danger); }
.btn-outline-danger:hover:not(:disabled) { background: rgba(220, 38, 38, 0.08); }

.btn-copy { background: var(--primary-light); color: var(--primary); padding: 8px 14px; }
.btn-copy:hover:not(:disabled) { background: var(--primary-light-hover); }

.btn-sm { padding: 7px 14px; font-size: 0.82rem; }

/* ─── Forms ─────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.form-group label .req { color: var(--danger); margin-left: 2px; }
.form-group input {
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    color: var(--text);
    background: var(--surface);
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
}
.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(124,58,237,.12);
}
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.flex-1 { flex: 1; min-width: 160px; }
.flex-2 { flex: 2; min-width: 200px; }

/* ─── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.card h2 { font-size: 1.15rem; font-weight: 700; }
.card p { color: var(--text-muted); font-size: 0.92rem; }

/* ─── Home page ─────────────────────────────────────────────── */
.home-main {
    max-width: 900px;
    margin: 0 auto;
    padding: 48px 24px;
}
.hero {
    text-align: center;
    margin-bottom: 40px;
}
.hero h1 { font-size: 2rem; font-weight: 800; margin-bottom: 12px; line-height: 1.2; }
.hero p { color: var(--text-muted); max-width: 520px; margin: 0 auto; font-size: 1rem; }

.cards-row { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 640px) {
    .cards-row { grid-template-columns: 1fr; }
    .hero h1 { font-size: 1.5rem; }
}

/* Links result section */
.create-result { display: flex; flex-direction: column; gap: 14px; }
.link-group { display: flex; flex-direction: column; gap: 6px; }
.link-group label { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); }
.link-row { display: flex; gap: 8px; }
.link-row input {
    padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.82rem;
    background: var(--surface-alt);
    color: var(--text-muted);
    flex: 1;
    min-width: 0;
}
.success-banner {
    background: var(--success-bg);
    color: var(--success);
    padding: 10px 16px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.95rem;
    text-align: center;
}

/* ─── Registry page ─────────────────────────────────────────── */
main { max-width: 900px; margin: 0 auto; padding: 32px 24px; display: flex; flex-direction: column; gap: 24px; }
@media (max-width: 480px) {
    main { padding: 20px 16px; gap: 16px; }
}

.registry-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.registry-header h1 { font-size: 1.6rem; font-weight: 800; }
.registry-header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; flex-shrink: 0; }
.subtitle { color: var(--text-muted); font-size: 0.9rem; margin-top: 4px; max-width: 500px; }
.text-muted { color: var(--text-muted); font-size: 0.82rem; }
.co-owner-badge { display: inline-block; background: var(--primary-light); color: var(--primary-hover); font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; vertical-align: middle; margin-left: 6px; letter-spacing: 0.02em; }

.gifts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.gifts-header h2 { font-size: 1.1rem; font-weight: 700; }
.gifts-stats { font-size: 0.85rem; color: var(--text-muted); font-weight: 600; }

/* ─── Gift cards ────────────────────────────────────────────── */
.gift-list { display: flex; flex-direction: column; gap: 12px; }

.gift-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary);
    transition: box-shadow 0.15s, opacity 0.2s;
}
.gift-card:hover { box-shadow: var(--shadow-lg); }
.gift-card--claimed {
    border-left-color: var(--claimed-border);
    opacity: 0.8;
}

.gift-card-body {
    padding: 18px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
@media (max-width: 480px) {
    .gift-card-body {
        padding: 14px 16px;
        gap: 10px;
    }
    .gift-card-body .gift-thumb {
        width: 64px;
        height: 64px;
    }
    .gift-actions {
        width: 100%;
        justify-content: flex-start;
    }
    .gift-actions .btn {
        min-height: 44px;
        padding: 10px 16px;
        font-size: 0.9rem;
    }
}

.gift-info { flex: 1; min-width: 0; }
.gift-name-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.gift-name { font-weight: 700; font-size: 1rem; }
.gift-description { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 4px; }
.gift-link { font-size: 0.85rem; color: var(--primary); font-weight: 500; }
.gift-link:hover { text-decoration: underline; }

.gift-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.claimed-msg { font-size: 0.85rem; color: var(--text-muted); }
.gift-thumb { width: 80px; height: 80px; object-fit: cover; border-radius: 8px; flex-shrink: 0; border: 1px solid var(--border); }

/* ─── Badges ────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
}
.badge-available { background: var(--badge-available-bg); color: var(--badge-available-text); }
.badge-claimed { background: var(--badge-claimed-bg); color: var(--badge-claimed-text); }
.badge-mine { background: var(--primary-light); color: var(--primary); }
.badge-category { background: var(--badge-category-bg); color: var(--badge-category-text); border: 1px solid var(--badge-category-border); font-size: 0.72rem; font-weight: 600; padding: 2px 8px; border-radius: 10px; letter-spacing: 0.01em; }

/* ─── Empty / loading / error states ───────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.empty-state p + p { margin-top: 6px; font-size: 0.9rem; }
.loading-state { text-align: center; padding: 80px 24px; color: var(--text-muted); }
.error-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--error-text);
    background: var(--error-bg);
    border-radius: var(--radius);
}

/* ─── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(2px);
}
.modal {
    background: var(--surface);
    border-radius: 16px;
    padding: 36px 32px;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 16px;
}
@media (max-width: 480px) {
    .modal {
        padding: 28px 20px;
        width: 94%;
        border-radius: 12px;
    }
}
.modal h2 { font-size: 1.3rem; font-weight: 800; }
.modal p { color: var(--text-muted); font-size: 0.93rem; }

/* ─── Toast notifications ───────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: max(80px, calc(env(safe-area-inset-bottom, 0px) + 24px));
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 99999;
}
.toast {
    padding: 14px 18px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    max-width: 320px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast-show { opacity: 1; transform: translateX(0); }
.toast-success { background: var(--success-bg); color: var(--success); }
.toast-info { background: var(--info-bg); color: var(--info-text); }
.toast-error { background: var(--error-bg); color: var(--error-text); }

/* ─── Guest name badge ──────────────────────────────────────── */
.guest-name-badge {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-light);
    padding: 6px 14px;
    border-radius: 99px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.guest-name-badge:hover { background: var(--primary-light-hover); }

/* ─── Footer ────────────────────────────────────────────────── */
.site-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    margin-top: 64px;
    padding: 24px 16px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.footer-inner {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}
.footer-links {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}
.footer-links a {
    color: var(--text-muted);
    font-size: 0.85rem;
}
.footer-links a:hover { color: var(--primary); }

/* ─── Cookie banner ─────────────────────────────────────────── */
.cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--text);
    color: #fff;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    z-index: 9999;
    font-size: 0.9rem;
}
.cookie-banner p { margin: 0; }
.cookie-banner a { color: var(--cookie-link); }
.cookie-banner a:hover { color: #fff; }

/* ─── Policy pages ──────────────────────────────────────────── */
.policy-container {
    max-width: 720px;
    margin: 0 auto;
    padding: 32px 16px 64px;
}
.policy-container h1 { margin-bottom: 4px; }
.policy-date { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 28px; }
.policy-container h2 { margin-top: 36px; margin-bottom: 10px; font-size: 1.15rem; }
.policy-container h3 { margin-top: 20px; margin-bottom: 6px; font-size: 1rem; }
.policy-container p { margin-bottom: 12px; }
.policy-container ul { padding-left: 20px; margin-bottom: 12px; }
.policy-container ul li { margin-bottom: 6px; }

/* ─── Occasion chips (used in registry hero and registry cards) ─── */
.hero-chip {
    display: inline-block;
    background: var(--chip-bg);
    border: 1px solid var(--chip-border);
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    letter-spacing: 0.02em;
}

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

/* ─── Dark mode ─────────────────────────────────────────────── */
/* Applied when user explicitly chose dark (data-theme="dark" on <html>) */
[data-theme="dark"] {
    --primary: #a78bfa;
    --primary-hover: #c4b5fd;
    --primary-light: #2e1065;
    --primary-light-hover: #4c1d95;
    --secondary: #94a3b8;
    --secondary-hover: #cbd5e1;
    --danger: #f87171;
    --danger-hover: #fca5a5;
    --success: #4ade80;
    --success-bg: #14532d;
    --info-bg: #1e3a5f;
    --info-text: #93c5fd;
    --error-bg: #450a0a;
    --error-text: #fca5a5;
    --bg: #0f0f13;
    --surface: #1c1c24;
    --surface-alt: #252530;
    --border: #2e2e3a;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.3);
    --shadow-lg: 0 4px 6px rgba(0,0,0,.5), 0 10px 30px rgba(0,0,0,.6);
    --claimed-border: #3e3e4a;
    --badge-available-bg: #064e3b;
    --badge-available-text: #6ee7b7;
    --badge-claimed-bg: #1e2330;
    --badge-claimed-text: #94a3b8;
    --badge-category-bg: #0c2340;
    --badge-category-text: #7dd3fc;
    --badge-category-border: #1e3a5f;
    --chip-bg: rgba(167,139,250,0.12);
    --chip-border: rgba(167,139,250,0.25);
    --cookie-link: #a78bfa;
}

/* Applied when OS is in dark mode and user hasn't made an explicit choice */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --primary: #a78bfa;
        --primary-hover: #c4b5fd;
        --primary-light: #2e1065;
        --primary-light-hover: #4c1d95;
        --secondary: #94a3b8;
        --secondary-hover: #cbd5e1;
        --danger: #f87171;
        --danger-hover: #fca5a5;
        --success: #4ade80;
        --success-bg: #14532d;
        --info-bg: #1e3a5f;
        --info-text: #93c5fd;
        --error-bg: #450a0a;
        --error-text: #fca5a5;
        --bg: #0f0f13;
        --surface: #1c1c24;
        --surface-alt: #252530;
        --border: #2e2e3a;
        --text: #f1f5f9;
        --text-muted: #94a3b8;
        --shadow: 0 1px 3px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.3);
        --shadow-lg: 0 4px 6px rgba(0,0,0,.5), 0 10px 30px rgba(0,0,0,.6);
        --claimed-border: #3e3e4a;
        --badge-available-bg: #064e3b;
        --badge-available-text: #6ee7b7;
        --badge-claimed-bg: #1e2330;
        --badge-claimed-text: #94a3b8;
        --badge-category-bg: #0c2340;
        --badge-category-text: #7dd3fc;
        --badge-category-border: #1e3a5f;
        --chip-bg: rgba(167,139,250,0.12);
        --chip-border: rgba(167,139,250,0.25);
        --cookie-link: #a78bfa;
    }
}

/* ─── Dark mode: extra overrides for elements with non-variable colours ─── */
/* Input focus ring uses a hardcoded rgba — update for dark */
[data-theme="dark"] .form-group input:focus,
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .form-group input:focus { box-shadow: 0 0 0 3px rgba(167,139,250,.2); }
}
[data-theme="dark"] .form-group input:focus { box-shadow: 0 0 0 3px rgba(167,139,250,.2); }

/* Modal overlay — darken further in dark mode */
[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,.7); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .modal-overlay { background: rgba(0,0,0,.7); }
}

/* ─── Theme toggle button ────────────────────────────────────── */
.theme-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px 6px;
    border-radius: 6px;
    line-height: 1;
    opacity: 0.75;
    transition: opacity 0.15s, background 0.15s;
    flex-shrink: 0;
}
.theme-toggle-btn:hover { opacity: 1; background: var(--primary-light); }

/* ─── Mobile hamburger menu ──────────────────────────────────── */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.3rem;
    padding: 4px 6px;
    border-radius: 6px;
    line-height: 1;
    color: var(--text);
    flex-shrink: 0;
    transition: background 0.15s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.mobile-menu-btn:hover { background: var(--primary-light); }
.mobile-menu {
    display: none;
    flex-direction: column;
    gap: 4px;
    padding: 10px 16px 14px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.mobile-menu.mobile-menu--open { display: flex; }
.mobile-menu .btn {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
}
.mobile-menu .guest-name-badge {
    display: block;
    padding: 8px 0 4px;
    font-weight: 600;
}
#header-actions { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
@media (max-width: 640px) {
    .mobile-menu-btn { display: inline-flex; align-items: center; }
    #header-actions { display: none !important; }
}

/* ── User nav dropdown ─────────────────────────────────────────── */
.user-nav-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.user-nav-trigger {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 10px 4px 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
}
.user-nav-trigger:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
    text-decoration: none;
}
.user-nav-trigger .user-nav-chevron {
    font-size: 0.65rem;
    opacity: 0.6;
    margin-left: 2px;
}
.user-nav-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 160px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    padding: 6px 0;
    flex-direction: column;
}
.user-nav-dropdown.open {
    display: flex;
    flex-direction: column;
}
.user-nav-dropdown a,
.user-nav-dropdown button {
    display: block;
    width: 100%;
    padding: 9px 16px;
    background: none;
    border: none;
    border-radius: 0;
    text-align: left;
    font-size: 0.875rem;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    transition: background 0.12s;
}
.user-nav-dropdown a:hover,
.user-nav-dropdown button:hover {
    background: var(--primary-light);
    color: var(--primary);
    text-decoration: none;
}
.user-nav-dropdown .dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}


/* ── Anchor scroll offset (account for sticky 60px header) ─────── */
#admin-overview, #admin-stats, #admin-recent-activity, #admin-all-registries, #admin-analytics,
#admin-revenue, #admin-managing-users, #admin-deleted-accounts,
#admin-tools, #admin-templates { scroll-margin-top: 76px; }
