/* IoT Device Cloud Platform - 深色科技风格CSS */

/* ===== CSS变量 ===== */
:root {
  --primary: #00D9FF;
  --primary-hover: #00c4e6;
  --secondary: #6366F1;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --bg-dark: #0F172A;
  --bg-surface: #1E293B;
  --bg-card: #263548;
  --border: #334155;
  --border-light: #475569;
  --text-primary: #F8FAFC;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --transition: all 0.15s ease;
}

/* ===== 重置样式 ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: var(--transition);
}

a:hover {
  color: var(--primary-hover);
}

/* ===== 管理员专用元素 ===== */
.admin-only {
  display: none;
}

/* ===== 布局 ===== */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
  width: 240px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-logo svg {
  width: 20px;
  height: 20px;
  color: white;
}

.sidebar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.nav-section {
  margin-bottom: 24px;
}

.nav-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 12px;
  margin-bottom: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 2px;
}

.nav-item:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(0, 217, 255, 0.1);
  color: var(--primary);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-item span {
  font-size: 14px;
}

/* 主内容区 */
.main-content {
  flex: 1;
  margin-left: 240px;
  min-height: 100vh;
}

/* 顶部栏 */
.topbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-title {
  font-size: 20px;
  font-weight: 600;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.user-info:hover {
  background: var(--bg-card);
}

.user-avatar {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--secondary), var(--primary));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

.user-name {
  font-size: 14px;
  font-weight: 500;
}

.user-company {
  font-size: 12px;
  color: var(--text-secondary);
}

/* 页面内容 */
.page-content {
  padding: 24px;
}

/* ===== 卡片组件 ===== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: var(--transition);
}

.card:hover {
  border-color: var(--border-light);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
}

/* 统计卡片 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon.blue {
  background: rgba(0, 217, 255, 0.15);
  color: var(--primary);
}

.stat-icon.green {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
}

.stat-icon.orange {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.stat-icon.red {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.stat-icon svg {
  width: 24px;
  height: 24px;
}

.stat-content {
  flex: 1;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: var(--primary);
  color: #000;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-icon:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* ===== 表单 ===== */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 217, 255, 0.1);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

/* 日期输入框特殊处理 - 防止日历下拉被裁剪 */
input[type="date"] {
  position: relative;
  z-index: 1;
}

/* 日期输入框在抽屉中需要更高z-index */
.drawer-body input[type="date"],
.tab-content input[type="date"] {
  position: relative;
  z-index: 1002;
}

/* 日期选择器容器不裁剪日历面板 */
.date-picker-wrapper {
  overflow: visible !important;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  filter: invert(0.7);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

/* 复选框组 */
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.checkbox-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ===== 表格 ===== */
.table-container {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table th {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: var(--bg-card);
}

.table td {
  font-size: 14px;
  color: var(--text-primary);
}

.table tbody tr {
  transition: var(--transition);
}

.table tbody tr:hover {
  background: var(--bg-card);
}

.table-actions {
  display: flex;
  gap: 8px;
}

/* ===== 状态标签 ===== */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-badge.online {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
}

.status-badge.online::before {
  background: var(--success);
  animation: pulse 2s infinite;
}

.status-badge.offline {
  background: rgba(100, 116, 139, 0.15);
  color: var(--text-muted);
}

.status-badge.offline::before {
  background: var(--text-muted);
}

.status-badge.alarm {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.status-badge.alarm::before {
  background: var(--danger);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ===== 模态框 ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95) translateY(-20px);
  transition: all 0.2s ease;
}

.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.modal-close:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* ===== Toast通知 ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

.toast.success {
  border-color: var(--success);
}

.toast.error {
  border-color: var(--danger);
}

.toast.warning {
  border-color: var(--warning);
}

.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--danger); }
.toast.warning .toast-icon { color: var(--warning); }

.toast-message {
  flex: 1;
  font-size: 14px;
}

