:root {
  --bg: #f5f6f4; --fg: #1b1f1d; --muted: #5f6763; --card: #ffffff; --line: #dfe3df;
  --brand: #0f5c4d; --brand-fg: #ffffff; --accent: #c98a12;
  --ok: #1d7a3e; --ok-bg: #e5f4ea; --warn: #8a5a00; --warn-bg: #fdf1d8; --bad: #b3261e; --bad-bg: #fbe7e5;
  --line-green: #06c755; --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121514; --fg: #e8ece9; --muted: #9aa39e; --card: #1b1f1d; --line: #2e3431;
    --brand: #3fb59a; --brand-fg: #06201a; --accent: #e3a83a;
    --ok: #67c98a; --ok-bg: #173323; --warn: #e8b85a; --warn-bg: #33280f; --bad: #f08a80; --bad-bg: #3a1c19;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.6 system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Sarabun", sans-serif; }
a { color: var(--brand); }
.muted { color: var(--muted); } .fine { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }
[hidden] { display: none !important; }

/* header */
#header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; min-width: 0; }
.brand-mark { flex: none; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--brand); color: var(--brand-fg); font-weight: 700; font-size: 15px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who-name { font-size: 14px; max-width: 36vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.login-wrap { position: relative; flex: none; }
.login-menu { position: absolute; right: 0; top: calc(100% + 8px); width: 240px; padding: 14px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 28px rgba(0,0,0,.14); display: grid; gap: 8px; }
.login-menu p { margin: 0; }

/* buttons */
.btn { font: inherit; font-size: 15px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--fg); cursor: pointer; }
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-fg); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.line { background: var(--line-green); border-color: var(--line-green); color: #fff; font-weight: 600; }
.btn.google { font-weight: 600; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.small { font-size: 13px; padding: 4px 10px; border-radius: 8px; }
.btn.block { width: 100%; }

/* layout */
main { max-width: 1040px; margin: 0 auto; padding: 24px 16px 64px; }
.hero { padding: 28px 24px; border-radius: 16px; background: linear-gradient(135deg, var(--brand), #0b3f35); color: #fff; margin-bottom: 24px; }
.hero h1 { margin: 0 0 6px; font-size: clamp(22px, 4vw, 30px); line-height: 1.3; }
.hero p { margin: 0; opacity: .9; }
h2 { font-size: 18px; margin: 28px 0 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.tile { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; }
.tile:hover { border-color: var(--brand); }
.tile .icon { font-size: 26px; }
.tile strong { font-size: 16px; }
.empty { color: var(--muted); font-size: 14px; }
.news .tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--warn-bg); color: var(--warn); margin-bottom: 6px; }

.notice { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 15px; }
.notice.error { background: var(--bad-bg); color: var(--bad); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }

/* form */
form { display: grid; gap: 16px; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 14px; }
legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
label { display: grid; gap: 4px; font-size: 14px; font-weight: 500; }
label .req { color: var(--bad); }
input[type=text], input[type=tel], input[type=email], input[type=search], select { font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); width: 100%; }
input:focus-visible, select:focus-visible, .btn:focus-visible, .switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice label { display: flex; align-items: flex-start; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-weight: 400; }
.choice label:has(input:checked) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, transparent); }
.choice strong { display: block; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 5px; }
.pdpa { font-size: 13.5px; color: var(--muted); background: var(--bg); border-radius: 10px; padding: 12px 14px; max-height: 180px; overflow: auto; }
.pdpa p { margin: 0 0 6px; }

/* admin */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar input { flex: 1 1 220px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 13.5px; padding: 5px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--fg); cursor: pointer; }
.chip[aria-pressed=true] { background: var(--brand); border-color: var(--brand); color: var(--brand-fg); }
.users { display: grid; gap: 12px; }
.user { display: grid; gap: 12px; }
.user-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; justify-content: space-between; }
.user-head strong { font-size: 16px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.badge.pending { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.active { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.banned { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.meta { font-size: 13.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 16px; }
.controls { display: grid; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; }
.ctl-row { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.ctl-row > .lbl { font-size: 13px; color: var(--muted); min-width: 64px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { font: inherit; font-size: 13.5px; padding: 5px 12px; border: 0; background: var(--card); color: var(--fg); cursor: pointer; border-left: 1px solid var(--line); }
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed=true] { background: var(--brand); color: var(--brand-fg); }
.seg button:disabled { cursor: not-allowed; opacity: .55; }
.proj { display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border: 1px solid var(--line); border-radius: 99px; font-size: 13.5px; }
.proj select { padding: 2px 6px; font-size: 13px; width: auto; border-radius: 6px; }
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: background .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:disabled { cursor: not-allowed; } .switch input:disabled + span { opacity: .5; }
.more { display: flex; justify-content: center; margin-top: 12px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 10px 16px; border-radius: 10px;
  background: var(--fg); color: var(--bg); font-size: 14px; transition: all .2s; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--bad); color: #fff; }

footer { text-align: center; font-size: 12.5px; color: var(--muted); padding: 24px 16px 40px; }

@media (max-width: 560px) {
  .brand-text small { display: none; }
  .choice { grid-template-columns: 1fr; }
  .hero { padding: 22px 18px; }
  .who-name { display: none; }
}
main.narrow { max-width: 680px; }
.page-title { font-size: 24px; margin: 0 0 4px; }
.page-sub { margin: 0 0 20px; }
.card > p:first-child { margin-top: 0; }
#header .btn { white-space: nowrap; }
.grid > .empty { grid-column: 1 / -1; }
