.mathaid-wrap {
  max-width: 1180px;
  margin: 0 auto;
  color: #1f2933;
  font-family: "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
}

.mathaid-toolbar,
.mathaid-result,
.mathaid-form,
.mathaid-admin-summary {
  border: 1px solid #d8dee6;
  border-radius: 8px;
  padding: 16px;
  margin: 16px 0;
  background: #fff;
}

.mathaid-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.mathaid-title {
  margin: 0;
  font-size: 28px;
  line-height: 1.25;
}

.mathaid-muted {
  color: #617083;
  font-size: 14px;
}

.mathaid-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.mathaid-grade-nav {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 0;
  margin: 8px 0 18px;
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid #d8dee6;
}

.mathaid-grade-nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 5px 12px;
  border: 1px solid #aeb9c5;
  border-radius: 999px;
  color: #243b53;
  background: #fff;
  text-decoration: none;
}

/* ── 兩欄條狀格局：1/3/5 年級在左，2/4/6 年級在右 ── */
.mathaid-grade-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 28px;
  align-items: start;
}

#grade-1 { grid-row: 1; grid-column: 1; }
#grade-2 { grid-row: 1; grid-column: 2; }
#grade-3 { grid-row: 2; grid-column: 1; }
#grade-4 { grid-row: 2; grid-column: 2; }
#grade-5 { grid-row: 3; grid-column: 1; }
#grade-6 { grid-row: 3; grid-column: 2; }

.mathaid-grade-section {
  margin: 24px 0 34px;
}

.mathaid-grade-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid #253858;
}

.mathaid-grade-heading h2 {
  margin: 0;
  font-size: 24px;
}

.mathaid-grade-heading span {
  color: #617083;
  font-size: 14px;
}

.mathaid-node-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.mathaid-card {
  border: 2px solid #c9d2dc;
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-sizing: border-box;
}

.mathaid-card h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #102a43;
  flex: 1;
}

.mathaid-card p {
  margin: 0;
  line-height: 1.55;
}

.mathaid-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mathaid-card-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mathaid-node-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 3px 9px;
  border-radius: 6px;
  background: #253858;
  color: #fff;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
  flex-shrink: 0;
}

/* 條狀節點卡片：改為超精簡的 2 行設計 */
.mathaid-node-card {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 10px 14px;
  background-color: rgba(255, 255, 255, 0.4);
}

.mathaid-strip-left {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.mathaid-strip-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: 100%;
  flex-wrap: wrap;
}

.mathaid-strip-mid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-start;
  flex-shrink: 0;
}

.mathaid-strip-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  flex: 1;
}

.mathaid-strip-right .mathaid-muted {
  font-weight: 500;
  color: #627d98;
  font-size: 13px;
}

.mathaid-badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid #c7d0da;
  border-radius: 999px;
  padding: 2px 8px;
  background: rgba(255, 255, 255, .75);
  font-size: 12px;
  color: #344054;
}

.mathaid-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
}

.mathaid-btn,
.mathaid-admin-nav a,
.mathaid-form button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 10px;
  border: 1px solid #46647d;
  border-radius: 6px;
  background: #35556f;
  color: #fff !important;
  text-decoration: none;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.2;
}

.mathaid-btn.secondary {
  background: #fff;
  color: #35556f !important;
}

.mathaid-question {
  border: 1px solid #d8dee6;
  border-radius: 8px;
  padding: 16px;
  margin: 14px 0;
  background: #fff;
}

.mathaid-question h3 {
  margin: 0 0 12px;
  font-size: 18px;
}

.mathaid-option {
  display: block;
  padding: 8px 10px;
  margin: 7px 0;
  border: 1px solid #d8dee6;
  border-radius: 6px;
  background: #fbfcfe;
}

.mathaid-option.correct {
  border-color: #1f8a4c;
  background: #eaf7ef;
}

.mathaid-option.wrong {
  border-color: #c23b3b;
  background: #fff0f0;
}

.mathaid-image {
  max-width: min(100%, 520px);
  height: auto;
  display: block;
  margin: 10px 0;
  border-radius: 6px;
}

.mathaid-hints {
  margin-top: 12px;
  padding: 12px;
  border-left: 4px solid #ed9b33;
  background: #fff8eb;
}

.mathaid-teaching {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #c8d5e3;
  border-radius: 8px;
  background: #f6f9fc;
}

.mathaid-teaching-steps {
  margin: 10px 0 0 20px;
  padding: 0;
}

.mathaid-teaching-step {
  margin: 8px 0;
  line-height: 1.6;
}

.mathaid-teaching-step.is-hidden {
  display: none;
}

.mathaid-table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  background: #fff;
}

