:root {
  --brand: #217346;
  --brand-dark: #185c37;
  --brand-soft: #e6f2ea;
  --bg: #f3f6f4;
  --card: #ffffff;
  --text: #202124;
  --muted: #5f6368;
  --line: #dadce0;
  --danger: #d93025;
  --ok: #188038;
  --warn: #b06000;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(60, 64, 67, .15), 0 1px 3px 1px rgba(60, 64, 67, .1);
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  line-height: 1.65;
}
a { color: var(--brand); }
button, input, select, textarea { font: inherit; }

.site-header {
  background: var(--brand);
  color: #fff;
  padding: 12px 16px;
}
.site-header .inner { max-width: 760px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.site-header a { color: #fff; text-decoration: none; font-weight: 600; }
.site-header .brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.site-header .brand img { height: 32px; width: auto; max-width: 160px; object-fit: contain; flex: none; }
.site-header .brand img[hidden] { display: none; }
.logo-preview { display: flex; align-items: center; min-height: 72px; padding: 12px; border: 1px dashed var(--line); border-radius: 8px; background: var(--brand); }
.logo-preview img { max-height: 64px; max-width: 100%; }
.logo-preview .muted { color: #fff; opacity: .85; }

.container { max-width: 760px; margin: 0 auto; padding: 16px 16px 48px; }
.container.wide { max-width: 1200px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 20px 24px;
  margin-bottom: 12px;
}
.card.hero { border-top: 10px solid var(--brand); }
.card h1 { font-size: 1.75rem; margin: 0 0 8px; line-height: 1.3; }
.card h2 { font-size: 1.2rem; margin: 0 0 8px; }
.card .pre { white-space: pre-line; }
.card.invalid { border-color: var(--danger); }
.tagline { font-weight: 700; color: var(--brand-dark); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.req { color: var(--danger); margin-left: 2px; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 12px 0 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }

.section-title {
  background: var(--brand);
  color: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 8px 24px;
  margin: 24px 0 0;
  font-weight: 600;
}
.section-title + .card { border-radius: 0 0 var(--radius) var(--radius); }

/* ---------- 課程列表 ---------- */
.course-list { display: grid; gap: 12px; }
.course-card { display: block; text-decoration: none; color: inherit; transition: box-shadow .15s; }
.course-card:hover { box-shadow: var(--shadow); }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: .8rem; font-weight: 600; background: var(--brand-soft); color: var(--brand-dark);
}
.badge.warn { background: #fef0d9; color: var(--warn); }
.badge.ok { background: #e6f4ea; color: var(--ok); }
.badge.danger { background: #fce8e6; color: var(--danger); }
.badge.gray { background: #eceff1; color: var(--muted); }

/* ---------- 表單 ---------- */
.q-title { font-weight: 600; margin-bottom: 4px; }
.q-help { color: var(--muted); font-size: .9rem; margin-bottom: 8px; }
.q-error { color: var(--danger); font-size: .875rem; margin-top: 8px; display: none; }
.card.invalid .q-error { display: block; }

.choice { display: flex; align-items: flex-start; gap: 10px; padding: 6px 0; cursor: pointer; }
.choice input { margin-top: 5px; accent-color: var(--brand); width: 18px; height: 18px; flex: none; }
.choice.disabled { color: var(--muted); cursor: not-allowed; }
.choice .note { font-size: .85rem; color: var(--muted); }

input[type=text], input[type=password], input[type=email], input[type=tel], input[type=date], input[type=number], input[type=url], select, textarea {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--line);
  padding: 8px 2px;
  background: transparent;
  outline: none;
  color: var(--text);
}
input:focus, textarea:focus, select:focus { border-bottom: 2px solid var(--brand); }
textarea { resize: vertical; min-height: 80px; }
.boxed input, .boxed select, .boxed textarea, input.boxed, select.boxed, textarea.boxed {
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; background: #fff;
}

.grid-wrap { overflow-x: auto; }
table.grid-q { border-collapse: collapse; width: 100%; min-width: 420px; }
table.grid-q th, table.grid-q td { padding: 10px 6px; text-align: center; font-size: .9rem; }
table.grid-q th { font-weight: 500; color: var(--muted); }
table.grid-q td:first-child { text-align: left; font-weight: 500; white-space: nowrap; }
table.grid-q tbody tr:nth-child(odd) { background: #f8f9fa; }
table.grid-q input { accent-color: var(--brand); width: 18px; height: 18px; }
table.grid-q tr.row-invalid td:first-child { color: var(--danger); }

.amount-box {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--brand-soft); border-radius: 8px; padding: 14px 18px;
}
.amount-box .formula { color: var(--muted); font-size: .9rem; }
.amount-box .amount { font-size: 1.6rem; font-weight: 700; color: var(--brand-dark); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 6px; padding: 8px 18px; cursor: pointer;
  background: var(--brand); color: #fff; font-weight: 600; text-decoration: none;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.secondary { background: #fff; color: var(--brand); border-color: var(--line); }
.btn.secondary:hover { background: var(--brand-soft); }
.btn.danger { background: #fff; color: var(--danger); border-color: var(--line); }
.btn.danger:hover { background: #fce8e6; }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; flex-wrap: wrap; }

.notice { padding: 12px 16px; border-radius: 8px; margin-bottom: 12px; }
.notice.warn { background: #fef7e0; color: #7a4f01; }
.notice.error { background: #fce8e6; color: #a50e0e; }
.notice.ok { background: #e6f4ea; color: #0d652d; }

.loading { text-align: center; padding: 48px 0; color: var(--muted); }

.bank {
  background: #f8f9fa; border: 1px dashed var(--line); border-radius: 8px; padding: 12px 16px;
  white-space: pre-line; font-size: 1.1rem; font-weight: 600;
}
.big-amount { font-size: 2rem; font-weight: 700; color: var(--brand-dark); }
.steps { padding-left: 1.2em; }
.steps li { margin-bottom: 6px; }

/* ---------- 後台 ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button {
  border: none; background: none; padding: 10px 16px; cursor: pointer; color: var(--muted);
  border-bottom: 3px solid transparent; font-weight: 600;
}
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar select, .toolbar input { width: auto; min-width: 160px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.stat .v { font-size: 1.4rem; font-weight: 700; }
.stat .k { color: var(--muted); font-size: .85rem; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
table.data { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid #d4e3d9; text-align: left; white-space: nowrap; vertical-align: middle; }
table.data th { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; position: sticky; top: 0; border-bottom: 2px solid var(--brand); }
table.data th + th, table.data td + td { border-left: 1px solid #d4e3d9; }
table.data tr:hover td { background: #eef7f1; }
table.data select { width: auto; border: 1px solid var(--line); border-radius: 4px; padding: 2px 4px; }
td.num, th.num { text-align: right; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 2px; }
.rows-editor .row { display: grid; gap: 6px; align-items: center; margin-bottom: 6px; }
.rows-editor .row.cols-4 { grid-template-columns: 1fr 2fr 1fr 1.3fr auto; }
.rows-editor .row.cols-3 { grid-template-columns: 1fr 2fr 1fr auto; }
.rows-editor .row.head { font-size: .8rem; color: var(--muted); }
.subcard { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 8px; background: #fcfcfd; }

dialog {
  border: none; border-radius: 12px; padding: 0; width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 48px); box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog .dlg-head { position: sticky; top: 0; background: #fff; padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; z-index: 1; }
dialog .dlg-body { padding: 16px 20px; }
dialog .dlg-foot { position: sticky; bottom: 0; background: #fff; padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; white-space: pre-line; word-break: break-word; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #323232; color: #fff; padding: 10px 18px; border-radius: 6px; z-index: 1000;
  max-width: calc(100vw - 32px);
}

@media (max-width: 600px) {
  .card { padding: 16px; }
  .card h1 { font-size: 1.4rem; }
  .form-grid { grid-template-columns: 1fr; }
  .rows-editor .row.cols-4, .rows-editor .row.cols-3 { grid-template-columns: 1fr 1fr; }
  .rows-editor .row.head { display: none; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: 6px; }
}

/* ---------- 頁首導覽 ---------- */
.site-header .nav { display: flex; gap: 16px; flex: none; }
.site-header .nav a { font-weight: 500; opacity: .92; }
.site-header .nav a:hover { opacity: 1; text-decoration: underline; }

/* ---------- 課程圖片 ---------- */
.course-card.has-thumb { display: grid; grid-template-columns: 240px 1fr; gap: 20px; align-items: start; }
.course-card .thumb { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; background: var(--brand-soft); }
.card.hero.has-cover { padding-top: 0; overflow: hidden; }
.card.hero .cover { display: block; width: calc(100% + 48px); max-width: none; margin: 0 -24px 16px; max-height: 360px; object-fit: cover; }
.section-img { display: block; max-width: 100%; height: auto; border-radius: 8px; margin: 4px 0 12px; }
.img-picker-preview { display: flex; align-items: center; justify-content: center; min-height: 60px; padding: 8px; border: 1px dashed var(--line); border-radius: 8px; background: #fafbfa; }
.img-picker-preview img { max-height: 160px; max-width: 100%; border-radius: 4px; }

/* ---------- 我的報名 ---------- */
.login-card { max-width: 480px; margin: 24px auto; }
.login-card .notice { margin: 12px 0 0; }
.reg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.reg-head h2 { margin: 0; }
.pay-form { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; }
.pay-form .form-grid { grid-template-columns: repeat(3, 1fr); }
.pay-form h3, .reg-card h3 { font-size: 1rem; margin: 0 0 8px; }
.reg-card .notice { margin: 16px 0 0; }
.reg-detail { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.reg-detail summary { cursor: pointer; color: var(--brand); font-weight: 600; }
.reg-detail .kv { margin-top: 12px; }
td.mismatch { color: var(--danger); font-weight: 600; }

@media (max-width: 600px) {
  .course-card.has-thumb { grid-template-columns: 1fr; gap: 12px; }
  .card.hero .cover { width: calc(100% + 32px); margin: 0 -16px 12px; }
  .site-header .nav { gap: 10px; }
  .pay-form .form-grid { grid-template-columns: 1fr; }
}
