@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@400;500;600;700;800&family=Inter:wght@400;500;600;700;800&display=swap");

:root {
  --bg: #ffffff;
  --bg-2: #f3f6ff;
  --surface: rgba(255, 255, 255, 0.85);
  --surface-solid: #ffffff;
  --border: rgba(20, 30, 70, 0.08);
  --text: #171a2b;
  --text-muted: #5c6079;
  --text-faint: #9497ab;
  --brand-1: #6d5ef8;
  --brand-2: #9b8bff;
  --brand-3: #17c9c9;
  --accent-pink: #ff6fa5;
  --success: #12a575;
  --success-bg: #e3faf1;
  --danger: #ef4770;
  --danger-bg: #fde9ee;
  --warn: #c8790a;
  --warn-bg: #fff6e2;
  --shadow-sm: 0 2px 10px rgba(90, 80, 200, 0.07);
  --shadow-md: 0 12px 32px rgba(90, 80, 200, 0.12);
  --shadow-lg: 0 24px 60px rgba(90, 80, 200, 0.16);
  --shadow-glow: 0 0 0 4px rgba(109, 94, 248, 0.14);
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 26px;
  --radius-pill: 999px;
  color-scheme: light;
}

/* ล็อกธีมเป็นโทนสว่างเสมอ ไม่สลับตามธีมเครื่องผู้ใช้ (ตามที่ต้องการ) */

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Noto Sans Thai", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4 { font-weight: 800; line-height: 1.25; margin: 0; }
p { margin: 0; }
a { color: inherit; }
button { font-family: inherit; }

/* ---------- พื้นหลังฟองลอย ---------- */
.bg-blobs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.55;
  animation: float 18s ease-in-out infinite;
}
.blob.b1 { width: 420px; height: 420px; top: -120px; left: -100px; background: radial-gradient(circle, var(--brand-2), transparent 70%); animation-duration: 22s; }
.blob.b2 { width: 380px; height: 380px; bottom: -140px; right: -80px; background: radial-gradient(circle, var(--brand-3), transparent 70%); animation-duration: 26s; animation-delay: -6s; }
.blob.b3 { width: 300px; height: 300px; top: 40%; right: 10%; background: radial-gradient(circle, var(--accent-pink), transparent 70%); animation-duration: 20s; animation-delay: -3s; opacity: 0.35; }
.blob.b4 { width: 260px; height: 260px; bottom: 10%; left: 8%; background: radial-gradient(circle, var(--brand-1), transparent 70%); animation-duration: 24s; animation-delay: -10s; opacity: 0.3; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -40px) scale(1.08); }
  66% { transform: translate(-25px, 25px) scale(0.95); }
}

@media (prefers-reduced-motion: reduce) {
  .blob { animation: none; }
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ---------- เลย์เอาต์ ---------- */
.page { min-height: 100vh; display: flex; flex-direction: column; }
.container { width: 100%; max-width: 900px; margin: 0 auto; padding: 0 20px; }
.container-wide { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 20px; }

.topnav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; gap: 16px; position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: -0.02em; }
.brand-badge {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-3));
  display: flex; align-items: center; justify-content: center; color: white; font-size: 16px;
  box-shadow: var(--shadow-sm);
}
.nav-links { display: flex; gap: 8px; align-items: center; }
.nav-links a { font-size: 14px; color: var(--text-muted); text-decoration: none; padding: 8px 14px; border-radius: var(--radius-pill); transition: all 0.2s ease; }
.nav-links a:hover { background: var(--surface); color: var(--text); }

/* ---------- การ์ดกระจก ---------- */
.glass {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  box-shadow: var(--shadow-md);
}
.card {
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s cubic-bezier(.2,.8,.2,1), box-shadow 0.25s ease;
}
.card.hoverable:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: var(--radius-pill); padding: 13px 26px;
  font-size: 15px; font-weight: 700; cursor: pointer;
  transition: transform 0.18s cubic-bezier(.2,.8,.2,1), box-shadow 0.18s ease, opacity 0.18s ease, background 0.18s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  color: white; box-shadow: 0 10px 24px rgba(109, 94, 248, 0.35);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(109, 94, 248, 0.45); }
.btn-ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-solid); transform: translateY(-2px); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { transform: translateY(-2px); }
.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }
.btn-block { width: 100%; }

