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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #f5f7fa;
    color: #333;
    overflow-x: hidden;
}

/* 侧边栏 */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 250px;
    height: 100vh;
    background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    z-index: 1000;
}

.logo {
    text-align: center;
    padding: 20px 0;
    border-bottom: 1px solid rgba(255,255,255,0.2);
    margin-bottom: 30px;
}

.logo h2 {
    font-size: 1.8em;
    margin-bottom: 5px;
}

.logo p {
    font-size: 0.9em;
    opacity: 0.8;
}

.nav-menu {
    list-style: none;
}

.nav-item {
    padding: 15px 20px;
    margin: 5px 0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
}

.nav-item:hover {
    background: rgba(255,255,255,0.1);
}

.nav-item.active {
    background: rgba(255,255,255,0.2);
    font-weight: bold;
}

.nav-item .icon {
    margin-right: 10px;
    font-size: 1.2em;
}

/* 主内容区 */
.main-content {
    margin-left: 250px;
    min-height: 100vh;
}

/* 顶部栏 */
.topbar {
    background: white;
    padding: 20px 40px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.topbar h1 {
    font-size: 1.8em;
    color: #667eea;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.status-indicator.online {
    background: #10b981;
    box-shadow: 0 0 10px #10b981;
}

/* 页面容器 */
.page-container {
    padding: 40px;
}

.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); }
}

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

.stat-card {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: transform 0.3s, box-shadow 0.3s;
}

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

.stat-icon {
    font-size: 3em;
}

.stat-info h3 {
    font-size: 2em;
    color: #667eea;
    margin-bottom: 5px;
}

.stat-info p {
    color: #666;
    font-size: 0.9em;
}

/* 内容网格 */
.content-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

/* 面板 */
.panel {
    background: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.panel.full-width {
    grid-column: 1 / -1;
}

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

.panel h3 {
    color: #667eea;
    font-size: 1.3em;
    margin-bottom: 20px;
}

/* 按钮 */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.3s;
    font-weight: 500;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #f5f7fa;
    color: #667eea;
    border: 1px solid #667eea;
}

.btn-secondary:hover {
    background: #667eea;
    color: white;
}

.btn-danger {
    background: #ef4444;
    color: white;
}

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

/* 表格 */
.table-container {
    overflow-x: auto;
}

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

.data-table thead {
    background: #f5f7fa;
}

.data-table th {
    padding: 8px 10px;
    text-align: left;
    font-weight: 600;
    color: #667eea;
    border-bottom: 2px solid #e5e7eb;
    font-size: 0.85em;
}

.data-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 0.85em;
}

.data-table tbody tr:hover {
    background: #f9fafb;
}

/* 状态标签 */
.status-badge {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 500;
    display: inline-block;
}

.status-online {
    background: #d1fae5;
    color: #065f46;
}

.status-offline {
    background: #fee2e2;
    color: #991b1b;
}

.status-tcp {
    background: #dbeafe;
    color: #1e40af;
}

/* 设备列表 */
.device-list {
    max-height: 400px;
    overflow-y: auto;
}

.device-item {
    padding: 10px 12px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

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

.device-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.device-info h4 {
    color: #667eea;
    margin-bottom: 0;
    font-size: 0.95em;
}

.device-info p {
    font-size: 0.8em;
    color: #666;
    margin: 0;
}

.device-sensors {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.8em;
}

.sensor-tag {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: 500;
}

.sensor-tag.low {
    background: #dbeafe;
    color: #1e40af;
}

.sensor-tag.high {
    background: #fef3c7;
    color: #92400e;
}

.sensor-tag.normal {
    background: #d1fae5;
    color: #065f46;
}

.sensor-tag.alert {
    background: #fee2e2;
    color: #991b1b;
}

.device-status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* 异常设备警告样式 */
.device-item.device-alert {
    background: #fef2f2;
    border-left: 3px solid #ef4444;
    border-radius: 4px;
}

.device-item.device-alert h4 a {
    color: #dc2626 !important;
}

/* 系统信息 */
.system-info {
    display: grid;
    gap: 15px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #e5e7eb;
}

.info-row span:first-child {
    color: #666;
}

.info-row span:last-child {
    font-weight: 600;
    color: #667eea;
}

/* 表单 */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #666;
    font-weight: 500;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 15px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 1em;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    animation: fadeIn 0.3s;
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s;
}

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

