/* ========================================
   移动端优化样式
   ======================================== */

/* 基础响应式文本隐藏 */
@media (max-width: 480px) {
    .header-title {
        display: inline;
    }
    
    .btn-text {
        display: none;
    }
    
    .status-text {
        display: none;
    }
}

@media (min-width: 481px) {
    .header-title,
    .btn-text,
    .status-text {
        display: inline;
    }
}

/* 移动端汉堡菜单按钮 */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--primary-color);
    cursor: pointer;
    padding: 0.5rem;
    transition: var(--transition);
}

.mobile-menu-toggle:hover {
    color: var(--secondary-color);
}

/* 移动端覆盖层 */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-overlay.active {
    display: block;
    opacity: 1;
}

/* ========================================
   平板设备适配 (768px - 1024px)
   ======================================== */
@media (max-width: 1024px) {
    .header-content {
        padding: 1rem 1.5rem;
    }

    .content {
        padding: 1.5rem;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 1rem;
    }

    .config-form {
        max-width: 100%;
    }

    .logout-btn {
        line-height: 0;
    }
}

/* ========================================
   移动端适配 (最大宽度 768px)
   ======================================== */
@media (max-width: 768px) {
    /* Header 优化 */
    .header-content {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.75rem;
        justify-content: center;
    }

    .header h1 {
        font-size: 1.25rem;
        flex: 1 1 100%;
        min-width: 0;
        text-align: center;
        order: -1;
    }

    .header h1 i {
        margin-right: 0.25rem;
    }

    .header-controls {
        gap: 0.5rem;
        flex-wrap: wrap;
        justify-content: center;
        flex: 1 1 100%;
    }

    .status-badge {
        padding: 0.375rem 0.75rem;
        font-size: 0.75rem;
    }

    /* 主内容区域 */
    .main-content {
        flex-direction: column;
    }

    /* 侧边栏移动端样式 */
    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 0;
        position: sticky;
        top: 73px;
        z-index: 90;
        background: var(--bg-primary);
    }

    .sidebar-nav {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 0.5rem 1rem;
        gap: 0.5rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .sidebar-nav::-webkit-scrollbar {
        display: none;
    }

    .nav-item {
        padding: 0.625rem 1rem;
        white-space: nowrap;
        border-radius: 0.375rem;
        border-right: none;
        font-size: 0.875rem;
        cursor: pointer;
        user-select: none;
        -webkit-user-select: none;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        touch-action: manipulation;
    }

    .nav-item.active {
        background: var(--primary-color) !important;
        color: white !important;
        border-right: none;
    }

    .nav-item:active {
        opacity: 0.8;
        transform: scale(0.98);
    }

    .nav-item i {
        width: 16px;
        font-size: 0.875rem;
        pointer-events: none;
    }

    .nav-item span {
        pointer-events: none;
    }

    /* 内容区域 */
    .content {
        padding: 1rem;
    }

    .section h2 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }

    /* 统计卡片 */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-icon {
        width: 48px;
        height: 48px;
        font-size: 1.25rem;
    }

    .stat-info h3 {
        font-size: 1.5rem;
    }

    .stat-info p {
        font-size: 0.8125rem;
    }

    /* 表单优化 */
    .config-panel {
        padding: 1rem;
        border-radius: 0.375rem;
    }

    .form-row,
    .config-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .form-group {
        margin-bottom: 1rem;
    }

    .form-group label {
        font-size: 0.875rem;
        margin-bottom: 0.375rem;
    }

    .form-control {
        padding: 0.625rem;
        font-size: 0.875rem;
    }

    textarea.form-control {
        min-height: 100px;
    }

    /* 按钮优化 */
    .btn {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
    }

    .form-actions {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .form-actions .btn {
        width: 100%;
    }

    /* 单选按钮组 */
    .radio-group {
        flex-direction: column;
        gap: 0.75rem;
    }

    /* 高级配置区域 */
    .advanced-config-section {
        padding: 1rem;
        margin-top: 1rem;
    }

    .advanced-config-section h3 {
        font-size: 1.125rem;
        margin-bottom: 1rem;
    }

    /* 系统信息面板 */
    .system-info-panel {
        padding: 1rem;
    }

    .system-info-panel h3 {
        font-size: 1.125rem;
        margin-bottom: 1rem;
    }

    .info-grid {
        gap: 0.75rem;
    }

    .info-item {
        padding: 0.75rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.375rem;
    }

    .info-label {
        font-size: 0.8125rem;
    }

    .info-value {
        font-size: 0.875rem;
    }

    /* 提供商列表 */
    .providers-container {
        padding: 0;
    }

    .providers-list {
        gap: 0.75rem;
    }

    .provider-card {
        padding: 1rem;
    }

    .provider-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .provider-actions {
        width: 100%;
        justify-content: flex-start;
        gap: 0.5rem;
    }

    .provider-actions .btn {
        flex: 1;
        min-width: 0;
    }

    /* 提供商详情 */
    .provider-summary {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .provider-summary-actions {
        margin-left: 0;
        width: 100%;
    }

    .provider-summary-actions .btn {
        width: 100%;
    }

    /* 模态框优化 */
    .provider-modal-content {
        width: 95%;
        max-width: 95%;
        max-height: 90vh;
        margin: 5vh auto;
        padding: 1rem;
    }

    .provider-modal-header {
        padding: 1rem;
        margin: -1rem -1rem 1rem -1rem;
    }

    .provider-modal-header h2 {
        font-size: 1.25rem;
    }

    .provider-modal-body {
        padding: 0;
        max-height: calc(90vh - 140px);
    }

    .config-section {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .config-section h3 {
        font-size: 1.125rem;
        margin-bottom: 0.75rem;
    }

    .config-item {
        padding: 0.75rem;
        gap: 0.5rem;
    }

    .config-label {
        font-size: 0.8125rem;
        min-width: 80px;
    }

    .config-value {
        font-size: 0.875rem;
    }

    /* 日志容器 */
    .logs-container {
        height: calc(100vh - 280px);
        min-height: 300px;
        font-size: 0.75rem;
        padding: 0.75rem;
    }

    .logs-controls {
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-bottom: 0.75rem;
    }

    .logs-controls .btn {
        flex: 1;
        min-width: 120px;
    }

    .log-entry {
        padding: 0.5rem;
        margin-bottom: 0.375rem;
        font-size: 0.75rem;
        line-height: 1.4;
    }

    .log-timestamp {
        font-size: 0.6875rem;
    }

    /* Toast 通知 */
    .toast-container {
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
        pointer-events: none;
    }

    .toast {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        border-radius: 0.375rem;
        pointer-events: auto;
    }

    /* 密码输入框 */
    .password-input-wrapper .form-control {
        padding-right: 2.5rem;
    }

    .password-toggle {
        right: 0.5rem;
        padding: 0.375rem;
    }

    /* 切换开关 */
    .toggle-switch {
        transform: scale(0.9);
    }

    /* OAuth刷新切换 */
    .oauth-refresh-toggle {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    /* 表单网格 */
    .form-grid {
        grid-template-columns: 1fr;
    }

    /* 路径路由示例移动端优化 */
    .routing-examples-panel {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .routing-examples-panel h3 {
        font-size: 1.125rem;
    }

    .routing-description {
        font-size: 0.8125rem;
    }

    .routing-examples-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .routing-example-card {
        border-radius: 0.375rem;
    }

    .routing-card-header {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .routing-card-header h4 {
        font-size: 0.9rem;
        flex-basis: 100%;
        margin-bottom: 0.25rem;
    }

    .routing-card-header i {
        font-size: 1rem;
    }

    .provider-badge {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }

    .routing-card-content {
        padding: 1rem;
    }

    .endpoint-path {
        font-size: 0.75rem;
        padding: 0.4rem 0.6rem;
        padding-right: 2rem;
        word-break: break-all;
    }

    .copy-btn {
        right: 0.4rem;
        padding: 0.2rem;
        min-width: 32px;
        min-height: 32px;
    }

    .usage-example pre {
        font-size: 0.7rem;
        padding: 0.75rem;
        overflow-x: auto;
        white-space: pre-wrap;
    }

    .routing-tips {
        padding: 1rem;
    }

    .routing-tips h4 {
        font-size: 0.9rem;
    }

    .routing-tips ul {
        padding-left: 1.25rem;
    }

    .routing-tips li {
        font-size: 0.8rem;
        margin-bottom: 0.5rem;
    }

    .routing-tips code {
        font-size: 0.7rem;
        padding: 0.1rem 0.2rem;
    }

    /* 协议标签移动端优化 */
    .protocol-tabs {
        margin-bottom: 0.75rem;
    }

    .protocol-tab {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    /* 池配置部分 */
    .pool-section {
        margin-top: 1rem;
    }

    .pool-section small {
        font-size: 0.75rem;
    }

    /* 系统提示部分 */
    .system-prompt-section {
        margin-top: 1rem;
    }

    .system-prompt-section textarea {
        min-height: 120px;
    }

    .logout-btn {
        line-height: 0;
    }
}

/* ========================================
   小屏幕移动设备 (最大宽度 480px)
   ======================================== */
@media (max-width: 480px) {
    /* Header 进一步优化 */
    .header h1 {
        font-size: 1.125rem;
    }

    .header-controls {
        width: 100%;
        justify-content: space-between;
    }

    .status-badge {
        flex: 1;
        justify-content: center;
    }

    /* 按钮文字简化 */
    #refreshBtn .fa-sync-alt::after {
        content: '';
    }

    /* 侧边栏导航 */
    .nav-item {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }

    .nav-item i {
        margin-right: 0.375rem;
    }

    /* 统计卡片 */
    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1.125rem;
    }

    .stat-info h3 {
        font-size: 1.375rem;
    }

    /* 表单控件 */
    .form-control {
        font-size: 16px; /* 防止iOS自动缩放 */
    }

    select.form-control {
        font-size: 16px;
    }

    /* 配置面板 */
    .config-panel {
        padding: 0.75rem;
    }

    .advanced-config-section {
        padding: 0.75rem;
    }

    /* 提供商卡片 */
    .provider-card {
        padding: 0.75rem;
    }

    .provider-name {
        font-size: 1rem;
    }

    /* 模态框 */
    .provider-modal-content {
        width: 98%;
        max-width: 98%;
        padding: 0.75rem;
    }

    .provider-modal-header {
        padding: 0.75rem;
        margin: -0.75rem -0.75rem 0.75rem -0.75rem;
    }

    .provider-modal-header h2 {
        font-size: 1.125rem;
    }

    .close-modal {
        width: 32px;
        height: 32px;
        font-size: 1.25rem;
    }

    /* 日志 */
    .logs-container {
        font-size: 0.6875rem;
        padding: 0.5rem;
    }

    .log-entry {
        padding: 0.375rem;
        font-size: 0.6875rem;
    }

    /* Toast */
    .toast {
        font-size: 0.8125rem;
        padding: 0.625rem 0.875rem;
    }

    .logout-btn {
        line-height: 0;
    }
}

/* ========================================
   横屏模式优化
   ======================================== */
@media (max-width: 768px) and (orientation: landscape) {
    .sidebar {
        position: relative;
        top: 0;
    }

    .sidebar-nav {
        padding: 0.375rem 1rem;
    }

    .nav-item {
        padding: 0.5rem 0.875rem;
    }

    .logs-container {
        height: calc(100vh - 200px);
        min-height: 200px;
    }

    .provider-modal-content {
        max-height: 85vh;
    }

    .provider-modal-body {
        max-height: calc(85vh - 120px);
    }

    .logout-btn {
        line-height: 0;
    }
}

/* ========================================
   触摸优化
   ======================================== */
@media (hover: none) and (pointer: coarse) {
    /* 增加可点击区域 */
    .btn {
        min-height: 10px;
        padding: 0.5rem;
    }

    .nav-item {
        min-height: 44px;
    }

    .password-toggle {
        min-width: 44px;
        min-height: 44px;
    }

    /* 移除悬停效果 */
    .nav-item:hover {
        background: transparent;
    }

    .nav-item:active {
        background: var(--bg-secondary);
    }

    .btn:hover {
        transform: none;
    }

    .btn:active {
        transform: scale(0.98);
    }

    /* 优化滚动 */
    .sidebar-nav,
    .logs-container,
    .provider-modal-body {
        -webkit-overflow-scrolling: touch;
    }

    .logout-btn {
        line-height: 0;
    }
}

/* ========================================
   暗色模式支持（可选）
   ======================================== */
@media (prefers-color-scheme: dark) {
    /* 如果需要暗色模式，可以在这里添加样式 */
}

/* ========================================
   打印样式
   ======================================== */
@media print {
    .header-controls,
    .sidebar,
    .form-actions,
    .logs-controls,
    .provider-actions,
    .mobile-menu-toggle,
    .mobile-overlay {
        display: none !important;
    }

    .main-content {
        flex-direction: column;
    }

    .content {
        padding: 0;
    }

    .section {
        display: block !important;
        page-break-after: always;
    }
}

/* ========================================
   辅助功能优化
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }

    .form-control {
        border: 2px solid var(--border-color);
    }

    .nav-item.active {
        border-right: 4px solid var(--primary-color);
    }
}