/* SocratiLearn Unified Stylesheet — v0.1.5 */
/* Sources: index.html + admin.html + report.html + graph.html */

/* === Shared Reset & Variables === */

/* ============================================================
   CSS Reset & Variables
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #f7f5f0;
  --surface:      #ffffff;
  --surface-warm: #fefaf3;
  --border:       #e8e0d5;
  --text:         #2c2416;
  --text-muted:   #8b7e6a;
  --accent:       #d4842a;
  --accent-light: #f5e6d3;
  --green:        #5a9e6f;
  --green-light:  #e6f4ea;
  --yellow:       #c9a234;
  --yellow-light: #fdf3d0;
  --red:          #c5554a;
  --red-light:    #fae8e6;
  --ai-bubble:    #faf7f0;
  --student-bubble: #e8f0fe;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.06);
  --shadow-md:    0 4px 16px rgba(0,0,0,.08);
  --radius:       12px;
  --radius-sm:    8px;
  --font:         'Segoe UI', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
}

html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); }

/* ============================================================
   Layout
   ============================================================ */
.app {
  display: flex; flex-direction: column; height: 100vh;
  max-width: 100%; margin: 0 auto;
}

/* ---- Top Bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm); z-index: 10;
}
.topbar-left   { display: flex; align-items: center; gap: 20px; }
.topbar-right  { display: flex; align-items: center; gap: 12px; }

.logo {
  font-size: 1.35rem; font-weight: 700; color: var(--accent);
  letter-spacing: -0.3px;
}
.logo-img { width: 36px; height: 36px; vertical-align: middle; margin-right: 6px; object-fit: contain; }
.logo .dot { color: var(--text); font-weight: 400; }
.logo .cn  { color: #e03131; font-weight: 800; font-family: Arial, Helvetica, sans-serif; font-size: 1.05em; letter-spacing: 0.5px; }
.logo-divider { color: var(--border); font-size: 1.1rem; margin: 0 2px; user-select: none; }
.logo-slogan  { font-size: .82rem; color: var(--text-muted); font-weight: 400; white-space: nowrap; }
.selector-group { display: flex; align-items: center; gap: 6px; }
.selector-group label { font-size: .82rem; color: var(--text-muted); white-space: nowrap; }
.selector-group select {
  padding: 6px 28px 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-size: .85rem; color: var(--text); cursor: pointer;
  appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%238b7e6a' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}
.selector-group select:focus { outline: 2px solid var(--accent-light); border-color: var(--accent); }

.admin-link {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); text-decoration: none;
  font-size: 1.1rem; transition: all .2s;
}
.admin-link:hover { background: var(--bg); color: var(--text); border-color: #ccc; }

/* ---- User Profile in Topbar ---- */
.user-profile {
  display: flex; align-items: center; gap: 8px; padding: 4px 14px 4px 6px;
  border-radius: 20px; cursor: pointer; transition: all .2s;
  text-decoration: none; white-space: nowrap; position: relative;
}
.user-profile.has-user {
  background: linear-gradient(135deg, #fefaf3 0%, #fdf3d0 100%);
  border: 1.5px solid #e8d5a0;
}
.user-profile.no-user {
  background: #fefefe; border: 1.5px dashed var(--border);
}
.user-profile:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); }

