* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #7c5cfc;
  --primary-light: #ede9fe;
  --bg: #f0f2f8;
  --card: #fff;
  --text: #1e1b2e;
  --muted: #6b7280;
  --border: #e8eaef;
  --success: #22c55e;
  --danger: #ef4444;
  --sidebar-w: 220px;
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #ede9fe 0%, #f0f2f8 100%); }
.login-card { background: var(--card); padding: 40px; border-radius: 16px; width: 380px; 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 { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.btn { padding: 10px 18px; border: none; border-radius: 8px; font-size: 14px; font-weight: 500; cursor: pointer; }
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-danger { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 10;
}
.sidebar-brand { padding: 20px 16px; display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; border-bottom: 1px solid var(--border); }
.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; }
.nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  font-size: 14px; color: var(--muted); cursor: pointer; margin-bottom: 2px; border: none; background: none; width: 100%; text-align: left;
  position: relative;
}
.nav-item:hover { background: #f8f9fc; color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 500; }
.nav-item.active::before { content: ''; position: absolute; left: 0; width: 3px; height: 24px; background: var(--primary); border-radius: 0 2px 2px 0; }
.sidebar-user { padding: 16px; 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; font-size: 14px; }
.user-info small { display: block; color: var(--muted); font-size: 11px; }

.main { flex: 1; margin-left: var(--sidebar-w); padding: 24px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.topbar h2 { font-size: 20px; font-weight: 600; }
.search-box { padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px; width: 240px; font-size: 13px; background: var(--card); }

.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi-card { background: var(--card); border-radius: 12px; padding: 18px; border: 1px solid var(--border); }
.kpi-card .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kpi-card .value { font-size: 26px; font-weight: 700; }
.kpi-card .sub { font-size: 11px; color: var(--muted); margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 16px; margin-bottom: 20px; }
.card { background: var(--card); border-radius: 12px; border: 1px solid var(--border); padding: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-head h3 { font-size: 15px; font-weight: 600; }
.card-head a { font-size: 12px; color: var(--primary); cursor: pointer; text-decoration: none; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 8px; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); font-size: 12px; }
td { padding: 12px 8px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.badge-on { background: #dcfce7; color: #166534; }
.badge-off { background: #f3f4f6; color: #6b7280; }
.switch { position: relative; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #d1d5db; border-radius: 22px; cursor: pointer; transition: 0.2s; }
.slider::before { content: ''; position: absolute; width: 18px; height: 18px; 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: 200px; display: flex; align-items: flex-end; gap: 8px; padding-top: 10px; }
.chart-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.chart-bar { width: 100%; max-width: 36px; background: linear-gradient(180deg, var(--primary), #a78bfa); border-radius: 4px 4px 0 0; min-height: 4px; }
.chart-label { font-size: 10px; color: var(--muted); }

.progress-item { margin-bottom: 12px; }
.progress-head { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.progress-bar { height: 6px; background: #f3f4f6; border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 3px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 20px; border-radius: 20px; font-size: 13px; opacity: 0; transition: 0.3s; z-index: 99; pointer-events: none; }
.toast.show { opacity: 1; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; 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; }

.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.modal-panel {
  position: relative; background: var(--card); border-radius: 12px; width: min(520px, 92vw);
  max-height: 80vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 16px 48px rgba(0,0,0,0.15);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.task-info-grid { padding: 12px 18px; }
.task-info-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.task-records-title { padding: 8px 18px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
.task-records-list { flex: 1; overflow-y: auto; padding: 0 18px 16px; max-height: 360px; }
.task-record-item { padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; font-family: monospace; }
.task-record-item:last-child { border-bottom: none; }

@media (max-width: 900px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
