/* 全站样式改造说明：基于 Bootstrap 的轻量主题层与通用布局类 */
:root {
  --app-bg: #f5f8ff;
  --app-surface: #ffffff;
  --app-primary: #2f6df6;
  --app-primary-soft: #eef4ff;
  --app-text: #1e3a5f;
  --app-text-muted: #64748b;
  --app-border: #dbe7ff;
  --app-shadow: 0 1px 6px rgba(47, 109, 246, 0.06);
  --app-radius-lg: 14px;
  --app-radius-md: 10px;
}

body {
  min-height: 100vh;
  background: var(--app-bg);
  color: var(--app-text);
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 1020;
  border-bottom: 1px solid var(--app-border);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
}

.app-navbar {
  min-height: 64px;
}

.app-brand {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--app-primary);
}

.app-nav-link {
  color: var(--app-text-muted);
  font-weight: 500;
}

.app-nav-link:hover {
  color: var(--app-primary);
}

.app-main {
  flex: 1;
  width: min(1200px, 95vw);
  margin: 22px auto 24px;
}

/* 编程做题页：主内容区更宽（不影响其他页）、仅当页内存在包装时生效 */
.app-main:has(.program-problem-page) {
  width: min(1800px, 90vw);
}

.app-content {
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius-lg);
  box-shadow: var(--app-shadow);
  padding: 1rem 1.25rem 1.25rem;
}

.app-card {
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius-md);
  background: var(--app-surface);
  box-shadow: none;
}

.app-section-title {
  margin-bottom: 0.75rem;
  font-size: 1.05rem;
  font-weight: 700;
}

.app-list-card {
  margin-bottom: 1rem;
}

.app-question-index {
  position: sticky;
  top: 88px;
}

.app-question-index .btn {
  width: 45px;
  margin-top: 5px;
}

.app-table-wrap {
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius-md);
  overflow: hidden;
}

.app-table-wrap .table {
  margin-bottom: 0;
}

.app-tag-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.app-footer {
  border-top: 1px solid var(--app-border);
  background: #ffffff;
  color: var(--app-text-muted);
}

.app-footer-inner {
  width: min(1200px, 95vw);
  margin: 0 auto;
  padding: 1.15rem 0;
  font-size: 0.9rem;
  line-height: 1.7;
  text-align: center;
}

.btn-primary {
  --bs-btn-bg: var(--app-primary);
  --bs-btn-border-color: var(--app-primary);
  --bs-btn-hover-bg: #255fe0;
  --bs-btn-hover-border-color: #255fe0;
  --bs-btn-active-bg: #1f56d0;
  --bs-btn-active-border-color: #1f56d0;
}

.btn-outline-primary {
  --bs-btn-color: var(--app-primary);
  --bs-btn-border-color: #bfd4ff;
  --bs-btn-hover-bg: var(--app-primary-soft);
  --bs-btn-hover-border-color: #9fbeff;
  --bs-btn-hover-color: #255fe0;
}

.navbar-toggler {
  border-color: #c8dcff;
}

.navbar-toggler:focus {
  box-shadow: 0 0 0 0.12rem rgba(47, 109, 246, 0.2);
}

.dropdown-menu {
  border: 1px solid var(--app-border);
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(47, 109, 246, 0.08);
}

.dropdown-item:active {
  background: var(--app-primary-soft);
  color: #1f56d0;
}

.alert {
  border-radius: 10px;
  border-width: 1px;
}

.alert-info {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

.alert-success {
  background: #ecfeff;
  border-color: #bae6fd;
  color: #0c4a6e;
}

.alert-warning {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

.alert-danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.modal-content {
  border: 1px solid var(--app-border);
  border-radius: 12px;
}

.nav-tabs {
  border-bottom-color: var(--app-border);
}

.nav-tabs .nav-link {
  color: var(--app-text-muted);
  border: 1px solid transparent;
}

.nav-tabs .nav-link.active {
  color: var(--app-primary);
  background: var(--app-primary-soft);
  border-color: var(--app-border) var(--app-border) #ffffff;
}

.ai-markdown h1,
.ai-markdown h2,
.ai-markdown h3,
.ai-markdown h4 {
  margin-top: 0.55rem;
  margin-bottom: 0.45rem;
  font-weight: 700;
}

.ai-markdown p {
  margin-bottom: 0.5rem;
}

.ai-markdown ul,
.ai-markdown ol {
  margin-bottom: 0.55rem;
  padding-left: 1.2rem;
}

.ai-markdown code {
  background: #f3f6ff;
  border: 1px solid #dbe7ff;
  border-radius: 4px;
  padding: 0.05rem 0.28rem;
}

.ai-markdown pre {
  background: #f8fbff;
  border: 1px solid #dbe7ff;
  border-radius: 8px;
  padding: 0.6rem;
  overflow: auto;
}

/* 编程提交详情：Ace 只读视图隐藏光标，避免误以为可编辑 */
.ace-readonly-view .ace_cursor,
.ace-readonly-view .ace_hidden-cursors .ace_cursor {
  opacity: 0 !important;
  display: none !important;
}

/* —— 编程题库 / 做题页 —— */
.program-bank-hero {
  border-radius: var(--app-radius-md);
  background: #ffffff;
  border: 1px solid var(--app-border);
  padding: 1.25rem 1.35rem;
  margin-bottom: 1.15rem;
  box-shadow: none;
}

.program-bank-hero-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--app-text);
  margin-bottom: 0.35rem;
}