.mathaid-table th,
.mathaid-table td {
  border: 1px solid #d8dee6;
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.mathaid-table th {
  background: #eef3f7;
}

.mathaid-form label {
  display: block;
  margin: 10px 0 4px;
  font-weight: 600;
}

.mathaid-form input[type="text"],
.mathaid-form input[type="url"],
.mathaid-form input[type="number"],
.mathaid-form select,
.mathaid-form textarea {
  width: 100%;
  max-width: 760px;
  box-sizing: border-box;
  border: 1px solid #b9c4cf;
  border-radius: 6px;
  padding: 8px;
}

.mathaid-form textarea {
  min-height: 82px;
}

.mathaid-json-input {
  min-height: 280px;
  font-family: Consolas, "Courier New", monospace;
}

.mathaid-code {
  max-width: 100%;
  overflow: auto;
  padding: 12px;
  border: 1px solid #d8dee6;
  border-radius: 8px;
  background: #f7f9fb;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
}

.mathaid-admin-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.mathaid-admin-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.mathaid-stat {
  border: 1px solid #d8dee6;
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

.mathaid-stat strong {
  display: block;
  font-size: 26px;
}

@media (max-width: 900px) {
  .mathaid-grade-grid {
    grid-template-columns: 1fr;
  }
  .mathaid-grade-section {
    grid-row: auto !important;
    grid-column: auto !important;
  }
}

@media (max-width: 640px) {
  .mathaid-title {
    font-size: 22px;
  }

  .mathaid-toolbar {
    align-items: stretch;
  }

  /* 條狀卡片在手機退回垂直排列 */
  .mathaid-node-card {
    flex-direction: column;
    align-items: stretch;
  }

  .mathaid-strip-left {
    flex-wrap: wrap;
  }

  .mathaid-strip-mid {
    justify-content: flex-start;
  }

  .mathaid-strip-right {
    flex-wrap: wrap;
    white-space: normal;
  }

  .mathaid-actions,
  .mathaid-admin-nav {
    flex-direction: column;
  }

  .mathaid-btn,
  .mathaid-admin-nav a {
    width: 100%;
  }
}

/* ── 後台題目管理 Split-Pane 版面 ── */
.mathaid-questions-container {
  display: grid;
  grid-template-columns: 7fr 5fr;
  gap: 24px;
  align-items: start;
  margin-top: 20px;
}

.mathaid-questions-list-pane {
  background: #fff;
  border: 1px solid #d8dee6;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.mathaid-questions-form-pane {
  position: sticky;
  top: 20px;
}

.mathaid-questions-form-pane form.card-form {
  background: #fff;
  border: 1px solid #d8dee6;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  margin-top: 0;
}

.pane-header, .form-pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e1e8f0;
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.pane-header h3, .form-pane-header h3 {
  margin: 0;
  font-size: 18px;
  color: #0f172a;
}

.reset-link {
  font-size: 13px;
  color: #3b82f6;
  text-decoration: none;
  font-weight: 500;
}

.reset-link:hover {
  text-decoration: underline;
}

/* 緊湊型表格調整 */
.compact-table th, .compact-table td {
  padding: 10px 8px;
  font-size: 13.5px;
  vertical-align: middle;
}

.editing-row {
  background-color: #f0f7ff !important;
  outline: 2px solid #3b82f6;
}

.question-snippet {
  color: #334155;
  font-weight: 500;
}

/* 狀態徽章與正解標籤 */
.badge-status {
  display: inline-flex;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  line-height: 1.5;
}

.badge-status.active {
  background-color: #d1fae5;
  color: #065f46;
}

.badge-status.inactive {
  background-color: #f3f4f6;
  color: #4b5563;
}

.badge-answer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background-color: #e0f2fe;
  color: #0369a1;
  font-weight: 700;
  border-radius: 50%;
  font-size: 12px;
}

.stars-display {
  color: #f59e0b;
  letter-spacing: -1px;
}

.action-link {
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
}

.action-link.edit {
  color: #3b82f6;
}

.action-link.delete {
  color: #ef4444;
}

.action-link:hover {
  text-decoration: underline;
}

/* 表單欄位與外框組 */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 14px;
  color: #334155;
}

.form-group select, .form-group input, .form-group textarea {
  border-radius: 6px;
  border: 1px solid #ccd6e0;
  padding: 8px 12px;
  box-sizing: border-box;
}

.field-desc {
  font-size: 12px;
  color: #64748b;
  display: block;
  margin-top: 4px;
}

.option-fieldset {
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background-color: #f8fafc;
}

.option-fieldset legend {
  font-weight: 700;
  font-size: 13px;
  color: #475569;
  padding: 0 6px;
}

/* 預覽圖片 */
.img-preview-box {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding: 6px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background-color: #f8fafc;
}

.preview-img {
  max-width: 60px;
  max-height: 40px;
  border-radius: 4px;
  object-fit: cover;
  border: 1px solid #cbd5e1;
}

.img-preview-box span {
  font-size: 11px;
  color: #64748b;
}

/* 行動裝置支援 */
@media (max-width: 1024px) {
  .mathaid-questions-container {
    grid-template-columns: 1fr;
  }
  .mathaid-questions-form-pane {
    position: static;
  }
}


.mathaid-badge-success { background-color: #d1fae5; color: #065f46; }
.mathaid-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; background: #e2e8f0; color: #475569; font-size: 13px; font-weight: bold; margin-right: 4px; border: 1px solid #cbd5e1; }
