:root {
  --color-bg: #f5f6f8;
  --color-surface: #ffffff;
  --color-text: #111827;
  --color-text-muted: #8b93a1;
  --color-primary: #2563eb;
  --color-primary-soft: #eef2ff;
  --color-primary-contrast: #ffffff;
  --color-border: #e8eaef;
  --color-success: #22c55e;
  --color-danger: #dc2626;
  --color-danger-bg: #fef2f2;
  --radius: 14px;
  --gap: 10px;
  --shadow-card: 0 1px 3px rgba(16, 24, 40, 0.07);
  --content-max: 768px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Sarabun", "Tahoma", sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; }
svg { display: block; }

/* ---------- App bar ---------- */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

/* app-bar ที่มีแถวค้นหา/ฟิลเตอร์ต่อท้าย — ล็อกไว้บนสุดทั้งก้อนด้วย sticky เดียวกัน */
.app-bar--stacked {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding-bottom: 12px;
}

.app-bar__row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-bar__menu {
  border: none;
  background: transparent;
  color: var(--color-text);
  padding: 2px;
  cursor: pointer;
}

.app-bar__title {
  flex: 1;
  font-size: 19px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-bar__action {
  font-size: 13px;
  color: var(--color-primary);
  font-weight: 600;
  padding: 6px 4px;
}

.app-bar__back {
  font-size: 26px;
  line-height: 1;
  color: var(--color-text);
  padding: 2px 8px 2px 0;
  font-weight: 600;
}

/* ---------- App content ---------- */
.app-content {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 10px 14px calc(env(safe-area-inset-bottom, 0px) + 24px);
}

.empty-state {
  text-align: center;
  color: var(--color-text-muted);
  padding: 40px 16px;
  font-size: 14px;
}

/* ---------- Search ---------- */
.search-bar {
  position: relative;
  display: flex;
  align-items: center;
}
.search-bar__icon {
  position: absolute;
  left: 12px;
  color: var(--color-text-muted);
  pointer-events: none;
}
.search-input {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 9px 34px 9px 34px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
}
.search-input:focus {
  outline: none;
  border-color: var(--color-primary);
  background: var(--color-surface);
}
.search-clear {
  position: absolute;
  right: 8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--color-text-muted);
  background: var(--color-border);
}

/* ---------- Toolbar (filter + create) ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 11px;
  background: var(--color-bg);
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-tabs::-webkit-scrollbar { display: none; }

.filter-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  padding: 7px 11px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--color-text-muted);
}
.filter-tab--active {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.35);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot--on { background: var(--color-success); }
.dot--off { background: #c3c8d1; }

/* ---------- List head (count + sort) ---------- */
.list-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px 10px;
}
.list-head__count {
  flex: 1;
  font-size: 13px;
  color: var(--color-text-muted);
}
.list-head__count strong {
  color: var(--color-text);
  font-size: 14px;
}

.select-wrap {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding-left: 9px;
}
.select-wrap__icon {
  color: var(--color-text-muted);
  pointer-events: none;
  flex-shrink: 0;
}
.select-control {
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--color-text);
  border: none;
  background: transparent;
  padding: 8px 6px;
  cursor: pointer;
}
.select-control:focus { outline: none; }

/* ---------- Card list ---------- */
.card-list {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.event-card {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow-card);
}

.event-card__icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.event-card__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.event-card__name {
  font-size: 14.5px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-card__row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--color-text-muted);
  min-width: 0;
}
.event-card__row svg { flex-shrink: 0; }
.event-card__row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reg-count {
  font-weight: 800;
  color: var(--color-primary);
}

.event-card__side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  align-self: stretch;
}

.switch-label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--color-text-muted);
  margin-bottom: auto;
}

.event-card__icons {
  display: flex;
  gap: 4px;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { background: var(--color-bg); color: var(--color-text); }
.icon-btn--danger:hover,
.icon-btn--danger:active {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

/* ---------- Switch ---------- */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch__track {
  position: absolute; inset: 0;
  background: #d7dae0;
  border-radius: 999px;
  transition: background 0.15s ease;
  cursor: pointer;
}
.switch__track::before {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.switch input:checked + .switch__track { background: var(--color-success); }
.switch input:checked + .switch__track::before { transform: translateX(18px); }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 2px;
  font-size: 14px;
  font-weight: 600;
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 18px 0 6px;
}
.page-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border-radius: 9px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text);
}
.page-btn--current {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-primary-contrast);
}
.page-btn--disabled {
  opacity: 0.4;
  pointer-events: none;
}
.page-gap {
  min-width: 20px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 13px;
}
.select-wrap--perpage { margin-left: auto; }

