/* ========================================
   移动端响应式优化样式
   支持分辨率: 320px - 414px (主流手机)
   ======================================== */

/* 基础移动端适配 */
@media screen and (max-width: 768px) {
    html {
        font-size: 14px;
        -webkit-text-size-adjust: 100%;
    }
    
    body {
        font-size: 14px;
        line-height: 1.5;
        overflow-x: hidden;
    }
    
    .container {
        padding: 0 12px;
        width: 100%;
        max-width: 100%;
    }
    
    .header {
        padding: 10px 0;
        position: sticky;
        top: 0;
    }
    
    .header-content {
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .logo {
        font-size: 18px;
    }
    
    .user-info {
        flex: 1;
        min-width: 0;
    }
    
    .user-avatar {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    
    .user-name {
        font-size: 13px;
    }
    
    .user-role {
        font-size: 11px;
    }
    
    .nav-menu {
        display: none !important;
    }
    
    .mobile-menu-btn {
        display: flex !important;
        min-width: 40px;
        padding: 10px;
    }
    
    .sidebar {
        width: 280px;
        max-width: 85vw;
    }
    
    main {
        padding: 15px 0 !important;
    }
    
    .card {
        border-radius: 10px;
    }
    
    .card-header {
        padding: 12px 15px;
        font-size: 15px;
    }
    
    .card-body {
        padding: 15px;
    }
    
    .btn {
        padding: 10px 16px;
        font-size: 13px;
        border-radius: 8px;
    }
    
    .btn-sm {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .btn-lg {
        padding: 12px 20px;
        font-size: 14px;
    }
    
    .form-control {
        padding: 10px 12px;
        font-size: 16px;
    }
    
    .form-label {
        font-size: 13px;
        margin-bottom: 6px;
    }
    
    .form-group {
        margin-bottom: 15px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 20px;
    }
    
    .stat-card {
        padding: 15px;
    }
    
    .stat-value {
        font-size: 20px;
    }
    
    .stat-label {
        font-size: 12px;
    }
    
    .product-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .product-card {
        border-radius: 10px;
    }
    
    .product-image {
        height: 150px;
    }
    
    .product-info {
        padding: 12px;
    }
    
    .product-name {
        font-size: 14px;
    }
    
    .product-desc {
        font-size: 12px;
        -webkit-line-clamp: 2;
    }
    
    .product-price {
        font-size: 16px;
    }
    
    .product-meta {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table {
        min-width: 600px;
        font-size: 12px;
    }
    
    .table th,
    .table td {
        padding: 10px 8px;
        white-space: nowrap;
    }
    
    .hero {
        padding: 30px 0;
    }
    
    .hero h1 {
        font-size: 22px;
        margin-bottom: 10px;
    }
    
    .hero p {
        font-size: 14px;
        margin-bottom: 20px;
    }
    
    .search-box {
        flex-direction: column;
        gap: 10px;
        padding: 0 15px;
    }
    
    .search-box input {
        width: 100%;
    }
    
    .search-box .btn {
        width: 100%;
    }
    
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        padding-bottom: 5px;
    }
    
    .tab {
        padding: 10px 16px;
        font-size: 13px;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    .modal-content {
        width: 95%;
        max-height: 85vh;
        margin: 10px;
    }
    
    .modal-header {
        padding: 15px;
    }
    
    .modal-title {
        font-size: 16px;
    }
    
    .modal-body {
        padding: 15px;
    }
    
    .modal-footer {
        padding: 10px 15px;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .announcement-bar {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    .footer {
        padding: 20px 0;
        margin-top: 30px;
    }
    
    .empty-state {
        padding: 40px 15px;
    }
    
    .empty-state i {
        font-size: 36px;
    }
    
    .pagination {
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .pagination a,
    .pagination span {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .badge {
        padding: 3px 8px;
        font-size: 11px;
    }
    
    .alert {
        padding: 12px 15px;
        font-size: 13px;
    }
}

/* 小屏手机适配 (320px - 375px) */
@media screen and (max-width: 375px) {
    html {
        font-size: 13px;
    }
    
    .container {
        padding: 0 10px;
    }
    
    .header {
        padding: 8px 0;
    }
    
    .logo {
        font-size: 16px;
    }
    
    .user-info {
        gap: 8px;
    }
    
    .user-avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    .user-name {
        font-size: 12px;
    }
    
    .user-role {
        font-size: 10px;
    }
    
    .btn {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    .btn-sm {
        padding: 5px 10px;
        font-size: 11px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    
    .stat-card {
        padding: 12px;
    }
    
    .stat-value {
        font-size: 18px;
    }
    
    .stat-label {
        font-size: 11px;
    }
    
    .hero h1 {
        font-size: 18px;
    }
    
    .hero p {
        font-size: 12px;
    }
    
    .product-image {
        height: 130px;
    }
    
    .product-info {
        padding: 10px;
    }
    
    .product-name {
        font-size: 13px;
    }
    
    .product-price {
        font-size: 15px;
    }
    
    .tab {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    .sidebar {
        width: 260px;
    }
    
    .sidebar-menu a {
        padding: 12px 15px;
        font-size: 14px;
    }
    
    .modal-content {
        width: 100%;
        border-radius: 0;
        max-height: 100vh;
        height: 100%;
    }
    
    .modal {
        align-items: stretch;
    }
}

/* 超小屏手机适配 (小于320px) */
@media screen and (max-width: 320px) {
    html {
        font-size: 12px;
    }
    
    .container {
        padding: 0 8px;
    }
    
    .logo {
        font-size: 14px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .hero h1 {
        font-size: 16px;
    }
    
    .btn {
        padding: 8px 10px;
        font-size: 11px;
    }
    
    .form-control {
        padding: 8px 10px;
        font-size: 14px;
    }
}

/* 横屏模式优化 */
@media screen and (max-width: 768px) and (orientation: landscape) {
    .login-container {
        min-height: auto;
        padding: 20px;
    }
    
    .login-box {
        max-width: 400px;
        padding: 20px;
    }
    
    .modal-content {
        max-height: 90vh;
    }
}

/* 高分辨率手机 */
@media screen and (min-width: 375px) and (max-width: 414px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .product-grid {
        grid-template-columns: 1fr;
    }
}

/* iPhone X 及以上安全区域适配 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .footer {
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
    
    .music-player {
        bottom: calc(20px + env(safe-area-inset-bottom));
    }
    
    .sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    .form-control {
        min-height: 44px;
    }
    
    .sidebar-menu a {
        min-height: 44px;
    }
    
    .tab {
        min-height: 44px;
    }
    
    .music-btn {
        min-width: 44px;
        min-height: 44px;
    }
}

/* 解决iOS Safari 100vh问题 */
@supports (-webkit-touch-callout: none) {
    .login-container {
        min-height: -webkit-fill-available;
    }
    
    .sidebar {
        height: -webkit-fill-available;
    }
}

/* 页面特定优化 */

/* 买家首页 */
@media screen and (max-width: 768px) {
    .welcome-banner {
        padding: 20px 15px;
        border-radius: 15px;
        margin-bottom: 20px;
    }
    
    .welcome-banner h2 {
        font-size: 1.3rem;
    }
    
    .welcome-banner p {
        font-size: 13px;
    }
    
    .quick-actions {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 20px;
    }
    
    .quick-action {
        padding: 15px 10px;
        border-radius: 12px;
    }
    
    .quick-action i {
        font-size: 1.5rem;
        margin-bottom: 10px;
    }
    
    .quick-action span {
        font-size: 13px;
    }
    
    .quick-action p {
        font-size: 11px;
    }
    
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 20px;
    }
    
    .stat-box {
        padding: 15px;
        border-radius: 12px;
    }
    
    .stat-box .value {
        font-size: 1.4rem;
    }
    
    .stat-box .label {
        font-size: 12px;
    }
    
    .section-header {
        flex-wrap: wrap;
        gap: 10px;
        margin-bottom: 15px;
    }
    
    .section-header h3 {
        font-size: 1rem;
    }
    
    .section-header a {
        font-size: 12px;
    }
    
    .order-item {
        padding: 12px;
        margin-bottom: 8px;
    }
    
    .activity-card {
        padding: 15px;
        border-radius: 12px;
    }
    
    .activity-item {
        padding: 10px 0;
    }
    
    .activity-icon {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }
    
    /* 两栏布局改为单栏 */
    .main-content-grid {
        display: block !important;
    }
    
    .main-content-grid > div {
        margin-bottom: 20px;
    }
}

/* 商城页面 */
@media screen and (max-width: 768px) {
    .shop-header {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    .shop-header .balance-info {
        font-size: 12px;
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* 登录页面 */
@media screen and (max-width: 768px) {
    .login-container {
        padding: 15px;
    }
    
    .login-box {
        padding: 25px 20px;
        border-radius: 15px;
    }
    
    .login-header .logo {
        font-size: 36px;
    }
    
    .login-header h1 {
        font-size: 20px;
    }
    
    .login-header p {
        font-size: 13px;
    }
    
    .role-tabs {
        flex-direction: column;
        gap: 8px;
    }
    
    .role-tab {
        padding: 10px;
    }
    
    .role-tab i {
        font-size: 16px;
    }
    
    .form-group input {
        padding: 12px 14px;
        font-size: 16px;
    }
    
    .btn-login {
        padding: 14px;
        font-size: 15px;
    }
    
    .error-message {
        padding: 12px 15px;
        font-size: 13px;
    }
    
    .register-fields .form-group:last-child > div {
        flex-direction: column;
        gap: 10px;
    }
    
    .register-fields .form-group:last-child input {
        width: 100%;
    }
    
    .register-fields .form-group:last-child button {
        width: 100%;
        padding: 12px;
    }
}

/* 订单页面 */
@media screen and (max-width: 768px) {
    .order-list {
        gap: 10px;
    }
    
    .order-card {
        border-radius: 10px;
        padding: 12px;
    }
    
    .order-header {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start !important;
    }
    
    .order-body {
        padding: 10px 0;
    }
    
    .order-footer {
        flex-direction: column;
        gap: 10px;
    }
    
    .order-footer .btn {
        width: 100%;
    }
    
    .countdown-timer {
        font-size: 14px;
        padding: 8px 12px;
    }
}

/* 个人中心 */
@media screen and (max-width: 768px) {
    .profile-header {
        flex-direction: column;
        text-align: center;
        gap: 15px;
    }
    
    .profile-avatar {
        width: 80px;
        height: 80px;
        font-size: 32px;
    }
    
    .profile-stats {
        flex-wrap: wrap;
        justify-content: center;
        gap: 15px;
    }
}

/* 音乐播放器移动端优化 */
@media screen and (max-width: 768px) {
    .music-player {
        left: 10px;
        right: 10px;
        bottom: 10px;
        min-width: auto;
        border-radius: 12px;
        padding: 12px;
    }
    
    .music-player.collapsed {
        left: auto;
        right: 10px;
        width: auto;
    }
    
    .music-info {
        gap: 10px;
    }
    
    .music-cover {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
    
    .music-title {
        font-size: 13px;
        max-width: 150px;
    }
    
    .music-mode {
        font-size: 11px;
    }
    
    .music-controls {
        gap: 10px;
    }
    
    .music-btn {
        font-size: 16px;
        padding: 6px;
    }
    
    .music-btn.play-btn {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }
    
    .music-volume {
        gap: 6px;
    }
    
    .volume-slider {
        height: 3px;
    }
    
    .music-list {
        max-height: 200px;
    }
    
    .music-list-item {
        padding: 8px;
        font-size: 13px;
    }
    
    .progress-bar {
        height: 3px;
    }
    
    .progress-time {
        font-size: 10px;
    }
    
    .music-player-toggle {
        width: 26px;
        height: 26px;
        font-size: 11px;
        top: -8px;
        right: -8px;
    }
}

@media screen and (max-width: 375px) {
    .music-player {
        padding: 10px;
        left: 8px;
        right: 8px;
        bottom: 8px;
    }
    
    .music-cover {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }
    
    .music-title {
        font-size: 12px;
        max-width: 120px;
    }
    
    .music-btn.play-btn {
        width: 34px;
        height: 34px;
    }
}

/* 隐藏音乐播放器时的底部间距 */
body:has(.music-player) main {
    padding-bottom: 100px;
}

@media screen and (max-width: 768px) {
    body:has(.music-player) main {
        padding-bottom: 120px;
    }
    
    body:has(.music-player.collapsed) main {
        padding-bottom: 30px;
    }
}

/* 滚动条优化 */
@media screen and (max-width: 768px) {
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }
    
    ::-webkit-scrollbar-track {
        background: transparent;
    }
    
    ::-webkit-scrollbar-thumb {
        background: var(--border);
        border-radius: 2px;
    }
}

/* 文字选择优化 */
@media screen and (max-width: 768px) {
    .sidebar-menu a,
    .btn,
    .tab {
        -webkit-tap-highlight-color: transparent;
    }
}

/* 图片优化 */
@media screen and (max-width: 768px) {
    img {
        max-width: 100%;
        height: auto;
    }
    
    .product-image {
        object-fit: cover;
    }
}

/* 防止文字溢出 */
@media screen and (max-width: 768px) {
    .card-header,
    .product-name,
    .music-title,
    .user-name,
    h1, h2, h3, h4, h5, h6 {
        word-break: break-word;
        overflow-wrap: break-word;
    }
    
    p, li, td, th {
        word-break: break-word;
    }
}

/* Flex布局修复 */
@media screen and (max-width: 768px) {
    .header-content {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 10px;
    }
    
    .header-content > * {
        flex-shrink: 0;
    }
    
    .user-info {
        flex: 1;
        min-width: 0;
        overflow: hidden;
    }
    
    .user-info > div {
        min-width: 0;
        overflow: hidden;
    }
    
    .user-name,
    .user-role {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}
