/* =========================================================
   教师端 · 学习激励管理后台
   继承 DESIGN.md：间距 / 圆角 / 状态 / 反馈
   风格：专业、温和、清楚、可信（非 Duo 游戏风）
   ========================================================= */

:root {
  /* Spacing 4px base */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 48px;

  /* Radius */
  --radius-tag: 8px;
  --radius-control: 12px;
  --radius-card: 16px;
  --radius-pill: 999px;

  /* Brand (project indigo — not Duo green) */
  --brand: #4f46e5;
  --brand-deep: #4338ca;
  --brand-soft: #eef2ff;
  --brand-border: #c7d2fe;

  /* Surfaces */
  --bg: #f5f6fa;
  --card: #ffffff;
  --card-muted: #f8f9fc;
  --white: #ffffff;

  /* Text */
  --ink: #1f2937;
  --muted: #6b7280;
  --muted-2: #9ca3af;

  /* Borders / states */
  --line: #e5e7eb;
  --line-strong: #d1d5db;

  /* Semantic */
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --disabled: #e5e7eb;
  --disabled-text: #9ca3af;

  /* Compat aliases */
  --primary: var(--brand);
  --primary-deep: var(--brand-deep);
  --primary-soft: var(--brand-soft);
  --radius: var(--radius-control);

  --sidebar-w: 232px;
  --tab-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.04);
  --shadow-md: 0 4px 14px rgba(17, 24, 39, 0.06);
  --focus: 0 0 0 3px rgba(79, 70, 229, 0.18);
  --trans: 180ms ease;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}
.hidden { display: none !important; }

button, input, select, textarea { font-family: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); }

/* ===== App shell / sidebar ===== */
.app-shell {
  min-height: 100vh;
  display: flex;
  background: var(--bg);
}
/* 小屏：侧栏收成底部 Tab；大屏见 media query */
.sidebar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding: 6px 8px var(--safe-bottom);
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
}
.sidebar-brand,
.sidebar-foot {
  display: none;
}
.main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-4) var(--space-3);
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(245, 246, 250, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-mobile-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.page-heading { flex: 1; min-width: 180px; }
.page-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.page-desc {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
}
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--brand-soft);
  color: var(--brand-deep);
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.brand-title { font-weight: 800; font-size: 0.95rem; }
.brand-sub { font-size: 0.75rem; color: var(--muted); font-weight: 600; }

.conn-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.conn-badge.ok { color: var(--ok); background: var(--ok-soft); border-color: #a7f3d0; }
.conn-badge.mock { color: #b45309; background: var(--warn-soft); border-color: #fde68a; }
.mobile-only { display: inline-flex; }

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  flex: 1;
  min-height: 0;
  background: transparent;
  border: none;
  padding: 0;
  height: auto;
  position: static;
}
.tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.78rem;
  border-radius: 10px;
  cursor: pointer;
  min-height: 44px;
  transition: background var(--trans), color var(--trans);
}
.tab:hover { background: var(--card-muted); color: var(--ink); }
.tab.active {
  color: var(--brand-deep);
  background: var(--brand-soft);
}
.tab:focus-visible { box-shadow: var(--focus); }

.page-root {
  flex: 1;
  min-width: 0;
  padding: var(--space-4);
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 24px);
}

/* Desktop sidebar */
@media (min-width: 1024px) {
  .sidebar {
    position: sticky;
    top: 0;
    left: auto;
    right: auto;
    bottom: auto;
    width: var(--sidebar-w);
    flex-shrink: 0;
    height: 100vh;
    padding: var(--space-5) var(--space-3);
    background: var(--card);
    border-right: 1px solid var(--line);
    border-top: none;
  }
  .sidebar-brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 4px 8px 20px;
  }
  .sidebar-foot {
    display: block;
    padding: 12px 8px 4px;
  }
  .sidebar .tabs {
    display: flex;
    flex-direction: column;
    gap: 6px;
    grid-template-columns: none;
  }
  .sidebar .tab {
    justify-content: flex-start;
    padding: 12px 14px;
    font-size: 0.92rem;
    border-radius: var(--radius-control);
  }
  .topbar-mobile-brand,
  .mobile-only { display: none !important; }
  .topbar {
    padding: var(--space-5) var(--space-6) var(--space-4);
  }
  .page-title { font-size: 1.5rem; }
  .page-root {
    padding: 0 var(--space-6) var(--space-8);
    max-width: 1440px;
  }
  .batch-bar { bottom: 28px; }
  .toast { bottom: 32px; }
}

