:root {
  --primary: #3b82f6;
  --primary-light: #dbeafe;
  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --border: var(--gray-200);
  --white: #ffffff;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-md: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--gray-700);
  background: var(--gray-100);
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  text-decoration: none;
}

.muted {
  color: var(--gray-500);
}

.hint {
  color: var(--gray-500);
  font-size: 12px;
}

/* 侧边栏布局 */
.sidebar-layout {
  display: flex;
  min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
  width: 260px;
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  left: 0;
  top: 0;
  z-index: 1000;
}

.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid var(--gray-200);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--gray-900);
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
}

.sidebar-brand:hover {
  color: var(--primary);
  text-decoration: none;
}

.sidebar-brand i {
  font-size: 24px;
  color: var(--primary);
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  color: var(--gray-600);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  margin-bottom: 4px;
  transition: all 0.2s ease;
}

.sidebar-link:hover {
  background: var(--gray-100);
  color: var(--gray-900);
  text-decoration: none;
}

.sidebar-link.active {
  background: var(--primary-light);
  color: var(--primary);
}

.sidebar-link i {
  width: 20px;
  text-align: center;
  font-size: 18px;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
}

.user-info {
  padding: 16px;
  margin-bottom: 12px;
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
}

.user-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.user-role {
  font-size: 12px;
  color: var(--gray-500);
}

.user-status {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-dot.active {
  background: var(--success);
}

.status-dot.expired {
  background: var(--danger);
}

.sidebar-link.logout {
  color: var(--gray-500);
  margin-top: 8px;
}

.sidebar-link.logout:hover {
  background: var(--danger-light);
  color: var(--danger);
}

/* 主内容区 */
.main-content {
  flex: 1;
  margin-left: 260px;
  padding: 32px;
  background: var(--gray-100);
  min-height: 100vh;
}

/* 页面头部 */
.page-header {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 24px;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  box-shadow: var(--shadow-sm);
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.page-header .subtitle {
  color: var(--gray-500);
  font-size: 14px;
}

/* 卡片样式 */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

/* 统计卡片 */
.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.stat-icon.blue {
  background: var(--primary-light);
  color: var(--primary);
}

.stat-icon.green {
  background: var(--success-light);
  color: var(--success);
}

.stat-icon.orange {
  background: var(--warning-light);
  color: var(--warning);
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.stat-label {
  font-size: 14px;
  color: var(--gray-500);
}

/* 按钮样式 */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--gray-300);
  background: var(--white);
  color: var(--gray-700);
  text-decoration: none;
}

.btn:hover {
  background: var(--gray-50);
  border-color: var(--gray-400);
  text-decoration: none;
}

.btn-quiet {
  background: var(--gray-50);
  border-color: var(--gray-200);
  color: var(--gray-700);
}

.btn-quiet:hover {
  background: var(--gray-100);
  border-color: var(--gray-300);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--white);
}

.btn-primary:hover {
  background: #2563eb;
  border-color: #2563eb;
  color: var(--white);
}

.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: var(--white);
}

.btn-success:hover {
  background: #059669;
  border-color: #059669;
  color: var(--white);
}

/* Toggle switch */
.ui-switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  vertical-align: middle;
}

.ui-switch input[type="checkbox"] {
  width: 44px;
  height: 24px;
  appearance: none;
  border-radius: 999px;
  border: 1px solid var(--gray-300);
  background: var(--gray-200);
  position: relative;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  flex-shrink: 0;
}

.ui-switch input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--white);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14);
  transition: transform 0.15s ease;
}

.ui-switch input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
}

.ui-switch input[type="checkbox"]:checked::after {
  transform: translateX(20px);
}

.ui-switch input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

.ui-switch input[type="checkbox"]:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.ui-switch-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--gray-600);
}

/* 徽章样式 */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success {
  background: var(--success-light);
  color: #065f46;
}

.badge-danger {
  background: var(--danger-light);
  color: #991b1b;
}

.badge-warning {
  background: var(--warning-light);
  color: #92400e;
}

