/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4f46e5;
    --secondary-color: #6366f1;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #3b82f6;
    --dark-bg: #1e293b;
    --darker-bg: #0f172a;
    --light-bg: #f8fafc;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-light: #94a3b8;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--light-bg);
    color: var(--text-primary);
    line-height: 1.6;
}

.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, var(--darker-bg) 0%, var(--dark-bg) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.login-card {
    background: white;
    width: 90%;
    max-width: 380px;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-card h2 {
    margin-bottom: 1rem;
}

/* 容器布局 */
.container {
    display: flex;
    min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
    width: 260px;
    background: linear-gradient(180deg, var(--darker-bg) 0%, var(--dark-bg) 100%);
    color: white;
    padding: 2rem 0;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.5rem;
    margin-bottom: 2rem;
}

.logo i {
    font-size: 2rem;
    color: var(--primary-color);
}

.logo h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

.nav-menu {
    display: flex;
    flex-direction: column;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    color: #cbd5e1;
    text-decoration: none;
    transition: all 0.3s;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: white;
}

.nav-item.active {
    background-color: rgba(79, 70, 229, 0.1);
    border-left-color: var(--primary-color);
    color: white;
}

.nav-item i {
    font-size: 1.2rem;
    width: 20px;
}

/* 主内容区 */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 2rem;
}

/* 顶部栏 */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    background: white;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.search-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--light-bg);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    width: 300px;
}

.search-box i {
    color: var(--text-light);
}

.search-box input {
    border: none;
    background: none;
    outline: none;
    width: 100%;
    font-size: 0.9rem;
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.server-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--light-bg);
    border-radius: 8px;
    font-size: 0.9rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-light);
    animation: pulse 2s infinite;
}

.status-dot.online {
    background-color: var(--success-color);
}

.status-dot.offline {
    background-color: var(--danger-color);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.3s;
}

.btn-icon:hover {
    background-color: var(--light-bg);
    color: var(--primary-color);
}

/* 页面 */
.page {
    display: none;
}

.page.active {
    display: block;
    animation: fadeIn 0.3s;
}

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

.page-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

/* 统计卡片 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.3s, box-shadow 0.3s;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
}

.stat-icon.blue { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.stat-icon.green { background: linear-gradient(135deg, #10b981 0%, #059669 100%); }
.stat-icon.orange { background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); }
.stat-icon.red { background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); }

.stat-info h3 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-info p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* 表格 */
.table-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead {
    background-color: var(--light-bg);
}

.data-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table td {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.data-table tbody tr {
    transition: background-color 0.2s;
}

.data-table tbody tr:hover {
    background-color: var(--light-bg);
}

/* 用户管理表格特殊样式 */
.data-table code {
    background-color: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
}

.data-table .detail-column {
    color: var(--text-secondary);
    font-size: 0.9em;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 10px;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-light);
}

/* 徽章 */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge.success {
    background-color: #d1fae5;
    color: #065f46;
}

.badge.danger {
    background-color: #fee2e2;
    color: #991b1b;
}

.badge.warning {
    background-color: #fef3c7;
    color: #92400e;
}

.badge.info {
    background-color: #dbeafe;
    color: #1e40af;
}

/* 按钮 */
.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
    background-color: var(--text-secondary);
    color: white;
}

.btn-secondary:hover {
    background-color: var(--text-primary);
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.3s;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-large {
    max-width: 800px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.3s;
}

.close-btn:hover {
    background-color: var(--light-bg);
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* 表单 */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* 信息框 */
.info-box {
    background: #dbeafe;
    border-left: 4px solid var(--info-color);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.info-box i {
    color: var(--info-color);
    font-size: 1.5rem;
}

/* 最近设备 */
.recent-devices {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.recent-devices h2 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* 监控网格 */
.monitor-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.monitor-card {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.monitor-card h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.monitor-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
}

.message-log {
    max-height: 400px;
    overflow-y: auto;
    background: var(--light-bg);
    padding: 1rem;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
}

.message-item {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 0.5rem;
}

.message-item:last-child {
    border-bottom: none;
}

.message-time {
    color: var(--text-light);
    font-size: 0.75rem;
}

/* 日志容器 */
.log-container {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    max-height: 600px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
}

.log-entry {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 0.5rem;
}

.log-entry:last-child {
    border-bottom: none;
}

/* 日志标签页 */
.log-tabs {
    display: flex;
    gap: 5px;
    border-bottom: 2px solid var(--border-color);
}

.log-tab {
    padding: 8px 16px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.log-tab:hover {
    color: var(--primary-color);
}

.log-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    font-weight: 500;
}

/* 后端日志容器 */
.backend-log-container {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.log-filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 1rem;
    align-items: center;
}

.log-filter-bar select,
.log-filter-bar input {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
}

.backend-log-list {
    max-height: 600px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
}

.backend-log-entry {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 8px;
    border-radius: 6px;
    background: var(--light-bg);
    transition: background 0.2s;
}

.backend-log-entry:hover {
    background: #f5f5f5;
}

.backend-log-entry.heartbeat {
    background: #fff3cd;
    border-left: 4px solid #ffc107;
}

.backend-log-entry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 8px;
}

.backend-log-time {
    color: var(--text-light);
    font-size: 0.8rem;
}

.backend-log-type {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.backend-log-type.mqtt {
    background: #e3f2fd;
    color: #1976d2;
}

.backend-log-type.http {
    background: #f3e5f5;
    color: #7b1fa2;
}

.backend-log-type.api {
    background: #e8f5e9;
    color: #388e3c;
}

.backend-log-event {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    background: var(--border-color);
    color: var(--text-primary);
}

.backend-log-event.heartbeat {
    background: #ffc107;
    color: #000;
    font-weight: 600;
}
.backend-log-event.client {
    background: #c8e6c9;
    color: #2e7d32;
    font-weight: 600;
}
.backend-log-event.disconnect {
    background: #ffcdd2;
    color: #c62828;
    font-weight: 600;
}
.backend-log-event.subscribe {
    background: #bbdefb;
    color: #1565c0;
    font-weight: 600;
}
.backend-log-event.publish {
    background: #e1bee7;
    color: #7b1fa2;
    font-weight: 600;
}

.backend-log-body {
    margin-top: 8px;
    padding: 8px;
    background: white;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.backend-log-body pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-all;
    font-size: 0.8rem;
    line-height: 1.4;
}

.backend-log-topic {
    color: #1976d2;
    font-weight: 500;
}

.backend-log-client {
    color: #388e3c;
    font-weight: 500;
}

.log-time {
    color: var(--text-light);
    margin-right: 1rem;
}

/* 设备详情 */
.device-detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.detail-item {
    padding: 1rem;
    background: var(--light-bg);
    border-radius: 8px;
}

.detail-item label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.detail-item .value {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* 下拉刷新样式 */
.pull-refresh-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 10px;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.pull-refresh-indicator.show {
    display: flex;
    animation: slideDown 0.3s ease;
}

.pull-refresh-indicator i {
    font-size: 1.2rem;
}

.pull-refresh-indicator span {
    font-size: 0.9rem;
    font-weight: 500;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
    }
    to {
        transform: translateY(0);
    }
}

/* 响应式设计 */
@media (max-width: 768px) {
    .sidebar {
        width: 200px;
    }

    .main-content {
        margin-left: 200px;
        padding: 1rem;
    }

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

    .device-detail-grid {
        grid-template-columns: 1fr;
    }

    .search-box {
        width: 200px;
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 60px;
    }

    .logo h2,
    .nav-item span {
        display: none;
    }

    .main-content {
        margin-left: 60px;
    }
}

