/* =============================================
   MyRecoveryPal - Main Stylesheet
   Brand Colors: Blue (#1e4d8b, #4db8e8) + Green (#52b788)
   ============================================= */

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

:root {
    /* Primary Brand Colors */
    --primary-dark: #1e4d8b;
    /* Brand blue used as text. Lightens in dark mode, where #1e4d8b on a dark
       surface is unreadable; --primary-dark stays put for solid panels. */
    --brand-text: #1e4d8b;
    /* Dark blue from logo */
    --primary-light: #4db8e8;
    /* Light blue/cyan from logo */
    --accent-green: #52b788;
    /* Green from checkmark */
    --accent-green-strong: #2e8059;
    /* Button green: 4.8:1 with white text */
    --accent-green-strong-hover: #256b4a;
    /* The primary action: brand blue, on a pill. Green is kept for success and
       progress (a streak, a completed check-in), not for buttons. */
    --cta-bg: #1e4d8b;
    --cta-bg-hover: #173c6e;
    --footer-bg: #0e1322;
    /* The one emphasis panel: ink with a warm glow in the top corner. Text on it is white. */
    --panel-ink: radial-gradient(70% 130% at 88% -10%, rgba(255, 205, 130, 0.24), transparent 62%), #0e1322;
    /* Green and red as text: pass 4.5:1 on the page in both themes */
    --green-text: #2b7a55;
    --danger-text: #b91c1c;

    /* Motion: one set of curves and durations for the whole site */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    /* entrances, anything appearing */
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
    /* things already on screen that move or resize */
    --ease-in: cubic-bezier(0.55, 0, 1, 0.45);
    /* exits only */
    --dur-fast: 120ms;
    /* press, hover, and menus in the nav (used constantly, so kept quick) */
    --dur-fast-exit: 96ms;
    /* a nav menu closing: 20% shorter than it opened */
    --dur-menu: 200ms;
    /* dropdowns, popovers */
    --dur-move: 280ms;
    /* layout moves and reveals */

    /* Legacy support (keeping old variable names) */
    --primary-color: #1e4d8b;
    --secondary-color: #4db8e8;
    --accent-color: #52b788;

    /* Text Colors */
    --text-dark: #0e1322;
    --text-light: #ffffff;
    --text-muted: #545c70;

    /* Background Colors */
    --bg-light: #f5f6fa;
    --bg-lighter: #ffffff;
    --bg-gray: #eef1f6;

    /* Shadows */
    /* Resting surfaces are outlined with a hairline, not lifted with a blur.
       A soft shadow is kept for things that really float or respond to hover. */
    --shadow: 0 0 0 1px var(--border-color);
    --shadow-hover: 0 0 0 1px var(--border-color), 0 10px 24px -8px rgba(15, 23, 42, 0.14);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.1);

    /* Gradients - Updated to match brand */
    --gradient-primary: #1e4d8b;
    --gradient-secondary: #1e4d8b;
    --gradient-accent: #2e8059;

    /* Borders */
    --border-radius: 10px;
    --border-radius-lg: 20px;
    --border-radius-xl: 28px;
    /* Buttons are pills. Inputs and small controls keep --radius-control. */
    --radius-btn: 999px;
    /* Pages are flat: no paper grain. The token stays so one line brings it back. */
    --grain: none;

    /* Additional variables for dark mode compatibility */
    --card-bg: #ffffff;
    --border-color: #e1e5ee;
    --input-bg: #ffffff;
    --input-border: #d1d5db;
    --dropdown-bg: #ffffff;
    --modal-bg: #ffffff;
    --nav-bg: #ffffff;

    /* iOS Safe Area Insets - Critical for notch/Dynamic Island support */
    --safe-area-inset-top: env(safe-area-inset-top);
    --safe-area-inset-right: env(safe-area-inset-right);
    --safe-area-inset-bottom: env(safe-area-inset-bottom);
    --safe-area-inset-left: env(safe-area-inset-left);
}

/* =============================================
   App-refresh design tokens (Check-in & Feed redesign)
   Card-based "app-refresh" visual language. Additive — new token
   names that map onto the existing brand palette above.
   ============================================= */