/* Pills (used across admin/teacher/student templates) */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  color: var(--gray-700);
}

.pill-ok {
  background: var(--success-light);
  border-color: #a7f3d0;
  color: #065f46;
}

.pill-bad {
  background: var(--danger-light);
  border-color: #fecaca;
  color: #991b1b;
}

/* 表格样式 */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.table th,
.table td {
  padding: 16px;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}

.table th {
  background: var(--gray-50);
  font-weight: 600;
  color: var(--gray-700);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table tbody tr:hover {
  background: var(--gray-50);
}

/* 输入框样式 */
input[type="text"],
input[type="password"],
input[type="email"],
select,
textarea {
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  width: 100%;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* 消息提示 */
.messages {
  margin-bottom: 20px;
}

.msg {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.msg-success {
  background: var(--success-light);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.msg-error {
  background: var(--danger-light);
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* Toast-like messages (teacher/student portals) */
.sidebar-layout.page-teacher .messages,
.sidebar-layout.page-student .messages {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 560px;
  z-index: 2000;
  margin: 0;
  pointer-events: none;
}

.sidebar-layout.page-teacher .messages .msg,
.sidebar-layout.page-student .messages .msg {
  margin: 0 0 10px 0;
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
}

/* Stem rendering (question text images) */
.stem-img {
  max-width: min(100%, 760px);
  height: auto;
  max-height: 300px;
  border-radius: 12px;
  border: 1px solid var(--gray-200);
  background: var(--gray-50);
}

.admin-content .stem-img {
  max-height: 260px;
  max-width: min(100%, 680px);
}

.admin-content .stem-img-inline {
  max-height: 60px;
  max-width: 220px;
}

.page-student .stem-img {
  max-height: 360px;
}

.page-student .stem-img-inline {
  max-height: 60px;
  max-width: 220px;
}

.page-teacher .stem-img {
  max-height: 320px;
}

.page-teacher .stem-img-inline {
  max-height: 60px;
  max-width: 220px;
}

.stem-img-inline {
  display: inline-block;
  vertical-align: middle;
  margin: 0 6px;
  max-height: 60px;
  max-width: 220px;
  border-radius: 10px;
}

.stem-img-block {
  display: block;
  margin: 10px 0;
  margin-right: auto;
  max-height: 320px;
  max-width: min(100%, 760px);
}

.stem-token {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  color: var(--gray-600);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.stem-blank {
  display: inline-block;
  width: 64px;
  border-bottom: 2px solid var(--gray-400);
  margin: 0 6px;
  transform: translateY(-1px);
}

/* Choice/option images */
.choices img {
  max-width: min(100%, 520px);
  height: auto;
  max-height: 160px;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--gray-200);
  background: var(--gray-50);
  display: block;
  margin-top: 8px;
  margin-left: 0;
  margin-right: auto;
}

.admin-content .choices img {
  max-height: 140px;
  max-width: min(100%, 480px);
}

body.page-student .choices img {
  max-height: 180px;
}

body.page-teacher .choices img {
  max-height: 160px;
}

/* 教师端特殊样式 */
body.page-teacher {
  /* Teacher portal: compact + blue sidebar + smaller radius */
  --primary: #194182;
  --primary-light: #d6e4f5;
  --radius-sm: 4px;
  --radius: 6px;
  --radius-md: 10px;
  font-size: 13px;
}

body.page-teacher .main-content {
  padding: 29px;
}

body.page-teacher .page-header {
  padding: 22px;
  margin-bottom: 22px;
  gap: 20px;
}

body.page-teacher .page-header h1 {
  font-size: 22px;
}

body.page-teacher .card,
body.page-teacher .stat-card {
  padding: 22px;
}

body.page-teacher .stat-icon {
  width: 44px;
  height: 44px;
}

body.page-teacher .stat-value {
  font-size: 29px;
}

body.page-teacher .btn {
  padding: 9px 14px;
  font-size: 13px;
  gap: 7px;
}

body.page-teacher .table .btn {
  padding: 6px 10px;
  font-size: 12px;
  gap: 6px;
}

body.page-teacher input[type="text"],
body.page-teacher input[type="password"],
body.page-teacher input[type="email"],
body.page-teacher select,
body.page-teacher textarea {
  padding: 9px 12px;
  font-size: 13px;
}

body.page-teacher .table th,
body.page-teacher .table td {
  padding: 14px;
}

body.page-teacher .table th {
  font-size: 11px;
}

body.page-teacher .badge {
  padding: 3px 10px;
  font-size: 11px;
}

body.page-teacher .sidebar {
  background: #0c2752;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
}

body.page-teacher .sidebar-header {
  padding: 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

body.page-teacher .sidebar-brand {
  color: rgba(255, 255, 255, 0.95);
  font-size: 17px;
}

body.page-teacher .sidebar-brand:hover {
  color: #ffffff;
}

body.page-teacher .sidebar-brand i {
  color: #ffffff;
  font-size: 22px;
}

body.page-teacher .sidebar-nav {
  padding: 14px 11px;
}

body.page-teacher .sidebar-link {
  padding: 11px 14px;
  gap: 10px;
  color: rgba(255, 255, 255, 0.86);
  font-size: 13px;
}

body.page-teacher .sidebar-link i {
  font-size: 16px;
}

body.page-teacher .sidebar-link:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

body.page-teacher .sidebar-link.active {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

body.page-teacher .sidebar-footer {
  padding: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
}

body.page-teacher .user-info {
  padding: 14px;
  margin-bottom: 10px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

body.page-teacher .user-name {
  color: #ffffff;
}

body.page-teacher .user-role {
  color: rgba(255, 255, 255, 0.72);
}

body.page-teacher .sidebar-link.logout {
  color: rgba(255, 255, 255, 0.78);
}

body.page-teacher .sidebar-link.logout:hover {
  background: rgba(239, 68, 68, 0.22);
  color: #ffffff;
}

/* 学生端特殊样式 */
.page-student .sidebar-brand i {
  color: var(--success);
}

.page-student .sidebar-link.active {
  background: var(--success-light);
  color: #065f46;
}

.page-student .btn-primary {
  background: var(--success);
  border-color: var(--success);
}

.page-student .btn-primary:hover {
  background: #059669;
  border-color: #059669;
}

/* 移动端 */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 12px;
  }
  
  .sidebar-header {
    width: 100%;
    padding: 12px;
  }
  
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 8px;
  }
  
  .sidebar-link span {
    display: none;
  }
  
  .sidebar-link {
    padding: 10px;
  }
  
  .sidebar-footer {
    width: 100%;
  }
  
  .main-content {
    margin-left: 0;
    padding: 20px;
  }
}

/* Auth pages (login/register): center card, no nav/footer */
.page-auth .container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 96px 16px 32px;
}

.page-auth .messages {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 560px;
  z-index: 2000;
  margin: 0;
}

.page-auth .auth-card {
  width: 100%;
  max-width: 520px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 28px;
  box-shadow: var(--shadow-md);
}

.page-auth .auth-top {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 14px;
}

.page-auth .auth-back-btn {
  padding: 8px 12px;
  font-size: 13px;
  background: var(--gray-50);
  border-color: var(--gray-200);
  color: var(--gray-700);
}

.page-auth .auth-card h1 {
  margin-bottom: 16px;
}

.page-auth .auth-card-sm {
  max-width: 420px;
}

.page-auth .form .field {
  margin-bottom: 14px;
}

.page-auth .form label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: var(--gray-700);
}

.page-auth .form input[type="text"],
.page-auth .form input[type="password"],
.page-auth .form input[type="email"],
.page-auth .form select,
.page-auth .form textarea {
  background: var(--gray-50);
}

.page-auth .form input:focus,
.page-auth .form select:focus,
.page-auth .form textarea:focus {
  background: var(--white);
}

.page-auth .form .btn {
  margin-top: 8px;
  justify-content: center;
}
