:root {
  --primary: #1677ff;
  --primary-hover: #4096ff;
  --primary-active: #0958d9;
  --primary-bg: #e6f4ff;
  --success: #52c41a;
  --warning: #faad14;
  --danger: #ff4d4f;
  --info: #1677ff;
  --text-primary: #1d2129;
  --text-secondary: #4e5969;
  --text-muted: #86909c;
  --border: #e5e6eb;
  --bg-page: #f2f3f5;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
  --radius: 6px;
  --radius-lg: 8px;
  --sidebar-width: 220px;
  --header-height: 56px;
  --font: 'Microsoft YaHei', 'PingFang SC', -apple-system, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; font-family: var(--font); font-size: 14px; color: var(--text-primary); background: var(--bg-page); }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c9cdd4; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a9adb4; }

/* ===== Login Page ===== */
.login-page {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-card {
  background: #fff; padding: 40px; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 400px; max-width: 90vw;
}
.login-card h1 { text-align: center; margin-bottom: 8px; font-size: 24px; color: var(--text-primary); }
.login-card .subtitle { text-align: center; color: var(--text-muted); margin-bottom: 32px; font-size: 14px; }
.login-card .form-group { margin-bottom: 20px; }
.login-card .form-group label { display: block; margin-bottom: 6px; font-weight: 500; color: var(--text-secondary); }
.login-card .form-group input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; transition: border-color 0.2s; outline: none; }
.login-card .form-group input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-bg); }
.login-card .btn { width: 100%; padding: 10px; }
.login-card .error-msg { color: var(--danger); font-size: 13px; text-align: center; margin-top: 12px; display: none; }

/* ===== Layout ===== */
.app-layout { display: none; height: 100vh; }
.app-layout.active { display: flex; }
.sidebar {
  width: var(--sidebar-width); background: #fff; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0; overflow: hidden;
}
.sidebar-header {
  height: var(--header-height); display: flex; align-items: center; padding: 0 20px;
  border-bottom: 1px solid var(--border); font-size: 18px; font-weight: 600; color: var(--primary);
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.nav-item {
  display: flex; align-items: center; padding: 10px 20px; cursor: pointer;
  color: var(--text-secondary); transition: all 0.2s; font-size: 14px; border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--primary-bg); color: var(--primary); }
