/* ===================================
   Design System - CSS Variables
   =================================== */
:root {
    /* Colors */
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #ec4899;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    /* Neutrals */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* Background */
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --bg-dark: #111827;
    --bg-overlay: rgba(0, 0, 0, 0.5);

    /* Text */
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --text-white: #ffffff;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-3xl: 4rem;

    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Transitions */
    --transition-fast: 150ms ease-in-out;
    --transition-base: 250ms ease-in-out;
    --transition-slow: 350ms ease-in-out;

    /* Typography - Fluid Sizing */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-size-xs: clamp(0.7rem, 0.65rem + 0.25vw, 0.75rem);
    --font-size-sm: clamp(0.8rem, 0.75rem + 0.25vw, 0.875rem);
    --font-size-base: clamp(0.9rem, 0.85rem + 0.25vw, 1rem);
    --font-size-lg: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
    --font-size-xl: clamp(1.1rem, 1rem + 0.5vw, 1.25rem);
    --font-size-2xl: clamp(1.25rem, 1.1rem + 0.75vw, 1.5rem);
    --font-size-3xl: clamp(1.5rem, 1.3rem + 1vw, 1.875rem);
    --font-size-3xl: clamp(1.5rem, 1.3rem + 1vw, 1.875rem);
    --font-size-4xl: clamp(1.75rem, 1.5rem + 1.25vw, 2.25rem);

    /* Sync Status Colors */
    --status-success: #ecfdf5;
    --status-success-text: #059669;
    --status-warning: #fffbeb;
    --status-warning-text: #d97706;
    --status-error: #fef2f2;
    --status-error-text: #dc2626;

    /* Responsive Breakpoints */
    --breakpoint-xs: 375px;
    /* Small phones */
    --breakpoint-sm: 640px;
    /* Large phones */
    --breakpoint-md: 768px;
    /* Tablets portrait */
    --breakpoint-lg: 1024px;
    /* Tablets landscape / Small laptops */
    --breakpoint-xl: 1280px;
    /* Laptops */
    --breakpoint-2xl: 1536px;
    /* Desktops */
}

/* ===================================
   Dark Mode Theme
   =================================== */
body.dark-mode {
    /* Dark Background */
    --bg-primary: #1f2937;
    --bg-secondary: #111827;
    --bg-tertiary: #374151;
    --bg-overlay: rgba(0, 0, 0, 0.7);

    /* Dark Text - LIGHT colors for dark backgrounds */
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --text-tertiary: #9ca3af;

    /* Adjusted Grays for Dark Mode */
    --gray-50: #374151;
    --gray-100: #4b5563;
    --gray-200: #6b7280;
    --gray-300: #9ca3af;

    /* Shadows for Dark Mode */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6), 0 10px 10px -5px rgba(0, 0, 0, 0.5);
}

/* Force light text in dark mode for all elements */
body.dark-mode,
body.dark-mode input,
body.dark-mode select,
body.dark-mode textarea,
body.dark-mode .stat-label,
body.dark-mode .stat-value {
    color: var(--text-primary) !important;
}

body.dark-mode input::placeholder,
body.dark-mode textarea::placeholder {
    color: var(--text-secondary) !important;
}

/* Dark mode for all input types including date, datetime-local, etc. */
body.dark-mode input[type="date"],
body.dark-mode input[type="datetime-local"],
body.dark-mode input[type="time"],
body.dark-mode input[type="week"],
body.dark-mode input[type="month"],
body.dark-mode input[type="text"],
body.dark-mode input[type="search"],
body.dark-mode input[type="number"],
body.dark-mode input[type="email"],
body.dark-mode input[type="tel"],
body.dark-mode select,
body.dark-mode textarea {
    background: var(--bg-tertiary) !important;
    border-color: var(--gray-200) !important;
    color: var(--text-primary) !important;
}

/* Dark mode for date picker calendar icon */
body.dark-mode input[type="date"]::-webkit-calendar-picker-indicator,
body.dark-mode input[type="datetime-local"]::-webkit-calendar-picker-indicator,
body.dark-mode input[type="time"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
    cursor: pointer;
}

/* Dark mode for search input icons */
body.dark-mode input[type="search"]::-webkit-search-cancel-button {
    filter: invert(1);
}

