:root {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --ink: #1d2b24;
  --ink-soft: #5b6b62;
  --line: #d9e3dc;
  --green: #2f7a5b;
  --green-soft: #e3f2ea;
  --amber: #b26a12;
  --amber-soft: #fdf0dc;
  --red: #b23b3b;
  --red-soft: #fbe6e6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(29, 43, 36, .06), 0 8px 24px rgba(29, 43, 36, .06);
}

* { box-sizing: border-box; }

/* display:flex 會蓋掉 hidden 屬性，這條把它拉回來 */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

h2, h3, h4 { margin: 0; font-weight: 700; }
p { margin: 0; }

/* ---- 頂列 ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 8px; }
.logo { color: var(--green); font-size: 20px; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: .02em; }

.topbar-controls { display: flex; gap: 8px; }

select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  min-height: 40px;
}

/* ---- 分頁 ---- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 65px;
  z-index: 19;
  overflow-x: auto;
}

.tab {
  font: inherit;
  font-weight: 600;
  border: none;
  background: none;
  color: var(--ink-soft);
  padding: 10px 14px;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

.tab.is-active { color: var(--green); border-bottom-color: var(--green); }

.tab-links { margin-left: auto; display: flex; gap: 12px; align-items: center; padding: 0 4px 8px; }
.tab-links a { font-size: 13px; color: var(--ink-soft); text-decoration: none; white-space: nowrap; }
.tab-links a:hover { color: var(--green); text-decoration: underline; }

@media (max-width: 720px) {
  .tab-links { margin-left: 8px; gap: 10px; }
}

/* 子頁共用的返回列 */
.subpage-back { padding: 12px 16px 0; max-width: 1100px; margin: 0 auto; }
.subpage-back a { font-size: 14px; color: var(--ink-soft); text-decoration: none; }
.subpage-back a:hover { color: var(--green); }

main { padding: 20px 16px 80px; max-width: 1100px; margin: 0 auto; }

.view { display: none; }
.view.is-active { display: block; }

.view-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.hint { color: var(--ink-soft); font-size: 14px; margin-top: 4px; }
.view-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- 按鈕 ---- */

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 9px 14px;
  min-height: 40px;
  cursor: pointer;
}

.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: #26654b; }
.btn-ghost { background: var(--surface); }
.btn-sm { padding: 6px 10px; min-height: 34px; font-size: 14px; }
.btn.is-on { background: var(--green-soft); border-color: var(--green); color: var(--green); }

.linkbtn {
  font: inherit;
  font-size: 13px;
  background: none;
  border: none;
  color: var(--ink-soft);
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

/* ---- 座位表 ---- */

.board {
  text-align: center;
  font-size: 13px;
  letter-spacing: .3em;
  color: var(--ink-soft);
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 14px;
}

.board-bottom { margin: 14px 0 0; }

.seating {
  display: grid;
  gap: 10px;
}

.seat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .08s ease, border-color .12s ease;
  min-height: 88px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.seat:active { transform: scale(.97); }
.seat.is-selected { border-color: var(--green); background: var(--green-soft); }
.seat.flash-up { animation: flashUp .5s ease; }
.seat.flash-down { animation: flashDown .5s ease; }

@keyframes flashUp {
  0% { background: var(--green-soft); }
  100% { background: var(--surface); }
}
@keyframes flashDown {
  0% { background: var(--amber-soft); }
  100% { background: var(--surface); }
}

.seat-no { font-size: 11px; color: var(--ink-soft); }
.seat-name { font-weight: 700; font-size: 15px; }
.seat-score { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.seat-score.pos { color: var(--green); }
.seat-score.neg { color: var(--red); }
.seat-score.zero { color: var(--ink-soft); }
.seat-today { font-size: 11px; color: var(--ink-soft); }

/* 手機直握時，座位表仍維持原本的排列，只把字級與留白收緊 */
@media (max-width: 560px) {
  main { padding: 16px 10px 80px; }
  .seating { gap: 6px; }
  .seat { padding: 8px 2px; min-height: 74px; border-radius: 10px; }
  .seat-name { font-size: 13px; letter-spacing: -.02em; }
  .seat-score { font-size: 17px; }
  .seat-no, .seat-today { font-size: 10px; }
  .tabs { top: 57px; }
}

.multibar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--green-soft);
  border: 1px solid var(--green);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--green);
  flex-wrap: wrap;
}

/* ---- 記錄面板 ---- */

.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20, 32, 26, .45); }