/* ---------- ฟอร์ม ---------- */
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.input, select.input, textarea.input {
  width: 100%; padding: 13px 16px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--surface-solid); color: var(--text);
  font-size: 15px; font-family: inherit; transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.input:focus { outline: none; border-color: var(--brand-1); box-shadow: var(--shadow-glow); }
.hint { font-size: 12.5px; color: var(--text-faint); }

/* ---------- แถบค้นหา ---------- */
.search-shell { display: flex; gap: 10px; padding: 8px; }
.search-shell .input { border: none; box-shadow: none; background: transparent; font-size: 17px; padding: 12px 14px; }
.search-shell .input:focus { box-shadow: none; }
.search-shell-wrap {
  background: var(--surface-solid); border: 1.5px solid var(--border);
  border-radius: var(--radius-pill); box-shadow: var(--shadow-md);
  transition: box-shadow 0.25s ease, border-color 0.25s ease;
}
.search-shell-wrap:focus-within { border-color: var(--brand-1); box-shadow: var(--shadow-lg), var(--shadow-glow); }

/* ---------- แบดจ์/ป้าย ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: var(--radius-pill); font-size: 12.5px; font-weight: 700; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-brand { background: rgba(109,94,248,0.12); color: var(--brand-1); }

/* ---------- แอนิเมชันเข้าฉาก ---------- */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
.fade-in-up { animation: fadeInUp 0.55s cubic-bezier(.2,.8,.2,1) both; }
.stagger > * { animation: fadeInUp 0.5s cubic-bezier(.2,.8,.2,1) both; }
.stagger > *:nth-child(1) { animation-delay: 0.03s; }
.stagger > *:nth-child(2) { animation-delay: 0.09s; }
.stagger > *:nth-child(3) { animation-delay: 0.15s; }
.stagger > *:nth-child(4) { animation-delay: 0.21s; }
.stagger > *:nth-child(5) { animation-delay: 0.27s; }
.stagger > *:nth-child(n+6) { animation-delay: 0.32s; }

@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid rgba(109,94,248,0.2); border-top-color: var(--brand-1); animation: spin 0.8s linear infinite; }

/* ---------- ตารางผลลัพธ์ / กริดแก้ไข ---------- */
.kv-grid { display: grid; grid-template-columns: minmax(120px, 220px) 1fr; gap: 0; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); }
.kv-grid .kv-key, .kv-grid .kv-val {
  padding: 12px 16px; font-size: 14.5px; border-bottom: 1px solid var(--border);
}
.kv-grid .kv-key { background: rgba(109,94,248,0.06); font-weight: 700; color: var(--text-muted); }
.kv-grid .kv-val { background: var(--surface-solid); font-weight: 600; }
.kv-grid > div:nth-last-child(-n+2) { border-bottom: none; }

.data-table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; background: var(--surface-solid); }
table.data-table th, table.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.data-table th { background: rgba(109,94,248,0.08); font-weight: 700; position: sticky; top: 0; }
table.data-table td[contenteditable="true"] { cursor: text; }
table.data-table td[contenteditable="true"]:focus { outline: 2px solid var(--brand-1); outline-offset: -2px; background: rgba(109,94,248,0.06); }
table.data-table tr:hover td { background: rgba(109,94,248,0.03); }

/* ---------- toast ---------- */
.toast-stack { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  padding: 14px 20px; border-radius: var(--radius-sm); background: var(--surface-solid);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 10px; animation: fadeInUp 0.3s ease both; max-width: 360px;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }

/* ---------- utility ---------- */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-24 { gap: 24px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; } .mt-32 { margin-top: 32px; }
.mb-8 { margin-top: 8px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.text-center { text-align: center; }
.text-sm { font-size: 13px; }
.w-full { width: 100%; }
.grow { flex: 1; }
.hidden { display: none !important; }
.footer { padding: 28px 20px 40px; text-align: center; color: var(--text-faint); font-size: 12.5px; }
.footer a { color: var(--text-muted); text-decoration: underline; }

@media (max-width: 640px) {
  .topnav { padding: 14px 16px; }
  .kv-grid { grid-template-columns: 1fr; }
  .kv-grid .kv-key { border-bottom: none; padding-bottom: 4px; }
  .kv-grid .kv-val { padding-top: 4px; }
}
