/* ============================================================
   components.css
   按钮、卡片、选项、进度条、标签栏、表格、弹窗

   按钮的三色三档与 v2 完全一致（theme.py 的 BUTTON_TIERS / BUTTON_STYLES）。
   v2 用 canvas 自绘圆角+投影+按下下沉，这里用 CSS 实现同样观感。
   ============================================================ */

/* ---------- 按钮基础 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--btn-normal-r);
  font-family: var(--font-cn);
  font-size: var(--btn-normal-fs);
  font-weight: 700;
  color: var(--c-text-on-color);
  padding: 0 var(--btn-normal-px);
  height: var(--btn-normal-h);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  /* v2 的手感：3px 投影 + 按下下沉 2px */
  box-shadow: 0 var(--btn-shadow) 0 var(--c-shadow);
  transition: transform .06s ease, box-shadow .06s ease, filter .15s;
  touch-action: manipulation;
  white-space: nowrap;
  text-align: center;
}

.btn:active:not(:disabled) {
  transform: translateY(var(--btn-sink));
  box-shadow: 0 calc(var(--btn-shadow) - var(--btn-sink)) 0 var(--c-shadow);
}

@media (hover: hover) {
  .btn:hover:not(:disabled) { filter: brightness(1.05); }
}

.btn:disabled, .btn[aria-disabled="true"] {
  background: var(--c-disabled) !important;
  color: #7B8794;
  cursor: not-allowed;
  box-shadow: 0 var(--btn-shadow) 0 #B4BDC4;
}

/* ---------- 三色 ---------- */
.btn-hero      { background: var(--c-hero); }
.btn-secondary { background: var(--c-secondary); }
.btn-neutral   { background: var(--c-neutral); }
.btn-danger    { background: var(--c-danger); color: #fff; }
.btn-danger:active:not(:disabled) { box-shadow: 0 1px 0 #8A1C16; }

/* ---------- 三档尺寸 ---------- */
.btn-hero-tier {
  height: var(--btn-hero-h);
  border-radius: var(--btn-hero-r);
  font-size: var(--btn-hero-fs);
  padding: 0 var(--btn-hero-px);
}
.btn-small {
  height: var(--btn-small-h);
  border-radius: var(--btn-small-r);
  font-size: var(--btn-small-fs);
  padding: 0 var(--btn-small-px);
  box-shadow: 0 var(--btn-shadow-sm) 0 var(--c-shadow);
}
.btn-small:active:not(:disabled) {
  box-shadow: 0 calc(var(--btn-shadow-sm) - var(--btn-sink)) 0 var(--c-shadow);
}

/* ---------- 整宽 ---------- */
.btn-block { display: flex; width: 100%; }

/* ---------- 选项按钮（白底 + 描边）---------- */
.btn-option {
  background: var(--c-option);
  color: var(--c-text);
  border: 2px solid var(--c-border);
  box-shadow: 0 var(--btn-shadow-sm) 0 var(--c-border);
  border-radius: var(--btn-normal-r);
  height: var(--btn-normal-h);
  font-size: var(--fs-normal);
}
.btn-option:active:not(:disabled) {
  box-shadow: 0 0 0 var(--c-border);
}

/* 答对 / 答错的状态色 */
.btn-option.is-correct {
  background: #D8F3E2;
  border-color: var(--c-green);
  box-shadow: 0 var(--btn-shadow-sm) 0 var(--c-green);
  color: var(--c-green);
  font-weight: 700;
}
.btn-option.is-wrong {
  background: #FBE0DE;
  border-color: var(--c-red);
  box-shadow: 0 var(--btn-shadow-sm) 0 var(--c-red);
  color: var(--c-red);
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--c-card);
  border-radius: var(--r-card);
  padding: var(--sp-5);
  box-shadow: 0 2px 10px rgba(31, 42, 51, .06);
}

.card-soft {
  background: var(--c-card-alt);
  border-radius: 14px;
  padding: var(--sp-4);
}

.divider {
  height: 1px;
  background: var(--c-border);
  border: none;
  margin: var(--sp-4) 0;
  opacity: .5;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-4);
  padding-top: var(--safe-t);
  background: var(--c-bg);
  /* 顶部安全区 + 内容高度 */
  box-sizing: content-box;
}