:root {
    /* ---- Semantic brand aliases ---- */
    --color-primary: #1e4d8b;
    --color-primary-strong: #0f2d56;
    --color-secondary: #4db8e8;
    --color-accent: #52b788;
    --color-accent-hover: #45a675;

    /* ---- Text ---- */
    --text-strong: #0e1322;
    --text-body: #0e1322;
    /* 4.7:1 on the page background, 4.5:1 on --surface-sunken */
    --text-faint: #676e7c;
    /* Links are navy in light mode: the light blue is 2.25:1 on white */
    --text-link: #1e4d8b;
    --text-link-hover: #0f2d56;
    --text-on-brand: #ffffff;

    /* ---- Surfaces ---- */
    --surface-page: #f5f6fa;
    --surface-card: #ffffff;
    --surface-sunken: #eef1f6;
    --surface-input: #ffffff;
    --surface-nav: rgba(255, 255, 255, 0.98);

    /* ---- Borders ---- */
    --border-input: #d1d5db;
    --border-divider: #eef1f5;

    /* ---- Gold (streaks, premium star, milestones) ---- */
    --gold-accent: #f5a623;
    --gold-soft: #f0c040;
    --gold-deep: #d4a017;
    /* Gold as text: 5.9:1 on white. Lightens in dark mode. */
    --gold-text: #8a5a00;

    /* ---- Feature gradients ---- */
    --gradient-court: #1e4d8b;
    --gradient-premium: #764ba2;
    --premium-from: #667eea;
    --premium-to: #764ba2;

    /* ---- Status ---- */
    --danger: #ef4444;

    /* ---- Spacing scale ---- */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;
    --space-8: 4rem;

    /* ---- Radius ---- */
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --radius-pill: 50px;
    --radius-chip: 25px;
    --radius-badge: 20px;
    /* The two radii new work uses: controls, and the surfaces that hold them */
    --radius-control: 10px;
    --radius-surface: 20px;

    /* ---- Shadows ---- */
    --shadow-sm: 0 1px 4px rgba(15, 45, 86, 0.25);
    --shadow-dropdown: 0 4px 20px rgba(0, 0, 0, 0.15);
    --shadow-accent: 0 10px 24px -10px rgba(30, 77, 139, 0.5);

    /* ---- Motion ---- */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: var(--dur-fast) var(--ease-out);
    --transition: var(--dur-menu) var(--ease-out);
    /* What a control animates on hover, focus and press. Named properties
       only, so layout properties never tween. */
    --transition-ui: color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out),
        border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-menu) var(--ease-out),
        opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
    --lift-hover: translateY(-2px);
    --lift-card: translateY(-5px);

    /* ---- Layout ---- */
    --nav-height: 70px;
    --blur-nav: blur(10px);

    /* ---- Typography ---- */
    /* Type scale: six sizes. New work uses these, not one-off values. */
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-md: 1.125rem;
    --text-lg: 1.375rem;
    --text-xl: 1.75rem;
    --text-display: clamp(2rem, 1rem + 4vw, 3.5rem);
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --tracking-label-wide: 0.12em;
}

[data-theme="dark"] {
    --text-strong: #e4e4e7;
    --text-body: #e4e4e7;
    --text-faint: #9ca3af;
    --green-text: #52b788;
    --danger-text: #f87171;
    --text-link: #4db8e8;
    --text-link-hover: #6bc5ed;
    --gold-text: #f0c040;

    --surface-page: #111827;
    --surface-card: #1f2937;
    --surface-sunken: #374151;
    --surface-input: #374151;
    --surface-nav: #111827;

    --border-input: #4b5563;
    --border-divider: #374151;

    --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.4);
    --shadow-dropdown: 0 4px 20px rgba(0, 0, 0, 0.4);

    --cta-bg: #2f66b3;
    --cta-bg-hover: #3b74c9;
    --footer-bg: #0a0f1c;
    --panel-ink: radial-gradient(70% 130% at 88% -10%, rgba(255, 205, 130, 0.18), transparent 62%), #0a0f1c;
}

/* =============================================
   Dark Mode Theme
   ============================================= */