/* Dark mode for number input spinners */
body.dark-mode input[type="number"]::-webkit-inner-spin-button,
body.dark-mode input[type="number"]::-webkit-outer-spin-button {
    filter: invert(1);
}

/* Dark mode focus states */
body.dark-mode input:focus,
body.dark-mode select:focus,
body.dark-mode textarea:focus {
    background: var(--bg-tertiary) !important;
    border-color: var(--primary) !important;
}

/* Theme Toggle Button */
.theme-toggle {
    font-size: 1.5rem;
    padding: 0.5rem;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.theme-toggle:hover {
    transform: scale(1.1);
}

/* ===================================
   Reset & Base Styles
   =================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    overflow-x: hidden;
    /* Force fit to width */
    max-width: 100vw;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    transition: background-color var(--transition-base), color var(--transition-base);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: var(--space-md);
}

h1 {
    font-size: var(--font-size-4xl);
}

h2 {
    font-size: var(--font-size-3xl);
}

h3 {
    font-size: var(--font-size-2xl);
}

h4 {
    font-size: var(--font-size-xl);
}

h5 {
    font-size: var(--font-size-lg);
}

h6 {
    font-size: var(--font-size-base);
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--primary-dark);
}

/* ===================================
   Utility Classes
   =================================== */
.hidden {
    display: none !important;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-lg);
}

/* ===================================
   Loading Screen
   =================================== */
.loading-screen {
    position: fixed;
    inset: 0;
    /* Human-designed warm gradient - avoiding typical AI purple/blue */
    background: linear-gradient(135deg, #FF8C42 0%, #FF6B35 50%, #F7931E 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    overflow: hidden;
}

/* Subtle texture overlay for human feel */
.loading-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(0, 0, 0, 0.05) 0%, transparent 50%);
    pointer-events: none;
}

.loading-content {
    text-align: center;
    color: white;
    position: relative;
    z-index: 1;
}

.preloader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.preloader-title {
    font-size: clamp(2.5rem, 8vw, 4.5rem);
    font-weight: 900;
    letter-spacing: 0.15em;
    margin: 0;
    color: #fff;
    text-shadow:
        0 2px 10px rgba(0, 0, 0, 0.2),
        0 4px 20px rgba(0, 0, 0, 0.15);
    font-family: 'Poppins', 'Inter', 'Segoe UI', sans-serif;

    /* Elegant reveal animation */
    opacity: 0;
    transform: translateY(20px);
    animation: revealTitle 1s ease-out 0.3s forwards;
}

.preloader-tagline {
    font-size: clamp(1.1rem, 3vw, 1.8rem);
    font-weight: 600;
    margin: 0;
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    font-family: 'Poppins', 'Inter', 'Segoe UI', sans-serif;
    line-height: 1.4;

    /* Sequential reveal - appears after title */
    opacity: 0;
    transform: translateY(15px);
    animation: revealTagline 0.8s ease-out 1.2s forwards;
}

/* Elegant reveal animations */
@keyframes revealTitle {
    0% {
        opacity: 0;
        transform: translateY(20px);
        letter-spacing: 0.05em;
    }

    100% {
        opacity: 1;
        transform: translateY(0);
        letter-spacing: 0.15em;
    }
}