.program-bank-hero-meta {
  font-size: 0.875rem;
  color: var(--app-text-muted);
  line-height: 1.5;
}

.program-bank-stat {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.65rem;
  padding: 0.35rem 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--app-border);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--app-primary);
}

.program-bank-table-wrap {
  border-radius: var(--app-radius-md);
  overflow: hidden;
  border: 1px solid var(--app-border);
  box-shadow: none;
  background: var(--app-surface);
}

.program-bank-table thead th {
  background: #f8fafc;
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  color: #64748b;
  border-bottom: 2px solid var(--app-border);
  padding: 0.8rem 1rem;
  white-space: nowrap;
}

.program-bank-table tbody td {
  padding: 0.85rem 1rem;
  vertical-align: middle;
  border-bottom-color: #f1f5f9;
}

.program-bank-table tbody tr {
  transition: background-color 0.14s ease;
}

.program-bank-table tbody tr:hover {
  background-color: #f8fafc;
}

.program-bank-table tbody tr:last-child td {
  border-bottom: 0;
}

.program-bank-table .col-id {
  font-variant-numeric: tabular-nums;
  color: var(--app-text-muted);
  font-weight: 600;
  width: 3.5rem;
}

.program-bank-table .title-link {
  font-weight: 600;
  color: var(--app-text);
  text-decoration: none;
  line-height: 1.4;
}

.program-bank-table .title-link:hover {
  color: var(--app-primary);
}

.badge-diff-easy {
  background: #f0f6ff !important;
  color: #2457c5 !important;
  border: 1px solid #cfe0ff;
  font-weight: 600;
  font-size: 0.72rem;
  padding: 0.35em 0.6em;
}

.badge-diff-medium {
  background: #e8f1ff !important;
  color: #1f4fb8 !important;
  border: 1px solid #bdd4ff;
  font-weight: 600;
  font-size: 0.72rem;
  padding: 0.35em 0.6em;
}

.badge-diff-hard {
  background: #dce9ff !important;
  color: #1b3f9c !important;
  border: 1px solid #9fbeff;
  font-weight: 600;
  font-size: 0.72rem;
  padding: 0.35em 0.6em;
}

.badge-diff-none {
  background: #f8fafc !important;
  color: #64748b !important;
  border: 1px solid #dbe7ff;
  font-weight: 500;
  font-size: 0.72rem;
  padding: 0.35em 0.6em;
}

.program-tag-pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 500;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid var(--app-border);
  color: #475569;
  margin: 0.12rem 0.28rem 0.12rem 0;
}

.program-bank-empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--app-text-muted);
  border: 2px dashed var(--app-border);
  border-radius: var(--app-radius-md);
  background: #ffffff;
}

.program-bank-empty-icon {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
  opacity: 0.65;
}

.program-pagination .page-link {
  border-radius: 0.45rem;
  margin: 0 0.28rem;
  border: 1px solid #e5e7eb;
  color: #475569;
  font-weight: 500;
  min-width: 2rem;
  text-align: center;
  background: #fff;
  box-shadow: none;
  transition: all 0.16s ease;
  padding: 0.5rem 0.92rem;
}

.program-pagination .page-link:hover {
  color: #1e3a5f;
  border-color: #b8d0ff;
  background: #f0f6ff;
  transform: none;
}

.program-pagination .page-item.active .page-link {
  background: #2f6df6;
  border-color: #2f6df6;
  color: #fff;
  box-shadow: none;
}

.program-pagination .page-item:first-child .page-link,
.program-pagination .page-item:last-child .page-link {
  padding-left: 1.1rem;
  padding-right: 1.1rem;
  font-size: 0.82rem;
}

.program-submissions-page nav[aria-label="分页"] {
  margin-top: 1.25rem !important;
  margin-bottom: 0.55rem;
}

@media (max-width: 768px) {
  .program-pagination .page-link {
    padding: 0.34rem 0.72rem;
    margin: 0 0.18rem;
    min-width: 2rem;
    font-size: 0.8rem;
  }
}

.program-submissions-table thead th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
  background: #f8fafc;
  border-bottom-width: 1px;
}

