/* Mobile specific styles - Luxury 奢华风 */
@media (max-width: 767.98px) {
    body {
        background-color: var(--lux-bg);
    }

    #app {
        display: flex;
        flex-direction: column;
        height: 100vh;
        width: 100vw; /* Ensure full width */
        overflow-x: hidden; /* Prevent horizontal scroll */
    }

    /* 顶部标题栏 */
    .mobile-header {
        height: calc(44px + env(safe-area-inset-top));
        padding-top: env(safe-area-inset-top);
        background-color: rgba(255, 250, 242, 0.86);
        border-bottom: 1px solid #dcdcdc;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        font-weight: 500;
        font-size: 17px;
        z-index: 100;
        flex-shrink: 0;
        width: 100%;
    }
    
    .header-left, .header-right {
        position: absolute;
        top: env(safe-area-inset-top);
        height: 44px;
        display: flex;
        align-items: center;
        padding: 0 15px;
        font-size: 16px;
    }
    .header-left { left: 0; }
    .header-right { right: 0; }

    /* Search Bar inside Header (Optional) or Content */
    .mobile-search-bar {
        background: #fff;
        padding: 8px 10px;
        border-bottom: 1px solid #eee;
        position: sticky;
        top: 0;
        z-index: 90;
    }

    .mobile-search-input {
        background: #f5f5f5;
        border-radius: 4px;
        padding: 6px 30px 6px 10px;
        width: 100%;
        font-size: 14px;
        border: none;
        outline: none;
        text-align: center;
        transition: all 0.3s;
    }

    .mobile-search-input:focus {
        text-align: left;
        background: #fff;
        border: 1px solid var(--lux-burgundy);
    }

    /* Mobile Search Results */
    .mobile-search-results {
        position: absolute;
        top: 100%;
        left: 0;
        width: 100%;
        background: white;
        border-bottom: 1px solid #eee;
        box-shadow: 0 4px 10px rgba(0,0,0,0.1);
        z-index: 95;
        max-height: 50vh;
        overflow-y: auto;
    }

    .mobile-search-item {
        padding: 12px 15px;
        border-bottom: 1px solid #f5f5f5;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    /* 主内容滚动区 */
    .main-content {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        background-color: var(--lux-bg);
        padding-bottom: calc(50px + env(safe-area-inset-bottom)); /* Space for tabbar */
        width: 100%;
    }

    /* 底部导航栏 */
    .mobile-tabbar {
        height: calc(50px + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background-color: rgba(255, 250, 242, 0.92);
        border-top: 1px solid #d5d5d5;
        display: flex;
        position: fixed;
        bottom: 0;
        width: 100%;
        z-index: 100;
    }

    .tab-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        color: #191919;
        font-size: 10px;
        cursor: pointer;
        position: relative;
        -webkit-tap-highlight-color: transparent;
    }

    .tab-item.active {
        color: var(--lux-burgundy);
    }

    .mobile-tabbar .tab-item.active::before {
        content: '';
        position: absolute;
        top: 4px;
        left: 50%;
        width: 24px;
        height: 3px;
        border-radius: 999px;
        background: var(--lux-burgundy);
        transform: translateX(-50%);
    }

    .tab-icon {
        font-size: 20px;
        margin-bottom: 2px;
    }

    /* 列表样式 */
    .mobile-list-item {
        background: white;
        padding: 15px;
        border-bottom: 1px solid #efefef;
        display: flex;
        align-items: center;
    }
    
    .mobile-list-item:active {
        background-color: #f5f5f5;
    }

    /* 登录页全屏优化 */
    .login-container {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: linear-gradient(135deg, #f5f7fa 0%, #ffffff 100%);
        z-index: 200;
        padding: 20px;
        padding-top: max(20px, env(safe-area-inset-top));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    /* 登录卡片适配移动端 */
    .login-box {
        width: 100% !important;
        max-width: 360px;
        margin: 0 auto;
        background: white;
        border-radius: 16px;
        box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
        padding: 32px 24px !important;
        text-align: center;
    }

    /* 优化 Logo 和标题 */
    .login-box .fas.fa-cubes {
        font-size: 40px !important;
        color: var(--lux-burgundy);
    }

    .login-box h2 {
        margin-top: 12px !important;
        margin-bottom: 24px !important;
        font-size: 22px;
        font-weight: 500;
        color: var(--lux-ink);
    }

    /* 优化输入框 */
    .login-box .input-group {
        margin-bottom: 16px;
    }

    .login-box .input-control {
        height: 48px !important;
        font-size: 16px !important;
        border-radius: 12px !important;
        padding: 0 16px !important;
        border: 1px solid #e5e5e5 !important;
        background-color: #f8f8f8;
        transition: all 0.3s;
    }

    .login-box .input-control:focus {
        background-color: white;
        border-color: var(--lux-burgundy) !important;
        box-shadow: 0 0 0 3px rgba(90, 22, 35, 0.10);
    }

    /* 优化按钮 */
    .login-box .btn-block {
        height: 48px !important;
        font-size: 16px !important;
        border-radius: 12px !important;
        font-weight: 500;
        margin-top: 8px;
        box-shadow: 0 2px 8px rgba(90, 22, 35, 0.20);
        transition: all 0.3s;
    }

    .login-box .btn-block:active {
        transform: scale(0.98);
        box-shadow: 0 1px 4px rgba(90, 22, 35, 0.20);
    }

    /* 优化链接 */
    .login-box a {
        font-size: 14px;
        text-decoration: none;
        color: var(--lux-burgundy);
        padding: 8px;
        display: inline-block;
        transition: opacity 0.3s;
    }

    .login-box a:active {
        opacity: 0.7;
    }

    /* 表单间距优化 */
    .login-box #login-form-container,
    .login-box #register-form-container {
        margin-top: 8px;
    }

    /* 仪表盘移动端优化 - 更紧凑的布局 */
    .content-body .grid {
        gap: 8px !important; /* 进一步缩小卡片间距 */
    }

    .content-body .gap-4 {
        gap: 8px !important; /* 覆盖所有 gap-4 */
    }

    .content-body .mb-6 {
        margin-bottom: 12px !important; /* 进一步缩小板块间距 */
    }

    .content-body .card {
        padding: 10px !important; /* 进一步缩小卡片内边距 */
        margin-bottom: 0 !important; /* 移除默认底部间距 */
    }

    /* 优化核心指标卡片 */
    .content-body .grid-cols-2 .card,
    .content-body .md\:grid-cols-4 .card {
        padding: 12px 10px !important;
    }

    .content-body .grid-cols-2 .card .text-xs,
    .content-body .md\:grid-cols-4 .card .text-xs {
        font-size: 11px !important;
    }

    .content-body .grid-cols-2 .card .text-xl,
    .content-body .md\:grid-cols-4 .card .text-xl {
        font-size: 18px !important;
        margin-top: 4px !important;
    }

    /* 优化快捷功能卡片 */
    .content-body .grid-cols-4 .card {
        padding: 12px 8px !important;
    }

    .content-body .grid-cols-4 .card .w-12 {
        width: 36px !important;
        height: 36px !important;
        margin-bottom: 4px !important;
    }

    .content-body .grid-cols-4 .card .text-xl {
        font-size: 16px !important;
    }

    .content-body .grid-cols-4 .card .text-sm {
        font-size: 12px !important;
    }

    /* 优化标题 */
    .content-body h3 {
        margin-bottom: 8px !important;
        font-size: 13px !important;
    }

    /* 优化动态列表 */
    .content-body .divide-y > div {
        padding: 10px 12px !important;
    }

    .content-body .divide-y .w-8 {
        width: 32px !important;
        height: 32px !important;
    }

    .content-body .divide-y .text-sm {
        font-size: 13px !important;
    }

    .content-body .divide-y .text-xs {
        font-size: 11px !important;
    }

    /* 商品列表和订单列表无缝衔接优化 - 强制移除所有间距 */
    #mobile-list-container {
        gap: 0 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    /* 移动端所有 flex-col gap-2 容器的间距移除 */
    .mobile-only.flex.flex-col.gap-2,
    .mobile-only.flex-col.gap-2,
    div.mobile-only[class*="gap-2"] {
        gap: 0 !important;
    }

    /* 商品列表卡片优化 */
    #mobile-list-container .card,
    #mobile-list-container > .card,
    .mobile-only #mobile-list-container .card {
        border-radius: 0 !important;
        margin: 0 !important;
        margin-bottom: 0 !important;
        border-left: none !important;
        border-right: none !important;
        border-top: none !important;
        border-bottom: 1px solid #f0f0f0 !important;
        padding: 12px 16px !important;
        box-shadow: none !important;
    }

    #mobile-list-container .card:first-child {
        border-top: 1px solid #f0f0f0 !important;
    }

    #mobile-list-container .card:last-child {
        border-bottom: none !important;
    }

    /* 订单列表卡片优化 - 多重选择器确保覆盖 */
    .mobile-only .flex.flex-col.gap-2 > .card,
    .mobile-only.flex.flex-col.gap-2 > .card,
    .mobile-only > .flex-col > .card,
    .mobile-only .card {
        border-radius: 0 !important;
        margin: 0 !important;
        margin-bottom: 0 !important;
        border-left: none !important;
        border-right: none !important;
        border-top: none !important;
        border-bottom: 1px solid #f0f0f0 !important;
        padding: 12px 16px !important;
        box-shadow: none !important;
    }

    .mobile-only .flex.flex-col.gap-2 > .card:first-child,
    .mobile-only.flex.flex-col.gap-2 > .card:first-child {
        border-top: 1px solid #f0f0f0 !important;
    }

    .mobile-only .flex.flex-col.gap-2 > .card:last-child,
    .mobile-only.flex.flex-col.gap-2 > .card:last-child {
        border-bottom: none !important;
    }

    /* Drawer Styles (Fixed for Vanilla CSS) */
    #mobile-drawer-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 200;
        /* Visibility managed by .hidden class */
        transition: opacity 0.3s ease;
    }
    
    #mobile-drawer {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 75%;
        max-width: 300px;
        background-color: white;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        z-index: 201;
        
        /* Transformation */
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        
        /* Layout */
        display: flex;
        flex-direction: column;
        padding-top: env(safe-area-inset-top);
    }

    #mobile-drawer.open {
        transform: translateX(0);
    }

    .drawer-header {
        padding: 20px;
        background-color: var(--lux-burgundy);
        color: white;
        font-weight: 600;
        font-size: 18px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .drawer-header i {
        opacity: 0.8;
        padding: 5px;
    }

    .drawer-body {
        padding: 10px 0;
        flex: 1;
        overflow-y: auto;
        background-color: white;
    }

    /* Drawer Menu Items Styling */
    #mobile-drawer .list-item {
        padding: 16px 20px; /* Larger touch area */
        border-bottom: 1px solid #f9f9f9;
        transition: background-color 0.2s;
        display: flex;
        align-items: center;
    }
    
    #mobile-drawer .list-item:first-child {
        border-top: 1px solid #f9f9f9;
    }

    #mobile-drawer .list-item > div:first-child {
        /* Targeting the icon container */
        width: 32px !important; /* Override inline style */
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #f5f5f5;
        border-radius: 8px;
        margin-right: 16px !important;
        color: var(--lux-muted) !important;
    }
    
    #mobile-drawer .list-item i {
        font-size: 16px;
    }

    #mobile-drawer .list-item.active > div:first-child {
        background-color: var(--lux-burgundy);
        color: white !important;
    }

    #mobile-drawer .list-item.active {
        background-color: rgba(234, 215, 174, 0.38);
        color: var(--lux-burgundy);
    }
    
    #mobile-drawer .list-item.active div[style*="font-weight"] {
        font-weight: 600 !important;
    }

    /* AI 聊天页面移动端适配 */
    .ai-chat-container {
        position: absolute !important;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        height: auto !important;
        max-height: none !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .ai-chat-messages {
        flex: 1 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 20px !important;
    }

    .chat-footer {
        position: sticky !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        background: #f7f7f7 !important;
        padding: 10px 12px !important;
        padding-bottom: calc(10px + env(safe-area-inset-bottom)) !important;
        border-top: 1px solid #e0e0e0 !important;
        z-index: 100 !important;
    }

    /* AI 聊天时隐藏底部 tabbar，避免遮挡 */
    .main-content:has(.ai-chat-container) {
        padding-bottom: 0 !important;
    }

    /* 仪表盘 Tab 面板：移动端限制高度，内部独立滚动 */
    .dash-tab-panels {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        /* 100svh - mobile-header(44px) - tabbar(50px) - content-header(~40px)
           - stats-toggle-row(~48px) - quick-actions(~120px) - tab-switcher(~44px) - gaps(~30px) */
        max-height: calc(100svh - 376px);
        /* fallback for older browsers */
        max-height: calc(100vh - 376px);
    }

    .mobile-header {
        background: rgba(255, 255, 255, 0.52);
        border-bottom: 1px solid rgba(255, 255, 255, 0.62);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
    }

    .mobile-search-bar {
        background: rgba(255, 255, 255, 0.72);
        border-bottom: 1px solid rgba(255, 255, 255, 0.62);
    }

    .mobile-search-input {
        background: rgba(255, 255, 255, 0.8);
        border-radius: 14px;
    }

    .main-content {
        background-color: transparent;
    }

    .mobile-tabbar {
        background: rgba(255, 255, 255, 0.56);
        border-top: 1px solid rgba(255, 255, 255, 0.62);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
    }

    .login-container {
        z-index: 200;
        padding: 18px;
        padding-top: max(18px, env(safe-area-inset-top));
        padding-bottom: max(18px, env(safe-area-inset-bottom));
        /* 当内容高度小于视口时垂直居中，否则允许滚动 */
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .login-shell {
        width: 100%;
        max-width: 420px;
        margin: 0 auto !important;
        min-height: auto;
        display: block;
        border-radius: 28px;
        /* 裁掉桌面端给 .login-shell 加的两个巨型装饰 orb（伪元素会溢出导致偏移） */
        overflow: hidden;
        position: relative;
        left: auto !important;
        right: auto !important;
        float: none !important;
    }

    /* 移动端禁用装饰 orb，避免 position:absolute 元素把盒子撑宽引发偏移 */
    .login-shell::before,
    .login-shell::after {
        display: none !important;
        content: none !important;
    }

    .login-brand-panel {
        display: none !important;
    }

    .login-box {
        width: 100% !important;
        max-width: 420px !important;
        margin-left: auto !important;
        margin-right: auto !important;
        padding: 24px 18px !important;
        border-radius: 24px;
        text-align: left;
        box-sizing: border-box;
    }

    .login-panel-logo {
        width: 64px;
        height: 64px;
        border-radius: 20px;
        font-size: 28px;
    }

    .login-panel-title {
        font-size: 24px;
    }

    .login-panel-subtitle {
        font-size: 12px;
    }

    .login-box .btn-block {
        border-radius: 999px !important;
    }

    .chat-footer {
        background: rgba(255, 255, 255, 0.72) !important;
        border-top: 1px solid rgba(255, 255, 255, 0.62) !important;
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }
}