@keyframes revealTagline {
    0% {
        opacity: 0;
        transform: translateY(15px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===================================
   Buttons
   =================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    font-size: var(--font-size-base);
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover:not(:disabled) {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--gray-200);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-warning:hover:not(:disabled) {
    background: var(--warning-dark);
    box-shadow: var(--shadow-md);
}

.btn-text {
    background: transparent;
    color: var(--text-secondary);
    padding: var(--space-sm);
}

.btn-text:hover {
    color: var(--text-primary);
}

.btn-large {
    padding: var(--space-md) var(--space-xl);
    font-size: var(--font-size-lg);
}

.btn-small {
    padding: var(--space-xs) var(--space-md);
    font-size: var(--font-size-sm);
    min-height: 36px;
    min-width: 36px;
}

/* Touch-friendly sizing for mobile */
.btn,
.menu-item,
button:not(.btn-small) {
    min-height: 44px;
    min-width: 44px;
}

/* ===================================
   Forms
   =================================== */
.form-group {
    margin-bottom: var(--space-lg);
}

.form-group label {
    display: block;
    margin-bottom: var(--space-sm);
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: var(--space-md);
    font-size: max(16px, var(--font-size-base));
    /* Prevents iOS zoom */
    font-family: var(--font-family);
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all var(--transition-base);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Form Validation Styles */
.form-group input:invalid:not(:placeholder-shown),
.form-group select:invalid:not(:placeholder-shown),
.form-group textarea:invalid:not(:placeholder-shown),
.form-group input.error,
.form-group select.error,
.form-group textarea.error {
    border-color: var(--danger);
    background-color: rgba(239, 68, 68, 0.05);
}

.form-group input:invalid:not(:placeholder-shown):focus,
.form-group select:invalid:not(:placeholder-shown):focus,
.form-group textarea:invalid:not(:placeholder-shown):focus,
.form-group input.error:focus,
.form-group select.error:focus,
.form-group textarea.error:focus {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-error-message {
    display: block;
    color: var(--danger);
    font-size: var(--font-size-sm);
    margin-top: var(--space-xs);
    font-weight: 500;
    animation: slideDown 0.2s ease-out;
}

.form-error-message::before {
    content: "⚠️ ";
    margin-right: 0.25rem;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Required field indicator */
.form-group label .required-indicator {
    color: var(--danger);
    margin-left: 0.25rem;
}

/* ===================================
   Cards
   =================================== */
.card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: var(--space-xl);
    transition: all var(--transition-base);
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

.card-header {
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-lg);
    border-bottom: 2px solid var(--gray-100);
}

.card-title {
    font-size: var(--font-size-2xl);
    font-weight: 600;
    margin-bottom: var(--space-sm);
}

/* ===================================
   Grid System
   =================================== */
.grid {
    display: grid;
    gap: var(--space-lg);
}

.grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-cols-4 {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 768px) {

    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: 1fr;
    }
}

/* ===================================
   App Container Layout
   =================================== */
.app-container {
    display: grid;
    grid-template-areas:
        "nav nav"
        "sidebar main";
    grid-template-columns: 250px 1fr;
    grid-template-rows: 70px 1fr;
    height: 100vh;
    overflow: hidden;
}

/* Offline Banner */
.offline-banner {
    background: var(--warning);
    color: white;
    text-align: center;
    padding: var(--space-xs) var(--space-md);
    font-size: var(--font-size-sm);
    font-weight: 600;
    position: fixed;
    top: 70px;
    /* Below navbar */
    left: 0;
    width: 100%;
    z-index: 99;
    box-shadow: var(--shadow-md);
    animation: slideDown 0.3s ease-out;
}

/* Sync Status Indicator */
.sync-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: 500;
    margin-right: var(--space-md);
    transition: all var(--transition-base);
}

.sync-status.synced {
    background: var(--status-success);
    color: var(--status-success-text);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.sync-status.syncing {
    background: var(--status-warning);
    color: var(--status-warning-text);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.sync-status.offline {
    background: var(--status-error);
    color: var(--status-error-text);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.sync-status.pending {
    background: var(--status-warning);
    color: var(--status-warning-text);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.sync-icon {
    font-size: 1rem;
}

/* Dark mode overrides for sync status */
body.dark-mode .sync-status.synced {
    background: rgba(5, 150, 105, 0.2);
    color: #34d399;
    border-color: rgba(5, 150, 105, 0.3);
}

body.dark-mode .sync-status.syncing,
body.dark-mode .sync-status.pending {
    background: rgba(217, 119, 6, 0.2);
    color: #fbbf24;
    border-color: rgba(217, 119, 6, 0.3);
}

body.dark-mode .sync-status.offline {
    background: rgba(220, 38, 38, 0.2);
    color: #f87171;
    border-color: rgba(220, 38, 38, 0.3);
}

/* Connection Status Indicator */
.connection-status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: 500;
    margin-right: var(--space-sm);
    transition: all var(--transition-base);
}

.connection-status.online {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.connection-status.offline {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.connection-icon {
    font-size: 0.9rem;
}

/* Dark mode for connection status */
body.dark-mode .connection-status.online {
    background: rgba(5, 150, 105, 0.15);
    color: #34d399;
    border-color: rgba(5, 150, 105, 0.3);
}

body.dark-mode .connection-status.offline {
    background: rgba(220, 38, 38, 0.15);
    color: #f87171;
    border-color: rgba(220, 38, 38, 0.3);
}

.top-nav {
    grid-area: nav;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-xl);
    box-shadow: var(--shadow-sm);
    z-index: 100;
}

.nav-brand h2 {
    margin: 0;
    font-size: var(--font-size-xl);
}

.live-clock {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    font-weight: 500;
}

.clock-time,
.clock-date {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.clock-divider {
    color: var(--gray-400);
}

@media (max-width: 768px) {
    .live-clock {
        font-size: var(--font-size-xs);
        gap: 0.25rem;
    }
}


.nav-user {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.sidebar {
    grid-area: sidebar;
    background: var(--bg-primary);
    border-right: 1px solid var(--gray-200);
    overflow-y: auto;
    padding: var(--space-lg) 0;
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-xl);
    color: var(--text-secondary);
    font-weight: 500;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
}

.menu-item:hover {
    background: var(--gray-50);
    color: var(--text-primary);
}

.menu-item.active {
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.1) 0%, transparent 100%);
    color: var(--primary);
    border-left-color: var(--primary);
}

.menu-item .icon {
    font-size: var(--font-size-xl);
}

.main-content {
    grid-area: main;
    overflow-y: auto;
    padding: var(--space-xl);
}

/* ===================================
   Responsive Design
   =================================== */
@media (max-width: 768px) {
    .app-container {
        display: flex;
        flex-direction: column;
        height: auto;
        /* Remove fixed height */
        min-height: 100vh;
        overflow: visible;
        /* Allow body scroll */
        width: 100%;
        max-width: 100vw;
    }

    .top-nav {
        position: sticky;
        top: 0;
        z-index: 1000;
        height: auto;
        min-height: 60px;
        flex-shrink: 0;
        padding: 0.5rem var(--space-sm);
        flex-wrap: wrap;
        gap: 0.5rem;
        width: 100%;
        box-sizing: border-box;
    }

    .nav-brand {
        flex: 1 1 auto;
        min-width: 0;
    }

    .nav-brand h2 {
        font-size: var(--font-size-base);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Nav user section - ensure visibility */
    .nav-user {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        flex-wrap: nowrap;
        justify-content: flex-end;
        flex-shrink: 0;
    }

    /* Language selector - compact */
    #language-selector {
        font-size: var(--font-size-xs);
        padding: 0.25rem 0.5rem;
        min-width: auto;
    }

    /* User email - make it smaller but visible */
    .nav-user .user-email {
        font-size: var(--font-size-xs);
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Logout button - always visible */
    .nav-user .btn {
        font-size: var(--font-size-xs);
        padding: 0.25rem 0.5rem;
        min-height: 32px;
        min-width: auto;
        white-space: nowrap;
        display: inline-flex;
        align-items: center;
        gap: 0.25rem;
    }

    /* Theme toggle */
    .theme-toggle {
        font-size: 1.2rem;
        padding: 0.25rem;
    }

    /* Sidebar Mobile: Off-canvas (Same as Tablet) */
    .sidebar {
        display: block !important;
        position: fixed;
        left: 0;
        top: auto;
        /* Allow top to vary or be handled by layout */
        bottom: 60px;
        /* Above bottom nav */
        top: 60px;
        /* Below top nav */
        height: auto;
        z-index: 999;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: var(--shadow-xl);
        width: 250px;
        background: var(--bg-primary);
        border-right: 1px solid var(--gray-200);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Show hamburger on mobile too */
    .menu-toggle {
        display: inline-flex !important;
    }

    .main-content {
        padding: var(--space-md);
        padding-bottom: 90px;
        /* Space for bottom nav */
        overflow: visible;
        /* Let body scroll */
        height: auto;
        flex: 1;
        width: 100%;
        max-width: 100vw;
        box-sizing: border-box;
    }

    /* Module actions stack vertically */
    .module-actions {
        flex-direction: column;
        width: 100%;
    }

    .module-actions .btn {
        width: 100%;
    }

    /* Module header responsive */
    .module-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-md);
    }
}

/* Very small screens - hide logout text, show only icon */
@media (max-width: 420px) {
    .nav-user .user-email {
        max-width: 100px;
    }

    .logout-text {
        display: none;
    }

    .logout-icon {
        display: inline;
    }

    #logout-btn {
        padding: 0.25rem 0.5rem;
        min-width: 36px;
    }
}

/* ===================================
   Bottom Navigation (Mobile)
   =================================== */
.bottom-nav {
    display: none;
    /* Hidden on desktop */
}

@media (max-width: 768px) {
    .bottom-nav {
        display: block;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-primary);
        border-top: 1px solid var(--gray-200);
        padding: 0.5rem 0;
        z-index: 1000;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }

    .bottom-nav-items {
        display: flex;
        justify-content: space-around;
        align-items: center;
        max-width: 600px;
        margin: 0 auto;
    }

    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.25rem;
        padding: 0.5rem;
        min-width: 60px;
        font-size: 0.7rem;
        color: var(--text-secondary);
        text-decoration: none;
        transition: color 0.2s;
        border-radius: var(--radius-sm);
    }

    .bottom-nav-item.active {
        color: var(--primary);
        background: rgba(99, 102, 241, 0.1);
    }

    .bottom-nav-item .icon {
        font-size: 1.5rem;
    }
}

/* ===================================
   Tablet Responsive (769px - 1024px)
   =================================== */
@media (min-width: 769px) and (max-width: 1024px) {
    .app-container {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 70px;
        height: calc(100vh - 70px);
        z-index: 999;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: var(--shadow-xl);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Sidebar Mobile/Tablet: Off-canvas */
    .sidebar {
        display: block !important;
        /* Force display for off-canvas toggle */
        position: fixed;
        left: 0;
        top: 70px;
        height: calc(100vh - 70px);
        z-index: 999;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: var(--shadow-xl);
        width: 250px;
        /* Ensure width is fixed directly */
        background: var(--bg-primary);
        /* Ensure background */
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Show hamburger button */
    .menu-toggle {
        display: inline-flex !important;
    }
}

/* Base styles for menu toggle (hidden on desktop) */
.menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.25rem;
    padding: 0.5rem;
    cursor: pointer;
    margin-right: 0.5rem;
    border-radius: var(--radius-sm);
    transition: background-color var(--transition-fast);
}

.menu-toggle:hover {
    background-color: var(--gray-100);
}

/* ===================================
   Small Mobile (< 640px)
   =================================== */
@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: 1fr;
        gap: var(--space-md);
    }

    .card {
        padding: var(--space-md);
    }

    /* Stack form rows */
    .form-row {
        flex-direction: column;
    }

    .form-row .form-group {
        width: 100%;
    }

    /* Smaller modal padding */
    .modal {
        max-width: 95vw;
        max-height: 90vh;
        margin: 1rem;
    }

    .modal-header h2 {
        font-size: var(--font-size-lg);
    }

    .modal-footer {
        flex-direction: column-reverse;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        width: 100%;
    }
}

/* ===================================
   Landscape Mode (Mobile)
   =================================== */
@media (max-height: 600px) and (orientation: landscape) {
    .app-container {
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
        margin: 0;
        padding: 0;
    }

    .top-nav {
        height: auto;
        min-height: 48px;
        padding: 0.25rem 0.5rem;
        flex-wrap: nowrap;
        width: 100%;
    }

    .nav-brand h2 {
        font-size: 0.9rem;
    }

    .nav-user {
        gap: 0.25rem;
    }

    .nav-user .user-email {
        display: none;
        /* Hide email in landscape to save space */
    }

    .nav-user .btn {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
        min-height: 28px;
    }

    .theme-toggle {
        font-size: 1rem;
    }

    .main-content {
        padding: 0.5rem;
        padding-bottom: 60px;
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
        margin: 0;
        box-sizing: border-box;
    }

    /* Ensure Sell Section takes full width */
    #sell-section-welcome {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
    }

    .bottom-nav {
        padding: 0.25rem 0;
        height: auto;
    }

    .bottom-nav-item {
        padding: 0.25rem;
        min-width: 50px;
        font-size: 0.65rem;
    }

    .bottom-nav-item .icon {
        font-size: 1rem;
    }

    /* Reduce modal size in landscape */
    .modal {
        max-height: 85vh;
        margin: 0.5rem;
    }

    .modal-body {
        max-height: calc(85vh - 100px);
    }

    /* Compact stats */
    .stat-card {
        padding: 0.5rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }
}

/* ===================================
   Accessibility
   =================================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* ===================================
   Performance Optimizations
   =================================== */
@media (max-width: 768px) {

    /* Reduce animation duration on mobile */
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.2s !important;
    }
}

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===================================
   Animations
   =================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn var(--transition-base);
}