@media (min-width: 1280px) {
  :root { --sidebar-w: 248px; }
}

/* ===== Panels / typography ===== */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.panel.loading, .muted { color: var(--muted); }
.panel.error, .error { color: var(--bad); }
.state-panel {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 180px;
  text-align: center;
}
.spinner {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.section-head { margin-bottom: var(--space-4); }
.section-head h2 {
  margin: 0 0 4px;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
}
.section-head .muted { margin: 0; font-size: 0.86rem; }
.empty { color: var(--muted); margin: 12px 0; }

.step-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--brand-deep);
  background: var(--brand-soft);
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  margin-bottom: 8px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  margin-bottom: var(--space-4);
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--muted);
}
.field { display: block; margin: 12px 0; }
.field.grow { flex: 1; min-width: 140px; }
.field > span {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}

.input, select.input, textarea.input {
  width: 100%;
  min-width: 140px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  padding: 10px 12px;
  font-size: 1em;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color var(--trans), box-shadow var(--trans);
}
.field-inline .input { width: auto; min-width: 180px; }
.input:hover { border-color: #b8c0d0; }
.input:focus { border-color: var(--brand); box-shadow: var(--focus); }
.input:disabled, .input[readonly] { background: var(--card-muted); color: var(--muted); }
.input.is-error { border-color: var(--bad); background: var(--bad-soft); }

/* Buttons */
.btn-primary, .btn-ghost {
  appearance: none;
  border: none;
  cursor: pointer;
  font-weight: 700;
  border-radius: var(--radius-control);
  font-size: 0.9rem;
  padding: 10px 16px;
  min-height: 40px;
  transition: background var(--trans), transform 120ms ease, box-shadow var(--trans), opacity var(--trans);
}
.btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 1px 0 rgba(67, 56, 202, 0.35);
}
.btn-primary:hover { background: var(--brand-deep); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled, .btn-primary.is-loading {
  background: var(--disabled);
  color: var(--disabled-text);
  box-shadow: none;
  cursor: not-allowed;
}
.btn-primary.is-success { background: var(--ok); color: #fff; }
.btn-ghost {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line-strong);
}
.btn-ghost:hover { background: var(--card-muted); }
.btn-ghost:active { transform: translateY(1px); }
.btn-ghost.active,
.btn-ghost[aria-expanded="true"] {
  background: var(--brand-soft);
  border-color: var(--brand-border);
  color: var(--brand-deep);
}
.btn-ghost:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-ghost.sm { padding: 7px 12px; font-size: 0.82rem; min-height: 34px; }

.footer-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.filter-group { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.82rem;
  padding: 7px 12px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  min-height: 34px;
  transition: background var(--trans), color var(--trans), border-color var(--trans);
}
.filter-btn:hover { background: var(--card-muted); }
.filter-btn.active, .filter-btn[aria-pressed="true"] {
  background: var(--brand-soft);
  border-color: var(--brand-border);
  color: var(--brand-deep);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--card);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92em;
}
.data-table th, .data-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table th {
  background: var(--card-muted);
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0.02em;
  position: sticky;
  top: 0;
  z-index: 1;
}
.data-table tbody tr { transition: background var(--trans); }
.data-table tbody tr:hover { background: #fafbff; }
.data-table tbody tr:nth-child(even):not(.history-row) { background: #fcfcfd; }
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--brand); }
.col-check { width: 40px; }
.data-table td strong { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.num-cell { font-variant-numeric: tabular-nums; text-align: right; }

.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 700;
}
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.tag-warn { background: #fff7ed; color: var(--warn); }
.tag-muted { background: #f3f4f6; color: var(--muted); }

.batch-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 12px);
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 14px;
  background: #111827;
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
  font-weight: 700;
}

