:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #e3e8ef;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --up: #15803d;
  --down: #b91c1c;
  --warn: #b45309;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

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

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.error-text { color: var(--down); font-size: 13px; min-height: 20px; margin: 10px 0 0; }
.info-text { color: var(--primary); font-size: 13px; min-height: 20px; margin: 2px 0 0; }
.msg { font-size: 13px; color: var(--muted); }

/* ---------- buttons / inputs ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-outline { background: #fff; color: var(--text); border-color: var(--border); }
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: #f1f5f9; color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; padding: 10px; }
.btn-danger { color: var(--down); background: transparent; }
.btn-danger:hover:not(:disabled) { background: #fef2f2; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
select { cursor: pointer; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input, .field select { width: 100%; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.inline-label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.select-sm { padding: 5px 8px; font-size: 13px; }

/* ---------- fatal / login ---------- */
.fatal {
  max-width: 680px;
  margin: 60px auto;
  padding: 24px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  color: var(--down);
}
.fatal h2 { margin: 0 0 8px; font-size: 18px; }
.fatal p { margin: 0; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 32px;
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.login-brand h1 { font-size: 18px; margin: 0; }
.login-brand p { margin: 2px 0 0; }
.login-logo {
  width: 44px; height: 44px; flex: none;
  border-radius: 12px; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700;
}

/* ---------- layout ---------- */
.topbar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
}
.brand-title { font-weight: 650; font-size: 15px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.account { font-size: 12px; color: var(--muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tabs {
  display: flex; gap: 4px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  overflow-x: auto;
}
.tab {
  border: none; background: transparent;
  font-family: inherit; font-size: 13px; color: var(--muted);
  padding: 12px 16px; cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.main { max-width: 1240px; margin: 0 auto; padding: 24px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.panel-head h2 { margin: 0; font-size: 18px; }
.panel-head p { margin: 4px 0 0; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.actions { display: flex; align-items: center; gap: 14px; margin-top: 16px; flex-wrap: wrap; }

/* ---------- cards / tables ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card h3 { margin: 0 0 14px; font-size: 15px; }
.card-wide { grid-column: 1 / -1; }
.basic-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.backup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.stat-line { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 18px; font-size: 13px; color: var(--muted); }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.inline-form input[name="name"] { flex: 1 1 120px; }
.inline-form input[name="grade"], .inline-form input[name="term"], .inline-form input[name="note"] { flex: 1 1 110px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; background: #f9fafb; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td input, td select { width: 100%; padding: 6px 8px; }
.exam-name { min-width: 130px; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
.table-wrap table { min-width: 640px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: 12px; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty h2 { color: var(--text); font-size: 17px; margin: 0 0 8px; }
.empty p { margin: 0 0 18px; }

/* ---------- dashboard ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px;
}
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 24px; font-weight: 700; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.kpi-sub.up { color: var(--up); }
.kpi-sub.down { color: var(--down); }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.chart-card h3 { margin: 0 0 4px; font-size: 15px; }
.chart-card p { margin: 0 0 12px; font-size: 12px; color: var(--muted); }
.chart-card svg { display: block; width: 100%; height: auto; overflow: visible; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- modal / toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal-card { background: var(--surface); border-radius: 12px; width: 100%; max-width: 460px; padding: 20px; box-shadow: 0 20px 40px rgba(0,0,0,.18); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body-pad { padding-top: 2px; }
.readonly-input { opacity: .78; cursor: default; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.2); }

@media (max-width: 760px) {
  .topbar { padding: 0 14px; }
  .tabs { padding: 0 14px; }
  .main { padding: 16px 14px; }
  .basic-grid, .backup-grid, .chart-grid { grid-template-columns: 1fr; }
  .account { display: none; }
  .brand-title { font-size: 13px; }
}
