/* ============================================================
   Family Moments — Mobile-First Application Styles
   UI Polish Update — Premium Feel

   Structure:
   1. Google Font Import
   2. CSS Custom Properties (Design Tokens)
   3. Base Reset & Typography
   4. Animations & Transitions
   5. Skeleton Loading
   6. Auth Layout
   7. App Layout (header, content, bottom nav)
   8. Components (cards, buttons, badges, empty states)
   9. Icon Badges (replaces emoji)
   10. Toast Notifications
   11. Loading Overlay
   12. Scroll Animations
   13. Utilities
   ============================================================ */

/* ── 1. Google Font ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800;900&display=swap');

/* ── 2. Design Tokens ───────────────────────────────────────── */
:root {
    /* Brand */
    --fm-primary:        #6366f1;
    --fm-primary-dark:   #4f46e5;
    --fm-primary-light:  #e0e7ff;
    --fm-secondary:      #f59e0b;
    --fm-danger:         #ef4444;
    --fm-success:        #22c55e;
    --fm-warning:        #f97316;

    /* Surfaces */
    --fm-bg:             #f8fafc;
    --fm-surface:        #ffffff;
    --fm-surface-2:      #f1f5f9;
    --fm-border:         #e2e8f0;
    --fm-border-light:   #f1f5f9;

    /* Text */
    --fm-text-primary:   #1e293b;
    --fm-text-secondary: #64748b;
    --fm-text-muted:     #94a3b8;

    /* Layout */
    --fm-header-height:     60px;
    --fm-bottom-nav-height: 64px;
    --fm-max-width:         480px;

    /* Radius */
    --fm-radius-xs: 6px;
    --fm-radius-sm: 8px;
    --fm-radius:    12px;
    --fm-radius-lg: 16px;
    --fm-radius-xl: 20px;

    /* Shadows */
    --fm-shadow-xs: 0 1px 2px rgba(0,0,0,.05);
    --fm-shadow-sm: 0 1px 4px rgba(0,0,0,.07);
    --fm-shadow:    0 4px 16px rgba(0,0,0,.10);
    --fm-shadow-lg: 0 8px 32px rgba(0,0,0,.14);

    /* Transitions */
    --fm-transition:      200ms ease;
    --fm-transition-slow: 350ms ease;
}

/* ── 3. Base Reset & Typography ─────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont,
                 'Segoe UI', Roboto, sans-serif;
    color: var(--fm-text-primary);
    background: var(--fm-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100%;
    overflow-x: hidden;
    line-height: 1.5;
}

button, a, [role="button"] {
    min-height: 44px;
    cursor: pointer;
}

a {
    color: var(--fm-primary);
    text-decoration: none;
}

a:hover { color: var(--fm-primary-dark); }

/* ── 4. Animations ──────────────────────────────────────────── */
@keyframes toastIn {
    from { opacity: 0; transform: translateY(-12px) scale(.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

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

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(.94); }
    to   { opacity: 1; transform: scale(1); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: .5; }
}

/* ── 5. Skeleton Loading ────────────────────────────────────── */
.skeleton {
    background: linear-gradient(
        90deg,
        #f1f5f9 25%,
        #e2e8f0 50%,
        #f1f5f9 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: var(--fm-radius-sm);
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    border-radius: 6px;
}
.skeleton-text.sm  { height: 11px; width: 60%; }
.skeleton-text.lg  { height: 18px; }

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    flex-shrink: 0;
}

.skeleton-card {
    background: #fff;
    border-radius: var(--fm-radius-lg);
    overflow: hidden;
    border: 1px solid var(--fm-border-light);
    margin-bottom: 1rem;
}

.skeleton-cover {
    width: 100%;
    aspect-ratio: 16/9;
}

.skeleton-body {
    padding: .875rem 1rem;
}

/* Memory card skeleton */
.memory-skeleton {
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--fm-border-light);
    margin: 0 1rem 1rem;
}

/* ── 6. Auth Layout ─────────────────────────────────────────── */
.auth-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem 1rem;
    background: linear-gradient(135deg, var(--fm-primary) 0%, var(--fm-primary-dark) 100%);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    animation: fadeInUp var(--fm-transition-slow) ease;
}

.auth-card {
    background: var(--fm-surface);
    border-radius: var(--fm-radius-xl);
    padding: 2rem 1.75rem;
    box-shadow: var(--fm-shadow-lg);
}

.auth-brand { text-align: center; margin-bottom: 2rem; }

.auth-logo {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--fm-primary-light);
    color: var(--fm-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.25rem;
    margin: 0 auto 1rem;
}

