/* 全局变量定义 */
:root {
    /* 核心色板 */
    --primary-color: #00d4ff;
    --primary-gradient: linear-gradient(135deg, #00d4ff 0%, #7b2ff7 100%);
    --secondary-color: #7b2ff7;
    --success-color: #2ed573;
    --warning-color: #ffa502;
    --danger-color: #ff4757;
    --danger-gradient: linear-gradient(135deg, #ff4757 0%, #ff6b81 100%);

    /* 背景色 */
    --bg-body: #0f172a;
    /* 深蓝灰背景 */
    --bg-glass: rgba(255, 255, 255, 0.03);
    --bg-glass-hover: rgba(255, 255, 255, 0.08);
    --bg-glass-active: rgba(0, 212, 255, 0.15);

    /* 边框与阴影 */
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-glass-hover: rgba(255, 255, 255, 0.2);
    --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.36);
    --shadow-glow: 0 0 20px rgba(0, 212, 255, 0.3);

    /* 文本颜色 */
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;

    /* 尺寸 */
    --sidebar-width: 260px;
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 8px;

    /* 动画 */
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 字体引入 */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* 基础重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-body);
    /* 更加丰富的背景渐变 */
    background-image:
        radial-gradient(circle at 10% 20%, rgba(123, 47, 247, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(0, 212, 255, 0.1) 0%, transparent 40%);
    height: 100vh;
    color: var(--text-main);
    display: flex;
    overflow: hidden;
    /* 防止因为光晕产生的滚动条 */
    /* 移动端优化：禁用页面在 iOS 上的回弹效果 */
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
}

/* 滚动条美化 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* 侧边栏样式 */
.sidebar {
    width: var(--sidebar-width);
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-glass);
    padding: 32px 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-header {
    padding: 0 32px;
    margin-bottom: 40px;
}

.sidebar-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
}

.sidebar-header p {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.nav-menu {
    list-style: none;
    flex: 1;
    padding: 0 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    padding: 14px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition-fast);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-weight: 500;
    position: relative;
    overflow: hidden;
}

.nav-item:hover {
    background: var(--bg-glass-hover);
    color: var(--text-main);
}

.nav-item.active {
    background: var(--bg-glass-active);
    color: var(--primary-color);
}

/* 激活状态的光晕指示器 */
.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 0 4px 4px 0;
    box-shadow: var(--shadow-glow);
}

.nav-item .icon {
    font-size: 1.25rem;
    width: 24px;
    text-align: center;
}

/* 侧边栏底部 */
.sidebar-footer {
    padding: 24px 32px;
    border-top: 1px solid var(--border-glass);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-main);
    padding: 8px 0;
}

.user-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-glass-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.user-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.btn-logout {
    background: rgba(255, 71, 87, 0.1);
    color: var(--danger-color);
    width: 100%;
    justify-content: center;
    transition: var(--transition-fast);
}

.btn-logout:hover {
    background: var(--danger-gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(255, 71, 87, 0.3);
}

/* 主内容区域 */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 40px 60px;
    position: relative;
}

/* 页面切换动画 */
.page {
    display: none;
    max-width: 1200px;
    margin: 0 auto;
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.page.active {
    display: block;
}

.page-header {
    margin-bottom: 40px;
}

.page-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 12px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1.5;
}

/* 通用卡片 - 毛玻璃风格 */
.card {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-glass);
    padding: 32px;
    margin-bottom: 32px;
    box-shadow: var(--shadow-glass);
    transition: var(--transition-smooth);
}

.card:hover {
    border-color: var(--border-glass-hover);
    transform: translateY(-2px);
}

/* 设备管理网格布局 */
.device-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    align-items: start;
}

#page-device .page-header {
    margin-bottom: 20px;
}

#page-device .stats {
    gap: 12px;
    margin-bottom: 18px;
}

#page-device .stat-card {
    padding: 16px;
}

#page-device .stat-value {
    font-size: 2rem;
    margin-bottom: 4px;
}

