:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --border: #e3e6eb;
  --brand: #1f4fd1;
  --brand-soft: #e8eefc;
  --good: #12805c;
  --good-soft: #e3f5ee;
  --warn: #b25e09;
  --warn-soft: #fdf1e2;
  --bad: #c0362c;
  --bad-soft: #fde8e6;
  --radius: 10px;
  font-family: "Segoe UI", "Noto Sans Thai", "Leelawadee UI", Tahoma, system-ui, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.5; }
a { color: var(--brand); }
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

/* ---------- top bar */
.topbar { background: #14213d; color: #fff; }
.topbar .wrap { display: flex; align-items: center; gap: 24px; min-height: 56px; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 16px; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a { color: #c9d3ea; text-decoration: none; padding: 6px 12px; border-radius: 6px; }
.topbar nav a:hover, .topbar nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.topbar form { margin: 0; }
.linklike { background: none; border: 0; color: #c9d3ea; cursor: pointer; font: inherit; }

main.wrap { padding-top: 24px; padding-bottom: 48px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

/* ---------- cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-side { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
@media (max-width: 900px) { .grid-side { grid-template-columns: 1fr; } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 2px; }
.stat .sub { color: var(--muted); font-size: 12px; }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- badges & scores */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef0f3; color: #475467; white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.score { font-weight: 700; font-variant-numeric: tabular-nums; }
.score.good { color: var(--good); } .score.warn { color: var(--warn); } .score.bad { color: var(--bad); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---------- forms */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cfd4dc; border-radius: 6px; font: inherit; background: #fff; color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.btn { display: inline-block; background: var(--brand); color: #fff; border: 1px solid var(--brand); padding: 8px 16px; border-radius: 6px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: #fff; color: var(--text); border-color: #cfd4dc; }
.btn.danger { background: #fff; color: var(--bad); border-color: #f0b4ae; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline { display: inline; margin: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filters input, .filters select { width: auto; min-width: 200px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: var(--good-soft); color: var(--good); border: 1px solid #b7e4d2; }
.flash.error { background: var(--bad-soft); color: var(--bad); border-color: #f3c1bb; }
.errors { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 10px 14px 10px 30px; }
.notice { background: var(--warn-soft); color: #7a4306; border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; }
.empty { color: var(--muted); padding: 16px 0; }

/* ---------- question editor */
.question { border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin-bottom: 12px; }
.question.core { border-color: #b8c8f4; background: #f8faff; }
.question summary { cursor: pointer; display: flex; gap: 10px; align-items: baseline; list-style: none; }
.question summary::-webkit-details-marker { display: none; }
.question summary .qtext { flex: 1; font-weight: 600; }
.question .edit { margin-top: 14px; }

details.answers summary { cursor: pointer; color: var(--brand); }
dl.answers { margin: 10px 0 0; }
dl.answers dt { color: var(--muted); font-size: 13px; margin-top: 8px; }
dl.answers dd { margin: 0; font-weight: 600; white-space: pre-line; }
.mono { font-family: Consolas, "Courier New", monospace; }
pre.body { white-space: pre-wrap; word-break: break-word; background: #f7f8fa; padding: 10px; border-radius: 6px; font-size: 13px; margin: 6px 0 0; max-height: 260px; overflow: auto; }

/* ---------- login */
.login { max-width: 360px; margin: 12vh auto; }

/* ---------- customer-facing survey */
body.survey { background: #eef1f6; }
.survey-wrap { max-width: 680px; margin: 0 auto; padding: 24px 16px 64px; }
.survey-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.survey-head .brand-name { font-weight: 700; font-size: 18px; color: #14213d; }
.survey .card { padding: 22px; }
.survey h1 { font-size: 22px; }
fieldset.q { border: 0; margin: 0 0 26px; padding: 0; }
fieldset.q:last-child { margin-bottom: 0; }
fieldset.q legend { font-weight: 600; margin-bottom: 10px; padding: 0; font-size: 16px; }
fieldset.q.has-error legend { color: var(--bad); }
fieldset.q.has-error .scale, fieldset.q.has-error .opts, fieldset.q.has-error textarea { outline: 2px solid var(--bad-soft); border-radius: 8px; }
.req { color: var(--bad); }
.scale { display: grid; gap: 6px; }
.scale-11 { grid-template-columns: repeat(11, 1fr); }
.scale-5 { grid-template-columns: repeat(5, 1fr); }
.scale label { position: relative; }
.scale input, .opts input { position: absolute; opacity: 0; pointer-events: none; }
.scale span { display: flex; align-items: center; justify-content: center; height: 44px; border: 1px solid #cfd4dc; border-radius: 8px; background: #fff; cursor: pointer; font-weight: 600; user-select: none; }
.scale label:hover span { border-color: var(--brand); }
.scale input:checked + span { background: var(--brand); color: #fff; border-color: var(--brand); }
.scale input:focus-visible + span, .opts input:focus-visible + span { outline: 3px solid #9fb5f0; }
.scale-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }
.opts { display: grid; gap: 8px; }
.opts label { position: relative; }
.opts span { display: block; padding: 11px 14px; border: 1px solid #cfd4dc; border-radius: 8px; background: #fff; cursor: pointer; }
.opts input:checked + span { border-color: var(--brand); background: var(--brand-soft); font-weight: 600; }
.submit-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.submit-row .btn { padding: 12px 28px; font-size: 16px; }
.survey-message { text-align: center; padding: 40px 24px; }
.survey-message .icon { font-size: 40px; }
@media (max-width: 520px) {
  .scale-11 { grid-template-columns: repeat(6, 1fr); }
  .scale span { height: 42px; }
}