.sheet-panel {
  position: relative;
  background: var(--surface);
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 18px 18px 24px;
  box-shadow: 0 -8px 40px rgba(20, 32, 26, .2);
}

@media (min-width: 640px) {
  .sheet { align-items: center; }
  .sheet-panel { border-radius: 18px; }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.behavior-group { margin-bottom: 16px; }

.group-title { font-size: 13px; margin-bottom: 8px; }
.group-title.positive { color: var(--green); }
.group-title.improve { color: var(--amber); }

.behaviors { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }

.bcard {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  padding: 12px 6px;
  cursor: pointer;
  text-align: center;
  min-height: 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.bcard:hover { background: var(--surface-2); }
.bcard .icon { font-size: 22px; }
.bcard .label { font-size: 13px; font-weight: 600; }
.bcard .delta { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bcard.positive { border-color: #bcdcca; }
.bcard.positive .delta { color: var(--green); }
.bcard.improve { border-color: #eddcbe; }
.bcard.improve .delta { color: var(--amber); }

.sheet-foot { font-size: 12px; color: var(--ink-soft); border-top: 1px solid var(--line); padding-top: 12px; }

/* ---- 提示 ---- */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 20px;
  background: var(--ink);
  color: #fff;
  padding: 10px 12px 10px 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 50;
  box-shadow: 0 8px 30px rgba(20, 32, 26, .3);
  font-size: 14px;
  max-width: calc(100vw - 32px);
}

.btn-undo { background: rgba(255,255,255,.16); border: none; color: #fff; }
.btn-undo:hover { background: rgba(255,255,255,.28); }

/* ---- 儀表板 ---- */

.alerts { display: grid; gap: 10px; margin-bottom: 18px; }

.alert {
  border-radius: 12px;
  padding: 12px 14px;
  border: 1px solid var(--amber);
  background: var(--amber-soft);
}

.alert.student { border-color: var(--red); background: var(--red-soft); }
.alert h4 { font-size: 15px; margin-bottom: 2px; }
.alert p { font-size: 13px; color: var(--ink-soft); }
.alert-empty { border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft); border-radius: 12px; padding: 12px 14px; font-size: 14px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 18px; }

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.stat .k { font-size: 13px; color: var(--ink-soft); }
.stat .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.panel h3 { font-size: 15px; margin-bottom: 12px; }

.trend { display: flex; align-items: flex-end; gap: 6px; height: 160px; overflow-x: auto; }

.tcol { flex: 1 1 0; min-width: 34px; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.tbars { flex: 1; width: 100%; display: flex; align-items: flex-end; gap: 3px; }
.tbar { flex: 1; border-radius: 4px 4px 0 0; min-height: 2px; }
.tbar.p { background: var(--green); }
.tbar.i { background: #e0a35a; }
.tlabel { font-size: 11px; color: var(--ink-soft); }

/* ---- 表格 ---- */

.filters { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; font-size: 14px; align-items: center; }
.filters label { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); }
.filters .check { gap: 6px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }
tr.voided { opacity: .45; text-decoration: line-through; }

.logtable, .studenttable {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow);
}

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.positive { background: var(--green-soft); color: var(--green); }
.pill.improve { background: var(--amber-soft); color: var(--amber); }
.pill.redeem { background: #ece6f6; color: #5b4a8a; }

.num { font-variant-numeric: tabular-nums; text-align: right; }
.empty { padding: 24px; text-align: center; color: var(--ink-soft); font-size: 14px; }

/* ---- 學生詳情 ---- */

.detail-stats { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.detail-stat { flex: 1 1 90px; background: var(--surface-2); border-radius: 10px; padding: 10px; text-align: center; }
.detail-stat .k { font-size: 12px; color: var(--ink-soft); }
.detail-stat .v { font-size: 20px; font-weight: 700; }
.timeline { list-style: none; padding: 0; margin: 0; max-height: 320px; overflow-y: auto; }
.timeline li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; align-items: center; }
.timeline .t { color: var(--ink-soft); font-size: 12px; min-width: 92px; }
.timeline .d { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.timeline .d.pos { color: var(--green); }
.timeline .d.neg { color: var(--amber); }

.notice {
  background: var(--green-soft);
  border: 1px solid #bcdcca;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--green);
  margin-bottom: 14px;
}

/* ---- 頁尾 ---- */

.foot {
  border-top: 1px solid var(--line);
  padding: 18px 16px 40px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
  display: grid;
  gap: 6px;
  justify-items: center;
}