.nav-item.active { background: var(--primary-bg); color: var(--primary); border-left-color: var(--primary); font-weight: 500; }
.nav-item .nav-icon { margin-right: 8px; font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer {
  padding: 12px 20px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-footer .user-info { font-size: 13px; color: var(--text-secondary); }
.sidebar-footer .logout-btn { cursor: pointer; color: var(--text-muted); font-size: 13px; }
.sidebar-footer .logout-btn:hover { color: var(--danger); }

.main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.main-header {
  height: var(--header-height); padding: 0 24px; display: flex; align-items: center;
  border-bottom: 1px solid var(--border); background: #fff; flex-shrink: 0;
}
.main-header h2 { font-size: 18px; font-weight: 600; }
.main-body { flex: 1; overflow-y: auto; padding: 24px; }
.page-view { display: none; }
.page-view.active { display: block; }

/* ===== Cards ===== */
.card {
  background: var(--bg-card); border-radius: var(--radius-lg); padding: 20px;
  box-shadow: var(--shadow-sm); margin-bottom: 16px;
}
.detail-groups { display: flex; flex-direction: column; gap: 16px; }
.detail-groups .table td { padding: 8px 12px; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; color: var(--text-primary); }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-card); border-radius: var(--radius-lg); padding: 20px;
  box-shadow: var(--shadow-sm); transition: box-shadow 0.2s;
}
.stat-card:hover { box-shadow: var(--shadow); }
.stat-card .stat-label { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--text-primary); }
.stat-card .stat-value.green { color: var(--success); }
.stat-card .stat-value.blue { color: var(--primary); }
.stat-card .stat-value.orange { color: var(--warning); }
.stat-card .stat-value.purple { color: #722ed1; }

/* ===== Tables ===== */
.table-wrapper { overflow-x: auto; }
.table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.table th {
  background: #fafafa; padding: 10px 12px; text-align: left; font-weight: 500;
  color: var(--text-secondary); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td {
  padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text-primary);
}
.table tr:hover td { background: #fafafa; }
.table .actions { white-space: nowrap; }
.table .actions .btn-sm { margin-right: 4px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 7px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; cursor: pointer; transition: all 0.2s; background: #fff; color: var(--text-primary); font-family: var(--font);
  white-space: nowrap; line-height: 1.5;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-primary:active { background: var(--primary-active); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #73d13d; border-color: #73d13d; color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #ff7875; border-color: #ff7875; color: #fff; }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-warning:hover { background: #ffd666; border-color: #ffd666; color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-link { border: none; background: none; color: var(--primary); padding: 4px 8px; }
.btn-link:hover { color: var(--primary-hover); background: none; }
.btn-cancel { background: #fff; border-color: var(--border); color: var(--text-primary); }
.btn-cancel:hover { border-color: var(--primary); color: var(--primary); }
.range-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.range-btn.active:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== Form ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; color: var(--text-secondary); font-size: 13px; }
.form-group label .required { color: var(--danger); margin-left: 2px; }
.form-control {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; outline: none; transition: border-color 0.2s; font-family: var(--font); background: var(--bg-input);
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-bg); }
.form-control::placeholder { color: #c9cdd4; }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row.three { grid-template-columns: 1fr 1fr 1fr; }
.form-row.four { grid-template-columns: 1fr 1fr 1fr 1fr; }
.form-inline { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-inline .form-group { margin-bottom: 0; }
.form-inline .form-control { width: auto; min-width: 120px; }
.form-inline label { margin-bottom: 4px; }
.form-checkbox { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-checkbox input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
.checkbox-group { display: flex; flex-wrap: wrap; gap: 8px; }
.checkbox-group label { display: flex; align-items: center; gap: 6px; font-weight: 400; cursor: pointer; padding: 4px 8px; border-radius: 4px; }
.checkbox-group label:hover { background: var(--primary-bg); }
.rule-input { text-align: center; }

/* ===== Filter Bar ===== */
.filter-bar {
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; padding: 16px 0;
  border-bottom: 1px solid var(--border); margin-bottom: 16px;
}
.filter-bar .form-group { margin-bottom: 0; }
.filter-bar .form-control { min-width: 130px; }
.filter-bar .btn { margin-bottom: 0; }

/* ===== Modal ===== */
.modal-overlay {
  display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45); z-index: 1000; align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius-lg); width: 600px; max-width: 90vw;
  max-height: 85vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.modal-sm { width: 420px; }
.modal-lg { width: 800px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { cursor: pointer; font-size: 20px; color: var(--text-muted); line-height: 1; padding: 0 4px; }
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ===== Pagination ===== */
.pagination {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  margin-top: 16px; padding: 8px 0;
}
.pagination .page-btn {
  min-width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
  font-size: 13px; color: var(--text-secondary); background: #fff; transition: all 0.2s; padding: 0 8px;
}
.pagination .page-btn:hover { border-color: var(--primary); color: var(--primary); }
.pagination .page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination .page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .page-info { font-size: 13px; color: var(--text-muted); margin: 0 8px; }

/* ===== Toast ===== */
.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); box-shadow: var(--shadow);
  font-size: 14px; display: flex; align-items: center; gap: 8px; animation: toastIn 0.3s ease; min-width: 280px;
  background: #fff; border-left: 4px solid var(--primary);
}
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast-icon { font-size: 16px; }
.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--danger); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-msg { flex: 1; }
.toast-close { cursor: pointer; color: var(--text-muted); font-size: 16px; line-height: 1; }
@keyframes toastIn { from { opacity: 0; transform: translateX(100px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateX(100px); } }

/* ===== Loading ===== */
.loading { display: none; text-align: center; padding: 40px 0; color: var(--text-muted); }
.loading.active { display: block; }
.loading-spinner {
  display: inline-block; width: 32px; height: 32px; 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); } }
.loading-text { margin-top: 8px; font-size: 13px; }

/* ===== Tags / Badges ===== */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; line-height: 1.5;
}
.tag-blue { background: var(--primary-bg); color: var(--primary); }
.tag-green { background: #f6ffed; color: var(--success); }
.tag-orange { background: #fff7e6; color: #d46b08; }
.tag-red { background: #fff2f0; color: var(--danger); }
.tag-gray { background: #f5f5f5; color: #8c8c8c; }
.tag-purple { background: #f9f0ff; color: #722ed1; }

/* ===== Status Badge ===== */
.status-badge { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: 12px; }
.status-active { background: #f6ffed; color: var(--success); border: 1px solid #b7eb8f; }
.status-inactive { background: #fff2f0; color: var(--danger); border: 1px solid #ffccc7; }

/* ===== Chart ===== */
.chart-container { margin-top: 16px; }
.chart-bar-group { display: flex; align-items: flex-end; gap: 12px; height: 200px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.chart-bar-item { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.chart-bar { width: 100%; max-width: 40px; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; transition: height 0.3s; position: relative; }
.chart-bar:hover { opacity: 0.8; }
.chart-bar-label { font-size: 11px; color: var(--text-muted); margin-top: 6px; white-space: nowrap; text-align: center; }
.chart-bar-value { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; text-align: center; }
.chart-legend { display: flex; gap: 16px; justify-content: center; margin-top: 12px; }
.chart-legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.chart-legend-color { width: 12px; height: 12px; border-radius: 2px; }

/* ===== Utility ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty-state .empty-text { font-size: 14px; }

/* ===== Config Table ===== */
.config-table .table td:first-child { font-weight: 500; width: 160px; color: var(--text-secondary); }
.config-table input[type="number"] { width: 100px; }

/* ===== Radio Group ===== */
.radio-group { display: flex; gap: 16px; }
.radio-group label { display: flex; align-items: center; gap: 4px; font-weight: 400; cursor: pointer; }

/* ===== Switch ===== */
.switch {
  position: relative; display: inline-block; width: 44px; height: 22px; cursor: pointer;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; inset: 0; background: #c9cdd4; border-radius: 11px; transition: 0.3s;
}
.switch-slider::before {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; top: 2px; left: 2px; transition: 0.3s;
}
.switch input:checked + .switch-slider { background: var(--primary); }
.switch input:checked + .switch-slider::before { transform: translateX(22px); }

/* ===== Checkbox in table ===== */
.table-checkbox { width: 40px; text-align: center; }
.table-checkbox input { width: 16px; height: 16px; cursor: pointer; }
.row-check { width: 16px; height: 16px; cursor: pointer; vertical-align: middle; }
.link-detail { color: var(--primary); text-decoration: none; }
.link-detail:hover { color: var(--primary-hover); text-decoration: underline; }

/* ===== Response ===== */
@media (max-width: 1366px) {
  .form-row { grid-template-columns: 1fr; }
  .form-row.three, .form-row.four { grid-template-columns: 1fr 1fr; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
}