/**
 * mystartup24 - Desktop Styles
 *
 * Mobile-First Responsive Design with full-width layout.
 * Supports Dark Mode via .dark class on <html>.
 *
 * Layout System:
 * - Mobile (< 1024px): Single column, full width
 * - Desktop (1024-1279px): 2 columns (content + right sidebar)
 * - Large (1280px+): 3 columns (left sidebar + content + right sidebar)
 */

/* ============================================
   CSS Custom Properties
   ============================================ */

:root {
    /* Layout */
    --header-height: 56px;
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);

    /* Sidebar Widths */
    --sidebar-left-width: 0px;
    --sidebar-right-width: 0px;

    /* Content */
    --content-max-width: 100%;
    --page-padding-x: 1rem;
    --page-padding-y: 1.5rem;
    --content-gap: 1.5rem;
}

/* Tablet: 640px+ */
@media (min-width: 640px) {
    :root {
        --page-padding-x: 1.5rem;
    }
}

/* Desktop: 1024px+ - 2 columns */
@media (min-width: 1024px) {
    :root {
        --sidebar-right-width: 280px;
        --page-padding-x: 2rem;
        --page-padding-y: 2rem;
        --content-gap: 2rem;
    }
}

/* Large Desktop: 1280px+ - 3 columns */
@media (min-width: 1280px) {
    :root {
        --sidebar-left-width: 220px;
        --sidebar-right-width: 300px;
        --page-padding-x: 2.5rem;
    }
}

/* XL Desktop: 1536px+ */
@media (min-width: 1536px) {
    :root {
        --sidebar-left-width: 240px;
        --sidebar-right-width: 320px;
        --page-padding-x: 3rem;
    }
}

/* 2K+ Desktop: 1920px+ */
@media (min-width: 1920px) {
    :root {
        --content-max-width: 1800px;
        --sidebar-left-width: 260px;
        --sidebar-right-width: 340px;
        --page-padding-x: 3rem;
    }
}

/* Sticky-Offset Utility */
.sticky-below-header {
    position: sticky;
    top: var(--header-height);
    z-index: 30;
}

/* ============================================
   Base Styles
   ============================================ */

body {
    background-color: var(--bg-page, #FAFAF8);
    background-image: radial-gradient(rgba(99, 102, 241, 0.07) 1px, transparent 1px);
    background-size: 24px 24px;
    min-height: 100vh;
}

html.dark body {
    background-color: var(--bg-page, #0F0F0F);
    background-image: radial-gradient(rgba(99, 102, 241, 0.04) 1px, transparent 1px);
    background-size: 24px 24px;
}

/* Mesh gradient overlay - subtle brand color blobs */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    background-image:
        radial-gradient(at 15% 15%, rgba(99, 102, 241, 0.06) 0px, transparent 50%),
        radial-gradient(at 85% 20%, rgba(14, 165, 233, 0.05) 0px, transparent 50%),
        radial-gradient(at 50% 80%, rgba(245, 158, 11, 0.04) 0px, transparent 50%);
}

html.dark body::before {
    background-image:
        radial-gradient(at 15% 15%, rgba(99, 102, 241, 0.10) 0px, transparent 50%),
        radial-gradient(at 85% 20%, rgba(14, 165, 233, 0.08) 0px, transparent 50%),
        radial-gradient(at 50% 80%, rgba(245, 158, 11, 0.06) 0px, transparent 50%);
}

/* ============================================
   Category Ambient Background
   Only visible when body.has-category-bg is set
   ============================================ */

body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    opacity: 0;
    background-image:
        radial-gradient(ellipse 600px 500px at 10% 20%,
            color-mix(in srgb, var(--cat-bg, transparent) 10%, transparent) 0%,
            transparent 70%),
        radial-gradient(ellipse 500px 400px at 85% 60%,
            color-mix(in srgb, var(--cat-bg, transparent) 7%, transparent) 0%,
            transparent 70%),
        radial-gradient(ellipse 400px 350px at 50% 90%,
            color-mix(in srgb, var(--cat-bg, transparent) 5%, transparent) 0%,
            transparent 70%);
}

body.has-category-bg::after {
    animation: cat-orbs-fade 0.6s ease-out forwards;
}