[data-theme="dark"] {
    /* Text Colors */
    --text-dark: #e4e4e7;
    --text-light: #111827;
    /* 4.7:1 on --bg-gray, the darkest surface muted text sits on */
    --text-muted: #a9b0bb;

    /* Background Colors */
    --bg-light: #1f2937;
    --bg-lighter: #111827;
    --bg-gray: #374151;

    /* Card and Component Backgrounds */
    --card-bg: #1f2937;
    --input-bg: #374151;
    --input-border: #4b5563;
    --dropdown-bg: #1f2937;
    --modal-bg: #1f2937;
    --nav-bg: #111827;

    /* Borders */
    --border-color: #374151;

    /* Shadows - darker for dark mode */
    --shadow: 0 0 0 1px var(--border-color);
    --shadow-hover: 0 0 0 1px var(--border-color), 0 10px 24px -8px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.3);

    /* Keep brand colors - they have good contrast */
    --primary-dark: #1e4d8b;
    --brand-text: #8fb8ee;
}

/* Aliases used by a few templates. Declared on the themed element so they
   resolve to that theme's values. */
:root,
[data-theme="dark"] {
    --text-primary: var(--text-dark);
    --text-color: var(--text-dark);
    --bg-card: var(--card-bg);
    --primary-light: #4db8e8;
    --accent-green: #52b788;
}

/* Dark Mode - Body and Base */
[data-theme="dark"] body {
    background: var(--bg-lighter) var(--grain);
    color: var(--text-dark);
}

