:root {
  --bg: #f2f4fa;
  --panel: #ffffff;
  --ink: #141a33;
  --muted: #667290;
  --line: #e1e5f0;
  --soft: #eef1f8;
  --brand: #2456f5;
  --brand-d: #1a3fc0;
  --brand-soft: #e7edff;
  --ok: #118a48;
  --ok-soft: #e1f5ea;
  --warn: #b86d00;
  --warn-soft: #fff1d6;
  --bad: #d22b39;
  --bad-soft: #fde7e9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 70, 0.06), 0 8px 24px rgba(20, 30, 70, 0.06);
  color-scheme: light;
  font-family: 'Noto Sans Thai', 'Leelawadee UI', 'Sarabun', Tahoma, system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.3;
}
p {
  margin: 0;
}
a {
  color: var(--brand);
}
.hidden,
[hidden] {
  display: none !important;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 0.85rem;
}
.grow {
  flex: 1 1 auto;
  min-width: 0;
}
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mono {
  font-variant-numeric: tabular-nums;
}

/* ปุ่ม */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
  min-height: 40px;
}
.btn:hover {
  background: var(--soft);
}
.btn:active {
  transform: translateY(1px);
}
.btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(36, 86, 245, 0.35);
  outline-offset: 1px;
}
.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn.primary:hover {
  background: var(--brand-d);
}
.btn.danger {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}
.btn.danger:hover {
  background: #b01f2c;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
}
.btn.ghost:hover {
  background: var(--soft);
}
.btn.sm {
  padding: 5px 11px;
  min-height: 32px;
  font-size: 0.88rem;
  border-radius: 8px;
}
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ช่องกรอก */
input[type='text'],
input[type='password'],
input[type='time'],
input[type='date'],
input[type='number'],
input[type='url'],
input[type='tel'],
input[type='search'],
select,
textarea {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cfd5e6;
  border-radius: 10px;
  padding: 9px 12px;
  min-height: 40px;
  width: 100%;
}
input[type='range'] {
  width: 100%;
  accent-color: var(--brand);
}
input[type='checkbox'] {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}
label.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-weight: 600;
  font-size: 0.92rem;
}
label.field .hint {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.82rem;
}

/* การ์ด / ป้าย */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card > h3 {
  font-size: 1.02rem;
  margin-bottom: 12px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--soft);
  color: var(--muted);
  white-space: nowrap;
}
.pill.ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.pill.bad {
  background: var(--bad-soft);
  color: var(--bad);
}
.pill.brand {
  background: var(--brand-soft);
  color: var(--brand-d);
}
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

/* สวิตช์ */
.switch {
  position: relative;
  width: 46px;
  height: 26px;
  flex: none;
  display: inline-block;
}
.switch input {
  opacity: 0;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}
.switch i {
  position: absolute;
  inset: 0;
  background: #c3c9dc;
  border-radius: 999px;
  transition: background 0.15s;
}
.switch i::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}
.switch input:checked + i {
  background: var(--ok);
}
.switch input:checked + i::after {
  transform: translateX(20px);
}
.switch input:focus-visible + i {
  outline: 3px solid rgba(36, 86, 245, 0.35);
}

/* ป๊อปอัป */
dialog {
  border: none;
  border-radius: 18px;
  padding: 0;
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  box-shadow: 0 20px 60px rgba(10, 20, 60, 0.35);
  color: var(--ink);
  background: var(--panel);
}
dialog::backdrop {
  background: rgba(15, 22, 50, 0.5);
}
dialog .dlg-head {
  padding: 18px 20px 0;
  font-size: 1.1rem;
  font-weight: 700;
}
dialog .dlg-body {
  padding: 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  max-height: calc(100vh - 170px);
}
dialog .dlg-foot {
  padding: 12px 20px 18px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.err {
  color: var(--bad);
  font-weight: 600;
  font-size: 0.9rem;
}

/* แจ้งเตือนชั่วคราว */
#toasts {
  position: fixed;
  z-index: 100;
  left: 50%;
  transform: translateX(-50%);
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: calc(100vw - 24px);
}
.toast {
  background: #1b2244;
  color: #fff;
  padding: 10px 18px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  font-weight: 600;
  animation: toast-in 0.18s ease-out;
  max-width: 560px;
}
.toast.bad {
  background: var(--bad);
}
.toast.ok {
  background: var(--ok);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