.modal-header {
    padding: 20px 30px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    color: #667eea;
}

.close {
    font-size: 1.5em;
    cursor: pointer;
    color: #999;
    transition: color 0.3s;
}

.close:hover {
    color: #333;
}

.modal-content form {
    padding: 30px;
}

/* 告警列表 */
.alerts-list {
    max-height: 500px;
    overflow-y: auto;
}

.alert-item {
    padding: 15px;
    border-left: 4px solid #f59e0b;
    background: #fef3c7;
    margin-bottom: 10px;
    border-radius: 6px;
}

.alert-item.error {
    border-left-color: #ef4444;
    background: #fee2e2;
}

.alert-item.success {
    border-left-color: #10b981;
    background: #d1fae5;
}

.alert-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.alert-title {
    font-weight: 600;
    color: #333;
}

.alert-time {
    font-size: 0.85em;
    color: #666;
}

.alert-message {
    color: #666;
    font-size: 0.9em;
}

.alert-item {
    cursor: pointer;
    transition: opacity 0.2s;
}

.alert-item:hover {
    opacity: 0.85;
}

.alert-item.alert-critical {
    border-left-color: #ef4444;
    background: #fee2e2;
}

.alert-item.alert-warning {
    border-left-color: #f59e0b;
    background: #fef3c7;
}

.alert-item.alert-info {
    border-left-color: #3b82f6;
    background: #eff6ff;
}

.alert-body p {
    margin: 4px 0;
    font-size: 0.9em;
}

.badge-danger {
    background: #fee2e2;
    color: #ef4444;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.85em;
}

.badge-info {
    background: #e0e7ff;
    color: #6366f1;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.85em;
}

#alerts-list .empty,
#alerts-list .error {
    text-align: center;
    padding: 30px;
    color: #999;
}

/* 加载状态 */
.loading {
    text-align: center;
    padding: 40px;
    color: #999;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .content-grid,
    .settings-grid {
        grid-template-columns: 1fr;
    }
}

/* ========== 模态框样式 ========== */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
    animation: fadeIn 0.3s;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #fefefe;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideIn 0.3s;
}

.modal-large .modal-content {
    max-width: 1200px;
    width: 95%;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: #333;
}

.modal-body {
    padding: 20px;
}

.close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

.close:hover,
.close:focus {
    color: #000;
}

/* 视频容器 */
.video-container {
    width: 100%;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 20px;
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-placeholder {
    text-align: center;
    color: #fff;
    padding: 40px;
}

.video-placeholder p {
    margin: 10px 0;
}

.video-info {
    font-size: 0.9em;
    color: #aaa;
}

.camera-details {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.camera-details h4 {
    margin-top: 0;
    color: #667eea;
}

.camera-details .detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #e0e0e0;
}

.camera-details .detail-row:last-child {
    border-bottom: none;
}

.camera-details .detail-label {
    font-weight: 600;
    color: #666;
}

.camera-details .detail-value {
    color: #333;
}

/* 面板操作区 */
.panel-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.search-input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    width: 250px;
}

.filter-select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background: white;
}

/* 动画 */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* 编辑设备浮动窗口 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal-overlay .modal-content {
    background: white;
    border-radius: 8px;
    width: 400px;
    max-width: 90%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.2s ease;
}

.modal-overlay .modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-overlay .modal-header h3 {
    margin: 0;
    font-size: 16px;
    color: #333;
}

.modal-overlay .modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #666;
    padding: 4px 8px;
}

.modal-overlay .modal-close:hover {
    color: #333;
}

.modal-overlay .modal-body {
    padding: 20px;
}

.modal-overlay .modal-footer {
    padding: 12px 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: #555;
    font-size: 14px;
}

.form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.1);
}

/* 可排序表头 */
.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 20px !important;
}

.sortable:hover {
    background: #f0f4f8;
}

.sortable::after {
    content: '↕';
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: #999;
}

.sortable.sort-asc::after {
    content: '↑';
    color: #007bff;
}

.sortable.sort-desc::after {
    content: '↓';
    color: #007bff;
}