/* Dark Mode - Headings */
[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3,
[data-theme="dark"] h4,
[data-theme="dark"] h5,
[data-theme="dark"] h6 {
    color: var(--text-dark);
}

/* Dark Mode - Links */
/* :where() keeps these at the same weight as the light-mode link rule, so a
   class that sets its own colour (a link styled as a button) still wins. */
:where([data-theme="dark"]) a {
    color: var(--primary-light);
}

:where([data-theme="dark"]) a:hover {
    color: #6bc5ed;
}

/* Dark Mode - Cards */
[data-theme="dark"] .card,
[data-theme="dark"] .resource-card,
[data-theme="dark"] .blog-card,
[data-theme="dark"] .feature-card,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .meeting-card,
[data-theme="dark"] .service-card,
[data-theme="dark"] .post-card,
[data-theme="dark"] .comment-card,
[data-theme="dark"] .profile-card,
[data-theme="dark"] .group-card,
[data-theme="dark"] .challenge-card {
    background: var(--card-bg);
    border-color: var(--border-color);
}

/* Dark Mode - Meeting directory. These templates hardcode light backgrounds
   while the dark heading/body colours above still apply, which left light
   text on white cards (the meeting name was nearly invisible). */
[data-theme="dark"] .meeting-detail-card,
[data-theme="dark"] .meeting-finder-container,
[data-theme="dark"] .meeting-filters,
[data-theme="dark"] .support-card {
    background: var(--card-bg);
    box-shadow: var(--shadow);
    color: var(--text-dark);
}

[data-theme="dark"] .meeting-detail-name,
[data-theme="dark"] .nearby-meeting {
    color: var(--text-dark);
}

[data-theme="dark"] .meeting-detail-time,
[data-theme="dark"] .nearby-meeting:hover {
    color: #a78bfa;
}

[data-theme="dark"] .meeting-detail-section h3 {
    color: var(--text-muted);
}

[data-theme="dark"] .meeting-detail-location {
    color: #d1d5db;
}

[data-theme="dark"] .nearby-meeting {
    border-bottom-color: var(--border-color);
}

[data-theme="dark"] .btn-filter:not(.active),
[data-theme="dark"] .toggle-btn:not(.active) {
    background: var(--input-bg);
    border-color: var(--input-border);
    color: var(--text-dark);
}

/* Dark Mode - Navigation */
[data-theme="dark"] .navbar,
[data-theme="dark"] #siteNav,
[data-theme="dark"] .nav-container {
    background: var(--nav-bg) !important;
    border-bottom-color: var(--border-color);
}

[data-theme="dark"] .navbar .nav-link,
[data-theme="dark"] .navbar a {
    color: var(--text-dark) !important;
}

[data-theme="dark"] .navbar .nav-link:hover,
[data-theme="dark"] .navbar a:hover {
    color: var(--primary-light) !important;
}

/* Dark Mode - Dropdowns */
[data-theme="dark"] .dropdown-menu {
    background: var(--dropdown-bg);
    border-color: var(--border-color);
}

[data-theme="dark"] .dropdown-item {
    color: var(--text-dark);
}

[data-theme="dark"] .dropdown-item:hover {
    background: var(--bg-gray);
    color: var(--text-dark);
}

/* Dark Mode - Forms */
[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] select,
[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select {
    background: var(--input-bg) !important;
    border-color: var(--input-border) !important;
    color: var(--text-dark) !important;
}

[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
    color: var(--text-muted) !important;
}

[data-theme="dark"] input:focus,
[data-theme="dark"] textarea:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus {
    border-color: var(--primary-light) !important;
    box-shadow: 0 0 0 2px rgba(77, 184, 232, 0.2) !important;
}

/* Dark Mode - Modals */
[data-theme="dark"] .modal-content {
    background: var(--modal-bg);
    border-color: var(--border-color);
}

[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-footer {
    border-color: var(--border-color);
}

/* Dark Mode - Badges */
[data-theme="dark"] .resource-type,
[data-theme="dark"] .badge,
[data-theme="dark"] .tag {
    background: var(--bg-gray);
    color: var(--text-dark);
}

/* Dark Mode - Tables */
[data-theme="dark"] table,
[data-theme="dark"] .table {
    color: var(--text-dark);
}

[data-theme="dark"] .table > :not(caption) > * > * {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-dark);
}

[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > * {
    background-color: var(--bg-gray);
}

/* Dark Mode - Sidebar */
[data-theme="dark"] .sidebar,
[data-theme="dark"] .quick-actions-card,
[data-theme="dark"] .checkin-widget,
[data-theme="dark"] .streak-card {
    background: var(--card-bg);
    border-color: var(--border-color);
}

/* Dark Mode - Search */
[data-theme="dark"] .search-section form,
[data-theme="dark"] .search-bar,
[data-theme="dark"] .search-container {
    background: var(--card-bg);
}

/* Dark Mode - Crisis Banner */
[data-theme="dark"] .crisis-banner {
    background: #7f1d1d;
    border-color: #991b1b;
}

[data-theme="dark"] .crisis-banner h3,
[data-theme="dark"] .crisis-banner h4 {
    color: #fecaca;
}

[data-theme="dark"] .crisis-banner p,
[data-theme="dark"] .crisis-banner a {
    color: #fecaca;
}

/* Dark Mode - Bootstrap Overrides */
[data-theme="dark"] .bg-white {
    background-color: var(--card-bg) !important;
}

[data-theme="dark"] .bg-light {
    background-color: var(--bg-light) !important;
}

[data-theme="dark"] .text-dark {
    color: var(--text-dark) !important;
}

[data-theme="dark"] .text-muted {
    color: var(--text-muted) !important;
}

[data-theme="dark"] .border {
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .border-bottom {
    border-color: var(--border-color) !important;
}

/* Dark Mode - Alerts */
[data-theme="dark"] .alert {
    border-color: var(--border-color);
}

[data-theme="dark"] .alert-info {
    background-color: rgba(77, 184, 232, 0.2);
    color: #93c5fd;
}

[data-theme="dark"] .alert-success {
    background-color: rgba(82, 183, 136, 0.2);
    color: #86efac;
}

[data-theme="dark"] .alert-warning {
    background-color: rgba(251, 191, 36, 0.2);
    color: #fcd34d;
}

[data-theme="dark"] .alert-danger {
    background-color: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

/* Dark Mode - List Groups */
[data-theme="dark"] .list-group-item {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-dark);
}

/* Dark Mode - Pagination */
[data-theme="dark"] .page-link {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-dark);
}

[data-theme="dark"] .page-link:hover {
    background-color: var(--bg-gray);
    color: var(--primary-light);
}

[data-theme="dark"] .page-item.active .page-link {
    background-color: var(--accent-green);
    border-color: var(--accent-green);
}

/* Dark Mode - Progress Bars */
[data-theme="dark"] .progress {
    background-color: var(--bg-gray);
}

/* Dark Mode - Chart containers */
[data-theme="dark"] .chart-card,
[data-theme="dark"] .chart-container {
    background: var(--card-bg);
}

/* Dark Mode - Insight cards */
[data-theme="dark"] .insight-card {
    background: linear-gradient(135deg, var(--bg-gray) 0%, var(--bg-light) 100%);
}

/* Dark Mode - Empty states */
[data-theme="dark"] .empty-state {
    background: var(--card-bg);
}

/* Dark Mode - Footer */
[data-theme="dark"] footer,
[data-theme="dark"] .footer {
    background: var(--nav-bg);
    border-top-color: var(--border-color);
}

/* Theme Toggle Button */
.theme-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
    color: var(--text-dark);
    font-size: 1.1rem;
}

.theme-toggle:hover {
    background: var(--bg-gray);
    transform: scale(1.1);
}

[data-theme="dark"] .theme-toggle {
    color: #fbbf24;
}

/* =============================================
   Skeleton Loaders
   ============================================= */

/* Base skeleton with shimmer animation */
.skeleton {
    background: linear-gradient(90deg,
        var(--bg-gray) 25%,
        var(--bg-light) 50%,
        var(--bg-gray) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: 4px;
}

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

/* Skeleton Component Variants */
.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    flex-shrink: 0;
}

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

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    width: 100%;
}

.skeleton-text:last-child {
    margin-bottom: 0;
}

.skeleton-text-short {
    width: 40%;
}

.skeleton-text-medium {
    width: 70%;
}

.skeleton-text-xs {
    height: 10px;
}

.skeleton-title {
    height: 18px;
    width: 50%;
    margin-bottom: 12px;
}

.skeleton-paragraph {
    height: 60px;
}

.skeleton-button {
    height: 36px;
    width: 80px;
    border-radius: 18px;
}

.skeleton-image {
    height: 200px;
    border-radius: 8px;
    width: 100%;
}

/* Skeleton Post Card */
.skeleton-post-card {
    background: var(--card-bg);
    border-radius: var(--border-radius-lg);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.skeleton-post-header {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.skeleton-post-header-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.skeleton-post-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.skeleton-post-actions {
    display: flex;
    gap: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

/* Skeleton Comment */
.skeleton-comment {
    display: flex;
    gap: 10px;
    padding: 12px 0;
    border-top: 1px solid var(--border-color);
}

.skeleton-comment:first-child {
    border-top: none;
}

.skeleton-comment-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Skeleton Container */
.skeleton-container {
    transition: opacity var(--dur-menu) var(--ease-out);
}

.skeleton-container.hidden {
    opacity: 0;
    pointer-events: none;
    position: absolute;
}

/* Content Container (initially hidden) */
.content-container {
    transition: opacity var(--dur-menu) var(--ease-out);
}

.content-container.loading {
    opacity: 0;
}

/* Dark mode - skeleton already uses CSS variables so it works automatically */

/* =============================================
   Toast Notifications
   ============================================= */

.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--card-bg);
    color: var(--text-dark);
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 280px;
    max-width: 400px;
    pointer-events: auto;
    animation: toast-slide-in 0.3s ease;
    border: 1px solid var(--primary-light);
}

.toast.toast-error {
    border-color: #ef4444;
}

.toast.toast-success {
    border-color: var(--accent-green);
}

.toast.toast-hiding {
    animation: toast-slide-out 0.3s ease forwards;
}

.toast-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.toast-error .toast-icon {
    color: #ef4444;
}

.toast-success .toast-icon {
    color: var(--accent-green);
}

.toast-message {
    flex: 1;
    font-size: 0.9rem;
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 1rem;
    opacity: 0.7;
    transition: opacity var(--dur-fast) var(--ease-out);
}

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

@keyframes toast-slide-in {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes toast-slide-out {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(100%);
        opacity: 0;
    }
}

/* Mobile toast positioning */
@media (max-width: 480px) {
    .toast-container {
        left: 10px;
        right: 10px;
        transform: none;
        bottom: 80px; /* Above mobile nav */
    }

    .toast {
        min-width: auto;
        max-width: none;
    }
}

/* =============================================
   Optimistic UI States
   ============================================= */

/* Like button optimistic animation */
.like-btn {
    transition: transform var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.like-btn:active {
    transform: scale(0.9);
}

.like-btn.liked i {
    animation: like-pop 0.3s ease;
}

@keyframes like-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* Optimistic comment state */
.comment.optimistic {
    opacity: 0.7;
    position: relative;
}

.comment.optimistic::after {
    content: 'Sending...';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
}

.comment.optimistic.error {
    opacity: 0.5;
    background: rgba(239, 68, 68, 0.1);
}

/* Comment appear animation */
.comment.new-comment {
    animation: comment-appear 0.3s ease;
}

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

/* =============================================
   Infinite Scroll
   ============================================= */

/* Loading indicator at bottom of feed */
.infinite-scroll-loader {
    text-align: center;
    padding: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: var(--text-muted);
}

.infinite-scroll-loader .spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--bg-gray);
    border-top-color: var(--primary-light);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* End of feed message */
.end-of-feed {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.end-of-feed i {
    display: block;
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.5;
}

/* Scroll sentinel (invisible trigger element) */
#scroll-sentinel {
    height: 1px;
    width: 100%;
}

/* Post appear animation for dynamically loaded posts */
.post-card.new-post {
    animation: post-appear 0.3s ease;
}

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

/* Hide traditional pagination when infinite scroll is active */
.pagination.hidden-by-infinite-scroll {
    display: none;
}

/* Typography */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-dark);
    background: var(--bg-light) var(--grain);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Form controls never exceed their column on a narrow screen. */
input,
select,
textarea {
    max-width: 100%;
    box-sizing: border-box;
}

/* Type: tight display tracking, balanced headings, no orphans in copy,
   figures that do not jiggle when they change. */
h1,
h2 {
    letter-spacing: -0.025em;
    text-wrap: balance;
}

h3 {
    letter-spacing: -0.015em;
    text-wrap: balance;
}

p,
li {
    text-wrap: pretty;
}

sup,
sub {
    line-height: 0;
}

/* Headlines break into even lines, with no orphaned last word */
h1,
h2,
h3 {
    text-wrap: balance;
}

/* Figures that update or sit in columns keep a fixed width per digit */
table,
time,
.stat-number,
.stat-value,
.member-stat-number,
.quick-stat-value,
.challenge-stat-value,
.sobriety-days-big,
.days-count {
    font-variant-numeric: tabular-nums;
}

.stat-number,
.big-number,
.days-display,
.sobriety-days,
.milestone-days,
time {
    font-variant-numeric: tabular-nums;
}

/* Headings default to the text ink. Inside a solid-colour panel that sets its
   own text colour, the panel sets --heading-color: currentColor so headings
   follow that text colour instead of disappearing into the background. */
.text-white,
.text-light {
    --heading-color: currentColor;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    color: var(--heading-color, var(--text-dark));
    font-weight: 600;
    line-height: 1.2;
}

a {
    color: var(--text-link);
    text-decoration: none;
    /* Keeps an underline clear of descenders (g, y) wherever one is shown */
    text-underline-offset: 0.2em;
    transition: color var(--dur-fast) var(--ease-out);
}

/* Superscripts must not make their line taller */
sup,
sub {
    line-height: 0;
}

a:hover {
    color: var(--text-link-hover);
}

/* Common Page Headers - Unified Style */
.page-header,
.blog-header,
.resources-header,
.category-header,
.educational-resources-header,
.support-header,
.journal-header,
.community-header,
.profile-header,
.dashboard-header,
.milestones-header,
.stats-header,
.prompts-header,
.entries-header,
.hero-section {
    /* Page titles sit on the page itself: no coloured band. */
    background: transparent !important;
    padding: 3rem 1rem 0.5rem !important;
    color: var(--text-dark) !important;
    text-align: center;
    position: relative;
    margin-bottom: 1.5rem;
}

.page-header h1,
.blog-header h1,
.resources-header h1,
.category-header h1,
.educational-resources-header h1,
.support-header h1,
.entries-header h1,
.hero-section h1 {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif !important;
    font-size: clamp(1.9rem, 1.1rem + 2.6vw, 2.9rem);
    color: var(--text-dark) !important;
    text-shadow: none;
    margin-bottom: 0.5rem;
}

.page-header p,
.blog-header p,
.resources-header p,
.category-header p,
.educational-resources-header p,
.support-header p,
.hero-section p {
    font-size: 1.1rem;
    color: var(--text-muted) !important;
    max-width: 60ch;
    margin: 0 auto;
}


/* Buttons - Unified Styles */
.btn,
.button,
.btn-primary,
.btn-success,
.cta-button,
.search-button,
.download-button {
    padding: 0.75rem 1.5rem;
    background: var(--cta-bg);
    color: #fff !important;
    border: none;
    border-radius: var(--radius-btn);
    font-weight: 600;
    cursor: pointer;
    /* A long label wraps inside the button instead of pushing the page wide */
    max-width: 100%;
    box-sizing: border-box;
    transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-menu) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
    display: inline-block;
    text-align: center;
    --heading-color: currentColor;
}

