/* ============================================================
   智慧居家安全守护系统 - 管理后台公共样式
   ============================================================ */

:root {
  /* 主色系 */
  --color-primary: #E06A3E;
  --color-primary-dark: #C4552E;
  --color-primary-light: #FCE0D4;
  --color-primary-bg: #FFF0E8;

  /* 辅助色 */
  --color-accent: #4A8D78;
  --color-accent-light: #DCEAE5;

  /* 中性色 */
  --color-text-primary: #1A1A1A;
  --color-text-secondary: #555555;
  --color-text-tertiary: #888888;
  --color-text-placeholder: #AAAAAA;
  --color-border: #D8D8D8;
  --color-border-light: #E8E8E8;
  --color-bg: #F5F5F5;
  --color-bg-card: #FFFFFF;

  /* 语义色 */
  --color-danger: #D94444;
  --color-danger-light: #FFE8E8;
  --color-warning: #D9943E;
  --color-warning-light: #FFF0E0;
  --color-success: #44996D;
  --color-success-light: #E6F8EE;
  --color-info: #4A7D96;
  --color-info-light: #E4F0F6;

  /* 尺寸 */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* 阴影 */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.10);

  /* 侧边栏 */
  --sidebar-width: 240px;
  --sidebar-collapsed: 64px;
  --header-height: 56px;

  /* 字号 */
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 16px;
  --text-lg: 18px;
  --text-xl: 22px;
  --text-xxl: 28px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--color-bg);
  color: var(--color-text-primary);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
ul, ol { list-style: none; }

/* ============================================================
   登录页
   ============================================================ */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
  background: #fff;
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 420px;
  box-shadow: var(--shadow-lg);
}

.login-box .logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-box .logo h1 {
  font-size: var(--text-xl);
  color: var(--color-primary);
  margin-bottom: 4px;
}

.login-box .logo p {
  color: var(--color-text-tertiary);
  font-size: var(--text-sm);
}

.login-box .form-group {
  margin-bottom: 20px;
}

.login-box label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

.login-box input, .login-box select {
  width: 100%;
  height: 44px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  font-size: var(--text-base);
  transition: border-color 0.2s;
  outline: none;
}

.login-box input:focus, .login-box select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(224,106,62,0.1);
}

.login-box .login-btn {
  width: 100%;
  height: 44px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--text-md);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.login-box .login-btn:hover {
  background: var(--color-primary-dark);
}

.login-box .login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-box .error-msg {
  color: var(--color-danger);
  font-size: var(--text-sm);
  margin-top: 8px;
  text-align: center;
}

/* ============================================================
   管理后台布局
   ============================================================ */