#page-device .stat-label {
    font-size: 0.82rem;
}

#page-device .card {
    padding: 20px;
    margin-bottom: 0;
}

#page-device .card-header {
    margin-bottom: 14px;
}

.card-tools {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.pending-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    background: rgba(0, 212, 255, 0.12);
    color: var(--primary-color);
    font-size: 0.82rem;
    font-weight: 700;
}

.btn-collapse-pending {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid var(--border-glass);
    font-size: 0.82rem;
    padding: 8px 12px;
}

.btn-collapse-pending:hover {
    background: rgba(255, 255, 255, 0.1);
}

.pending-collapsible {
    display: block;
}

.pending-collapsible.collapsed {
    display: none;
}

.pending-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pending-item {
    display: grid;
    grid-template-columns: minmax(140px, 1.2fr) auto auto auto;
    gap: 10px;
    align-items: center;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-glass);
    background: rgba(255, 255, 255, 0.02);
}

.pending-main {
    min-width: 0;
}

.pending-device-name {
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pending-device-id {
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 0.76rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pending-time {
    color: var(--text-muted);
    font-size: 0.8rem;
    white-space: nowrap;
}

.pending-actions .btn {
    font-size: 0.78rem;
    padding: 6px 10px;
    white-space: nowrap;
}

.pending-access .access-code {
    font-size: 0.9rem;
    padding: 3px 7px;
}

@media (max-width: 1200px) {
    #page-device .stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    #page-device .stats {
        grid-template-columns: 1fr;
    }

    .pending-item {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .pending-time {
        white-space: normal;
    }
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 统计卡片 */
.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    margin-bottom: 40px;
}

.stat-card {
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.01) 100%);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 24px;
    text-align: center;
    transition: var(--transition-fast);
}

.stat-card:hover {
    transform: translateY(-4px);
    border-color: rgba(0, 212, 255, 0.3);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 800;
    font-family: 'Inter', sans-serif;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

/* 按钮系统 */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    transition: var(--transition-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.85rem;
}

.btn-primary {
    background: var(--primary-gradient);
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 212, 255, 0.2);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 212, 255, 0.4);
}

.btn-success {
    background: linear-gradient(135deg, #2ed573 0%, #7bed9f 100%);
    color: #fff;
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(46, 213, 115, 0.3);
}

.btn-refresh {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid var(--border-glass);
}

.btn-refresh:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
}

.btn-edit {
    background: rgba(255, 165, 2, 0.15);
    color: var(--warning-color);
    border: 1px solid rgba(255, 165, 2, 0.2);
}

.btn-edit:hover {
    background: rgba(255, 165, 2, 0.25);
    border-color: var(--warning-color);
}

.btn-cancel {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-glass);
}

.btn-cancel:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.btn-danger {
    background: var(--danger-gradient);
    color: #fff;
    box-shadow: 0 4px 12px rgba(255, 71, 87, 0.2);
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 71, 87, 0.4);
}

/* 表格样式 */
table {
    width: 100%;
    border-collapse: separate;
    /* 使用 separate 以便圆角生效 */
    border-spacing: 0;
    margin-top: 10px;
}

#allDevicesList .table-all-devices {
    table-layout: fixed;
    margin-top: 0;
}

#allDevicesList .table-all-devices th,
#allDevicesList .table-all-devices td {
    padding: 12px 10px;
}

@media (min-width: 769px) {
    #allDevicesList .table-all-devices th:nth-child(1),
    #allDevicesList .table-all-devices td:nth-child(1) {
        width: 20%;
    }

    #allDevicesList .table-all-devices th:nth-child(2),
    #allDevicesList .table-all-devices td:nth-child(2) {
        width: 24%;
    }

    #allDevicesList .table-all-devices th:nth-child(3),
    #allDevicesList .table-all-devices td:nth-child(3) {
        width: 10%;
    }

    #allDevicesList .table-all-devices th:nth-child(4),
    #allDevicesList .table-all-devices td:nth-child(4) {
        width: 18%;
        white-space: nowrap;
    }

    #allDevicesList .table-all-devices th:nth-child(5),
    #allDevicesList .table-all-devices td:nth-child(5) {
        width: 28%;
    }
}