/* ---------- Drawer ---------- */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer[hidden] { display: none; }
.drawer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
}
.drawer__panel {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 250px;
  max-width: 80%;
  background: var(--color-surface);
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  box-shadow: 2px 0 16px rgba(16, 24, 40, 0.15);
}
.drawer__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px 12px;
}
.drawer__brand { flex: 1; font-size: 16px; font-weight: 800; }
.drawer__close {
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
}
.drawer__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}
.drawer__item--active { background: var(--color-primary-soft); color: var(--color-primary); }
.drawer__item--danger { color: var(--color-danger); }
.drawer__sep {
  height: 1px;
  background: var(--color-border);
  margin: 8px 6px;
}

/* ---------- Forms ---------- */
.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.field input,
.field select {
  font: inherit;
  font-size: 16px;
  font-weight: 400;
  color: var(--color-text);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  width: 100%;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--color-primary);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
/* ช่อง datetime-local มีความกว้างขั้นต่ำในตัวราว 250px ถ้าบีบ 2 คอลัมน์บนจอแคบจะล้นขอบ
   จึงวางซ้อนกันบนมือถือ แล้วค่อยแยก 2 คอลัมน์เมื่อจอกว้างพอ */
.field-row > * { min-width: 0; }
@media (min-width: 560px) {
  .field-row { grid-template-columns: 1fr 1fr; }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary { background: var(--color-primary); color: var(--color-primary-contrast); }
.btn-primary:active { transform: scale(0.98); }
.btn-block { width: 100%; }

/* ต้องประกาศหลัง .btn เสมอ ไม่งั้น padding/font-size ของ .btn จะทับ (specificity เท่ากัน อันหลังชนะ)
   ขนาดตั้งใจให้สูงเท่าแถบ .filter-tabs ที่อยู่ข้างกัน */
.btn-create {
  margin-left: auto;
  flex-shrink: 0;
  gap: 5px;
  padding: 10px 13px;
  font-size: 12.5px;
  line-height: 1.4;
  border-radius: 10px;
}

.alert {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
}
.alert-error { background: var(--color-danger-bg); color: var(--color-danger); }

/* ---------- Login / standalone screens (ไม่มีการ์ด เน้นเรียบสะอาด) ---------- */
.login {
  min-height: 100vh;
  min-height: 100dvh; /* กันจอกระตุกตอนแถบ URL บนมือถือย่อ/ขยาย */
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  padding: 28px 22px calc(env(safe-area-inset-bottom, 0px) + 28px);
}

.login__inner {
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.login__brand {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-soft);
  color: var(--color-primary);
  margin: 0 auto 20px;
}

.login__title {
  margin: 0 0 5px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.login__sub {
  margin: 0 0 26px;
  font-size: 14px;
  color: var(--color-text-muted);
}

.login__alert { margin-bottom: 0; }

.login__form {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.login-field input {
  text-align: left;
  font: inherit;
  font-size: 16px; /* 16px ขึ้นไป กัน iOS ซูมเองตอนโฟกัสช่องกรอก */
  font-weight: 500;
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 13px 14px;
  width: 100%;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.login-field input:focus {
  outline: none;
  background: var(--color-surface);
  border-color: var(--color-primary);
}

.login__submit {
  margin-top: 10px;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 16px;
}

/* ---------- Registration report ---------- */
.summary-bar {
  padding: 10px 4px 14px;
  font-size: 14px;
  color: var(--color-text-muted);
}
.summary-bar strong { color: var(--color-text); font-size: 16px; }

.reg-card {
  display: flex;
  gap: 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow-card);
}
.reg-card__avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  background: var(--color-border);
}
.reg-card__avatar--placeholder { background: var(--color-border); }
.reg-card__body { min-width: 0; }
.reg-card__name { font-size: 14px; font-weight: 700; }
.reg-card__meta {
  font-size: 12px;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reg-card__time { font-size: 11px; color: var(--color-text-muted); margin-top: 2px; }

/* ---------- QR page ---------- */
.qr-event-name {
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  margin: 6px 0 18px;
}
.qr-block {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  text-align: center;
  box-shadow: var(--shadow-card);
}
.qr-block__label {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 10px;
}
.qr-block__image {
  width: 100%;
  max-width: 260px;
  height: auto;
  margin: 0 auto;
  border-radius: 8px;
  background: #fff;
}
.qr-block__url {
  margin-top: 10px;
  font-size: 11px;
  color: var(--color-text-muted);
  word-break: break-all;
}