html.dark body::after {
    background-image:
        radial-gradient(ellipse 600px 500px at 10% 20%,
            color-mix(in srgb, var(--cat-bg, transparent) 15%, transparent) 0%,
            transparent 70%),
        radial-gradient(ellipse 500px 400px at 85% 60%,
            color-mix(in srgb, var(--cat-bg, transparent) 10%, transparent) 0%,
            transparent 70%),
        radial-gradient(ellipse 400px 350px at 50% 90%,
            color-mix(in srgb, var(--cat-bg, transparent) 8%, transparent) 0%,
            transparent 70%);
}

@keyframes cat-orbs-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    body.has-category-bg::after {
        animation: none;
        opacity: 1;
    }
}

/* ============================================
   App Wrapper (Responsive Centering)
   ============================================ */

.app-wrapper {
    min-height: 100vh;
}

.app-container {
    width: 100%;
    max-width: 100%;
    background-color: transparent;
    margin: 0;
}

html.dark .app-container {
    background-color: transparent;
}

/* ============================================
   Large Screen Container Centering
   ============================================ */

@media (min-width: 1920px) {
    .app-container {
        max-width: var(--content-max-width);
        margin: 0 auto;
        background-color: var(--bg-card, #FFFFFF);
        box-shadow: 0 0 60px rgba(0, 0, 0, 0.04);
    }

    html.dark .app-container {
        background-color: var(--bg-card, #1A1A1A);
        box-shadow: 0 0 60px rgba(0, 0, 0, 0.3);
    }
}

/* ============================================
   Header Styles
   ============================================ */

.app-header {
    position: sticky;
    top: 0;
    z-index: 40;
    width: 100%;
    background-color: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

html.dark .app-header {
    background-color: rgba(26, 26, 26, 0.78);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.app-header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 var(--page-padding-x);
    max-width: var(--content-max-width);
    margin: 0 auto;
}

/* ============================================
   Page Layout Grid System
   ============================================ */

.page-layout {
    display: flex;
    flex-direction: column;
    gap: var(--content-gap);
    padding: var(--page-padding-y) var(--page-padding-x);
    max-width: var(--content-max-width);
    margin: 0 auto;
}

/* Single column layout for text-heavy pages */
.page-layout-single {
    display: block;
    max-width: 48rem; /* 768px */
    margin: 0 auto;
    padding: var(--page-padding-y) var(--page-padding-x);
}

/* Desktop: 2 columns (content + right sidebar) */
@media (min-width: 1024px) {
    .page-layout {
        display: grid;
        grid-template-columns: 1fr var(--sidebar-right-width);
        grid-template-areas: "main sidebar-right";
    }

    .page-layout-single {
        display: block;
    }

    .page-layout > .main-content {
        grid-area: main;
        min-width: 0;
    }

    .page-layout > .sidebar-right {
        grid-area: sidebar-right;
    }
}

/* Tablet: center main-content for better readability (no sidebar visible) */
@media (min-width: 640px) and (max-width: 1023px) {
    .page-layout-3col > .main-content {
        max-width: 42rem; /* 672px */
        margin-left: auto;
        margin-right: auto;
    }
}

/* Large Desktop: 3 columns */
@media (min-width: 1280px) {
    .page-layout-3col {
        grid-template-columns: var(--sidebar-left-width) 1fr var(--sidebar-right-width);
        grid-template-areas: "sidebar-left main sidebar-right";
    }

    .page-layout-3col > .sidebar-left {
        grid-area: sidebar-left;
    }
}

/* ============================================
   Settings Layout (sidebar + content)
   ============================================ */

.settings-layout {
    display: flex;
    flex-direction: column;
    padding: var(--page-padding-y) var(--page-padding-x);
    max-width: var(--content-max-width);
    margin: 0 auto;
}

@media (min-width: 1024px) {
    .settings-layout {
        display: grid;
        grid-template-columns: 220px 1fr;
        gap: 2.5rem;
        max-width: 56rem; /* 896px - comfortable for settings */
    }
}

.settings-sidebar {
    display: none;
}

@media (min-width: 1024px) {
    .settings-sidebar {
        display: block;
        position: sticky;
        top: calc(var(--header-height) + 1rem);
        height: fit-content;
    }
}

.settings-sidebar-title {
    font-size: 0.6875rem;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0 0.5rem;
    margin-bottom: 0.5rem;
}

html.dark .settings-sidebar-title {
    color: #6b7280;
}

/* Tablet: constrain form width for better readability */
@media (min-width: 768px) and (max-width: 1023px) {
    .settings-content-tablet {
        max-width: 36rem; /* 576px */
        margin-left: auto;
        margin-right: auto;
    }
}

/* ============================================
   Content Wrapper (for full-width sections)
   ============================================ */

.content-wrapper {
    width: 100%;
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding-inline: var(--page-padding-x);
}

/* ============================================
   Footer Styles
   ============================================ */

.app-footer {
    width: 100%;
}

/* ============================================
   Sidebar Styles
   ============================================ */

.sidebar {
    display: none;
}

.sidebar-left,
.sidebar-right {
    display: none;
}

@media (min-width: 1024px) {
    .sidebar-right {
        display: block;
        position: sticky;
        top: calc(var(--header-height) + 1rem);
        height: fit-content;
        max-height: calc(100vh - var(--header-height) - 2rem);
        overflow-y: auto;
        overflow-x: hidden;
        min-width: 0;
        scrollbar-width: thin;
    }
}

@media (min-width: 1280px) {
    .sidebar-left {
        display: block;
        position: sticky;
        top: calc(var(--header-height) + 1rem);
        height: fit-content;
    }
}

/* Sidebar Cards */
.sidebar-card {
    background-color: var(--bg-card, #FFFFFF);
    border: 1px solid var(--border-default, #E8E5E0);
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 1rem;
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.sidebar-card:hover {
    border-color: var(--border-hover, #D4D0CA);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

html.dark .sidebar-card {
    background-color: var(--bg-elevated, #222222);
    border-color: rgba(255, 255, 255, 0.12);
}

html.dark .sidebar-card:hover {
    border-color: rgba(255, 255, 255, 0.22);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.sidebar-card:last-child {
    margin-bottom: 0;
}

.sidebar-card-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary, #5C5C5C);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
    padding-left: 0.625rem;
    border-left: 2px solid var(--accent-orange, #FF6B2B);
}

html.dark .sidebar-card-title {
    color: rgba(255, 255, 255, 0.82);
}

/* Sidebar Flat Sections (no card background) */
.sidebar-section {
    padding: 0;
}

.sidebar-section-title {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted, #8C8C8C);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.375rem;
    padding: 0 0.5rem;
    padding-left: 0.625rem;
    border-left: 2px solid var(--accent-orange, #FF6B2B);
}

html.dark .sidebar-section-title {
    color: var(--text-muted, rgba(255, 255, 255, 0.45));
}

.sidebar-divider {
    height: 1px;
    background-color: var(--border-default, #E8E5E0);
    margin: 0.75rem 0.5rem;
    flex-shrink: 0;
}

html.dark .sidebar-divider {
    background-color: var(--border-default, rgba(255, 255, 255, 0.08));
}

/* "Show more/less" toggle button */
.sidebar-toggle-btn {
    color: var(--text-muted, #8C8C8C);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.sidebar-toggle-btn:hover {
    color: var(--accent-orange, #FF6B2B);
    background-color: var(--bg-sidebar, #F5F3F0);
}

html.dark .sidebar-toggle-btn {
    color: var(--text-muted, rgba(255, 255, 255, 0.45));
}

html.dark .sidebar-toggle-btn:hover {
    color: var(--accent-orange, #FF6B2B);
    background-color: var(--bg-elevated, #242424);
}

/* Sidebar Navigation Links */
.sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.75rem;
    margin: 0 -0.75rem;
    font-size: 0.875rem;
    color: #374151;
    border-radius: 0.5rem;
    transition: background-color 0.15s, color 0.15s;
}

/* Compact variant for flat sidebar */
.sidebar-nav-link-compact {
    padding: 0.375rem 0.5rem;
    margin: 0;
    font-size: 0.8125rem;
    gap: 0.5rem;
    border-radius: 0.375rem;
}

.sidebar-nav-link:hover {
    background-color: #f3f4f6;
    color: #111827;
}

.sidebar-nav-link.active {
    background-color: #eff6ff;
    color: #2563eb;
    font-weight: 500;
}

html.dark .sidebar-nav-link {
    color: #d1d5db;
}

html.dark .sidebar-nav-link:hover {
    background-color: #374151;
    color: #f9fafb;
}

html.dark .sidebar-nav-link.active {
    background-color: #1e3a8a;
    color: #93c5fd;
}

/* Sidebar Mini Product Card */
.sidebar-product {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
}

.sidebar-product:not(:last-child) {
    border-bottom: 1px solid #f3f4f6;
}

html.dark .sidebar-product:not(:last-child) {
    border-bottom-color: #374151;
}

.sidebar-product-logo {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.5rem;
    object-fit: cover;
    flex-shrink: 0;
}

.sidebar-product-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

html.dark .sidebar-product-name {
    color: #f9fafb;
}

.sidebar-product-meta {
    font-size: 0.75rem;
    color: #6b7280;
}

html.dark .sidebar-product-meta {
    color: #9ca3af;
}

/* ============================================
   Form Input Styles (Touch-optimized)
   ============================================ */

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    min-height: 48px;
    font-size: 1rem;
    line-height: 1.5;
    color: #111827;
    background-color: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 0.75rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-input::placeholder {
    color: #9ca3af;
}

html.dark .form-input {
    background-color: #1f2937;
    border-color: #4b5563;
    color: #f9fafb;
}

html.dark .form-input:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

html.dark .form-input::placeholder {
    color: #6b7280;
}

/* Textarea */
.form-textarea {
    min-height: 120px;
    resize: vertical;
}

/* Select */
.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1.25rem;
    padding-right: 2.5rem;
}

html.dark .form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%239ca3af' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
}

/* Checkbox & Radio */
.form-checkbox,
.form-radio {
    width: 1.25rem;
    height: 1.25rem;
    color: #2563eb;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    cursor: pointer;
    flex-shrink: 0;
}

.form-radio {
    border-radius: 50%;
}

html.dark .form-checkbox,
html.dark .form-radio {
    border-color: #4b5563;
    background-color: #1f2937;
}

/* Button */
.form-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.75rem 1.5rem;
    min-height: 48px;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
}

.form-button:active {
    transform: scale(0.98);
}

.form-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.form-button-primary {
    background-color: #2563eb;
    color: #ffffff;
    border: none;
}

.form-button-primary:hover:not(:disabled) {
    background-color: #1d4ed8;
}

html.dark .form-button-primary {
    background-color: #3b82f6;
}

html.dark .form-button-primary:hover:not(:disabled) {
    background-color: #60a5fa;
}

.form-button-secondary {
    background-color: transparent;
    color: #374151;
    border: 1px solid #d1d5db;
}

.form-button-secondary:hover:not(:disabled) {
    background-color: #f9fafb;
    border-color: #9ca3af;
}

html.dark .form-button-secondary {
    color: #d1d5db;
    border-color: #4b5563;
}

html.dark .form-button-secondary:hover:not(:disabled) {
    background-color: #374151;
}

/* ============================================
   Utility: Hide Scrollbar
   ============================================ */

.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

/* ============================================
   Auth Pages Override
   ============================================ */

body.bg-gradient-to-br {
    background: linear-gradient(to bottom right, #2563eb, #1e40af) !important;
}

html.dark body.bg-gradient-to-br {
    background: linear-gradient(to bottom right, #1e3a8a, #0f172a) !important;
}

body.bg-gradient-to-br .app-wrapper {
    background: transparent;
}

body.bg-gradient-to-br .app-container {
    background: transparent;
    box-shadow: none;
}

html.dark body.bg-gradient-to-br .app-container {
    background: transparent;
}

/* ============================================
   Utility: browser-only / app-only
   ============================================ */

.app-only {
    display: none !important;
}

/* ============================================
   Bottom Navigation Bar (hidden by default)
   ============================================ */

.app-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    align-items: center;
    justify-content: space-around;
    z-index: 50;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

html.dark .app-bottom-nav {
    background: #111827;
    border-top-color: #1f2937;
}

/* ============================================
   PWA Standalone Mode (CSS Media Query)
   ============================================ */

@media (display-mode: standalone), (display-mode: fullscreen) {
    :root {
        --header-height: calc(56px + env(safe-area-inset-top, 0px));
        --bottom-nav-height: 60px;
        /* Reset sidebars for PWA mode */
        --sidebar-left-width: 0px;
        --sidebar-right-width: 0px;
        --content-max-width: 100%;
        --page-padding-x: 1rem;
    }

    /* Full-width, no container effect */
    .app-container {
        max-width: 100% !important;
        box-shadow: none !important;
        margin: 0 !important;
    }

    body {
        padding: 0 !important;
        overscroll-behavior-y: contain;
    }

    /* Reserve space for bottom nav */
    .app-main-content {
        padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    }

    /* Hide sidebars in PWA mode */
    .sidebar-left,
    .sidebar-right {
        display: none !important;
    }

    /* Page layout becomes single column */
    .page-layout {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: unset !important;
    }

    /* Show bottom nav */
    .app-bottom-nav {
        display: flex !important;
    }

    /* Hide browser-only elements */
    .browser-only {
        display: none !important;
    }

    /* Show app-only elements */
    .app-only {
        display: flex !important;
    }

    /* Hide footer in PWA */
    .app-footer {
        display: none !important;
    }

    /* Status bar blur overlay (iOS notch) */
    header::before {
        content: '';
        position: absolute;
        top: calc(-1 * env(safe-area-inset-top, 0px));
        left: 0;
        right: 0;
        height: env(safe-area-inset-top, 0px);
        background: rgba(255, 255, 255, 0.85);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        z-index: 1;
    }

    html.dark header::before {
        background: rgba(17, 24, 39, 0.85);
    }

    /* Touch targets */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="url"],
    input[type="number"],
    input[type="tel"],
    textarea,
    select {
        min-height: 48px;
        font-size: 16px; /* Prevent auto-zoom on iOS */
    }

    button,
    [role="button"],
    .btn {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ============================================
   PWA Standalone: Landscape Mode
   ============================================ */

@media (display-mode: standalone) and (orientation: landscape) {
    .app-container {
        padding-left: env(safe-area-inset-left, 0px);
        padding-right: env(safe-area-inset-right, 0px);
    }

    .app-bottom-nav {
        padding-left: env(safe-area-inset-left, 0px);
        padding-right: env(safe-area-inset-right, 0px);
    }
}

/* ============================================
   PWA Standalone: JS-Class Fallback
   (Enables Playwright testing)
   ============================================ */

html.pwa-standalone .app-container {
    max-width: 100% !important;
    box-shadow: none !important;
    margin: 0 !important;
}

html.pwa-standalone body {
    padding: 0 !important;
    overscroll-behavior-y: contain;
}

html.pwa-standalone .app-main-content {
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
}

/* Hide sidebars in PWA mode */
html.pwa-standalone .sidebar-left,
html.pwa-standalone .sidebar-right {
    display: none !important;
}

/* Page layout becomes single column */
html.pwa-standalone .page-layout {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: unset !important;
}

html.pwa-standalone .app-bottom-nav {
    display: flex !important;
}

html.pwa-standalone .browser-only {
    display: none !important;
}

html.pwa-standalone .app-only {
    display: flex !important;
}

/* Hide footer in PWA */
html.pwa-standalone .app-footer {
    display: none !important;
}

html.pwa-standalone header::before {
    content: '';
    position: absolute;
    top: calc(-1 * env(safe-area-inset-top, 0px));
    left: 0;
    right: 0;
    height: env(safe-area-inset-top, 0px);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1;
}

html.pwa-standalone.dark header::before {
    background: rgba(17, 24, 39, 0.85);
}

html.pwa-standalone input[type="text"],
html.pwa-standalone input[type="email"],
html.pwa-standalone input[type="password"],
html.pwa-standalone input[type="search"],
html.pwa-standalone input[type="url"],
html.pwa-standalone input[type="number"],
html.pwa-standalone input[type="tel"],
html.pwa-standalone textarea,
html.pwa-standalone select {
    min-height: 48px;
    font-size: 16px;
}

html.pwa-standalone button,
html.pwa-standalone [role="button"],
html.pwa-standalone .btn {
    min-height: 44px;
    min-width: 44px;
}

/* Landscape fallback */
html.pwa-standalone .app-container {
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
}

/* ============================================
   Keyboard Open: Hide Bottom Nav
   ============================================ */

html.keyboard-open .app-bottom-nav {
    display: none !important;
}

html.keyboard-open .app-main-content {
    padding-bottom: 0;
}

/* ============================================
   Pull-to-Refresh Indicator
   ============================================ */

.ptr-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-60px);
    width: 40px;
    height: 40px;
    background: #ffffff;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease-out;
    z-index: 9999;
}

html.dark .ptr-indicator {
    background: #1f2937;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.ptr-icon {
    width: 20px;
    height: 20px;
    color: #3b82f6;
    transition: transform 0.15s;
}

.ptr-indicator.ptr-ready .ptr-icon {
    color: #10b981;
}

.ptr-indicator.ptr-refreshing .ptr-icon {
    animation: ptr-spin 0.8s linear infinite;
}

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

/* ============================================
   Rank Badges
   ============================================ */

.rank-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 0.375rem;
    color: var(--text-muted, #8C8C8C);
    background: transparent;
    flex-shrink: 0;
}

.rank-badge-1 {
    color: #D97706;
    background: linear-gradient(135deg, #FEF3C7, #FDE68A);
}

.rank-badge-2 {
    color: #6B7280;
    background: linear-gradient(135deg, #F3F4F6, #E5E7EB);
}

.rank-badge-3 {
    color: #B45309;
    background: linear-gradient(135deg, #FDE68A, #D97706);
}

.rank-badge-4,
.rank-badge-5 {
    color: var(--text-secondary, #5C5C5C);
    background: var(--bg-sidebar, #F5F3F0);
}

html.dark .rank-badge {
    color: var(--text-muted, rgba(255, 255, 255, 0.45));
}

html.dark .rank-badge-1 {
    color: #FBBF24;
    background: rgba(251, 191, 36, 0.15);
}

html.dark .rank-badge-2 {
    color: #9CA3AF;
    background: rgba(156, 163, 175, 0.15);
}

html.dark .rank-badge-3 {
    color: #F59E0B;
    background: rgba(245, 158, 11, 0.15);
}

html.dark .rank-badge-4,
html.dark .rank-badge-5 {
    color: var(--text-secondary, rgba(255, 255, 255, 0.65));
    background: var(--bg-elevated, #242424);
}

/* ============================================
   Micro-Interactions
   ============================================ */

/* Product card hover lift */
.pc-item {
    transition: background-color 0.15s ease;
    border-radius: 0.75rem;
}

@media (min-width: 640px) {
    .pc-item {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }
}

.pc-item:hover {
    background-color: var(--bg-sidebar, #F5F3F0);
}

html.dark .pc-item:hover {
    background-color: var(--bg-elevated, #242424);
}

/* Upvote button pop animation */
[data-testid="upvote-button"] {
    transition: transform 0.12s ease-out, background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

[data-testid="upvote-button"]:active {
    transform: scale(0.92);
}

[data-testid="upvote-button"].upvote-pop {
    animation: upvote-pop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes upvote-pop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.15); }
    70%  { transform: scale(0.95); }
    100% { transform: scale(1); }
}

/* Staggered card entrance */
[data-testid="product-card"] {
    animation: fade-in-up 0.35s ease-out both;
}

[data-testid="product-card"]:nth-child(1) { animation-delay: 0ms; }
[data-testid="product-card"]:nth-child(2) { animation-delay: 40ms; }
[data-testid="product-card"]:nth-child(3) { animation-delay: 80ms; }
[data-testid="product-card"]:nth-child(4) { animation-delay: 120ms; }
[data-testid="product-card"]:nth-child(5) { animation-delay: 160ms; }
[data-testid="product-card"]:nth-child(6) { animation-delay: 200ms; }
[data-testid="product-card"]:nth-child(7) { animation-delay: 240ms; }
[data-testid="product-card"]:nth-child(8) { animation-delay: 280ms; }
[data-testid="product-card"]:nth-child(n+9) { animation-delay: 300ms; }

@keyframes fade-in-up {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Main content page entrance */
.main-content {
    animation: page-enter 0.4s ease-out;
}

@keyframes page-enter {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Filter tab active indicator transition */
.filter-tab {
    transition: background-color 0.15s ease, color 0.15s ease;
}

/* Category pill hover scale */
a[href*="category="] {
    transition: transform 0.12s ease-out, border-color 0.15s, background-color 0.15s;
}

a[href*="category="]:hover {
    transform: scale(1.02);
}

/* Top categories card hover */
.grid a[href*="category="] {
    transition: transform 0.15s ease-out, border-color 0.15s, box-shadow 0.15s;
}

.grid a[href*="category="]:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

html.dark .grid a[href*="category="]:hover {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* Smooth section entrance with IntersectionObserver */
.section-animate {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

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

/* ============================================
   Dark Mode Toggle Button
   ============================================ */

[data-testid="dark-mode-toggle"] {
    min-width: 44px;
    min-height: 44px;
}

[data-testid="dark-mode-toggle"]:active {
    transform: scale(0.95);
}

/* Smooth dark mode transitions */
html.transitioning *,
html.transitioning *::before,
html.transitioning *::after {
    transition: background-color 0.2s ease,
                color 0.2s ease,
                border-color 0.2s ease,
                box-shadow 0.2s ease !important;
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    [data-testid="product-card"],
    [data-testid="upvote-button"],
    a[href*="category="],
    .grid a[href*="category="],
    .section-animate {
        animation: none !important;
        transition: none !important;
    }

    [data-testid="product-card"]:hover,
    .grid a[href*="category="]:hover {
        transform: none !important;
        box-shadow: none !important;
    }
}