th,
td {
    padding: 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-glass);
}

th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: rgba(255, 255, 255, 0.02);
}

/* 表头圆角 */
th:first-child {
    border-top-left-radius: var(--radius-sm);
}

th:last-child {
    border-top-right-radius: var(--radius-sm);
}

td {
    color: var(--text-main);
    font-size: 0.95rem;
    transition: background-color 0.2s;
}

tr:hover td {
    background: var(--bg-glass-hover);
}

/* 最后一行的边框处理 */
tr:last-child td {
    border-bottom: none;
}

.device-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    align-items: center;
}

.device-actions .btn {
    min-width: 0;
    padding: 6px 10px;
    font-size: 0.78rem;
    white-space: nowrap;
}

.pagination-bar {
    margin-top: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.pagination-bar.compact {
    justify-content: flex-end;
}

.pagination-meta {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.pagination-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.btn-page {
    border: 1px solid var(--border-glass);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-main);
    border-radius: 8px;
    padding: 5px 10px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: var(--transition-fast);
}

.btn-page:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-page.active {
    border-color: rgba(0, 212, 255, 0.5);
    background: rgba(0, 212, 255, 0.16);
    color: var(--primary-color);
}

.btn-page:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-delete-device {
    background: rgba(255, 71, 87, 0.12);
    color: var(--danger-color);
    border: 1px solid rgba(255, 71, 87, 0.22);
    box-shadow: none;
}

.btn-delete-device:hover {
    background: rgba(255, 71, 87, 0.2);
    border-color: rgba(255, 71, 87, 0.36);
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(255, 71, 87, 0.18);
}

.access-code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
    letter-spacing: 1px;
    background: rgba(0, 212, 255, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
}

/* Service Management related styles */
.service-section {
    margin-bottom: 24px;
}

.service-card {
    background: var(--bg-glass);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-glass);
    overflow: hidden;
    transition: var(--transition-smooth);
}

.service-card:hover {
    border-color: rgba(0, 212, 255, 0.3);
}

.service-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border-glass);
}

.service-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
}

.service-icon {
    font-size: 1.5rem;
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.2));
}

.service-body {
    padding: 24px;
}

.config-item {
    display: flex;
    margin-bottom: 16px;
    align-items: center;
    /* 垂直居中对齐 */
}

/* 针对多行或长内容的对齐调整 */
.config-item:has(.config-value:empty) {
    display: none;
}

.config-label {
    width: 140px;
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

.config-value {
    flex: 1;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    color: #00d4ff;
    word-break: break-all;
    background: rgba(0, 0, 0, 0.3);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
}

.config-value.readonly {
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.15);
}

/* 编辑模式输入框 */
.config-input {
    flex: 1;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    color: var(--text-main);
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-glass-hover);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    outline: none;
    transition: all 0.2s ease;
}

.config-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.15);
}

.config-input::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

.service-actions {
    display: flex;
    justify-content: flex-end;
    padding: 16px 24px;
    background: rgba(0, 0, 0, 0.1);
    border-top: 1px solid var(--border-glass);
    gap: 12px;
}

/* 状态点动画 */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success-color);
    box-shadow: 0 0 10px var(--success-color);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(46, 213, 115, 0.7);
    }

    70% {
        transform: scale(1);
        box-shadow: 0 0 0 6px rgba(46, 213, 115, 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(46, 213, 115, 0);
    }
}

/* Toast 提示 */
.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    padding: 16px 24px;
    border-radius: var(--radius-md);
    color: #fff;
    font-weight: 500;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 1000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.toast.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.toast-success {
    background: rgba(46, 213, 115, 0.9);
    backdrop-filter: blur(10px);
}

.toast-error {
    background: rgba(255, 71, 87, 0.9);
    backdrop-filter: blur(10px);
}

