* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #7c5cfc;
  --primary-light: #ede9fe;
  --bg: #f0f2f8;
  --card: #fff;
  --text: #1e1b2e;
  --muted: #6b7280;
  --border: #e8eaef;
  --danger: #ef4444;
  --sidebar-w: 240px;
  --bottom-nav-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}
html { -webkit-text-size-adjust: 100%; overflow-x: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
  background: var(--bg); color: var(--text);
  overflow-x: hidden; max-width: 100vw;
}
body.scroll-lock { overflow: hidden; touch-action: none; }
.hidden { display: none !important; }

/* Login */
.login-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; padding-top: calc(16px + var(--safe-top));
  background: linear-gradient(135deg, #ede9fe 0%, #f0f2f8 100%);
}
.login-card {
  background: var(--card); padding: 32px 24px; border-radius: 16px;
  width: min(380px, 100%); box-shadow: 0 8px 32px rgba(124,92,252,0.12);
}
.login-card h1 { font-size: 22px; margin-bottom: 8px; }
.login-card p { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input, .input-text, select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 16px; background: var(--card);
}
.btn {
  padding: 12px 18px; border: none; border-radius: 8px;
  font-size: 15px; font-weight: 500; cursor: pointer;
  min-height: 44px; touch-action: manipulation;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; min-height: 40px; }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-danger { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }

.filter-bar { margin-bottom: 12px; }
.toolbar-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.scroll-x table { min-width: 900px; }
.badge-ban { background: #fef2f2; color: #dc2626; padding: 2px 8px; border-radius: 6px; font-size: 12px; }
.badge-normal { background: #ecfdf5; color: #059669; padding: 2px 8px; border-radius: 6px; font-size: 12px; }
.action-link { color: var(--primary); cursor: pointer; margin-right: 8px; font-size: 13px; border: none; background: none; }

.app-selector {
  max-width: 160px; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; background: #fff; margin-left: auto; margin-right: 8px;
}
@media (max-width: 480px) {
  .app-selector { max-width: 120px; font-size: 12px; }
}

/* ===== 移动优先布局 ===== */
.app-shell {
  min-height: 100vh; min-height: 100dvh;
  width: 100%; max-width: 100vw; overflow-x: hidden;
}
.app-body {
  display: flex; flex-direction: column; flex: 1;
  width: 100%; min-height: 100vh; min-height: 100dvh;
}

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 30;
  width: min(var(--sidebar-w), 86vw);
  background: var(--card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
  transform: translateX(-105%);
  transition: transform 0.25s ease;
  box-shadow: none;
}
.sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.15); }

.sidebar-brand {
  padding: 14px 16px; display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 15px; border-bottom: 1px solid var(--border);
}
.sidebar-close {
  margin-left: auto; width: 40px; height: 40px; flex-shrink: 0;
  border: none; background: #f3f4f6; border-radius: 8px; font-size: 22px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.brand-icon {
  width: 32px; height: 32px; background: var(--primary); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 16px;
  flex-shrink: 0;
}
.nav { flex: 1; padding: 12px 8px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 12px;
  border-radius: 8px; font-size: 15px; color: var(--muted);
  margin-bottom: 4px; border: none; background: none; width: 100%; text-align: left;
  min-height: 48px; cursor: pointer; position: relative;
}
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.sidebar-user {
  padding: 16px; padding-bottom: calc(16px + var(--safe-bottom));
  border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--primary-light);
  color: var(--primary); display: flex; align-items: center; justify-content: center;
}
.user-info small { display: block; color: var(--muted); font-size: 11px; }

.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 25;
}
.sidebar-overlay:not(.hidden) { display: block; }

.main {
  flex: 1; width: 100%; min-width: 0;
  display: flex; flex-direction: column;
  padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
}
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; padding-top: calc(10px + var(--safe-top));
  background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 8; flex-shrink: 0;
}
.topbar h2 {
  font-size: 17px; font-weight: 600; flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.menu-btn {
  width: 44px; height: 44px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--card); font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.logout-btn { flex-shrink: 0; }

.page-content {
  flex: 1; padding: 12px; width: 100%; max-width: 100%;
  overflow-x: hidden;
}

/* 底部导航 - 固定底部，不参与 flex 横排 */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: stretch;
  background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -4px 16px rgba(0,0,0,0.08);
  height: calc(var(--bottom-nav-h) + var(--safe-bottom));
}
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 4px 2px; border: none; background: none;
  color: var(--muted); font-size: 10px; cursor: pointer;
  touch-action: manipulation; min-width: 0;
}
.bottom-nav-item .icon { font-size: 20px; line-height: 1; }
.bottom-nav-item.active { color: var(--primary); font-weight: 600; }

.muted-hint { font-size: 12px; color: var(--muted); }
.desktop-only { display: none !important; }
.mobile-only { display: flex !important; }
.mobile-block { display: block !important; }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px; margin-bottom: 14px;
}
.kpi-card {
  background: var(--card); border-radius: 12px; padding: 14px;
  border: 1px solid var(--border); min-width: 0;
}
.kpi-card .label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.kpi-card .value { font-size: 22px; font-weight: 700; line-height: 1.2; word-break: break-all; }
.kpi-card .sub { font-size: 10px; color: var(--muted); margin-top: 4px; }