.program-submissions-table td {
  vertical-align: middle;
}

.program-submissions-page .badge {
  min-width: 3.6rem;
  text-align: center;
}

.program-result-badge {
  min-width: 4.1rem;
  padding: 0.35rem 0.62rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.program-result-pass {
  color: #14532d !important;
  background: #f0fdf4 !important;
  border: 1px solid #bbf7d0;
}

.program-result-fail {
  color: #991b1b !important;
  background: #fef2f2 !important;
  border: 1px solid #fecaca;
}

.program-result-error {
  color: #9a3412 !important;
  background: #fff7ed !important;
  border: 1px solid #fed7aa;
}

.program-result-pending {
  color: #475569 !important;
  background: #f8fafc !important;
  border: 1px solid #cbd5e1;
}

.program-problem-header .problem-title {
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 1.25rem;
}

.program-problem-io pre {
  border-radius: 10px;
  border: 1px solid var(--app-border);
  background: #f8fafc !important;
  font-size: 0.85rem;
}

#program-debug-panel pre {
  border-radius: 8px;
  border: 1px solid var(--app-border);
  background: #fff !important;
}

/* 做题页 Ace 编辑区：适中高度，随窗口变化 */
#program-editor.program-code-editor {
  min-height: clamp(280px, 38vh, 560px);
  width: 100%;
}

/* 做题页：大屏两列（题面 | 编辑器） */
@media (min-width: 992px) {
  .program-problem-two-col .program-problem-pane-left {
    flex: 0 0 30%;
    max-width: 30%;
  }

  .program-problem-two-col .program-problem-pane-right {
    flex: 0 0 70%;
    max-width: 70%;
  }

  .program-problem-two-col .program-problem-pane-left {
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    padding-right: 0.25rem;
  }

  .program-problem-two-col .program-problem-pane-right {
    position: sticky;
    top: 76px;
    align-self: flex-start;
  }

  .program-problem-two-col #program-editor.program-code-editor {
    min-height: calc(100vh - 320px);
    max-height: calc(100vh - 260px);
  }
}

.program-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
  margin-bottom: 0.35rem;
}

/*
 * 首页题集卡片：固定断点列数（对齐原 col-12 / col-sm-6 / col-lg-4）。
 * 勿用 auto-fit + minmax：列数会随“当前行是否排满”变化，最后一行被拉高、其它页全窄，显得翻页后卡片变小。
 */
.home-question-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}

@media (min-width: 576px) {
  .home-question-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 992px) {
  .home-question-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.home-question-grid > .card {
  min-width: 0;
  /** 铺满网格单元，避免与 SSR 占位宽度不一致 */
  width: 100%;
}

/* 首页增强（方案 A） */
.app-home-hero {
  background: linear-gradient(135deg, #f8fbff 0%, #ffffff 60%);
}

.app-home-metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.app-home-metric {
  border: 1px solid var(--app-border);
  border-radius: 10px;
  background: #f8fbff;
  padding: 0.65rem 0.75rem;
}

.app-home-metric .k {
  font-size: 1.2rem;
  line-height: 1.1;
  font-weight: 700;
  color: #1f56d0;
}

.app-home-metric .v {
  margin-top: 0.2rem;
  font-size: 0.8rem;
  color: var(--app-text-muted);
}

/* exam 页面布局增强 */
.exam-bottom-bar {
  position: sticky;
  bottom: 8px;
  z-index: 20;
  border-color: #cfe0ff;
  box-shadow: 0 4px 14px rgba(47, 109, 246, 0.08);
}

.question-nav-btn {
  margin-top: 0.35rem;
}

@media (min-width: 1200px) {
  .app-question-index {
    position: sticky;
    top: 84px;
    max-height: none;
    overflow-y: visible;
    padding-right: 0;
  }
}

/* exam 填空输入框美化 */
input.gap_filling {
  width: min(100%, 420px);
  height: 2.2rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid #c9dafc;
  border-radius: 8px;
  background: #f9fbff;
  color: #1e3a5f;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}

input.gap_filling:hover {
  border-color: #aac6ff;
  background: #ffffff;
}

input.gap_filling:focus {
  border-color: #2f6df6;
  background: #ffffff;
  box-shadow: 0 0 0 0.12rem rgba(47, 109, 246, 0.16);
}

@media (max-width: 768px) {
  .app-home-metric-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.1rem;
  }

  .app-home-metric-grid {
    display: flex;
    gap: 0.6rem;
    width: max-content;
    min-width: 100%;
  }

  .app-home-metric {
    min-width: 138px;
  }
}

@media (max-width: 768px) {
  .app-main {
    width: 95vw;
    margin-top: 14px;
  }

  .app-content {
    padding: 0.9rem;
  }

  .app-question-index {
    position: static;
    top: auto;
  }
}