.btn:hover,
.button:hover,
.btn-primary:hover,
.btn-success:hover,
.cta-button:hover,
.search-button:hover,
.download-button:hover {
    background: var(--cta-bg-hover);
    color: #fff !important;
    --heading-color: currentColor;
}

/* Press feedback */
.btn:active,
.button:active,
.btn-primary:active,
.btn-success:active,
.cta-button:active,
.search-button:active,
.download-button:active {
    transform: scale(0.97);
}

/* A disabled outline button ("Current Plan" on pricing) has no fill, so the
   white label every .btn gets was invisible on the light card behind it. */
.btn-outline-secondary:disabled,
.btn-outline-secondary.disabled {
    background: transparent;
    color: var(--text-muted) !important;
    box-shadow: 0 0 0 1px var(--border-color) inset;
}

.btn-secondary,
.btn-secondary:hover {
    background: var(--bg-gray);
    color: var(--text-dark) !important;
}

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

/* Cards - Unified Styles */
.card,
.resource-card,
.blog-card,
.feature-card,
.stat-card,
.meeting-card,
.service-card {
    background: var(--card-bg, #fff);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: transform var(--dur-menu) var(--ease-out), box-shadow var(--dur-menu) var(--ease-out);
}

/* Only cards that are themselves links lift on hover. A container that
   merely holds content gives no feedback, because nothing happens on click. */
a.card:hover,
a.resource-card:hover,
a.blog-card:hover,
a.meeting-card:hover,
a.service-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
}