.hidden {
    display: none !important;
}

/* 列表加载与空状态 */
.loading {
    padding: 40px;
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
}

.empty-state {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
    opacity: 0.7;
}

/* 登录页特定样式 (Login Page Specifics) */
.login-body {
    background-image:
        radial-gradient(circle at 10% 20%, rgba(123, 47, 247, 0.2) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(0, 212, 255, 0.15) 0%, transparent 40%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.login-card {
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-glass);
    padding: 48px 40px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.5s ease-out;
}

@media (max-width: 480px) {
    .login-card {
        padding: 32px 24px;
        margin: 0 16px;
    }

    .login-header h1 {
        font-size: 1.8rem;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-header {
    text-align: center;
    margin-bottom: 40px;
}

.login-header h1 {
    font-size: 2.2rem;
    font-weight: 800;
    margin-bottom: 12px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.form-group {
    margin-bottom: 24px;
}

.form-label {
    display: block;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 10px;
    font-weight: 500;
}

.form-input {
    width: 100%;
    padding: 14px 18px;
    font-size: 1rem;
    color: var(--text-main);
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-glass-hover);
    border-radius: var(--radius-sm);
    outline: none;
    transition: all 0.2s ease;
}

.form-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(0, 212, 255, 0.1);
    background: rgba(0, 0, 0, 0.6);
}

.btn-login {
    width: 100%;
    padding: 16px;
    font-size: 1.05rem;
    font-weight: 600;
    color: #fff;
    background: var(--primary-gradient);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: 10px;
    box-shadow: 0 4px 15px rgba(0, 212, 255, 0.3);
}

.btn-login:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 212, 255, 0.5);
}

.btn-login:active {
    transform: translateY(0);
}

.btn-login:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
    filter: grayscale(0.5);
}

.error-message {
    background: rgba(255, 71, 87, 0.15);
    border: 1px solid rgba(255, 71, 87, 0.3);
    color: #ff6b81;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 24px;
    font-size: 0.9rem;
    display: none;
    animation: shake 0.4s ease-in-out;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

.error-message.show {
    display: block;
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    /* 顶部栏容器：包含 Logo 和 导航菜单 */
    .sidebar {
        width: 100%;
        height: auto;
        /* 自适应高度 */
        min-height: 60px;
        padding: 8px 16px;
        flex-direction: column;
        /*改为垂直排列 */
        align-items: stretch;
        justify-content: flex-start;
        border-right: none;
        border-bottom: 1px solid var(--border-glass);
        position: fixed;
        top: 0;
        left: 0;
        z-index: 1000;
        background: #0f172a;
        gap: 8px;
    }

    .sidebar-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        margin-bottom: 4px;
    }

    .sidebar-header h1 {
        font-size: 1.2rem;
        margin-bottom: 0;
    }

    /* 隐藏副标题 */
    .sidebar-header p {
        display: none;
    }

    /* 用户信息/退出按钮放在 Header 右侧，绝对定位 */
    .sidebar-footer {
        position: absolute;
        top: 12px;
        right: 16px;
        padding: 0;
        border: none;
        display: block;
        margin-top: 0;
    }

    .user-info {
        display: none;
    }

    .btn-logout {
        width: auto;
        padding: 6px 12px;
        font-size: 0.8rem;
        border-radius: 14px;
        background: rgba(255, 71, 87, 0.15);
        color: #ff6b81;
        border: 1px solid rgba(255, 71, 87, 0.3);
    }

    .btn-logout:active {
        background: rgba(255, 71, 87, 0.25);
    }

    .btn-logout span {
        display: inline;
    }

    /* 顶部导航菜单 */
    .nav-menu {
        position: relative !important;
        /* 不再固定底部，跟随 Sidebar */
        bottom: auto;
        top: auto;
        left: auto;
        right: auto;
        width: 100%;
        height: auto;
        flex-direction: row;
        justify-content: space-between;
        padding: 0;
        background: transparent;
        border: none;
        box-shadow: none;
        z-index: auto;
        gap: 8px;
    }

    .nav-item {
        flex: 1;
        flex-direction: row;
        /* 水平排列图标和文字 */
        justify-content: center;
        align-items: center;
        padding: 8px;
        gap: 6px;
        border-radius: var(--radius-sm);
        background: rgba(255, 255, 255, 0.03);
        height: auto;
        margin: 0;
    }

    .nav-item .icon {
        font-size: 1rem;
        margin: 0;
    }

    .nav-item span:last-child {
        font-size: 0.85rem;
    }

    /* 激活状态 */
    .nav-item.active {
        background: var(--primary-gradient);
        color: #fff;
    }

    /* 移除之前的激活样式 */
    .nav-item.active::after {
        display: none;
    }

    /* 主内容区域：顶部留出更多空间 */
    .main-content {
        margin-left: 0;
        /* Sidebar 高度增加，增加 padding 防止遮挡 */
        padding: 170px 16px 20px 16px;
        width: 100%;
        height: 100vh;
        overflow-y: auto;
    }

    .stats {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .config-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .config-label {
        width: 100%;
    }

    /* 页面标题缩小 */
    .page-title {
        font-size: 1.5rem;
        margin-top: 10px;
    }

    .page-subtitle {
        font-size: 0.9rem;
    }
}

/* ============================================================
   AI 聊天页面样式
   ============================================================ */

/* 聊天容器 */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 80px);
    max-width: 900px;
    margin: 0 auto;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-glass);
    overflow: hidden;
}