/* Modal */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 60;
}
.modal {
  width: min(480px, 100%);
  max-height: min(86vh, 720px);
  overflow: auto;
  background: #fff;
  border-radius: var(--radius-card);
  padding: 20px;
  box-shadow: var(--shadow-md);
}
.modal h3 { margin: 0 0 6px; font-size: 1.1rem; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}
.modal-actions.left { justify-content: flex-start; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip {
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
}
.chip-disabled { background: #f3f4f6; color: var(--muted); }

/* CRM / scores */
.rule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.rule-card {
  background: var(--card-muted);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  padding: 14px;
}
.rule-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.rule-title { font-weight: 800; }
.rule-value {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--brand-deep);
  font-variant-numeric: tabular-nums;
}
.score-action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.behavior-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}
.filter-result-hint {
  margin: 10px 0 8px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--brand-deep);
}
.filter-error {
  margin: 0 0 8px;
  padding: 10px 12px;
  background: var(--bad-soft);
  border: 1px solid #fecaca;
  border-radius: var(--radius-control);
  color: #b91c1c;
  font-size: 0.86rem;
}
#time-range-wrap.is-disabled { opacity: 0.55; }
#time-range-wrap.is-disabled .input { cursor: not-allowed; background: #f3f4f6; }
.assignment-filter-bar { margin-bottom: 12px; }
.assignment-notice {
  padding: 10px 12px;
  background: var(--warn-soft);
  border: 1px solid #fde68a;
  border-radius: var(--radius-control);
  color: #92400e;
  font-size: 0.88rem;
  line-height: 1.5;
  margin-bottom: 10px;
}
.assignment-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.assignment-controls .grow { flex: 1; min-width: 180px; }
.assignment-history-toggle {
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.reward-summary {
  margin: 10px 0 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--brand-deep);
  padding: 10px 12px;
  background: var(--brand-soft);
  border-radius: var(--radius-control);
}
.scope-radios { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 6px; }
.scope-radio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  cursor: pointer;
}

/* Config */
.config-grid { display: flex; flex-direction: column; gap: 8px; }
.config-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 10px;
  align-items: center;
  background: var(--card-muted);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  padding: 12px 14px;
}
.config-label { font-weight: 700; }
.config-default { font-size: 0.85rem; color: var(--muted); }
.config-note {
  margin: 0 0 12px;
  padding: 10px 12px;
  background: var(--card-muted);
  border-radius: var(--radius-control);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.86rem;
}

/* Share */
.share-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.panel-highlight {
  border-color: var(--brand-border);
  background: linear-gradient(180deg, #fafafe 0%, #fff 40%);
}
.qr-box {
  display: flex;
  justify-content: center;
  padding: 12px;
  background: var(--card-muted);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  margin: 10px 0;
}
.coming-soon {
  margin-top: 12px;
  padding: 12px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-control);
  color: var(--brand-deep);
  font-weight: 600;
  line-height: 1.5;
}
.msg-textarea {
  min-height: 180px;
  resize: vertical;
  white-space: pre-wrap;
  line-height: 1.55;
}
.msg-preview-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--card-muted);
  padding: 4px;
}
.msg-preview-card .msg-textarea {
  border: none;
  background: transparent;
  box-shadow: none;
}
.var-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}
.rule-collapse {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: #fff;
}
.rule-collapse > summary {
  cursor: pointer;
  list-style: none;
  padding: 12px 14px;
  font-weight: 700;
  color: var(--brand-deep);
}
.rule-collapse[open] > summary { border-bottom: 1px solid var(--line); }
.rule-manager { padding: 12px; }

.history-row td { background: #fff !important; }
.history-box {
  border-left: 4px solid var(--brand);
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}
.history-top {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.history-filter { width: auto; min-width: 180px; }
.history-list { margin: 0; padding: 0; list-style: none; }
.history-item {
  display: grid;
  grid-template-columns: 2fr auto 1.2fr;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
}
.history-item:last-child { border-bottom: none; }
.score-plus { color: var(--ok); font-weight: 800; }
.history-actions { display: flex; justify-content: flex-end; margin-top: 8px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + 24px);
  transform: translateX(-50%) translateY(16px);
  background: #111827;
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 0.88rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 80;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: var(--ok); }
.toast.bad { background: var(--bad); }

/* Responsive */
@media (max-width: 1023px) {
  .share-grid { grid-template-columns: 1fr; }
  .config-row { grid-template-columns: 1fr; gap: 4px; }
}
@media (max-width: 768px) {
  html, body { font-size: 16px; }
  .field-inline { width: 100%; }
  .field-inline .input { flex: 1; min-width: 0; }
  .score-action-bar { flex-direction: column; align-items: stretch; }
  .score-action-bar .btn-primary { width: 100%; }
  .msg-textarea { min-height: 180px; font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .spinner { animation: none; border-top-color: var(--brand); }
}
