/* ========== Reset & Variables ========== */
:root {
  --primary: #4f46e5;
  --primary-light: #818cf8;
  --primary-dark: #3730a3;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --bg-sidebar: #1e293b;
  --text: #1e293b;
  --text-light: #64748b;
  --text-sidebar: #cbd5e1;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-width: 200px;
  --header-height: 56px;
  --transition: .2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 14px;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ========== Layout ========== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-header h1 {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
}

.sidebar-header .sub {
  font-size: 11px;
  color: #64748b;
  margin-top: 2px;
}

.sidebar-nav { flex: 1; padding: 8px 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  cursor: pointer;
  font-size: 14px;
  color: #94a3b8;
  border-left: 3px solid transparent;
  transition: all var(--transition);
}

.nav-item:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }
.nav-item.active {
  background: rgba(79,70,229,.15);
  color: var(--primary-light);
  border-left-color: var(--primary-light);
}

.nav-item .icon { font-size: 16px; width: 22px; text-align: center; }

.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ========== Header ========== */
.header {
  height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 12px;
}

.header-title { font-size: 17px; font-weight: 700; }

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-light);
}

/* ========== Content ========== */
.content {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.page { display: none; }
.page.active { display: block; }

/* ========== Cards ========== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ========== Grids ========== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }

/* 图表网格（保留兼容） */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.charts-grid .chart-box {
  min-height: 260px;
}

/* 图表行（两图并排） */
.grid-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* 表格分隔线 */
.tb-sep {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* ========== Stat Cards ========== */
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.stat-card .label { font-size: 12px; color: var(--text-light); margin-bottom: 4px; }
.stat-card .value { font-size: 24px; font-weight: 700; }
.stat-card .sub { font-size: 11px; color: var(--text-light); margin-top: 2px; }

.stat-card.blue .value { color: var(--info); }
.stat-card.green .value { color: var(--success); }
.stat-card.orange .value { color: var(--warning); }
.stat-card.red .value { color: var(--danger); }

/* ========== Filters ========== */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.filter-bar .form-group { margin-bottom: 0; min-width: 160px; }
.filter-bar .form-group label { font-size: 12px; }
.filter-bar .form-control { padding: 6px 10px; font-size: 13px; }

/* ========== Forms ========== */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text);
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  background: var(--bg-card);
  outline: none;
  transition: border-color var(--transition);
}

.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 60px; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.form-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-inline .form-group { margin-bottom: 0; }

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ========== Tables ========== */
.table-wrap { overflow-x: auto; }

/* 可滚动表格容器 —— 用于与图表同处一卡时限制高度 */
.table-scroll { overflow-x: auto; overflow-y: auto; max-height: 360px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: #f8fafc;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-light);
  white-space: nowrap;
}

tr:hover td { background: #f8fafc; }

td.up { color: var(--success); font-weight: 600; }
td.down { color: var(--danger); font-weight: 600; }
td.same { color: var(--text-light); }

/* ========== Upload Zone ========== */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: #fafbfc;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--primary);
  background: #f0f0ff;
}

.upload-zone .big-icon { font-size: 40px; margin-bottom: 8px; }
.upload-zone p { color: var(--text-light); font-size: 14px; }
.upload-zone .hint { font-size: 12px; margin-top: 6px; color: #94a3b8; }

/* ========== Tags / Badges ========== */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.tag-red { background: #fef2f2; color: var(--danger); }
.tag-yellow { background: #fffbeb; color: #b45309; }
.tag-green { background: #f0fdf4; color: #15803d; }
.tag-blue { background: #eff6ff; color: #1d4ed8; }
.tag-gray { background: #f1f5f9; color: #475569; }

/* ========== Toast ========== */
.toast-container {
  position: fixed;
  top: 72px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: slideIn .3s ease, fadeOut .3s ease 2.7s;
  max-width: 360px;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--info); }
.toast.warning { background: var(--warning); }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* ========== Modal ========== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-light);
  padding: 4px;
}

.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-light);
}

.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; margin-bottom: 6px; color: var(--text); }
.empty-state p { font-size: 13px; margin-bottom: 16px; }

/* ========== Chart ========== */
.chart-box {
  position: relative;
  width: 100%;
  min-height: 260px;
}

.chart-box-sm { min-height: 200px; }
.chart-box-lg { min-height: 360px; }

/* ========== Progress Bar ========== */
.progress-bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar .fill {
  height: 100%;
  border-radius: 4px;
  transition: width .5s ease;
}

/* ========== Rank Badge ========== */
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
}
.rank-1 { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.rank-2 { background: linear-gradient(135deg, #94a3b8, #64748b); }
.rank-3 { background: linear-gradient(135deg, #d97706, #b45309); }
.rank-other { background: #cbd5e1; }

/* ========== Subject Tag ========== */
.subject-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg);
  color: var(--text);
  margin: 1px;
}

/* ========== Alert List ========== */
.alert-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}

.alert-item .alert-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.alert-item.decline .alert-icon { background: #fef2f2; }
.alert-item.warning .alert-icon { background: #fffbeb; }

.alert-item .alert-info { flex: 1; }
.alert-item .alert-name { font-weight: 600; font-size: 13px; }
.alert-item .alert-detail { font-size: 12px; color: var(--text-light); margin-top: 1px; }

/* ========== Pagination ========== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.pagination button {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: all .15s;
  outline: none;
}

.pagination button:hover:not(:disabled):not(.active) {
  background: var(--bg);
  border-color: var(--primary-light);
  color: var(--primary);
}

.pagination button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 600;
  cursor: default;
}

.pagination button:disabled {
  opacity: .3;
  cursor: default;
}

.pagination .pg-num {
  min-width: 32px;
  height: 32px;
  padding: 0 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pagination .pg-nav {
  min-width: 32px;
  height: 32px;
  padding: 0 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
}

.pagination .pg-ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 32px;
  font-size: 13px;
  color: var(--text-light);
  letter-spacing: 2px;
}

.pagination .info {
  margin-left: 8px;
  font-size: 12px;
  color: var(--text-light);
  white-space: nowrap;
}

/* ========== Subject Max Grid ========== */
.subject-max-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
}

/* ========== Import Preview ========== */
.import-preview { max-height: 300px; overflow-y: auto; margin: 12px 0; }

/* ========== Misc ========== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ========== Responsive ========== */
@media (max-width: 1024px) {
  .grid-4, .grid-5 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .main { margin-left: 0; }
  .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; }
  .charts-grid, .grid-row { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .filter-bar { flex-direction: column; }
  .filter-bar .form-group { width: 100%; }
  .header-title { font-size: 14px; }
}

/* ========== Print ========== */
@media print {
  .sidebar, .header, .filter-bar, .toast-container, .btn { display: none !important; }
  .main { margin-left: 0 !important; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  body { background: #fff; }
}