/* 聊天头部 */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border-glass);
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-main);
}

.chat-icon {
    font-size: 1.5rem;
}

/* 聊天头部操作区 */
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* 静音按钮 */
.btn-mute {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-glass);
    background: rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.1rem;
}

.btn-mute:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary-color);
}

.btn-mute.muted {
    background: rgba(255, 100, 100, 0.1);
    border-color: var(--danger-color);
}

.btn-mute.muted .mute-icon {
    opacity: 0.6;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all 0.3s ease;
}

.status-indicator.online {
    background: var(--success-color);
    box-shadow: 0 0 8px var(--success-color);
    animation: pulse 2s infinite;
}

.status-indicator.error {
    background: var(--danger-color);
    box-shadow: 0 0 8px var(--danger-color);
}

.status-indicator.offline {
    background: var(--text-muted);
}

/* 聊天消息区域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* 欢迎消息 */
.chat-welcome {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.welcome-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    animation: wave 1.5s ease-in-out infinite;
}

@keyframes wave {

    0%,
    100% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(20deg);
    }

    75% {
        transform: rotate(-20deg);
    }
}

.chat-welcome h3 {
    font-size: 1.3rem;
    color: var(--text-main);
    margin-bottom: 12px;
    font-weight: 600;
}

.chat-welcome p {
    font-size: 0.95rem;
    line-height: 1.6;
}

/* 消息样式 */
.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: messageSlide 0.3s ease-out;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-ai {
    align-self: flex-start;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-glass-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.message-user .message-avatar {
    background: rgba(0, 212, 255, 0.2);
}

.message-ai .message-avatar {
    background: rgba(123, 47, 247, 0.2);
}

.message-bubble {
    position: relative;
    padding: 14px 18px;
    border-radius: var(--radius-md);
    line-height: 1.6;
    font-size: 0.95rem;
}

.message-user .message-bubble {
    background: var(--primary-gradient);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message-ai .message-bubble {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
}

.message-content {
    white-space: pre-wrap;
    word-break: break-word;
}

/* 流式消息动画 */
.message.streaming .message-content::after {
    content: '▌';
    animation: blink 0.8s infinite;
    color: var(--primary-color);
}

@keyframes blink {

    0%,
    50% {
        opacity: 1;
    }

    51%,
    100% {
        opacity: 0;
    }
}

/* 重新播放按钮 */
.btn-replay {
    position: absolute;
    bottom: -8px;
    right: -8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    opacity: 0;
    transition: all 0.2s ease;
}

.message-ai:hover .btn-replay {
    opacity: 1;
}

.btn-replay:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    transform: scale(1.1);
}

/* 正在播放状态 */
.btn-replay.playing {
    opacity: 1;
    background: var(--primary-color);
    border-color: var(--primary-color);
    animation: audioWave 1s ease-in-out infinite;
}

@keyframes audioWave {

    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(0, 212, 255, 0.4);
    }

    50% {
        transform: scale(1.1);
        box-shadow: 0 0 0 8px rgba(0, 212, 255, 0);
    }
}