.user-profile-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; line-height: 1;
}
.user-profile.has-user .user-profile-avatar { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.user-profile.no-user .user-profile-avatar { background: var(--bg); }

.user-profile-name {
  font-size: .84rem; font-weight: 600; color: var(--text); line-height: 1.2;
}
.user-profile.has-user .user-profile-name { color: #6b4a10; }
.user-profile-arrow {
  font-size: .6rem; color: var(--text-muted); margin-left: 1px;
  transition: transform .2s;
}
.user-profile:hover .user-profile-arrow { transform: translateX(2px); }

/* ---- Divider ---- */
.topbar-divider {
  width: 1px; height: 28px; background: var(--border); margin: 0 6px;
}

/* ---- Points Badge ---- */
.points-badge {
  font-size: .82rem; font-weight: 600; color: var(--accent);
  background: var(--accent-light); padding: 4px 12px;
  border-radius: 14px; white-space: nowrap; cursor: pointer;
  text-decoration: none; transition: all .15s;
}
.points-badge:hover { background: #ecd9b8; transform: translateY(-1px); }

/* ---- Main Body ---- */
.main-body { display: flex; flex: 1; overflow: hidden; }

/* ---- Chat Area ---- */
.chat-area {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  border-right: 1px solid var(--border);
}

.chat-header {
  padding: 14px 24px; background: var(--surface-warm); border-bottom: 1px solid var(--border);
}
.chat-header h2 { font-size: 1rem; font-weight: 600; }
.chat-header p  { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 20px 24px;
  display: flex; flex-direction: column; gap: 16px;
}

/* Bubbles */
.bubble {
  display: flex; gap: 10px; max-width: 85%; animation: fadeUp .35s ease-out;
}
.bubble.ai     { align-self: flex-start; }
.bubble.student { align-self: flex-end; flex-direction: row-reverse; }

.bubble-avatar {
  flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}
.bubble.ai .bubble-avatar     { background: var(--accent-light); }
.bubble.student .bubble-avatar { background: #d0e0f5; }

.bubble-body {
  padding: 12px 16px; border-radius: var(--radius); font-size: .9rem; line-height: 1.65;
  box-shadow: var(--shadow-sm);
}
.bubble.ai .bubble-body {
  background: var(--ai-bubble); border: 1px solid var(--border);
  border-top-left-radius: 4px;
}
.bubble.student .bubble-body {
  background: var(--student-bubble); border: 1px solid #c8d8ee;
  border-top-right-radius: 4px;
}
.bubble-label {
  font-size: .73rem; font-weight: 600; margin-bottom: 4px; letter-spacing: .3px;
}
.bubble.ai .bubble-label     { color: var(--accent); }
.bubble.student .bubble-label { color: #4a6fa5; }

/* Red-line bubble */
.bubble.ai.red-line .bubble-body {
  border-color: var(--red); border-width: 2px;
  background: var(--red-light);
}
.bubble.ai.red-line .bubble-label { color: var(--red); }

/* Thinking indicator */
.thinking-dots { display: flex; gap: 4px; padding: 4px 0; }
.thinking-dots span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: bounce 1.2s infinite ease-in-out;
}
.thinking-dots span:nth-child(2) { animation-delay: .15s; }
.thinking-dots span:nth-child(3) { animation-delay: .3s; }
.thinking-status {
  font-size: .78rem; color: var(--text-muted); font-style: italic; margin-top: 2px;
}

/* ---- Input Area ---- */
.chat-input-area {
  padding: 16px 24px; background: var(--surface); border-top: 1px solid var(--border);
}
.chat-input-row {
  display: flex; gap: 10px; align-items: center;
}
.chat-input-row textarea {
  flex: 1; resize: none; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .88rem; font-family: var(--font);
  line-height: 1.5; min-height: 44px; max-height: 100px; transition: border-color .2s;
}
.chat-input-row textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.chat-input-row textarea:disabled { background: #f5f3ef; cursor: not-allowed; }

.btn-send {
  flex-shrink: 0; padding: 10px 20px; border: none; border-radius: var(--radius);
  background: var(--accent); color: #fff; font-size: .88rem; font-weight: 600;
  cursor: pointer; transition: all .2s;
}
.btn-send:hover:not(:disabled) { background: #b8711e; }
.btn-send:disabled { opacity: .5; cursor: not-allowed; }

.btn-voice {
  flex-shrink: 0; width: 44px; height: 44px; border: 1px solid var(--border);
  border-radius: 50%; background: var(--surface); color: var(--text-muted);
  font-size: 1.2rem; cursor: pointer; transition: all .2s;
  display: flex; align-items: center; justify-content: center;
}
.btn-voice:hover:not(:disabled) { background: var(--bg); border-color: #ccc; }
.btn-voice:disabled { opacity: .4; cursor: not-allowed; }
.btn-voice.recording {
  background: var(--red); border-color: var(--red); color: #fff;
  animation: pulse-rec 1.2s infinite;
}
@keyframes pulse-rec {
  0%, 100% { box-shadow: 0 0 0 0 rgba(197,85,74,.5); }
  50%      { box-shadow: 0 0 0 12px rgba(197,85,74,0); }
}

.voice-hint {
  position: fixed; bottom: 120px; left: 50%; transform: translateX(-50%);
  padding: 8px 16px; border-radius: 20px; background: rgba(0,0,0,.75); color: #fff;
  font-size: .82rem; z-index: 100; pointer-events: none; animation: fadeUp .3s ease-out;
}

/* Mode switch + hint button row */
.btn-row {
  display: none;  /* hidden until subject picked */
  gap: 6px; margin-top: 8px; align-items: center;
}
/* Radio buttons styled like hint button */
.mode-radio {
  padding: 5px 10px; border: 1px dashed var(--accent);
  border-radius: var(--radius-sm); background: transparent; color: var(--text-muted);
  font-size: .78rem; cursor: pointer; transition: all .2s; user-select: none;
  white-space: nowrap;
}
.mode-radio input { display: none; }
.mode-radio:has(input:checked) {
  background: var(--accent-light); color: var(--accent);
  border-style: solid; font-weight: 600;
}
.mode-radio:hover { border-color: var(--accent); background: var(--accent-light); }

.btn-hint {
  padding: 5px 14px; border: 1px dashed var(--accent);
  border-radius: var(--radius-sm); background: transparent; color: var(--accent);
  font-size: .78rem; cursor: pointer; transition: all .2s; white-space: nowrap;
}
.btn-hint:hover:not(:disabled) { background: var(--accent-light); }
.btn-hint:disabled { opacity: .4; cursor: not-allowed; }
.hint-refresh-row { margin-top: 10px; display: flex; gap: 8px; justify-content: flex-end; }
.btn-hint-refresh,
.btn-hint-answer {
  padding: 4px 12px; border: 1px solid var(--accent); border-radius: 14px;
  background: transparent; color: var(--accent); font-size: .76rem;
  cursor: pointer; transition: all .2s; white-space: nowrap;
}
.btn-hint-refresh:hover,
.btn-hint-answer:hover { background: var(--accent-light); }

/* ================================================================
   Side Panels — base class (scratchpad + sidebar)
   ================================================================ */
.side-panel {
  display: flex; flex-direction: column;
  overflow: hidden; position: relative;
  transition: width 0.3s ease, min-width 0.3s ease;
}
.side-panel[data-side="left"]  { border-right: 1px solid var(--border); }
.side-panel[data-side="right"] { border-left: 1px solid var(--border); }

/* Expand width */
.side-panel.expanded { width: 320px; min-width: 320px; }
.side-panel.expanded.narrow { width: 280px; min-width: 280px; }

/* Collapse */
.side-panel.collapsed { width: 40px; min-width: 40px; cursor: pointer; }

/* Collapse bar (visible when collapsed) */
.panel-collapse-bar {
  display: none;
  flex-direction: column; align-items: center; gap: 10px;
  padding: 18px 4px; height: 100%;
  color: var(--text-muted); font-size: .82rem;
  user-select: none; background: var(--surface);
}
.side-panel.collapsed .panel-collapse-bar { display: flex; }
.side-panel.collapsed .panel-body { display: none; }
.vertical-label {
  writing-mode: vertical-lr; letter-spacing: 2px;
  font-weight: 600; font-size: .8rem;
}
.collapse-arrow { font-size: .75rem; }

/* ── Scratchpad Panel ── */
.scratchpad-panel { background: #fafaf9; }
.scratchpad-panel.expanded { width: 320px; min-width: 320px; }

.scratchpad-tools {
  display: flex; align-items: center; gap: 5px; padding: 6px 8px;
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
  background: #fff; flex-shrink: 0;
}
.panel-collapse-btn {
  margin-left: auto; width: 26px; height: 26px;
  border: 1px solid var(--border); border-radius: 6px;
  background: #fff; cursor: pointer; font-size: .75rem;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); transition: all .15s;
  flex-shrink: 0;
}
.panel-collapse-btn:hover { background: var(--accent-light); border-color: var(--primary); }

/* Panel body: flex column so canvas fills remaining height */
.side-panel .panel-body {
  display: flex; flex-direction: column; flex: 1; overflow: hidden;
}
.scratchpad-tools button {
  width: 30px; height: 28px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; cursor: pointer; font-size: .82rem;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.scratchpad-tools button:hover { background: var(--accent-light); }
.scratchpad-tools button.active { border-color: var(--primary); background: var(--accent-light); box-shadow: 0 0 0 2px rgba(141,110,71,.2); }

.color-btn { width: 22px !important; height: 22px !important; border-radius: 50% !important; padding: 0 !important; }
.color-btn.active { box-shadow: 0 0 0 3px rgba(141,110,71,.35) !important; }

.width-btn { font-size: 1rem !important; font-weight: 700; letter-spacing: -2px; }
.tool-divider { width: 1px; height: 20px; background: var(--border); margin: 0 2px; }

.scratchpad-canvas-wrap { flex: 1; overflow: hidden; position: relative; background: #fdfdfc; }
.scratchpad-canvas-wrap canvas { display: block; }

/* ── Sidebar Panel (wraps old .sidebar for index.html) ── */
.sidebar-panel { background: var(--surface); }
.sidebar-panel .sidebar-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: .9rem;
}
.sidebar-panel .sidebar-body { padding: 14px 18px; flex: 1; }
.sidebar-panel .sidebar-footer {
  padding: 10px 18px; border-top: 1px solid var(--border);
  font-size: .8rem; text-align: center;
}
.sidebar-panel .sidebar-footer a { color: var(--primary); text-decoration: none; }
.sidebar-panel .sidebar-footer a:hover { text-decoration: underline; }
.sidebar-panel.collapsed .panel-collapse-bar { background: var(--surface-warm); }

/* ---- Sidebar (other pages: report/graph keep legacy) ---- */
.sidebar {
  width: 280px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--surface); overflow-y: auto;
}
.sidebar-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: .9rem;
}
.sidebar-body { padding: 14px 18px; flex: 1; }

.mastery-list { display: flex; flex-direction: column; gap: 8px; }
.mastery-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: var(--radius-sm); background: var(--bg); transition: background .2s;
}
.mastery-item:hover { background: #f0ece4; }

.mastery-dot {
  width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0;
  position: relative;
}
.mastery-dot.high   { background: var(--green); box-shadow: 0 0 6px rgba(90,158,111,.4); }
.mastery-dot.medium { background: var(--yellow); box-shadow: 0 0 6px rgba(201,162,52,.4); }
.mastery-dot.low    { background: var(--red); box-shadow: 0 0 6px rgba(197,85,74,.4); }

.mastery-info { flex: 1; min-width: 0; }
.mastery-name  { font-size: .82rem; font-weight: 500; }
.mastery-score { font-size: .72rem; color: var(--text-muted); }

.sidebar-footer {
  padding: 14px 18px; border-top: 1px solid var(--border);
}
.sidebar-footer a {
  display: block; text-align: center; padding: 8px; border-radius: var(--radius-sm);
  background: var(--bg); color: var(--accent); text-decoration: none;
  font-size: .84rem; font-weight: 500; transition: background .2s;
}
.sidebar-footer a:hover { background: var(--accent-light); }

/* ---- Toasts ---- */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  padding: 10px 20px; border-radius: var(--radius); font-size: .85rem;
  font-weight: 500; z-index: 999; animation: fadeUp .3s ease-out;
  box-shadow: var(--shadow-md);
}
.toast.warn  { background: #fff3cd; color: #856404; border: 1px solid #ffc107; }
.toast.info  { background: #d1ecf1; color: #0c5460; border: 1px solid #17a2b8; }

/* ============================================================
   Animations
   ============================================================ */
@keyframes fadeUp  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounce  { 0%, 80%, 100% { transform: scale(0.6); } 40% { transform: scale(1.15); } }

/* ---- Subject chip (inline in input row) ---- */
.subject-chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 8px 12px;
  border-radius: 16px; font-size: .82rem; font-weight: 600; cursor: pointer;
  background: var(--accent-light); color: var(--accent); border: 1.5px solid transparent;
  transition: all .15s; white-space: nowrap; flex-shrink: 0; position: relative;
}
.subject-chip:hover { border-color: var(--accent); }
/* Subject picker (first visit) */
.subject-pick-row { display: flex; gap: 10px; justify-content: center; margin-bottom: 12px; }
.subject-pick-btn {
  padding: 10px 20px; border-radius: var(--radius); border: 2px solid var(--border);
  background: var(--surface); font-size: .88rem; font-weight: 600; cursor: pointer;
  transition: all .2s; font-family: var(--font);
}
.subject-pick-btn:hover { border-color: var(--accent); background: var(--accent-light); }
.subject-pick-btn.picked { border-color: var(--accent); background: var(--accent-light); }
.subject-pick-btn:disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }

/* ============================================================
   Responsive: stack sidebar below on narrow screens
   ============================================================ */
@media (max-width: 800px) {
  .main-body { flex-direction: column; }
  /* Side panels: auto-collapse on narrow screens */
  .side-panel.expanded { width: 100%; min-width: unset; max-height: 220px; }
  .side-panel.collapsed { display: none; }
  .side-panel[data-side="left"][class*="expanded"]  { border-right: none; border-bottom: 1px solid var(--border); }
  .side-panel[data-side="right"][class*="expanded"] { border-left: none; border-top: 1px solid var(--border); }
  .sidebar { width: 100%; flex-shrink: 1; max-height: 220px; border-top: 1px solid var(--border); }
  .chat-area { border-right: none; }
  .topbar-left { gap: 10px; flex-wrap: wrap; }
  .topbar-right { gap: 8px; }
  .topbar-divider { display: none; }
  .user-profile { padding: 3px 10px 3px 4px; gap: 6px; }
  .user-profile-avatar { width: 24px; height: 24px; font-size: .85rem; }
  .user-profile-name { font-size: .78rem; }
}

/* === admin.html === */

/* ============================================================
   Layout
   ============================================================ */
.app {
  display: flex; flex-direction: column; height: 100vh;
  max-width: 100%; margin: 0 auto;
}

/* ---- Top Bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm); z-index: 10;
}
.topbar-left  { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; gap: 10px; }

.back-link {
  display: flex; align-items: center; gap: 4px; text-decoration: none;
  color: var(--text-muted); font-size: .85rem; font-weight: 500; transition: color .2s;
}
.back-link:hover { color: var(--accent); }

.page-title { font-size: 1.1rem; font-weight: 700; }

/* ---- Main Body ---- */
.main-body { display: flex; flex: 1; overflow: hidden; }

/* ---- Sidebar Nav (admin pages use <nav class="sidebar">, scoped to beat .sidebar {width:0;overflow:hidden;flex:0 0 0px} cascade) ---- */
nav.sidebar {
  width: 180px; flex: 0 0 180px; overflow-y: auto; overflow-x: hidden;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 12px 0;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 12px 20px;
  font-size: .86rem; font-weight: 500; color: var(--text-muted); cursor: pointer;
  transition: all .15s; border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active {
  color: var(--accent); background: var(--accent-light); border-left-color: var(--accent);
  font-weight: 600;
}
.nav-icon { font-size: 1.1rem; width: 22px; text-align: center; }

/* ---- Content Area ---- */
.content {
  flex: 1; padding: 20px 24px; overflow-y: auto;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); margin-bottom: 20px; overflow: hidden;
}
.card-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: .9rem; display: flex; align-items: center; gap: 8px;
}
.card-body { padding: 20px; }

/* ---- Model Config Table ---- */
.model-table {
  width: 100%; border-collapse: collapse; font-size: .85rem;
}
.model-table th {
  text-align: left; padding: 10px 12px; background: var(--bg);
  font-weight: 600; font-size: .78rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px;
}
.model-table th:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.model-table th:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.model-table td {
  padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle;
}
.model-table tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 12px;
  font-size: .73rem; font-weight: 600; letter-spacing: .2px;
}
.badge.active  { background: var(--green-light); color: var(--green); }
.badge.standby { background: var(--bg); color: var(--text-muted); }
.badge.peak    { background: var(--red-light); color: var(--red); }
.badge.offpeak { background: var(--green-light); color: var(--green); }

/* ---- Radio Switch ---- */
.radio-group { display: flex; flex-direction: column; gap: 8px; }
.radio-option {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  border: 2px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
  transition: all .2s;
}
.radio-option:hover     { border-color: #ccc; background: #fcfcfc; }
.radio-option.selected  { border-color: var(--accent); background: var(--accent-light); }

.radio-option input[type="radio"] { accent-color: var(--accent); width: 18px; height: 18px; }
.radio-body { flex: 1; }
.radio-title { font-size: .88rem; font-weight: 600; }
.radio-desc  { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }
.radio-cost  { font-size: .78rem; color: var(--accent); font-weight: 500; text-align: right; }

/* ---- Stats Grid ---- */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px;
}
.stat-item {
  text-align: center; padding: 18px 12px; border-radius: var(--radius-sm); background: var(--bg);
}
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.stat-label { font-size: .76rem; color: var(--text-muted); margin-top: 2px; }

/* ---- Price Timeline ---- */
.price-bar {
  display: flex; height: 40px; border-radius: var(--radius-sm); overflow: hidden; gap: 2px;
}
.price-segment {
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 600; color: #fff;
}
.price-segment.peak    { background: #d67a70; }
.price-segment.offpeak { background: #7cc08a; }

.cost-summary {
  display: flex; gap: 20px; margin-top: 12px; font-size: .82rem;
}
.cost-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px;
}
.cost-dot.peak    { background: #d67a70; }
.cost-dot.offpeak { background: #7cc08a; }

/* ---- Toast ---- */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  padding: 10px 20px; border-radius: 8px; font-size: .85rem; font-weight: 500;
  z-index: 999; animation: fadeUp .3s ease-out; box-shadow: var(--shadow-md);
  font-family: var(--font);
}
.toast.warn  { background: #fff3cd; color: #856404; }
.toast.info  { background: #d1ecf1; color: #0c5460; }
.toast.success { background: #d4edda; color: #155724; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   User Management
   ============================================================ */
/* Active user bar */
.active-user-bar {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px;
  background: var(--surface-warm); border-radius: var(--radius);
  border: 1px solid var(--border); margin-bottom: 20px; flex-wrap: wrap;
}
.active-user-bar .label-text { font-size: .82rem; color: var(--text-muted); white-space: nowrap; }
.active-user-bar select {
  flex: 1; min-width: 140px; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: .85rem; font-family: var(--font);
  background: var(--surface); cursor: pointer;
}
.active-user-bar select:focus { outline: 2px solid var(--accent-light); border-color: var(--accent); }
.active-user-current {
  font-size: .8rem; color: var(--green); font-weight: 600;
  display: flex; align-items: center; gap: 4px;
}
.no-user-hint {
  font-size: .82rem; color: var(--text-muted); padding: 4px 0;
}

/* User card grid */
.user-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px;
}
.user-card {
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  border: 2px solid var(--border); text-align: center; transition: all .2s;
  position: relative;
}
.user-card:hover { border-color: #ccc; box-shadow: var(--shadow-md); }
.user-card.active { border-color: var(--accent); background: var(--accent-light); }
.user-card .active-tag {
  position: absolute; top: 8px; right: 10px;
  font-size: .68rem; background: var(--green); color: #fff;
  padding: 2px 8px; border-radius: 10px; font-weight: 600;
}
.user-avatar {
  font-size: 2.8rem; margin-bottom: 8px; display: block; line-height: 1.2;
}
.user-name {
  font-size: .95rem; font-weight: 700; margin-bottom: 4px;
}
.user-grade {
  display: inline-block; padding: 2px 10px; border-radius: 12px;
  font-size: .73rem; font-weight: 500; background: var(--bg); color: var(--text-muted);
  margin-bottom: 10px;
}
.user-meta {
  font-size: .7rem; color: var(--text-muted); margin-bottom: 12px;
  line-height: 1.5;
}
.user-card-actions {
  display: flex; gap: 8px; justify-content: center;
}
.btn-sm {
  padding: 5px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: .76rem; font-weight: 500; cursor: pointer; font-family: var(--font);
  transition: all .15s; background: var(--surface); color: var(--text);
}
.btn-sm:hover { background: var(--bg); }
.btn-sm.danger { color: var(--red); border-color: var(--red); }
.btn-sm.danger:hover { background: var(--red-light); }
.btn-sm.primary { color: var(--accent); border-color: var(--accent); }
.btn-sm.primary:hover { background: var(--accent-light); }

.btn-add-user {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 14px; margin-top: 16px;
  border: 2px dashed var(--accent); border-radius: var(--radius);
  background: transparent; color: var(--accent); font-size: .88rem;
  font-weight: 600; cursor: pointer; font-family: var(--font); transition: all .2s;
}
.btn-add-user:hover { background: var(--accent-light); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .2s ease;
}
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 28px 24px 20px;
  width: 90%; max-width: 420px; box-shadow: 0 16px 48px rgba(0,0,0,.18);
  animation: fadeUp .25s ease;
}
.modal-title { font-size: 1rem; font-weight: 700; margin-bottom: 20px; }
.modal-field { margin-bottom: 16px; }
.modal-field label {
  display: block; font-size: .82rem; font-weight: 600; margin-bottom: 6px;
}
.modal-field input, .modal-field select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: .85rem; font-family: var(--font);
}
.modal-field input:focus, .modal-field select:focus {
  outline: 2px solid var(--accent-light); border-color: var(--accent);
}
.modal-field .error-msg {
  font-size: .73rem; color: var(--red); margin-top: 3px; display: none;
}

/* Avatar picker */
.avatar-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.avatar-option {
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--border);
  font-size: 1.4rem; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all .15s; background: var(--bg);
}
.avatar-option:hover { border-color: var(--accent); transform: scale(1.1); }
.avatar-option.selected { border-color: var(--accent); background: var(--accent-light); box-shadow: 0 0 0 3px var(--accent-light); }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.btn-modal {
  padding: 9px 22px; border-radius: var(--radius-sm); font-size: .85rem;
  font-weight: 600; cursor: pointer; font-family: var(--font); border: none; transition: all .15s;
}
.btn-modal.cancel { background: var(--bg); color: var(--text); }
.btn-modal.cancel:hover { background: #e8e0d5; }
.btn-modal.confirm { background: var(--accent); color: #fff; }
.btn-modal.confirm:hover { background: #b8711e; }

/* Confirm dialog */
.confirm-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .15s ease;
}
.confirm-dialog {
  background: var(--surface); border-radius: var(--radius); padding: 24px;
  width: 90%; max-width: 360px; text-align: center;
  box-shadow: 0 16px 48px rgba(0,0,0,.2); animation: fadeUp .2s ease;
}
.confirm-dialog .confirm-icon { font-size: 2.5rem; margin-bottom: 10px; }
.confirm-dialog .confirm-text { font-size: .9rem; line-height: 1.6; margin-bottom: 18px; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 700px) {
  nav.sidebar { width: 60px; }
  nav.sidebar .nav-item span:not(.nav-icon) { display: none; }
  nav.sidebar .nav-item { justify-content: center; padding: 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .user-grid { grid-template-columns: repeat(2, 1fr); }
  .active-user-bar { flex-direction: column; align-items: stretch; }
}

/* === report.html === */

/* ============================================================
   Layout
   ============================================================ */
.page {
  max-width: 100%; margin: 0 auto; padding: 24px;
}

/* ---- Top Bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); margin-bottom: 20px;
}
.topbar-left  { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; gap: 10px; }

.back-link {
  display: flex; align-items: center; gap: 4px; text-decoration: none;
  color: var(--text-muted); font-size: .85rem; font-weight: 500; transition: color .2s;
}
.back-link:hover { color: var(--accent); }

.page-title { font-size: 1.2rem; font-weight: 700; }

.btn {
  padding: 8px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-size: .84rem; font-weight: 500; cursor: pointer;
  transition: all .2s; font-family: var(--font); color: var(--text);
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #b8711e; }

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); margin-bottom: 20px; overflow: hidden;
}
.card-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: .92rem; display: flex; align-items: center; gap: 8px;
}
.card-body { padding: 20px; }

/* ---- Student Overview ---- */
.overview-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px;
}
.overview-item {
  text-align: center; padding: 14px 10px; border-radius: var(--radius-sm);
  background: var(--bg);
}
.overview-value { font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.overview-label { font-size: .76rem; color: var(--text-muted); margin-top: 2px; }

.overview-student {
  display: flex; align-items: center; gap: 14px; margin-bottom: 16px;
}
.overview-avatar {
  width: 52px; height: 52px; border-radius: 50%; background: var(--accent-light);
  display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
  flex-shrink: 0;
}
.overview-name { font-size: 1.15rem; font-weight: 700; }
.overview-meta { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }

/* ---- Mastery Bar Chart ---- */
.mastery-chart { display: flex; flex-direction: column; gap: 10px; }
.mastery-row {
  display: flex; align-items: center; gap: 12px;
}
.mastery-row-label {
  width: 90px; flex-shrink: 0; font-size: .82rem; text-align: right; font-weight: 500;
}
.mastery-row-bar-wrap {
  flex: 1; height: 22px; background: var(--bg); border-radius: 11px; overflow: hidden; position: relative;
}
.mastery-row-bar {
  height: 100%; border-radius: 11px; transition: width .6s ease-out; position: relative;
}
.mastery-row-bar.high   { background: linear-gradient(90deg, #7cc08a, var(--green)); }
.mastery-row-bar.medium { background: linear-gradient(90deg, #d4b548, var(--yellow)); }
.mastery-row-bar.low    { background: linear-gradient(90deg, #d67a70, var(--red)); }
.mastery-row-pct {
  width: 42px; flex-shrink: 0; font-size: .78rem; font-weight: 600; text-align: left;
}

/* ---- Weak Nodes + Error Tags ---- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.weak-list { display: flex; flex-direction: column; gap: 10px; }
.weak-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-radius: var(--radius-sm); background: var(--red-light); border: 1px solid #f0d0cc;
}
.weak-item.medium-warn { background: var(--yellow-light); border-color: #eee0b8; }
.weak-rank { font-weight: 700; font-size: .9rem; color: var(--red); min-width: 20px; }
.weak-item.medium-warn .weak-rank { color: var(--yellow); }
.weak-name  { font-size: .85rem; font-weight: 500; flex: 1; }
.weak-score { font-size: .78rem; color: var(--text-muted); }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; }
.tag {
  padding: 6px 14px; border-radius: 20px; font-size: .8rem; font-weight: 500;
}
.tag.error   { background: var(--red-light); color: var(--red); border: 1px solid #f0c8c2; }
.tag.warning { background: var(--yellow-light); color: #8a6d14; border: 1px solid #eee0b8; }
.tag.info    { background: var(--blue-light); color: var(--blue); border: 1px solid #c8dae8; }

/* ---- Timeline ---- */
.timeline { position: relative; padding-left: 28px; }
.timeline::before {
  content: ''; position: absolute; left: 10px; top: 4px; bottom: 4px;
  width: 2px; background: var(--border); border-radius: 1px;
}
.timeline-item { position: relative; margin-bottom: 16px; }
.timeline-item:last-child { margin-bottom: 0; }
.timeline-dot {
  position: absolute; left: -22px; top: 4px; width: 14px; height: 14px;
  border-radius: 50%; border: 2px solid #fff; box-shadow: var(--shadow-sm);
}
.timeline-dot.green  { background: var(--green); }
.timeline-dot.yellow { background: var(--yellow); }
.timeline-dot.red    { background: var(--red); }
.timeline-content {
  padding: 10px 14px; border-radius: var(--radius-sm); background: var(--bg);
}
.timeline-time  { font-size: .75rem; color: var(--text-muted); }
.timeline-title { font-size: .85rem; font-weight: 600; margin-top: 2px; }
.timeline-detail { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }

/* ---- Radar placeholder ---- */
.radar-placeholder {
  display: flex; align-items: center; justify-content: center;
  height: 200px; background: var(--bg); border-radius: var(--radius-sm);
  border: 2px dashed var(--border); color: var(--text-muted); font-size: .85rem;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 640px) {
  .two-col { grid-template-columns: 1fr; }
  .overview-grid { grid-template-columns: repeat(2, 1fr); }
  .page { padding: 12px; }
  .mastery-row-label { width: 65px; font-size: .75rem; }
}

/* === graph.html === */

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

/* ---- Top Bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  z-index: 20; flex-shrink: 0; gap: 12px; flex-wrap: wrap;
}
.topbar-left  { display: flex; align-items: center; gap: 14px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.logo { font-size: 1.1rem; font-weight: 700; color: var(--accent); white-space: nowrap; }
.logo .dot { color: var(--text); font-weight: 400; }
.back-link { font-size: .8rem; color: var(--text-muted); text-decoration: none; }
.back-link:hover { color: var(--accent); }

/* Grade tabs */
.grade-tabs { display: flex; gap: 4px; }
.grade-tab {
  padding: 4px 12px; border-radius: 14px; border: 1px solid var(--border);
  background: #fff; font-size: .78rem; cursor: pointer; transition: all .2s;
  font-family: var(--font); white-space: nowrap;
}
.grade-tab:hover { background: #f5f0e8; }
.grade-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Controls */
.ctrl-group { display: flex; align-items: center; gap: 6px; }
.btn-icon {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border);
  background: #fff; cursor: pointer; font-size: .9rem; display: flex;
  align-items: center; justify-content: center; transition: all .2s;
}
.btn-icon:hover { background: #f5f0e8; }
.btn-icon.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.search-input {
  padding: 5px 12px; border: 1px solid var(--border); border-radius: 16px;
  font-size: .8rem; font-family: var(--font); width: 140px; outline: none;
}
.search-input:focus { border-color: var(--accent); }

/* Theme switch */
.theme-switch {
  display: flex; gap: 2px; background: #f0ece4; border-radius: 16px; padding: 2px;
}
.theme-btn {
  padding: 5px 10px; border: none; border-radius: 14px; font-size: .75rem;
  cursor: pointer; background: transparent; font-family: var(--font);
  transition: all .2s; white-space: nowrap;
}
.theme-btn.active { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* ---- Main Body ---- */
.main-body { display: flex; flex: 1; overflow: hidden; position: relative; }

/* Canvas container */
.canvas-wrap {
  flex: 1; position: relative; overflow: hidden;
  transition: flex 0.4s cubic-bezier(0.4,0,0.2,1);
}
.canvas-wrap.collapsed { flex: 0; }
.canvas-wrap canvas { display: block; }

/* Sidebar (graph.html: collapsible right panel, <aside class="sidebar"> only) */
aside.sidebar {
  flex: 0 0 0px; width: 0; overflow: hidden;
  background: var(--surface); border-left: 1px solid var(--border);
  transition: flex-basis 0.35s cubic-bezier(0.4,0,0.2,1);
  display: flex; flex-direction: column; z-index: 10;
}
aside.sidebar.open { flex-basis: 400px; }
aside.sidebar.fullscreen { flex-basis: 100%; }

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sidebar-title { font-size: .95rem; font-weight: 700; }
.sidebar-actions { display: flex; gap: 6px; }
.sidebar-btn {
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--border);
  background: #fff; cursor: pointer; font-size: .85rem; display: flex;
  align-items: center; justify-content: center; transition: all .15s;
}
.sidebar-btn:hover { background: #f5f0e8; }

.sidebar-body {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 14px;
}

/* Node info cards */
.info-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.info-tag {
  padding: 3px 10px; border-radius: 12px; font-size: .73rem; font-weight: 500;
}
.info-tag.grade   { background: #e6f0f8; color: #4a7fa5; }
.info-tag.domain  { background: #f5e6d3; color: #b8711e; }
.info-tag.diff    { background: #fae8e6; color: #c5554a; }

.info-card {
  padding: 14px 16px; border-radius: var(--radius-sm); background: #faf8f4;
  border: 1px solid var(--border);
}
.info-card h4 { font-size: .8rem; font-weight: 600; margin-bottom: 6px; color: var(--accent); }
.info-card p  { font-size: .82rem; line-height: 1.6; color: var(--text); }

.rel-list { display: flex; flex-wrap: wrap; gap: 6px; }
.rel-chip {
  padding: 4px 10px; border-radius: 12px; font-size: .75rem; cursor: pointer;
  background: #eef3f9; border: 1px solid #d0dce8; transition: all .15s;
}
.rel-chip:hover { background: #d0dce8; }
.rel-chip.prereq { background: #fef9e7; border-color: #fde68a; }

/* ---- Learning Path Chain ---- */
.chain-wrap {
  display: flex; flex-direction: column; gap: 0;
  padding: 4px 0;
}
.chain-node {
  display: flex; align-items: stretch; gap: 0; position: relative;
}
.chain-line {
  width: 28px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  position: relative;
}
.chain-line::before {
  content: ''; position: absolute; top: 0; left: 50%; width: 2px; height: 100%;
  background: #d0d0d0; transform: translateX(-50%);
}
.chain-node:first-child .chain-line::before { top: 50%; }
.chain-node:last-child .chain-line::before { height: 50%; top: 0; }
.chain-node:first-child:last-child .chain-line::before { display: none; }

.chain-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; z-index: 1;
  border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.chain-dot.prereq  { background: #c9a234; }
.chain-dot.prereq.mastered { background: var(--green); box-shadow: 0 0 5px rgba(90,158,111,.5); }
.chain-dot.prereq.average  { background: var(--yellow); box-shadow: 0 0 4px rgba(201,162,52,.4); }
.chain-dot.prereq.weak     { background: var(--red); box-shadow: 0 0 6px rgba(197,85,74,.5); animation: pulse-weak 1.8s infinite; }
.chain-dot.current { background: var(--accent); width: 14px; height: 14px; box-shadow: 0 0 0 4px rgba(212,132,42,.25); }
.chain-dot.next   { background: #5a9e6f; }
.chain-dot.next.mastered { background: var(--green); box-shadow: 0 0 5px rgba(90,158,111,.5); }
.chain-dot.next.average  { background: var(--yellow); box-shadow: 0 0 4px rgba(201,162,52,.4); }
.chain-dot.next.weak     { background: var(--red); box-shadow: 0 0 6px rgba(197,85,74,.5); animation: pulse-weak 1.8s infinite; }

.chain-card {
  flex: 1; padding: 8px 12px; margin: 3px 0 3px 6px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); cursor: pointer; transition: all .15s;
  background: #fafaf8; min-width: 0;
}
.chain-card:hover { background: #f0ece4; border-color: #ccc; transform: translateX(2px); }
.chain-card.current-card {
  background: #fef9f0; border-color: var(--accent); border-width: 2px;
  cursor: default; transform: none; box-shadow: 0 2px 8px rgba(212,132,42,.15);
}
.chain-card.current-card:hover { background: #fef9f0; transform: none; }

.chain-card-name { font-size: .82rem; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 6px; }
.chain-card-meta { font-size: .7rem; color: var(--text-muted); margin-top: 2px; }
.chain-card-arrow {
  font-size: .7rem; color: var(--accent); font-weight: 700; margin-left: 4px;
  opacity: 0; transition: opacity .15s;
}
.chain-card:hover .chain-card-arrow { opacity: 1; }

/* ---- Chain Mastery Indicators ---- */
.chain-mastery-dot {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0;
  display: inline-block;
}
.chain-mastery-dot.mastered { background: var(--green); box-shadow: 0 0 5px rgba(90,158,111,.5); }
.chain-mastery-dot.average  { background: var(--yellow); box-shadow: 0 0 4px rgba(201,162,52,.4); }
.chain-mastery-dot.weak     { background: var(--red); box-shadow: 0 0 6px rgba(197,85,74,.5); animation: pulse-weak 1.8s infinite; }

.chain-mastery-mini-bar {
  height: 4px; border-radius: 2px; margin-top: 5px; background: #e8e0d5;
  overflow: hidden; transition: width .4s;
}
.chain-mastery-mini-fill {
  height: 100%; border-radius: 2px; transition: width .5s ease-out;
}
.chain-mastery-mini-fill.mastered { background: var(--green); }
.chain-mastery-mini-fill.average  { background: var(--yellow); }
.chain-mastery-mini-fill.weak     { background: var(--red); }

.chain-mastery-pct {
  font-size: .68rem; font-weight: 700; margin-left: 6px; flex-shrink: 0;
}
.chain-mastery-pct.mastered { color: var(--green); }
.chain-mastery-pct.average  { color: var(--yellow); }
.chain-mastery-pct.weak     { color: var(--red); }

/* Subtle left border tint by mastery */
.chain-card.chain-mastered  { border-left: 3px solid var(--green); }
.chain-card.chain-average   { border-left: 3px solid var(--yellow); }
.chain-card.chain-weak      { border-left: 3px solid var(--red); }
.chain-card.current-card.chain-mastered,
.chain-card.current-card.chain-average,
.chain-card.current-card.chain-weak { border-left-width: 4px; }

/* ---- Knowledge Point Tags (in Modal) ---- */
.kp-tags-section {
  margin-bottom: 16px;
}
.kp-tags-label {
  font-size: .73rem; font-weight: 600; color: var(--text-muted);
  margin-bottom: 8px; display: flex; align-items: center; gap: 4px;
}
.kp-tags-row {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.kp-tag-chip {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 12px; border-radius: 20px;
  background: #fafaf8; border: 1px solid var(--border);
  cursor: pointer; transition: all .18s;
  font-family: var(--font); user-select: none;
  border-left: 3px solid #ccc; /* fallback, overridden by category */
}
.kp-tag-chip:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
  border-color: #bbb;
}
.kp-tag-chip:active { transform: scale(0.96); }

.kp-tag-chip.cat-数与代数   { border-left-color: #7eb8da; }
.kp-tag-chip.cat-图形与几何 { border-left-color: #5a9e6f; }
.kp-tag-chip.cat-统计与概率 { border-left-color: #8e6bb8; }
.kp-tag-chip.cat-综合与实践 { border-left-color: #d4842a; }

.kp-tag-dot {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0;
}
.kp-tag-dot.mastered { background: var(--green); box-shadow: 0 0 5px rgba(90,158,111,.5); }
.kp-tag-dot.average  { background: var(--yellow); box-shadow: 0 0 4px rgba(201,162,52,.4); }
.kp-tag-dot.weak     { background: var(--red); box-shadow: 0 0 6px rgba(197,85,74,.5); animation: pulse-weak 1.8s infinite; }

.kp-tag-name {
  font-size: .82rem; font-weight: 600; color: var(--text);
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kp-tag-pct {
  font-size: .73rem; font-weight: 700;
}
.kp-tag-pct.mastered { color: var(--green); }
.kp-tag-pct.average  { color: var(--yellow); }
.kp-tag-pct.weak     { color: var(--red); }

.kp-tag-hint {
  font-size: .65rem; color: var(--text-muted); margin-left: 2px;
  opacity: 0; transition: opacity .15s;
}
.kp-tag-chip:hover .kp-tag-hint { opacity: 1; }

/* ---- Vote / Feedback Bar (in Modal) ---- */
.vote-bar {
  display: flex; align-items: center; gap: 6px;
  margin-top: 16px; padding-top: 12px;
  border-top: 1px solid var(--border);
}
.vote-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 14px; border-radius: 18px; border: 1px solid var(--border);
  background: #fff; cursor: pointer; font-size: .82rem; font-family: var(--font);
  transition: all .15s; user-select: none;
}
.vote-btn:hover:not(:disabled) { background: #f9f6f0; border-color: #ccc; transform: translateY(-1px); }
.vote-btn:active:not(:disabled) { transform: scale(0.95); }

.vote-btn.upvoted { background: #e6f4ea; border-color: var(--green); color: #2d6a3f; font-weight: 600; }
.vote-btn.downvoted { background: #fae8e6; border-color: var(--red); color: #a13d3d; font-weight: 600; }

.vote-count { font-weight: 700; min-width: 18px; text-align: center; }

.vote-meta {
  margin-left: auto; font-size: .7rem; color: var(--text-muted);
  display: flex; align-items: center; gap: 8px;
}
.vote-warn-badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px; border-radius: 10px;
  background: #fae8e6; color: var(--red); font-size: .7rem; font-weight: 600;
  animation: pulse-weak 1.8s infinite;
}

.chain-label {
  font-size: .68rem; font-weight: 600; color: var(--text-muted);
  padding: 4px 0 2px 34px; letter-spacing: .5px;
}

/* Grade legend */
.grade-legend {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 14px; padding: 8px 16px; border-radius: 20px;
  background: rgba(0,0,0,.55); backdrop-filter: blur(8px);
  font-size: .73rem; color: #fff; z-index: 5; pointer-events: none;
}
.grade-legend span { display: flex; align-items: center; gap: 4px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; }

/* Toast */
.toast {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  padding: 8px 18px; border-radius: 20px; font-size: .8rem; font-weight: 500;
  z-index: 999; animation: fadeUp .3s ease-out;
  background: rgba(0,0,0,.75); color: #fff; pointer-events: none;
}
@keyframes fadeUp { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes pulse-weak { 0%,100%{opacity:.6} 50%{opacity:1} }
@keyframes modalIn { from { opacity:0; transform:translate(-50%,-50%) scale(.9); } to { opacity:1; transform:translate(-50%,-50%) scale(1); } }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 100;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
.modal-card {
  background: #fff; border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 90%; max-width: 640px; max-height: 85vh; overflow-y: auto;
  animation: modalIn .25s ease;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: .9rem; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border);
  background: #fff; cursor: pointer; font-size: 1rem; display: flex;
  align-items: center; justify-content: center;
}
.modal-close:hover { background: #f5f0e8; }
.modal-body { padding: 20px; }
.modal-q-title { font-size: .95rem; line-height: 1.7; margin-bottom: 16px; font-weight: 500; }

/* Option buttons */
.opt-list { display: flex; flex-direction: column; gap: 8px; }
.opt-btn {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; cursor: pointer; font-size: .88rem; font-family: var(--font);
  transition: all .15s; text-align: left;
}
.opt-btn:hover { border-color: var(--accent); background: #fef9f0; }
.opt-btn.selected { border-color: var(--accent); background: #fef3e0; }
.opt-btn.correct { border-color: var(--green); background: #e6f4ea; }
.opt-btn.wrong { border-color: var(--red); background: #fae8e6; }
.opt-key { font-weight: 700; color: var(--accent); min-width: 20px; }

/* Answer feedback */
.feedback-bar {
  margin-top: 14px; padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: .84rem; line-height: 1.6; display: none;
}
.feedback-bar.show { display: block; }
.feedback-bar.correct { background: #e6f4ea; border: 1px solid #b7dfc4; color: #2d6a3f; }
.feedback-bar.wrong   { background: #fae8e6; border: 1px solid #f0c8c2; color: #a13d3d; }

/* Mastery buttons */
.mastery-row {
  display: flex; gap: 10px; margin-top: 12px;
}
.mastery-btn {
  flex: 1; padding: 10px 8px; border: 2px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; cursor: pointer; font-size: .8rem; font-family: var(--font);
  text-align: center; transition: all .15s;
}
.mastery-btn:hover { transform: translateY(-1px); }
.mastery-btn.mastered { border-color: var(--green); }
.mastery-btn.mastered:hover,.mastery-btn.mastered.chosen { background: #e6f4ea; border-color: var(--green); box-shadow: 0 2px 8px rgba(90,158,111,.25); }
.mastery-btn.average  { border-color: var(--yellow); }
.mastery-btn.average:hover,.mastery-btn.average.chosen { background: #fdf3d0; border-color: var(--yellow); box-shadow: 0 2px 8px rgba(201,162,52,.25); }
.mastery-btn.weak     { border-color: var(--red); }
.mastery-btn.weak:hover,.mastery-btn.weak.chosen { background: #fae8e6; border-color: var(--red); box-shadow: 0 2px 8px rgba(197,85,74,.25); }
.mastery-icon { font-size: 1.3rem; display: block; margin-bottom: 2px; }

/* ================================================================
   Answer mode (index.html)
   ================================================================ */
#userInput.answer-mode {
  border-color: var(--green) !important;
  border-width: 2px;
  box-shadow: 0 0 0 3px rgba(90,158,111,.15);
}

.btn-send.send-answer {
  background: var(--green) !important;
  color: #fff !important;
}

/* ================================================================
   PIN Gate (history.html)
   ================================================================ */
#pinGate {
  display: flex; align-items: center; justify-content: center;
  min-height: calc(100vh - 120px);
}
.pin-gate-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 16px; padding: 48px 40px;
  text-align: center; max-width: 400px; width: 100%;
  box-shadow: 0 4px 24px rgba(0,0,0,.06);
}
.pin-gate-icon { font-size: 3rem; margin-bottom: 16px; }
.pin-gate-card h2 { margin: 0 0 8px; font-size: 1.3rem; }
.pin-gate-card p { color: var(--text-muted); margin: 0 0 24px; }
.pin-input-row { display: flex; justify-content: center; }
.pin-input-row input {
  font-size: 2rem; text-align: center; width: 160px;
  letter-spacing: 12px; padding: 12px 16px;
  border: 2px solid var(--border); border-radius: 12px;
  font-family: var(--font);
}
.pin-input-row input:focus { outline: none; border-color: var(--primary); }

/* ================================================================
   History Page (history.html)
   ================================================================ */
.history-summary {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 12px; margin-bottom: 24px;
}
.summary-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px 16px; text-align: center;
}
.summary-value { font-size: 1.8rem; font-weight: 700; margin-bottom: 4px; }
.summary-label { font-size: .8rem; color: var(--text-muted); }

.history-date-group { margin-bottom: 16px; }
.history-date-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 12px;
  cursor: pointer; user-select: none; transition: background .15s;
}
.history-date-header:hover { background: var(--bg); }
.history-date-header span:first-child { font-weight: 700; font-size: .95rem; flex: 1; }
.history-date-count {
  background: var(--primary); color: #fff; font-size: .78rem;
  padding: 2px 10px; border-radius: 20px; font-weight: 600;
}
.history-date-arrow { font-size: 1.2rem; color: var(--text-muted); }
.history-date-body { padding: 8px 0; }

.history-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; margin-bottom: 10px; overflow: hidden;
  transition: box-shadow .15s;
}
.history-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,.06); }
.history-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.history-card-meta { font-size: .84rem; color: var(--text); }
.history-status {
  font-size: .8rem; font-weight: 600; padding: 3px 10px; border-radius: 20px;
}
.history-status.correct { background: #e6f4ea; color: var(--green); }
.history-status.wrong { background: #fae8e6; color: var(--red); }
.history-status.unanswered { background: #f0f0f0; color: var(--text-muted); }

.history-card-body { padding: 16px; }
.history-q, .history-a { margin-bottom: 8px; font-size: .9rem; line-height: 1.6; }

.history-answer-details,
.history-solution-details,
.history-convo-details {
  margin-top: 8px; padding: 8px 12px;
  background: var(--bg); border-radius: 8px;
}
.history-answer-details summary,
.history-solution-details summary,
.history-convo-details summary {
  cursor: pointer; font-size: .85rem; color: var(--text);
  padding: 4px 0; user-select: none;
}
.history-answer-details summary:hover,
.history-solution-details summary:hover,
.history-convo-details summary:hover { color: var(--primary); }
.history-correct-answer {
  margin-top: 8px; padding: 10px 14px;
  background: #e6f4ea; border: 1px solid #b7d7bd;
  border-radius: 8px; font-size: .95rem; font-weight: 600; color: var(--green);
}
.history-solution {
  margin-top: 8px; padding: 10px 14px;
  background: #fdf3d0; border: 1px solid #e8d58a;
  border-radius: 8px; font-size: .88rem; line-height: 1.7;
}
.history-convo {
  margin-top: 8px; font-size: .82rem; color: var(--text-muted);
  max-height: 200px; overflow-y: auto;
}
.convo-preview-line {
  padding: 4px 0; border-bottom: 1px solid var(--border);
}
.history-kp { margin-top: 8px; font-size: .82rem; }
.kp-tag {
  display: inline-block; background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 8px; font-size: .78rem; margin: 2px;
  color: var(--text-muted);
}

.history-card-footer {
  padding: 10px 16px; border-top: 1px solid var(--border);
  background: var(--bg);
}
.review-actions { font-size: .82rem; }
.review-tag { font-weight: 600; }
.review-tag.correct { color: var(--green); }
.review-tag.wrong { color: var(--red); }
.review-tag.partial { color: var(--yellow); }
.review-tag.none { color: var(--text-muted); }
.review-note {
  margin-top: 4px; padding: 6px 10px; background: #fff;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: .82rem; color: var(--text);
}
.review-buttons { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.btn-review {
  padding: 4px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; cursor: pointer; font-size: .78rem;
  font-family: var(--font); transition: all .15s;
}
.btn-review.correct:hover { background: #e6f4ea; border-color: var(--green); }
.btn-review.wrong:hover { background: #fae8e6; border-color: var(--red); }
.btn-review.partial:hover { background: #fdf3d0; border-color: var(--yellow); }
.btn-note {
  padding: 4px 12px; border: 1px dashed var(--border); border-radius: 6px;
  background: #fff; cursor: pointer; font-size: .78rem;
  font-family: var(--font);
}
.btn-note:hover { border-color: var(--primary); }

/* ================================================================
   AI Question Generation Card (index.html)
   ================================================================ */
.gen-question-card {
  background: linear-gradient(135deg, #f0f4ff 0%, #fdf6e8 100%);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; margin: 8px 0;
}
.gen-question-title { font-size: 1.05rem; line-height: 1.7; margin-bottom: 14px; }
.gen-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.gen-option {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: #fff; border: 1px solid var(--border);
  border-radius: 10px; font-size: .9rem;
}
.gen-option-key {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: #fff; font-weight: 700; font-size: .82rem;
  flex-shrink: 0;
}
.gen-meta {
  font-size: .8rem; color: var(--text-muted);
  padding-top: 10px; border-top: 1px dashed var(--border);
}
.gen-answer-template { margin-top: 12px; }
.gen-template-code {
  display: block; padding: 12px 16px;
  background: #fefaf3; border: 1.5px dashed var(--accent);
  border-radius: 10px; font-size: 1rem; color: var(--accent);
  letter-spacing: 1px; cursor: pointer; transition: all .2s;
  user-select: none;
}
.gen-template-code:hover {
  background: var(--accent-light); border-style: solid;
  box-shadow: 0 2px 8px rgba(212,132,42,.15);
}
.gen-template-code:active { transform: scale(.98); }

/* ================================================================
   Intent mode selector (出题 | 提问)
   ================================================================ */
.intent-select {
  flex-shrink: 0;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg-card); color: var(--text); font-size: .82rem;
  cursor: pointer; font-family: var(--font);
  transition: border-color .15s;
  max-width: 90px;
}
.intent-select:hover, .intent-select:focus { border-color: var(--primary); outline: none; }
.intent-select option[value="generate"] { background: #fdf3d0; }
.intent-select option[value="tutor"] { background: #e6f4ea; }

/* ============================================================
   Guest / Logged-in visibility
   ============================================================ */
/* Default: guest sections hidden, logged-in sections visible */
.guest-welcome { display: none; }

/* Guest mode: show welcome, hide interactive elements */
body.is-guest .guest-welcome        { display: flex; align-items: center; justify-content: center; min-height: 60vh; }
body.is-guest .logged-in-only       { display: none !important; }
body.is-guest .side-panel           { display: none !important; }
body.is-guest .topbar .selector-group,
body.is-guest .topbar .topbar-right a.admin-link,
body.is-guest .topbar .topbar-right .user-profile,
body.is-guest .topbar .topbar-divider { display: none !important; }
body.is-guest .topbar .logo-slogan  { opacity: 1; }

/* Guest mode: disable interactive elements but keep visible */
body.is-guest .chat-input-area { pointer-events: none; opacity: .45; }
body.is-guest .chat-input-area * { pointer-events: none !important; }
body.is-guest #subjectPicker { pointer-events: none !important; }
body.is-guest #subjectPicker button { pointer-events: none !important; cursor: not-allowed; }
body.is-guest .btn-row { pointer-events: none !important; opacity: .45; }

/* Guest overlay: covers input area, clicking redirects to login */
.guest-overlay { display: none; }
body.is-guest .chat-input-area { position: relative; }
body.is-guest .guest-overlay {
  display: block; position: absolute; inset: 0; z-index: 10;
  cursor: pointer;
}

/* Logged-in: normal */
body.is-logged-in .guest-welcome    { display: none !important; }

/* Guest card */
.guest-card {
  text-align: center; padding: 48px 32px; max-width: 400px;
}
.guest-card h2 { font-size: 28px; margin: 16px 0 8px; }
.guest-sub { color: var(--text-muted); font-size: 15px; line-height: 1.8; margin-bottom: 28px; }
.guest-actions { display: flex; gap: 12px; justify-content: center; }
.guest-hint { margin-top: 20px; font-size: 13px; color: var(--text-muted); }
.guest-hint a { color: var(--accent); }

/* Responsive */
@media (max-width: 768px) {
  .topbar { padding: 8px 12px; }
  .grade-tabs { overflow-x: auto; }
  .search-input { width: 100px; }
  aside.sidebar.open { flex-basis: 100%; }
  aside.sidebar.fullscreen { flex-basis: 100%; }
  .history-summary { grid-template-columns: repeat(2, 1fr); }
  .pin-gate-card { margin: 0 16px; padding: 36px 24px; }
}

/* ============================================================
   Admin Backend Styles (v0.3)
   ============================================================ */

/* ── Stats Grid ── */
.admin-stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.admin-stat-card { background: #fff; border-radius: 10px; padding: 16px 18px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.admin-stat-card .stat-icon { font-size: 1.4rem; margin-bottom: 4px; }
.admin-stat-card .stat-value { font-size: 1.6rem; font-weight: 700; color: #1a1a2e; }
.admin-stat-card .stat-label { font-size: .76rem; color: #888; margin-top: 2px; }
.admin-stat-card .stat-sub { font-size: .7rem; color: #aaa; margin-top: 2px; }
.admin-stat-card.warn .stat-value { color: #e67e22; }
.admin-stat-card.good .stat-value { color: #27ae60; }

/* ── Trend Chart ── */
.admin-chart { background: #fff; border-radius: 10px; padding: 18px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.admin-chart h3 { margin: 0 0 14px; font-size: .9rem; color: #555; }
.admin-chart-bars { display: flex; align-items: flex-end; gap: 10px; height: 160px; }
.admin-chart-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.admin-chart-bar { width: 100%; max-width: 44px; border-radius: 4px 4px 0 0; min-height: 2px; }
.admin-chart-bar.flash { background: #3498db; }
.admin-chart-bar.pro { background: #e74c3c; }
.admin-chart-legend { display: flex; gap: 16px; justify-content: center; margin-top: 8px; font-size: .75rem; color: #888; }

/* ── Filter Bar ── */
.admin-filter-bar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: flex-end; }
.admin-filter-bar select, .admin-filter-bar input { padding: 6px 10px; border: 1px solid #ddd; border-radius: 6px; font-size: .8rem; }
.admin-filter-bar input[type="text"] { width: 200px; }
.admin-filter-bar .field { min-width: 110px; }
.admin-filter-bar .field label { display: block; font-size: .73rem; font-weight: 600; color: #777; margin-bottom: 2px; }
.admin-filter-bar .field select, .admin-filter-bar .field input { width: 100%; box-sizing: border-box; }

/* ── Data Table ── */
.admin-table-wrap { background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.admin-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.admin-table th { background: #fafafa; padding: 9px 10px; text-align: left; font-weight: 600; color: #777; border-bottom: 2px solid #eee; font-size: .73rem; white-space: nowrap; }
.admin-table td { padding: 7px 10px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
.admin-table tr:hover td { background: #fafaff; }
.admin-table tr.disabled td { opacity: .5; }
.admin-table .title-cell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.admin-table .title-cell:hover { color: #3498db; }

/* ── Badges ── */
.badge-role { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .68rem; font-weight: 600; }
.badge-role.student { background: #e3f2fd; color: #1976d2; }
.badge-role.parent { background: #fce4ec; color: #c62828; }
.badge-role.admin { background: #fff3e0; color: #e65100; }
.badge-status { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: .7rem; font-weight: 600; }
.badge-status.pending { background: #fef3e2; color: #e67e22; }
.badge-status.approved { background: #e8f5e9; color: #27ae60; }
.badge-status.rejected { background: #fce4ec; color: #c62828; }
.badge-diff { display: inline-block; padding: 1px 6px; border-radius: 8px; font-size: .65rem; }
.badge-diff.easy { background: #e8f5e9; color: #27ae60; }
.badge-diff.medium { background: #fef3e2; color: #e67e22; }
.badge-diff.hard { background: #fce4ec; color: #c62828; }
.badge-event { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: .7rem; font-weight: 600; }
.badge-tx { display: inline-block; padding: 1px 7px; border-radius: 8px; font-size: .68rem; font-weight: 600; }
.badge-tx.recharge { background: #e8f5e9; color: #2e7d32; }
.badge-tx.api_cost, .badge-tx.consume { background: #fce4ec; color: #c62828; }
.badge-tx.server, .badge-tx.domain { background: #e3f2fd; color: #1565c0; }
.badge-tx.accounting { background: #f3e5f5; color: #7b1fa2; }
.badge-tx.refund { background: #fef3e2; color: #e67e22; }
.badge-tx.trial { background: #e3f2fd; color: #1976d2; }
.badge-tx.admin_recharge { background: #e8f5e9; color: #2e7d32; }

/* ── Buttons ── */
.btn-sm { font-size: .72rem; padding: 3px 10px; border-radius: 4px; cursor: pointer; border: 1px solid #ddd; background: #fff; }
.btn-sm:hover { background: #f5f5f5; }
.btn-sm.primary { border-color: #3498db; color: #3498db; }
.btn-sm.danger { border-color: #fce4ec; color: #e74c3c; }
.btn-sm.danger:hover { background: #fef0f0; }
.btn-sm.warn { border-color: #fef3e2; color: #e67e22; }
.btn-approve { background: #27ae60; color: #fff; border: none; padding: 4px 12px; border-radius: 5px; cursor: pointer; font-size: .75rem; }
.btn-reject { background: #e74c3c; color: #fff; border: none; padding: 4px 12px; border-radius: 5px; cursor: pointer; font-size: .75rem; }
.btn-approve:hover, .btn-reject:hover { opacity: .85; }

/* ── Modal ── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 100; justify-content: center; align-items: center; }
.modal-overlay.show { display: flex; }
.modal-box { background: #fff; border-radius: 12px; padding: 22px; max-width: 620px; width: 90%; max-height: 80vh; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,.2); }
.modal-box h3 { margin: 0 0 14px; font-size: .92rem; }
.modal-box .field { margin-bottom: 10px; }
.modal-box .field label { display: block; font-size: .74rem; font-weight: 600; color: #666; margin-bottom: 2px; }
.modal-box .field .hint { font-size: .68rem; color: #bbb; margin-top: 2px; }
.modal-box .field input, .modal-box .field select { width: 100%; padding: 7px 10px; border: 1px solid #ddd; border-radius: 6px; font-size: .85rem; box-sizing: border-box; }
.modal-box .actions { margin-top: 14px; display: flex; gap: 8px; justify-content: flex-end; }
.modal-section-title { font-size: .78rem; font-weight: 700; color: #888; margin: 12px 0 6px; padding-top: 8px; border-top: 1px dashed #e8e8e8; }
.modal-section-title:first-of-type { margin-top: 0; border-top: none; padding-top: 0; }

/* ── Helpers ── */
.amount-plus { color: #27ae60; font-weight: 600; }
.amount-minus { color: #e74c3c; font-weight: 600; }
.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 3px; }
.status-dot.active { background: #27ae60; }
.status-dot.inactive { background: #e74c3c; }
.empty-state { text-align: center; padding: 40px; color: #bbb; font-size: .85rem; }
.pagination { display: flex; justify-content: center; gap: 6px; margin-top: 14px; }
.pagination button { padding: 4px 10px; border: 1px solid #ddd; background: #fff; border-radius: 5px; cursor: pointer; font-size: .78rem; }
.pagination button.active { background: #3498db; color: #fff; border-color: #3498db; }
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: #ccc; border-radius: 24px; transition: .3s; }
.toggle-slider:before { content: ''; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .3s; }
.toggle-switch input:checked + .toggle-slider { background: #27ae60; }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(20px); }
.avatar-picker { display: flex; gap: 5px; flex-wrap: wrap; }
.avatar-picker span { font-size: 1.2rem; cursor: pointer; padding: 3px 6px; border-radius: 6px; border: 2px solid transparent; }
.avatar-picker span.selected { border-color: #3498db; background: #eef5ff; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 8px; }
.form-row .field { flex: 1; min-width: 110px; }
.form-row .field label { display: block; font-size: .73rem; font-weight: 600; color: #777; margin-bottom: 2px; }
.form-row .field input, .form-row .field select { width: 100%; padding: 7px 10px; border: 1px solid #ddd; border-radius: 6px; font-size: .82rem; box-sizing: border-box; }
.refresh-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.summary-strip { display: flex; gap: 14px; margin-top: 10px; flex-wrap: wrap; font-size: .78rem; color: #666; }

@media (max-width: 900px) {
  .admin-stats-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .admin-table-wrap { overflow-x: auto; }
}