.admin-layout {
  display: flex;
  min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
  width: var(--sidebar-width);
  background: #1E1E2D;
  color: #fff;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease;
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.sidebar-header .logo-icon {
  width: 32px;
  height: 32px;
  background: var(--color-primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-header .logo-text {
  margin-left: 12px;
  font-size: var(--text-md);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar.collapsed .logo-text { display: none; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.sidebar-nav .nav-group {
  margin-bottom: 4px;
}

.sidebar-nav .nav-group-title {
  padding: 8px 20px 4px;
  font-size: 11px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar.collapsed .nav-group-title { display: none; }

.sidebar-nav .nav-item {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  color: rgba(255,255,255,0.65);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  position: relative;
}

.sidebar-nav .nav-item:hover {
  color: #fff;
  background: rgba(255,255,255,0.06);
}

.sidebar-nav .nav-item.active {
  color: #fff;
  background: rgba(224,106,62,0.2);
  border-right: 3px solid var(--color-primary);
}

.sidebar-nav .nav-item .nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar.collapsed .nav-item .nav-icon { margin-right: 0; }

.sidebar-nav .nav-item .nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar.collapsed .nav-item .nav-label { display: none; }

.sidebar-nav .nav-item .badge {
  margin-left: auto;
  background: var(--color-danger);
  color: #fff;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
}

.sidebar.collapsed .nav-item .badge { display: none; }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 12px;
  flex-shrink: 0;
}

.sidebar-footer .user-info {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.sidebar-footer .user-info:hover {
  background: rgba(255,255,255,0.06);
}

.sidebar-footer .user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-footer .user-detail {
  margin-left: 10px;
  overflow: hidden;
}

.sidebar.collapsed .sidebar-footer .user-detail { display: none; }

.sidebar-footer .user-name {
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
}

.sidebar-footer .user-role {
  font-size: var(--text-xs);
  color: rgba(255,255,255,0.45);
  white-space: nowrap;
}

/* 主内容区 */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  transition: margin-left 0.3s ease;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main-content.expanded {
  margin-left: var(--sidebar-collapsed);
}

/* 顶部导航 */
.top-header {
  height: var(--header-height);
  background: #fff;
  border-bottom: 1px solid var(--color-border-light);
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.top-header .collapse-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  margin-right: 16px;
}

.top-header .collapse-btn:hover {
  background: var(--color-bg);
}

.top-header .breadcrumb {
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
}

.top-header .breadcrumb span {
  color: var(--color-text-primary);
  font-weight: 500;
}

.top-header .header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.top-header .header-actions .action-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  color: var(--color-text-secondary);
}

.top-header .header-actions .action-btn:hover {
  background: var(--color-border-light);
}

.top-header .header-actions .action-btn .dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  background: var(--color-danger);
  border-radius: 50%;
  border: 2px solid #fff;
}

/* 页面内容 */
.page-content {
  padding: 24px;
  flex: 1;
}

.page-header {
  margin-bottom: 24px;
}

.page-header h2 {
  font-size: var(--text-xl);
  font-weight: 600;
}

.page-header p {
  color: var(--color-text-tertiary);
  font-size: var(--text-sm);
  margin-top: 4px;
}

/* ============================================================
   统计卡片
   ============================================================ */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: #fff;
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.stat-card .stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.stat-card .stat-icon.blue { background: #E4F0F6; color: #4A7D96; }
.stat-card .stat-icon.red { background: #FFE8E8; color: #D94444; }
.stat-card .stat-icon.orange { background: #FFF0E0; color: #D9943E; }
.stat-card .stat-icon.green { background: #E6F8EE; color: #44996D; }
.stat-card .stat-icon.purple { background: #F0E6F6; color: #7B4A96; }

.stat-card .stat-info h3 {
  font-size: var(--text-xxl);
  font-weight: 700;
  line-height: 1.2;
}

.stat-card .stat-info p {
  color: var(--color-text-tertiary);
  font-size: var(--text-sm);
  margin-top: 4px;
}

.stat-card .stat-change {
  font-size: var(--text-xs);
  margin-top: 6px;
}

.stat-card .stat-change.up { color: var(--color-success); }
.stat-card .stat-change.down { color: var(--color-danger); }

/* ============================================================
   卡片面板
   ============================================================ */
.panel {
  background: #fff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border-light);
}

.panel-header h3 {
  font-size: var(--text-md);
  font-weight: 600;
}

.panel-header .panel-actions {
  display: flex;
  gap: 8px;
}

.panel-body {
  padding: 20px;
}

.panel-body.no-padding {
  padding: 0;
}

/* ============================================================
   表格
   ============================================================ */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

table th, table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--color-border-light);
  font-size: var(--text-sm);
  white-space: nowrap;
}

table th {
  background: #FAFAFA;
  font-weight: 600;
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

table tr:hover td {
  background: #FAFAFA;
}

table .text-right { text-align: right; }
table .text-center { text-align: center; }

/* 表格内的状态标签 */
.status-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: var(--text-xs);
  font-weight: 500;
}

.status-tag.info { background: var(--color-info-light); color: var(--color-info); }
.status-tag.success { background: var(--color-success-light); color: var(--color-success); }
.status-tag.warning { background: var(--color-warning-light); color: var(--color-warning); }
.status-tag.danger { background: var(--color-danger-light); color: var(--color-danger); }
.status-tag.default { background: #F0F0F0; color: #888; }

/* ============================================================
   筛选栏
   ============================================================ */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border-light);
  flex-wrap: wrap;
}

.filter-bar .filter-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-bar label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.filter-bar input, .filter-bar select {
  height: 34px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  font-size: var(--text-sm);
  outline: none;
  transition: border-color 0.2s;
}

.filter-bar input:focus, .filter-bar select:focus {
  border-color: var(--color-primary);
}

.filter-bar input { width: 200px; }
.filter-bar select { min-width: 140px; }

/* ============================================================
   按钮
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); opacity: 1; }

.btn-success { background: var(--color-success); color: #fff; }
.btn-warning { background: var(--color-warning); color: #fff; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-info { background: var(--color-info); color: #fff; }

.btn-outline {
  background: #fff;
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
}
.btn-outline:hover { border-color: var(--color-primary); color: var(--color-primary); opacity: 1; }

.btn-sm { height: 28px; padding: 0 10px; font-size: var(--text-xs); }
.btn-lg { height: 40px; padding: 0 24px; font-size: var(--text-md); }

.btn-text {
  background: none;
  border: none;
  color: var(--color-primary);
  padding: 0 4px;
}
.btn-text:hover { text-decoration: underline; opacity: 1; }

/* ============================================================
   分页
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--color-border-light);
}

.pagination .page-info {
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
}

.pagination .page-btns {
  display: flex;
  gap: 4px;
}

.pagination .page-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--color-border);
  background: #fff;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.pagination .page-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.pagination .page-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.pagination .page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pagination .page-size {
  margin-left: 12px;
}

.pagination .page-size select {
  height: 32px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0 8px;
  font-size: var(--text-sm);
  outline: none;
}

/* ============================================================
   模态框
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 560px;
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
}

.modal.small { width: 420px; }
.modal.large { width: 720px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border-light);
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: var(--text-lg);
  font-weight: 600;
}

.modal-header .modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--color-text-tertiary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-header .modal-close:hover {
  background: var(--color-bg);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--color-border-light);
  flex-shrink: 0;
}

/* 模态框表单 */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row.single { grid-template-columns: 1fr; }

.form-item {
  margin-bottom: 16px;
}

.form-item:last-child { margin-bottom: 0; }

.form-item label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

.form-item label .required {
  color: var(--color-danger);
  margin-left: 2px;
}

.form-item input, .form-item select, .form-item textarea {
  width: 100%;
  height: 38px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  font-size: var(--text-base);
  outline: none;
  transition: border-color 0.2s;
}

.form-item textarea {
  height: 80px;
  padding: 10px 12px;
  resize: vertical;
}

.form-item input:focus, .form-item select:focus, .form-item textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(224,106,62,0.1);
}

/* ============================================================
   提示消息
   ============================================================ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: var(--text-sm);
  box-shadow: var(--shadow-md);
  animation: slideInRight 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 360px;
}

.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }
.toast.warning { background: var(--color-warning); }
.toast.info { background: var(--color-info); }

/* ============================================================
   空状态 & 加载
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-text-tertiary);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.3;
}

.empty-state p {
  font-size: var(--text-base);
}

.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.loading-spinner .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border-light);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ============================================================
   详情面板
   ============================================================ */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.detail-item {
  display: flex;
  flex-direction: column;
}

.detail-item .detail-label {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  margin-bottom: 4px;
}

.detail-item .detail-value {
  font-size: var(--text-base);
  font-weight: 500;
}

/* ============================================================
   图表区域
   ============================================================ */
.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.chart-box {
  background: #fff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.chart-box h3 {
  font-size: var(--text-md);
  font-weight: 600;
  margin-bottom: 16px;
}

.chart-placeholder {
  height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-tertiary);
  background: #FAFAFA;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}

/* ============================================================
   告警列表特殊样式
   ============================================================ */
.alert-urgent-row td {
  background: #FFF5F5 !important;
}

.alert-urgent-row:hover td {
  background: #FFE8E8 !important;
}

.alert-type-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.alert-type-tag .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.alert-type-tag .dot.sos { background: #D94444; }
.alert-type-tag .dot.fall { background: #D9943E; }
.alert-type-tag .dot.heart { background: #E06A3E; }
.alert-type-tag .dot.battery { background: #4A8D78; }
.alert-type-tag .dot.offline { background: #888; }

/* ============================================================
   动画
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 1200px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .chart-row { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar { width: var(--sidebar-collapsed); }
  .sidebar .logo-text,
  .sidebar .nav-group-title,
  .sidebar .nav-item .nav-label,
  .sidebar .nav-item .badge,
  .sidebar .user-detail { display: none; }
  .sidebar .nav-item .nav-icon { margin-right: 0; }
  .main-content { margin-left: var(--sidebar-collapsed); }
  .stat-cards { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}