/* iOS 静音模式提示 */
.audio-hint {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    color: var(--text-main);
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    border: 1px solid var(--border-glass);
}

.audio-hint.show {
    opacity: 1;
    pointer-events: auto;
}

.audio-hint-icon {
    font-size: 1.2rem;
}

.audio-hint-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    margin-left: 8px;
    font-size: 1rem;
}

.audio-hint-close:hover {
    color: var(--text-main);
}

/* 聊天输入区域 */
.chat-input-area {
    padding: 20px 24px;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid var(--border-glass);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    transition: all 0.2s ease;
}

.chat-input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    outline: none;
    line-height: 1.5;
    max-height: 120px;
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.chat-input-actions {
    display: flex;
    gap: 8px;
}

/* 语音按钮 */
.btn-voice {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s ease;
}

.btn-voice:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border-glass-hover);
}

.btn-voice.recording {
    background: rgba(255, 71, 87, 0.2);
    border-color: var(--danger-color);
    animation: recording-pulse 1s infinite;
}

@keyframes recording-pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(255, 71, 87, 0.4);
    }

    50% {
        box-shadow: 0 0 0 8px rgba(255, 71, 87, 0);
    }
}

/* 发送按钮 */
.btn-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-gradient);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 212, 255, 0.3);
}

.btn-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 212, 255, 0.5);
}

.btn-send:active {
    transform: scale(0.95);
}

.send-icon {
    transform: rotate(-45deg);
}

/* 输入提示 */
.chat-input-hint {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 0 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

#voiceStatus {
    color: var(--warning-color);
}

.char-count {
    font-family: 'JetBrains Mono', monospace;
}