/* Crisis Banner - Consistent Style */
.crisis-banner {
    background: #FEE2E2;
    border: 2px solid #FCA5A5;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin: 1.5rem auto;
    text-align: center;
    max-width: 1200px;
}

.crisis-banner h3,
.crisis-banner h4 {
    color: #DC2626;
    margin-bottom: 0.75rem;
}

/* Search Bars - Unified */
.search-section form,
.search-bar,
.search-container {
    display: flex;
    gap: 0.5rem;
    box-shadow: var(--shadow);
    border-radius: 50px;
    overflow: hidden;
    background: var(--card-bg, #fff);
    max-width: 600px;
    margin: 2rem auto;
}

.search-input,
input[type="search"] {
    flex: 1;
    border: none;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    outline: none;
}

/* Resource Type Badges */
.resource-type,
.badge,
.tag,
.meeting-type-badge,
.attendance-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    background: var(--bg-gray);
    color: var(--text-dark);
}

/* Fix old purple gradients */
.gradient-text {
    color: var(--brand-text, #1e4d8b);
}

/* Statistics and Numbers */
.stat-number,
.big-number {
    color: var(--brand-text, #1e4d8b);
    font-weight: 700;
}

/* Mobile Responsive */
@media (max-width: 768px) {

    .page-header h1,
    .blog-header h1,
    .resources-header h1,
    .category-header h1,
    .educational-resources-header h1,
    .support-header h1,
    .hero-section h1 {
        font-size: 2rem;
    }

    .page-header,
    .blog-header,
    .resources-header,
    .category-header,
    .educational-resources-header,
    .support-header,
    .hero-section {
        padding: 1.75rem 1rem 0.25rem !important;
    }
}