.auth-logo--pending  { background: #fef3c7; color: var(--fm-secondary); }
.auth-logo--rejected,
.auth-logo--error    { background: #fee2e2; color: var(--fm-danger); }
.auth-logo--blocked  { background: #f3f4f6; color: #9ca3af; }

.auth-title {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--fm-text-primary);
    margin: 0 0 .375rem;
    letter-spacing: -.3px;
}

.auth-subtitle {
    color: var(--fm-text-secondary);
    font-size: .95rem;
    margin: 0;
}

.btn-google-signin {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    width: 100%;
    padding: .875rem 1.25rem;
    background: var(--fm-surface);
    border: 2px solid var(--fm-border);
    border-radius: var(--fm-radius);
    color: var(--fm-text-primary);
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    transition: all var(--fm-transition);
    text-decoration: none;
}

.btn-google-signin:hover {
    border-color: var(--fm-primary);
    background: var(--fm-primary-light);
    color: var(--fm-primary-dark);
    box-shadow: 0 0 0 3px rgba(99,102,241,.2);
    transform: translateY(-1px);
}

.btn-google-signin:active { transform: translateY(0); }

.google-icon { width: 22px; height: 22px; flex-shrink: 0; }

.auth-note {
    text-align: center;
    color: var(--fm-text-muted);
    font-size: .8rem;
    margin: 1.25rem 0 0;
}

.status-message {
    background: var(--fm-surface-2);
    border-radius: var(--fm-radius);
    padding: 1rem 1.25rem;
    font-size: .9rem;
    color: var(--fm-text-secondary);
    text-align: center;
    margin-bottom: .5rem;
}

/* ── 7. App Layout ──────────────────────────────────────────── */
.app-body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--fm-bg);
}

/* Header */
.app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 1000;
    height: var(--fm-header-height);
    background: var(--fm-surface);
    border-bottom: 1px solid var(--fm-border);
    box-shadow: var(--fm-shadow-sm);
}

.app-header-inner {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 1rem;
    max-width: var(--fm-max-width);
    margin: 0 auto;
}

.app-header-left {
    flex: 1;
    display: flex;
    align-items: center;
}

.app-logo-text {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--fm-primary);
    letter-spacing: -.3px;
}

.app-header-title {
    flex: 2;
    text-align: center;
    font-weight: 700;
    font-size: .95rem;
    color: var(--fm-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-header-right {
    flex: 1;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.app-header-back {
    background: none;
    border: none;
    padding: .5rem;
    font-size: 1.25rem;
    color: var(--fm-primary);
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    border-radius: var(--fm-radius-sm);
    transition: background var(--fm-transition);
}

.app-header-back:hover { background: var(--fm-surface-2); }

.app-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--fm-border);
    transition: transform var(--fm-transition);
}

.app-avatar:active { transform: scale(.9); }

.app-avatar-placeholder {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--fm-primary-light);
    color: var(--fm-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

/* Main Content */
.app-content {
    margin-top: var(--fm-header-height);
    margin-bottom: var(--fm-bottom-nav-height);
    min-height: calc(100vh - var(--fm-header-height) - var(--fm-bottom-nav-height));
    max-width: var(--fm-max-width);
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

/* Bottom Navigation */
.app-bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 1000;
    height: var(--fm-bottom-nav-height);
    background: var(--fm-surface);
    border-top: 1px solid var(--fm-border);
    display: flex;
    align-items: center;
    box-shadow: 0 -4px 16px rgba(0,0,0,.06);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.app-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .2rem;
    padding: .5rem .25rem;
    color: var(--fm-text-muted);
    font-size: .68rem;
    font-weight: 600;
    text-decoration: none;
    transition: color var(--fm-transition);
    min-height: var(--fm-bottom-nav-height);
    position: relative;
}

.app-nav-item i {
    font-size: 1.4rem;
    line-height: 1;
    transition: transform var(--fm-transition);
}

.app-nav-item.active { color: var(--fm-primary); }
.app-nav-item:hover  { color: var(--fm-primary); }

.app-nav-item.active i {
    transform: scale(1.1);
}

/* Active indicator */
.app-nav-item.active::after {
    content: '';
    position: absolute;
    bottom: 6px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--fm-primary);
}

/* ── 8. Components ──────────────────────────────────────────── */

/* Card */
.fm-card {
    background: var(--fm-surface);
    border-radius: var(--fm-radius);
    box-shadow: var(--fm-shadow-sm);
    border: 1px solid var(--fm-border);
    overflow: hidden;
    transition: transform var(--fm-transition), box-shadow var(--fm-transition);
}

.fm-card-body { padding: 1rem 1.25rem; }

/* Button press effect */
.fm-card:active { transform: scale(.985); }

/* Empty State */
.empty-state {
    padding: 3rem 1.5rem;
    text-align: center;
    animation: fadeIn var(--fm-transition-slow);
}

.empty-state-icon {
    font-size: 3.5rem;
    display: block;
    margin-bottom: 1rem;
    color: var(--fm-text-muted);
    opacity: .4;
}

.empty-state-title {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--fm-text-primary);
    margin-bottom: .5rem;
    letter-spacing: -.2px;
}

.empty-state-body {
    font-size: .88rem;
    color: var(--fm-text-secondary);
    max-width: 280px;
    margin: 0 auto;
    line-height: 1.6;
}

/* Section Header */
.fm-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1rem .5rem;
}