/* 聊天页面响应式 */
@media (max-width: 768px) {

    /* 移动端重播按钮始终显示，无需 hover */
    .btn-replay {
        opacity: 0.6;
        background: rgba(0, 0, 0, 0.4);
    }

    .btn-replay.playing {
        opacity: 1;
        background: var(--primary-color);
    }

    .chat-container {
        height: calc(100vh - 160px);
        border-radius: 0;
        border: none;
        background: transparent;
    }

    .chat-header {
        padding: 12px 16px;
    }

    .chat-title {
        font-size: 1rem;
    }

    .chat-messages {
        padding: 12px;
    }

    .message {
        max-width: 90%;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }

    .message-bubble {
        padding: 10px 14px;
        font-size: 0.9rem;
    }

    .chat-input-area {
        padding: 12px 16px;
    }

    .chat-input-wrapper {
        padding: 10px 12px;
    }

    .chat-input {
        font-size: 0.95rem;
    }

    .btn-voice,
    .btn-send {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    .chat-welcome {
        padding: 40px 16px;
    }

    .welcome-icon {
        font-size: 2.5rem;
    }

    .chat-welcome h3 {
        font-size: 1.1rem;
    }

    .chat-welcome p {
        font-size: 0.85rem;
    }
}

/* ============================================================
   移动端深度适配 (Media Queries)
   ============================================================ */

@media (max-width: 768px) {

    /* 全局滚动优化 */
    /* 全局滚动优化 */
    .main-content {
        /* 
           保持与上方 Media Query 相同的 padding-top (120px) 以防止遮挡 
           同时保留 padding-bottom 以适应可能的底部操作（如有）
        */
        padding: 120px 16px 80px 16px;
        height: 100vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* 1. 登录页优化 */
    .login-body {
        position: static;
        /* 登录页允许滚动 */
        overflow-y: auto;
        min-height: 100vh;
    }

    /* 2. 表格转卡片视图 (Mobile Table Cards) */
    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    /* 隐藏表头 */
    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    tr {
        margin-bottom: 16px;
        background: rgba(255, 255, 255, 0.03);
        border: 1px solid var(--border-glass);
        border-radius: var(--radius-sm);
        padding: 12px;
    }

    tr:last-child {
        margin-bottom: 0;
    }

    td {
        border: none;
        position: relative;
        padding: 8px 0 8px 100px;
        /* 为标签留出空间 */
        min-height: 36px;
        display: flex;
        align-items: center;
        text-align: right;
        justify-content: flex-end;
    }

    td::before {
        position: absolute;
        left: 0;
        top: 8px;
        width: 90px;
        white-space: nowrap;
        font-weight: 600;
        color: var(--text-muted);
        text-align: left;
        content: attr(data-label);
        /* 使用 data-label 显示标题 */
    }

    .card-tools {
        gap: 6px;
    }

    .card-tools .btn {
        padding: 6px 10px;
        font-size: 0.78rem;
    }

    .device-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .device-actions .btn {
        font-size: 0.74rem;
        padding: 5px 8px;
    }

    .pagination-bar {
        flex-direction: column;
        align-items: flex-end;
    }

    .pagination-meta {
        width: 100%;
        text-align: right;
    }

    /* 3. 服务配置优化 */
    .service-card {
        margin-bottom: 16px;
    }

    .service-header {
        padding: 16px;
    }

    .service-body {
        padding: 16px;
    }

    .config-item {
        background: rgba(0, 0, 0, 0.2);
        padding: 12px;
        border-radius: var(--radius-sm);
        margin-bottom: 12px;
    }

    .config-label {
        margin-bottom: 8px;
        font-size: 0.85rem;
    }

    .config-value,
    .config-input {
        width: 100%;
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    .service-actions {
        flex-direction: column;
        gap: 8px;
    }

    .service-actions button {
        width: 100%;
    }

    /* 4. AI 聊天移动端布局重构 */
    #page-chat {
        /* 聊天页占满剩余空间 */
        height: calc(100vh - 130px);
        /* 减去顶部栏和底部导航 */
        flex-direction: column;
    }

    #page-chat.active {
        display: flex;
    }

    .chat-container {
        /* 移除边框和背景，融入页面 */
        height: 100%;
        max-height: none;
        border: none;
        background: transparent;
        border-radius: 0;
        backdrop-filter: none;
        /* 关键修复：修复输入框定位失效 */
        -webkit-backdrop-filter: none;
    }

    .chat-messages {
        /* 消息区域自适应 */
        flex: 1;
        padding: 16px 12px;
        /* 关键修复：为固定的输入区域留出空间 */
        padding-bottom: 100px;
        /* 关键修复：确保 iOS 可以滚动 */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .chat-input-area {
        /* 固定在屏幕底部 */
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(15, 23, 42, 0.95);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        padding: 10px 12px 12px 12px;
        border-top: 1px solid var(--border-glass);
        z-index: 90;
    }

    .chat-input-wrapper {
        background: rgba(255, 255, 255, 0.05);
    }

    /* 适配底部安全区域 (iPhone X+) */
    @supports (padding-bottom: env(safe-area-inset-bottom)) {
        .nav-menu {
            padding-bottom: 0;
            height: auto;
        }

        .chat-input-area {
            /* 输入框在底部，需要 padding-bottom */
            padding-bottom: calc(12px + env(safe-area-inset-bottom));
            bottom: 0;
        }

        .chat-messages {
            /* 关键修复：为安全区域留出额外空间 */
            padding-bottom: calc(120px + env(safe-area-inset-bottom));
        }

        .main-content {
            padding-bottom: calc(80px + env(safe-area-inset-bottom));
        }
    }
}