:root {
  --primary: #15803d;
  --primary-dark: #166534;
  --primary-soft: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --bg: #f6faf7;
  --card: #ffffff;
}

* { box-sizing: border-box; }

body {
  font-family: "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  line-height: 1.6;
}

h1 { font-size: 1.4rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.5rem; }
a { color: var(--primary); }
code { background: #f1f5f9; padding: 0.1rem 0.3rem; border-radius: 4px; }

.topbar { background: var(--card); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 960px; margin: 0 auto; padding: 0.6rem 1rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.25rem;
}
.brand { font-weight: bold; font-size: 1.1rem; color: var(--primary); text-decoration: none; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; flex: 1; }
.topbar nav a, .user-info a { color: var(--text); text-decoration: none; }
.topbar nav a:hover, .user-info a:hover { color: var(--primary); }
.user-info { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; }
.role-tag { background: var(--primary-soft); color: var(--primary-dark); padding: 0.1rem 0.5rem; border-radius: 999px; }

.container { max-width: 960px; margin: 0 auto; padding: 1rem; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 1.25rem; margin-bottom: 1rem;
}
.card.narrow { max-width: 480px; margin-left: auto; margin-right: auto; }
.hero { border-top: 4px solid var(--primary); }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.nowrap { white-space: nowrap; }
.notice { background: var(--warn-bg); color: var(--warn); padding: 0.6rem 0.8rem; border-radius: 8px; }

.flash { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash-success { background: var(--primary-soft); color: var(--primary-dark); }
.flash-error { background: var(--danger-bg); color: var(--danger); }

label { display: block; margin-bottom: 0.85rem; font-size: 0.95rem; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=file], select {
  display: block; width: 100%; margin-top: 0.25rem; padding: 0.55rem 0.7rem;
  border: 1px solid var(--border); border-radius: 8px; font-size: 1rem; background: #fff;
  font-family: inherit;
}

.btn {
  display: inline-block; padding: 0.5rem 1rem; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font-size: 0.95rem; cursor: pointer; text-decoration: none;
  font-family: inherit;
}
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: var(--danger-bg); }
.btn-small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
.btn-block { display: block; width: 100%; padding: 0.7rem; font-size: 1.05rem; }
.link-btn { background: none; border: none; padding: 0; color: var(--primary); cursor: pointer; font: inherit; text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
form.inline { display: inline; }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.actions { display: flex; gap: 0.5rem 0.75rem; align-items: center; flex-wrap: wrap; }
.inline-form { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { margin-bottom: 0; }

.badge { display: inline-block; padding: 0.05rem 0.5rem; border-radius: 999px; font-size: 0.8rem; white-space: nowrap; }
.badge-success { background: var(--primary-soft); color: var(--primary-dark); }
.badge-muted { background: #f1f5f9; color: var(--muted); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }

.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { text-align: left; padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: normal; font-size: 0.85rem; }
.row-muted td { color: var(--muted); }
.row-selected td { background: var(--primary-soft); }

.lookup { display: grid; grid-template-columns: 1fr 1fr auto; gap: 0.75rem; align-items: end; margin-top: 1rem; }
.lookup label { margin-bottom: 0; }
.lookup .btn { padding: 0.6rem 1.2rem; }

.result { text-align: center; }
.result-done { border-color: var(--primary); background: linear-gradient(#fff, var(--primary-soft)); }
.result-name { font-size: 1.6rem; font-weight: bold; margin: 0; }
.result-count { font-size: 1.1rem; margin: 0.25rem 0; }
.result-count strong { font-size: 2.2rem; color: var(--primary); }
.progress { background: #e5e7eb; border-radius: 999px; height: 12px; overflow: hidden; max-width: 360px; margin: 0.5rem auto; }
.progress-bar { background: var(--primary); height: 100%; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; margin-top: 0.75rem; }
.stat { background: var(--bg); border-radius: 10px; padding: 0.75rem; text-align: center; }
.stat-num { display: block; font-size: 1.8rem; font-weight: bold; color: var(--primary); }

.class-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 0.5rem; margin-top: 0.75rem; }
.class-btn {
  display: flex; flex-direction: column; align-items: center; padding: 0.7rem 0.4rem;
  border: 1px solid var(--border); border-radius: 10px; text-decoration: none; color: var(--text); background: #fff;
}
.class-btn:hover, .class-btn.active { border-color: var(--primary); background: var(--primary-soft); }
.class-btn small { color: var(--muted); }

.record-list { list-style: none; padding: 0; margin: 0.5rem 0 1rem; }
.record-item {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.35rem 0.25rem; border-bottom: 1px solid var(--border);
}
.record-item.is-checked { background: var(--primary-soft); }
.record-check { display: flex; align-items: center; gap: 0.6rem; margin: 0; flex: 1; cursor: pointer; padding: 0.3rem 0; }
.record-check input { width: 1.3rem; height: 1.3rem; accent-color: var(--primary); }
.record-check .seat { width: 1.8rem; text-align: right; color: var(--muted); }
.record-check .name { flex: 1; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.record-check .count { font-size: 0.8rem; color: var(--muted); }
.record-check .count-done { color: var(--primary); font-weight: bold; }
.bag-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-shrink: 0; }
.bag-toggle label { margin: 0; }
.bag-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.bag-toggle span { display: block; padding: 0.3rem 0.55rem; font-size: 0.85rem; cursor: pointer; background: #fff; }
.bag-toggle input:checked + span { background: var(--primary); color: #fff; }
.record-item:not(.is-checked) .bag-toggle input:checked + span { background: #e2e8f0; color: var(--muted); }
.sticky-save { position: sticky; bottom: 0.75rem; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); }

.sample { background: #f1f5f9; padding: 0.75rem; border-radius: 8px; font-size: 0.9rem; }

@media (max-width: 560px) {
  .lookup { grid-template-columns: 1fr 1fr; }
  .lookup .btn { grid-column: 1 / -1; }
  .stats { grid-template-columns: 1fr 1fr 1fr; }
  .stat-num { font-size: 1.4rem; }
  .table { font-size: 0.875rem; }
  .user-info { width: 100%; justify-content: flex-end; }
  .record-check { gap: 0.4rem; }
  .record-check .seat { width: 1.3rem; }
  .bag-toggle span { padding: 0.3rem 0.4rem; }
}