.fm-section-title {
    font-size: .72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--fm-text-muted);
    margin: 0;
}

/* ── 9. Icon Badges (replaces emoji) ────────────────────────── */

/* Stat icon — used in tree stats, dashboard */
.icon-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.icon-badge.sm {
    width: 32px;
    height: 32px;
    font-size: .9rem;
    border-radius: 8px;
}

.icon-badge.lg {
    width: 52px;
    height: 52px;
    font-size: 1.4rem;
    border-radius: 14px;
}

/* Color variants */
.icon-badge-primary   { background: #e0e7ff; color: #6366f1; }
.icon-badge-success   { background: #d1fae5; color: #059669; }
.icon-badge-warning   { background: #fef3c7; color: #d97706; }
.icon-badge-danger    { background: #fee2e2; color: #ef4444; }
.icon-badge-pink      { background: #fce7f3; color: #db2777; }
.icon-badge-purple    { background: #ede9fe; color: #7c3aed; }
.icon-badge-slate     { background: #f1f5f9; color: #475569; }
.icon-badge-amber     { background: #fef3c7; color: #f59e0b; }

/* Big stat icon — used in tree stats page */
.big-icon-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 14px;
    font-size: 1.5rem;
    margin: 0 auto .5rem;
}

/* ── 10. Toast Notifications ────────────────────────────────── */
.toast-container {
    position: fixed;
    top: calc(var(--fm-header-height) + .75rem);
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    width: calc(100% - 2rem);
    max-width: 420px;
    pointer-events: none;
}

.fm-toast {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
    background: var(--fm-surface);
    border-radius: var(--fm-radius);
    padding: .875rem 1rem;
    margin-bottom: .5rem;
    box-shadow: var(--fm-shadow-lg);
    border-left: 4px solid var(--fm-primary);
    pointer-events: all;
    animation: toastIn var(--fm-transition) ease;
}

.fm-toast.toast-success { border-color: var(--fm-success); }
.fm-toast.toast-error   { border-color: var(--fm-danger);  }
.fm-toast.toast-warning { border-color: var(--fm-warning); }

.fm-toast-icon { font-size: 1.2rem; flex-shrink: 0; margin-top: 1px; }
.fm-toast.toast-success .fm-toast-icon { color: var(--fm-success); }
.fm-toast.toast-error   .fm-toast-icon { color: var(--fm-danger);  }
.fm-toast.toast-warning .fm-toast-icon { color: var(--fm-warning); }
.fm-toast.toast-info    .fm-toast-icon { color: var(--fm-primary); }

.fm-toast-body {
    flex: 1;
    font-size: .9rem;
    color: var(--fm-text-primary);
    line-height: 1.4;
    font-weight: 500;
}

/* ── 11. Loading Overlay ────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,.75);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(3px);
}

.loading-spinner {
    background: var(--fm-surface);
    padding: 1.5rem;
    border-radius: var(--fm-radius);
    box-shadow: var(--fm-shadow-lg);
}

/* ── 12. Scroll Animations ──────────────────────────────────── */

/* Elements with this class animate on scroll */
.animate-on-scroll {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.animate-on-scroll.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Staggered animation for lists */
.animate-on-scroll:nth-child(1) { transition-delay: 0ms; }
.animate-on-scroll:nth-child(2) { transition-delay: 60ms; }
.animate-on-scroll:nth-child(3) { transition-delay: 120ms; }
.animate-on-scroll:nth-child(4) { transition-delay: 180ms; }
.animate-on-scroll:nth-child(5) { transition-delay: 240ms; }
.animate-on-scroll:nth-child(6) { transition-delay: 300ms; }

/* Page enter animation */
.page-enter {
    animation: fadeInUp 0.3s ease both;
}

/* ── 13. Utilities ──────────────────────────────────────────── */
.text-primary   { color: var(--fm-primary) !important; }
.text-muted     { color: var(--fm-text-muted) !important; }
.fw-800         { font-weight: 800 !important; }
.fw-700         { font-weight: 700 !important; }
.letter-tight   { letter-spacing: -.3px; }

.bg-primary-light {
    background: var(--fm-primary-light) !important;
    color: var(--fm-primary) !important;
}

/* Micro-interactions */
.btn { touch-action: manipulation; }

.press-effect {
    transition: transform var(--fm-transition);
}
.press-effect:active { transform: scale(.94); }

/* Inputs — prevent iOS zoom */
input, select, textarea {
    font-size: 16px !important;
    font-family: inherit;
}

/* Divider */
.fm-divider {
    height: 1px;
    background: var(--fm-border-light);
    margin: 0;
    border: none;
}

/* Pill badge */
.fm-pill {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    font-size: .72rem;
    font-weight: 700;
    padding: .2rem .65rem;
    border-radius: 20px;
}

/* Smooth image loading */
img {
    transition: opacity 0.3s ease;
}

img[loading="lazy"] {
    opacity: 0;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* Safe area support */
.safe-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0);
}