.topbar-title {
  font-size: var(--fs-title);
  font-weight: 700;
  flex: 1;
  text-align: center;
  /* 与左右按钮视觉平衡 */
  margin: 0;
}

.topbar-side { min-width: 76px; display: flex; }
.topbar-side.right { justify-content: flex-end; }

/* ---------- 进度条 ---------- */
.progress {
  height: 18px;
  background: var(--c-bg-soft);
  border-radius: var(--r-pill);
  overflow: hidden;
  border: 1px solid var(--c-border);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--c-secondary), var(--c-hero));
  border-radius: var(--r-pill);
  transition: width .4s ease;
}

/* ---------- 统计小格 ---------- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-2);
}

.stat {
  text-align: center;
  padding: var(--sp-2) 0;
}

.stat-value {
  font-size: var(--fs-big);
  font-weight: 700;
  line-height: 1.15;
}

.stat-label {
  font-size: var(--fs-small);
  color: var(--c-text-light);
  margin-top: 2px;
}

/* ---------- 标签栏（家长模式）---------- */
.tabs {
  display: flex;
  flex-wrap: wrap;          /* 手机上一行放不下就换行，别让「账号」标签被挤出屏幕 */
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  /* 居中排列 */
  justify-content: center;
}

/* 换行之后每行居中，手机上两行也整齐 */
@media (max-width: 599px) {
  .tabs { gap: 6px; padding: 6px 8px; }
  .tab { padding: 0 12px; font-size: 13px; }
}

.tab {
  flex: 0 0 auto;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--r-pill);
  border: none;
  background: var(--c-neutral);
  color: var(--c-text);
  font-family: inherit;
  font-size: var(--fs-small);
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}

.tab.is-active {
  background: var(--c-hero);
  color: var(--c-text-on-color);
}

/* ---------- 列表（替代 v2 的 Treeview）---------- */
.list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.list-item {
  background: var(--c-card);
  border-radius: 14px;
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.list-item .li-main { flex: 1; min-width: 0; }

.li-title {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.li-sub {
  font-size: var(--fs-small);
  color: var(--c-text-light);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 掌握状态徽标 */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: var(--r-pill);
  font-size: var(--fs-tiny);
  font-weight: 700;
  white-space: nowrap;
}
.badge-new      { background: #EDF2F6; color: #5A6672; }
.badge-learning { background: #FFF1D6; color: var(--c-warn); }
.badge-mastered { background: #D8F3E2; color: var(--c-green); }
.badge-off      { background: #EDF2F6; color: #8A96A2; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(31, 42, 51, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  z-index: 100;
  animation: fadeUp .16s ease-out;
}

.modal {
  background: var(--c-card);
  border-radius: var(--r-card);
  padding: var(--sp-5);
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
}

.modal-title {
  font-size: var(--fs-title);
  font-weight: 700;
  margin-bottom: var(--sp-3);
}

/* ---------- 轻提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-b));
  transform: translateX(-50%);
  background: rgba(31, 42, 51, .93);
  color: #fff;
  padding: 11px 20px;
  border-radius: var(--r-pill);
  font-size: var(--fs-small);
  z-index: 200;
  max-width: 88vw;
  text-align: center;
  animation: fadeUp .18s ease-out;
}

.toast.is-error { background: var(--c-red); }
.toast.is-success { background: var(--c-green); }

/* ---------- 表单行 ---------- */
.field { margin-bottom: var(--sp-3); }

.field-label {
  display: block;
  font-size: var(--fs-small);
  color: var(--c-text-light);
  margin-bottom: 5px;
  font-weight: 700;
}

.field-hint {
  font-size: var(--fs-tiny);
  color: var(--c-text-light);
  margin-top: 4px;
}

.form-error {
  color: var(--c-red);
  font-size: var(--fs-small);
  margin-top: var(--sp-2);
  min-height: 20px;
}

/* ---------- 横条提示 ---------- */
.notice {
  border-radius: 12px;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-small);
  line-height: 1.55;
}
.notice-warn { background: #FFF4DE; color: var(--c-warn); border: 1px solid #F0D9A8; }
.notice-info { background: var(--c-bg-soft); color: var(--c-text); border: 1px solid var(--c-border); }
.notice-ok   { background: #E4F6EA; color: var(--c-green); border: 1px solid #A9DCBB; }
.notice-bad  { background: #FBE6E4; color: var(--c-red); border: 1px solid #EFB7B2; }
