/* 後台樣式。配色變數跟前台那份一致，但版面寬得多（要放表格）。 */
:root {
  color-scheme: light dark;
  --fg: #1a1a1a;
  --bg: #fdfdfd;
  --card: #ffffff;
  --line: #e2e2e2;
  --accent: #f38020;
  --ok: #1a7f37;
  --bad: #c1121f;
  --muted: #6b7280;
  --row-hover: #f6f7f9;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #ececec;
    --bg: #16181d;
    --card: #1f2229;
    --line: #333842;
    --ok: #4ac26b;
    --bad: #ff6b6b;
    --muted: #9aa3b2;
    --row-hover: #262a33;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 2rem 1rem;
  font-family: -apple-system, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.6;
  color: var(--fg);
  background: var(--bg);
}

.wrap {
  max-width: 68rem;
  margin: 0 auto;
}

.wrap.gate {
  max-width: 26rem;
  margin-top: 12vh;
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 .3rem;
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 .8rem;
}

.hint {
  margin: 0;
  font-size: .85rem;
  color: var(--muted);
}

code {
  padding: .1rem .3rem;
  border-radius: .25rem;
  background: var(--row-hover);
  font-size: .85em;
}

/* ---------- 密碼畫面 ---------- */

.gate-form {
  display: flex;
  gap: .5rem;
  margin: 1.2rem 0 0;
}

.gate-form input {
  flex: 1;
  min-width: 0;
}

/* ---------- 頂端 ---------- */

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.top-actions {
  display: flex;
  gap: .5rem;
}

/* ---------- 表單元件 ---------- */

input, select {
  padding: .5rem .7rem;
  border: 1px solid var(--line);
  border-radius: .45rem;
  background: var(--card);
  color: var(--fg);
  font-family: inherit;
  font-size: .9rem;
}

input:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

button {
  padding: .5rem 1.1rem;
  border: 0;
  border-radius: .45rem;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
}

button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

button.ghost {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  font-weight: 500;
}

button.link {
  padding: .2rem .5rem;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg);
  font-size: .8rem;
  font-weight: 500;
}

/* ---------- 狀態訊息 ---------- */

.status {
  padding: .7rem .9rem;
  border: 1px solid var(--line);
  border-radius: .45rem;
  background: var(--card);
  font-size: .88rem;
}

.status.error {
  border-color: var(--bad);
  color: var(--bad);
}

/* ---------- 統計卡 ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: .7rem;
  margin-bottom: 1.5rem;
}

.card {
  padding: .8rem .9rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: var(--card);
}

.card .label {
  font-size: .78rem;
  color: var(--muted);
}

.card .value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
}

/* ---------- 區塊 ---------- */

.panel {
  padding: 1.1rem 1.2rem;
  margin-bottom: 1.5rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: var(--card);
}

.count {
  font-size: .85rem;
  font-weight: 400;
  color: var(--muted);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .9rem;
}

.filters input { flex: 1; min-width: 12rem; }

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

/* 窄螢幕時讓表格自己橫向滑動，不要把整頁撐寬 */
.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}

th, td {
  padding: .5rem .6rem;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}

th {
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover { color: var(--fg); }

tbody tr:hover { background: var(--row-hover); }

tbody tr.detail-row:hover { background: transparent; }

td.empty {
  padding: 1.2rem .6rem;
  color: var(--muted);
  text-align: center;
  white-space: normal;
}

.wrapped { white-space: normal; min-width: 14rem; }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .82rem;
  color: var(--muted);
}

/* ---------- 狀態標籤 ---------- */

.badge {
  display: inline-block;
  padding: .1rem .5rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  font-size: .78rem;
}

.badge.submitted { border-color: var(--ok); color: var(--ok); }
.badge.in_progress { border-color: var(--accent); color: var(--accent); }
.badge.revoked { border-color: var(--bad); color: var(--bad); }
.badge.unused { color: var(--muted); }

.warn {
  color: var(--bad);
  font-size: .78rem;
}

/* ---------- 答對率長條 ---------- */

.rate {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.bar {
  position: relative;
  width: 6rem;
  height: .5rem;
  border-radius: 1rem;
  background: var(--line);
  overflow: hidden;
}

.bar span {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--ok);
}

/* ---------- 逐題明細 ---------- */

.detail-row > td {
  padding: 0 .6rem 1rem;
  white-space: normal;
}

.detail {
  padding: .9rem 1rem;
  border: 1px solid var(--line);
  border-radius: .45rem;
  background: var(--bg);
}

.detail-head {
  margin: 0 0 .7rem;
  font-size: .85rem;
  color: var(--muted);
}

.detail ol {
  margin: 0;
  padding-left: 1.3rem;
}

.detail li { margin-bottom: .7rem; }

.detail .q-title { font-weight: 600; }

.detail .picked { font-size: .85rem; }

.correct { color: var(--ok); }
.wrong { color: var(--bad); }
.blank { color: var(--muted); }