.grid-2 { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.card {
  background: var(--card); border-radius: 12px; border: 1px solid var(--border);
  padding: 14px; margin-bottom: 12px; width: 100%; max-width: 100%;
}
.card-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 10px; margin-bottom: 12px; flex-wrap: wrap;
}
.card-head h3 { font-size: 15px; font-weight: 600; }
.card-head a { font-size: 12px; color: var(--primary); cursor: pointer; white-space: nowrap; }
.card-desc { font-size: 12px; color: var(--muted); margin-bottom: 12px; line-height: 1.5; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-size: 12px; font-weight: 500; }

.badge { display: inline-block; padding: 3px 8px; border-radius: 10px; font-size: 11px; }
.badge-on { background: #dcfce7; color: #166534; }
.badge-off { background: #f3f4f6; color: #6b7280; }

.switch { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; background: #d1d5db; border-radius: 26px; cursor: pointer;
}
.slider::before {
  content: ''; position: absolute; width: 22px; height: 22px; left: 2px; bottom: 2px;
  background: #fff; border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.chart-box {
  height: 160px; display: flex; align-items: flex-end; gap: 6px;
  overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px;
}
.chart-bar-wrap { flex: 0 0 32px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.chart-bar {
  width: 100%; background: linear-gradient(180deg, var(--primary), #a78bfa);
  border-radius: 4px 4px 0 0; min-height: 4px;
}
.chart-label { font-size: 9px; color: var(--muted); }

.flex-row { display: flex; flex-direction: column; gap: 10px; }
.flex-row .btn { width: 100%; }
.check-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.check {
  display: flex; align-items: center; gap: 10px; font-size: 15px;
  min-height: 48px; cursor: pointer;
}
.check input { width: 22px; height: 22px; accent-color: var(--primary); }
.form-row { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }

.channel-card { border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 10px; }
.channel-card h4 { font-size: 14px; margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 6px; }

.user-cards { flex-direction: column; gap: 12px; width: 100%; }
.user-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: #fafbfc; width: 100%; }
.user-card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.user-card-head strong { font-size: 15px; word-break: break-all; }
.user-card-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
  font-size: 12px; color: var(--muted); margin-bottom: 12px;
}
.user-card-grid span b { display: block; color: var(--text); font-size: 14px; margin-top: 2px; }
.user-card-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.user-card-actions .btn { flex: 1; min-width: calc(50% - 28px); }

.data-list { flex-direction: column; gap: 8px; width: 100%; }
.data-list-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px; background: #f8f9fc; border-radius: 8px; font-size: 13px; width: 100%;
}
.data-list-item .main { font-weight: 500; min-width: 0; word-break: break-all; }
.data-list-item .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.data-list-item .nums { text-align: right; flex-shrink: 0; font-size: 12px; color: var(--muted); }
.data-list-item .nums b { display: block; color: var(--text); font-size: 14px; }

.toast {
  position: fixed; bottom: calc(72px + var(--safe-bottom)); left: 50%;
  transform: translateX(-50%); max-width: calc(100vw - 32px);
  background: var(--text); color: #fff; padding: 12px 20px; border-radius: 20px;
  font-size: 14px; opacity: 0; transition: 0.3s; z-index: 200; text-align: center;
}
.toast.show { opacity: 1; }

.modal { position: fixed; inset: 0; z-index: 100; display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.45); }
.modal-panel {
  position: relative; margin: auto 0 0; width: 100%; max-height: 92vh;
  background: var(--card); border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column; overflow: hidden;
  padding-bottom: var(--safe-bottom);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.task-info-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 14px;
}
.task-records-title { padding: 10px 16px; font-size: 12px; color: var(--muted); }
.task-records-list {
  overflow-y: auto; padding: 0 16px 16px; max-height: 50vh;
  -webkit-overflow-scrolling: touch;
}
.task-record-item { padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }

/* ===== 桌面端 (宽屏) ===== */
@media (min-width: 1025px) {
  .app-body { flex-direction: row; }
  .sidebar {
    transform: none; position: fixed;
    width: var(--sidebar-w);
  }
  .sidebar.open { box-shadow: none; }
  .sidebar-close { display: none; }
  .sidebar-overlay { display: none !important; }
  .main {
    margin-left: var(--sidebar-w);
    padding-bottom: 0;
  }
  .menu-btn { display: none; }
  .bottom-nav { display: none !important; }
  .desktop-only { display: block !important; }
  .mobile-only { display: none !important; }
  .mobile-block { display: none !important; }
  .kpi-row { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .grid-2 { display: grid; grid-template-columns: 1.2fr 0.8fr; }
  .flex-row { flex-direction: row; align-items: stretch; }
  .flex-row .btn { width: auto; }
  .check-row { flex-direction: row; flex-wrap: wrap; gap: 16px; }
  .form-row { display: grid; grid-template-columns: 1fr 1fr; }
  .card-head { flex-direction: row; align-items: center; }
  .card-head .btn { width: auto; }
  .modal-panel {
    margin: auto; width: min(520px, 92vw); max-height: 85vh;
    border-radius: 12px; padding-bottom: 0;
  }
  .toast { bottom: 24px; }
  .page-content { padding: 20px 24px; }
  .topbar { padding: 14px 24px; }
  .topbar h2 { font-size: 20px; }
}

@media (max-width: 380px) {
  .kpi-card .value { font-size: 18px; }
  .bottom-nav-item { font-size: 9px; }
  .bottom-nav-item .icon { font-size: 18px; }
}