/* ===== 报警联系人选择器 ===== */
.contact-checkbox-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.contact-checkbox-item:hover {
  background: var(--bg-hover);
}
.contact-checkbox-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}
.contact-cb-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.contact-cb-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}
.contact-cb-channels {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.contact-channel-tag {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 500;
}
.contact-channel-tag.phone { background: rgba(59,130,246,0.15); color: #60a5fa; }
.contact-channel-tag.sms   { background: rgba(16,185,129,0.15); color: #34d399; }
.contact-channel-tag.wechat{ background: rgba(132,204,22,0.15); color: #a3e635; }
.contact-channel-tag.email { background: rgba(245,158,11,0.15); color: #fbbf24; }

/* 标签式徽章 */
.tag-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(99,102,241,0.15);
  color: #a5b4fc;
  margin-right: 3px;
  margin-bottom: 2px;
}
.tag-badge.tag-user {
  background: rgba(16,185,129,0.15);
  color: #34d399;
}

/* ===== 设备树选择 ===== */
.device-tree-root {
  padding: 8px;
}

.device-tree-node {
  margin-bottom: 2px;
}

.device-tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 13px;
  color: var(--text-primary);
}

.device-tree-item:hover {
  background: rgba(99, 102, 241, 0.1);
}

.device-tree-item-selected {
  background: rgba(99, 102, 241, 0.2) !important;
  border: 1px solid rgba(99, 102, 241, 0.4);
}

.device-tree-child {
  padding-left: 28px;
  font-size: 12px;
  color: var(--text-secondary);
}

.device-tree-child:hover {
  color: var(--text-primary);
}

.device-tree-arrow {
  transition: transform 0.2s;
  flex-shrink: 0;
}

.device-tree-device-id {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
}

.device-tree-subcode {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
}

.device-tree-badge {
  margin-left: 4px;
  padding: 1px 6px;
  background: var(--primary);
  color: white;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
}

.device-tree-children {
  display: block;
}

.device-tree-children[style*="none"] {
  display: none;
}

/* ===== 图表容器 ===== */
.chart-container {
  position: relative;
  height: 300px;
}

.chart-container.small {
  height: 200px;
}

/* ===== 分页 ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.pagination-info {
  font-size: 13px;
  color: var(--text-secondary);
}

.pagination-buttons {
  display: flex;
  gap: 8px;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  width: 100%;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.pagination-ellipsis {
  padding: 0 6px;
  color: var(--text-secondary);
  align-self: center;
}

.pagination-jump {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.pagination-jump .page-jump-input {
  width: 60px;
  text-align: center;
  padding: 4px 6px;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ===== 加载动画 ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== 空状态 ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 16px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 20px;
}

/* ===== 项目树 ===== */
.project-tree {
  list-style: none;
}

.tree-item {
  margin-bottom: 4px;
}

.tree-node {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  gap: 8px;
}

/* 设备管理页面项目选择器：子项目显示在父项目下面 */
.tree-select-dropdown .tree-node {
  display: block;
  padding: 0;
}

.tree-node:hover {
  background: var(--bg-card);
}

.tree-toggle {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.tree-toggle.expanded {
  transform: rotate(90deg);
}

.tree-icon {
  width: 16px;
  height: 16px;
  color: var(--primary);
}

.tree-name {
  flex: 1;
  font-size: 14px;
}

.tree-count {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 2px 8px;
  border-radius: 10px;
}

.tree-children {
  list-style: none;
  padding-left: 28px;
  margin-top: 4px;
  display: none;
}

.tree-children.expanded {
  display: block;
}

/* ===== 设备详情抽屉 ===== */
.drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.drawer-overlay.active {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 600px;
  max-width: 100%;
  height: 100vh;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  z-index: 1001;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

.drawer-overlay.active .drawer {
  transform: translateX(0);
}

.drawer-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-title {
  font-size: 18px;
  font-weight: 600;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.drawer-section {
  margin-bottom: 24px;
}

.drawer-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ===== 实时数据 ===== */
.realtime-feed {
  max-height: 300px;
  overflow-y: auto;
}

.feed-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.feed-item:last-child {
  border-bottom: none;
}

.feed-device {
  font-weight: 500;
  min-width: 100px;
}

.feed-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px;
  color: var(--primary);
}

.feed-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

/* ===== 登录页面 ===== */
.login-container {
  min-height: 100vh;
  display: flex;
}

.login-left {
  flex: 1;
  background: linear-gradient(135deg, var(--bg-dark), var(--bg-surface));
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 60px;
}

.login-brand {
  text-align: center;
}

.login-logo {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
}

.login-logo svg {
  width: 48px;
  height: 48px;
  color: white;
}

.login-brand h1 {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
}

.login-brand p {
  color: var(--text-secondary);
  font-size: 16px;
}

.login-features {
  margin-top: 48px;
  text-align: left;
}

.login-feature {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  color: var(--text-secondary);
}

.login-feature svg {
  width: 20px;
  height: 20px;
  color: var(--primary);
}

.login-right {
  width: 480px;
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 60px;
}

.login-form h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.login-form p {
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.login-form .form-group {
  margin-bottom: 20px;
}

.login-form .btn {
  width: 100%;
  padding: 12px;
  margin-top: 8px;
}

.login-remember {
  margin: -4px 0 20px;
}

.remember-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.remember-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary-color, #3b82f6);
  cursor: pointer;
}

.login-divider {
  text-align: center;
  margin: 24px 0;
  color: var(--text-muted);
  font-size: 13px;
}

/* ===== 网格布局 ===== */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

/* ===== 响应式 ===== */
@media (max-width: 1200px) {
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .main-content {
    margin-left: 0;
  }
  
  .login-left {
    display: none;
  }
  
  .login-right {
    width: 100%;
  }
  
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .drawer {
    width: 100%;
  }
}

/* ===== 开关 ===== */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border);
  border-radius: 24px;
  transition: 0.3s;
}

.switch-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: 0.3s;
}

.switch input:checked + .switch-slider {
  background-color: var(--primary);
}

.switch input:checked + .switch-slider:before {
  transform: translateX(20px);
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab, .tab-btn {
  padding: 12px 20px;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-size: 14px;
  font-family: inherit;
}

.tab:hover, .tab-btn:hover {
  color: var(--text-primary);
}

.tab.active, .tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ===== 数据时间轴 ===== */
.timeline {
  position: relative;
  padding-left: 24px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  padding-bottom: 20px;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -18px;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
}

.timeline-item.online::before {
  background: var(--success);
}

.timeline-item.offline::before {
  background: var(--danger);
}

.timeline-item.connection::before {
  background: #3B82F6;
}

.timeline-item.data::before {
  background: #06B6D4;
}

.timeline-item.alarm::before {
  background: var(--danger);
}

.timeline-item.system::before {
  background: var(--text-secondary);
}

.timeline-item.error::before {
  background: #F59E0B;
}

.timeline-time {
  font-size: 12px;
  color: var(--text-muted);
}

.timeline-message {
  font-size: 14px;
  margin-top: 4px;
}

/* ===== 树形选择器 ===== */
.tree-select-container {
  position: relative;
  width: 100%;
}

.tree-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  min-height: 38px;
}

.tree-select-trigger:hover {
  border-color: var(--border-light);
}

.tree-select-trigger .selected-text {
  color: var(--text-muted);
}

.tree-select-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 300px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1000;
  margin-top: 4px;
}

.tree-select-dropdown.show {
  display: block;
}

.tree-node {
  padding: 0;
}

.tree-node-header {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  transition: var(--transition);
  gap: 8px;
}

.tree-node-header:hover {
  background: var(--bg-surface);
}

.tree-node-header.selected {
  background: rgba(0, 217, 255, 0.1);
  color: var(--primary);
}

.tree-node-toggle {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s;
}

.tree-node-toggle.expanded {
  transform: rotate(90deg);
}

.tree-node-toggle.empty {
  visibility: hidden;
}

.tree-node-icon {
  width: 16px;
  height: 16px;
  color: var(--warning);
}

.tree-node-name {
  flex: 1;
}

.tree-node-badge {
  font-size: 11px;
  background: var(--bg-surface);
  padding: 2px 6px;
  border-radius: 10px;
  color: var(--text-secondary);
}

.tree-children {
  padding-left: 20px;
  display: none;
}

.tree-children.expanded {
  display: block;
}

/* 移动端适配 */
@media (max-width: 768px) {
  .tree-select-dropdown {
    position: fixed;
    left: 10px;
    right: 10px;
    max-height: 60vh;
    top: 50%;
    transform: translateY(-50%);
    margin-top: 0;
  }
}

/* ===== 项目管理页面父项目树形选择器 ===== */
.proj-tree-node {
  margin-bottom: 2px;
}

.proj-tree-parent {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  gap: 4px;
}

.proj-tree-parent:hover {
  background: var(--bg-surface);
}

.proj-tree-leaf {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  gap: 4px;
  flex: 1;
}

.proj-tree-leaf:hover {
  background: var(--bg-surface);
}

.proj-tree-leaf.selected {
  background: rgba(0, 217, 255, 0.1);
  color: var(--primary);
}

.proj-tree-toggle {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.proj-tree-toggle:not(.leaf) {
  cursor: pointer;
}

.proj-tree-children {
  display: none;
  padding-left: 20px;
}

.proj-tree-children.expanded {
  display: block;
}

.proj-tree-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 父项目选择器样式重置 */
#parentProjectTree {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  background: var(--bg-dark);
}

/* ===== AI 智能分析面板（Phase 2） ===== */
.ai-analysis-card {
  margin: 16px 0 8px;
  padding: 18px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.ai-analysis-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.ai-analysis-title {
  display: flex;
  align-items: center;
  gap: 12px;
}
.ai-analysis-icon {
  font-size: 28px;
  line-height: 1;
}
.ai-analysis-title h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.ai-analysis-sub {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-muted);
}
.ai-anomaly-summary {
  display: flex;
  gap: 10px;
  margin: 14px 0 8px;
  flex-wrap: wrap;
}
.ai-badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
}
.ai-badge-critical { background: #ef4444; }
.ai-badge-warning  { background: #f59e0b; }
.ai-badge-info     { background: #3b82f6; }
.ai-anomaly-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}
.ai-empty {
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px 2px;
}
.ai-anomaly-item {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--bg-card);
}
.ai-anomaly-item.ai-sev-critical { border-left-color: #ef4444; }
.ai-anomaly-item.ai-sev-warning  { border-left-color: #f59e0b; }
.ai-anomaly-item.ai-sev-info     { border-left-color: #3b82f6; }
.ai-anomaly-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.ai-anomaly-device { font-weight: 600; }
.ai-anomaly-time { margin-left: auto; font-size: 12px; color: var(--text-muted); }
.ai-tag {
  padding: 1px 8px;
  border-radius: 6px;
  font-size: 11px;
  background: var(--bg-dark);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.ai-tag-flatline { color: #6b7280; border-color: #6b7280; }
.ai-tag-spike { color: #f59e0b; border-color: #f59e0b; }
.ai-tag-drift { color: #3b82f6; border-color: #3b82f6; }
.ai-tag-over_threshold { color: #ef4444; border-color: #ef4444; }
.ai-tag-dead_zone { color: #6b7280; border-color: #6b7280; }
.ai-tag-no_data { color: #d97706; border-color: #d97706; }
.ai-sev-tag-critical { color: #ef4444; border-color: #ef4444; }
.ai-sev-tag-warning { color: #f59e0b; border-color: #f59e0b; }
.ai-sev-tag-info { color: #3b82f6; border-color: #3b82f6; }
.ai-anomaly-msg {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}
