/* Log in by Toe — สไตล์ร่วมของหน้า login / account / admin (ไม่พึ่งฟอนต์/ไลบรารีภายนอก) */
:root {
  --bg: #f4f4f8; --surface: #fff; --surface-2: #eeeef4; --line: rgba(20,20,40,.1);
  --text: #14141c; --muted: #6a6a78; --accent: #5b4bff; --accent-soft: rgba(91,75,255,.1);
  --good: #12b76a; --warn: #f79009; --bad: #e5484d;
  --shadow: 0 1px 2px rgba(16,16,40,.04), 0 10px 30px rgba(16,16,40,.08);
  color-scheme: light;
}
/* ธีม: ค่าเริ่มต้นตามระบบ · ผู้ใช้สลับเองได้ด้วยปุ่มมุมขวาล่าง (เก็บใน localStorage, ตั้ง data-theme ที่ <html>) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b12; --surface: #15151f; --surface-2: #1d1d29; --line: rgba(255,255,255,.09);
    --text: #f3f3f7; --muted: #a2a2b2; --accent: #8b7dff; --accent-soft: rgba(139,125,255,.16);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0b12; --surface: #15151f; --surface-2: #1d1d29; --line: rgba(255,255,255,.09);
  --text: #f3f3f7; --muted: #a2a2b2; --accent: #8b7dff; --accent-soft: rgba(139,125,255,.16);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); line-height: 1.55; -webkit-font-smoothing: antialiased;
  font-family: "Noto Sans Thai", "Sarabun", "Prompt", "Segoe UI", system-ui, -apple-system, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.25; }

/* ---------- ฟอร์ม/ปุ่ม ---------- */
.field { display: block; font-size: 14px; font-weight: 600; margin-bottom: 14px; }
.field input, .field select {
  display: block; width: 100%; height: 46px; margin-top: 6px; padding: 0 14px; border-radius: 12px; font-size: 16px; font-weight: 400;
  border: 1px solid var(--line); background: var(--surface-2); outline: none; transition: .15s;
}
.field input:focus, .field select:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 4px var(--accent-soft); }
.field .hint { display: block; margin-top: 5px; font-size: 12.5px; font-weight: 400; color: var(--muted); }
.pw { position: relative; display: block; }
.pw input { padding-right: 48px; }
.eye { position: absolute; right: 4px; bottom: 4px; width: 38px; height: 38px; border: 0; background: none; border-radius: 10px; color: var(--muted); font-size: 12px; font-weight: 600; }
.eye:hover, .eye[aria-pressed="true"] { color: var(--accent); }
.err { min-height: 22px; margin: -2px 0 8px; color: var(--bad); font-size: 14px; font-weight: 500; }
.ok { color: var(--good); font-size: 14px; font-weight: 500; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 18px; border: 1px solid transparent;
  border-radius: 12px; font-weight: 600; font-size: 15px; transition: .15s; text-decoration: none; color: inherit; white-space: nowrap;
}
.btn:focus-visible, .eye:focus-visible, .link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--text); color: var(--bg); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-ghost { background: var(--surface); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--bad); border-color: var(--line); }
.btn-danger:hover { background: rgba(229,72,77,.1); }
.btn:disabled { opacity: .6; cursor: progress; transform: none; box-shadow: none; }
.btn.sm { height: 34px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }
.btn.block { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; }

/* ---------- หน้า login ---------- */
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; position: relative; overflow: hidden; }
.auth-shell::before {
  content: ""; position: absolute; inset: -20% -10% auto -10%; height: 90%; pointer-events: none; filter: blur(8px);
  background: radial-gradient(40% 50% at 15% 40%, rgba(91,75,255,.25), transparent 70%), radial-gradient(35% 45% at 85% 30%, rgba(0,194,168,.2), transparent 70%);
}
.auth-card { position: relative; width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 28px; box-shadow: var(--shadow); padding: 32px 28px 26px; }
.mark { width: 54px; height: 54px; border-radius: 16px; margin: 0 auto 14px; display: grid; place-items: center; background: conic-gradient(from 210deg, #5b4bff, #00c2a8, #ffb547, #ff5c8a, #5b4bff); }
.mark span { width: 40px; height: 40px; border-radius: 12px; background: rgba(10,10,20,.85); color: #fff; display: grid; place-items: center; font: 800 15px/1 system-ui, sans-serif; letter-spacing: .02em; }
.auth-card h1 { font-size: 24px; text-align: center; }
.auth-card .sub { margin: 6px 0 22px; text-align: center; color: var(--muted); font-size: 14.5px; }
.note { margin: 16px 0 0; padding: 12px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.5; background: rgba(247,144,9,.12); color: #b45f06; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .note { color: #f5b85a; } }
:root[data-theme="dark"] .note { color: #f5b85a; }
.center { text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- แอป (account / admin) ---------- */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-bottom: 1px solid var(--line); }
.topbar .in { max-width: 1100px; margin: 0 auto; padding: 0 20px; height: 62px; display: flex; align-items: center; gap: 14px; }
.topbar .mark { margin: 0; width: 34px; height: 34px; border-radius: 10px; }
.topbar .mark span { width: 24px; height: 24px; border-radius: 7px; font-size: 10.5px; }
.topbar b { font-size: 16px; }
.home-link { display: flex; align-items: center; gap: 14px; color: inherit; text-decoration: none; }
.home-link:hover b { text-decoration: underline; }
.auth-card .home-link { display: block; width: fit-content; margin: 0 auto; }
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tabs a { padding: 7px 13px; border-radius: 999px; font-size: 14.5px; font-weight: 500; color: var(--muted); text-decoration: none; }
.tabs a:hover { background: var(--surface-2); color: var(--text); }
.tabs a[aria-current="page"] { background: var(--text); color: var(--bg); }
.topbar .sp { flex: 1; }
.who { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.who .nm { line-height: 1.2; text-align: right; }
.who small { display: block; color: var(--muted); font-size: 12px; }

main.page { max-width: 1100px; margin: 0 auto; padding: 28px 20px 80px; }
.page h1 { font-size: clamp(24px, 3vw, 32px); margin-bottom: 4px; }
.page .lead { color: var(--muted); margin: 0 0 24px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); padding: 22px; margin-bottom: 18px; }
.card h2 { font-size: 18px; margin-bottom: 4px; }
.card .lead { margin-bottom: 16px; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
/* หน้า "ระบบของฉัน" */
.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-bottom: 28px; }
.apps-sub { font-size: 16px; color: var(--muted); margin: 8px 0 12px; }
.app { display: flex; align-items: center; gap: 14px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); color: inherit; text-decoration: none; transition: transform .15s, border-color .15s; }
.app:hover, .app:focus-visible { transform: translateY(-2px); border-color: var(--accent); }
.app-ic { width: 46px; height: 46px; flex: none; display: grid; place-items: center; font-size: 22px; border-radius: 14px; background: var(--surface-2); }
.app-tx { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.app-tx b { font-size: 16px; }
.app-tx small { color: var(--muted); font-size: 13px; line-height: 1.4; }
.profile { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 14px; font-size: 14.5px; margin: 14px 0 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px 18px; }
.stat b { display: block; font-size: 28px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 13.5px; }
.banner { background: rgba(247,144,9,.13); color: #b45f06; border-radius: 16px; padding: 12px 16px; margin-bottom: 18px; font-size: 14.5px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .banner { color: #f5b85a; } }
:root[data-theme="dark"] .banner { color: #f5b85a; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar h2 { margin-right: auto; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; min-width: 720px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12.5px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td .u { display: flex; align-items: center; gap: 10px; }
td small { color: var(--muted); display: block; font-size: 12.5px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.pill.on { background: rgba(18,183,106,.14); color: var(--good); }
.pill.off { background: rgba(229,72,77,.12); color: var(--bad); }
.pill.must { background: rgba(247,144,9,.14); color: var(--warn); margin-left: 6px; }
.acts { display: flex; gap: 6px; flex-wrap: wrap; }
td select { height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 8px; font-size: 13.5px; }

dialog { width: min(440px, calc(100% - 32px)); border: 1px solid var(--line); border-radius: 24px; padding: 26px; background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(5,5,12,.55); backdrop-filter: blur(4px); }
dialog h2 { margin-bottom: 16px; font-size: 20px; }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.audit { font-size: 13.5px; }
.audit td { padding: 8px 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 120px); background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 14px; box-shadow: var(--shadow); transition: transform .3s; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .grid2, .stats { grid-template-columns: 1fr; }
  .who .nm { display: none; }
  .topbar .in { padding: 0 14px; gap: 8px; }
  .topbar b { display: none; }
  .kv { grid-template-columns: 110px 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.mt { margin-top: 14px; }

/* ปุ่มสลับธีม */
.theme-toggle { position: fixed; right: 16px; bottom: 16px; z-index: 40; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); font-size: 20px; line-height: 1; display: grid; place-items: center; padding: 0; }
.theme-toggle:hover { background: var(--surface-2); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- รูปโปรไฟล์ / อวตาร์ ---------- */
.avatar { display: grid; place-items: center; border-radius: 50%; overflow: hidden; flex: none; width: 38px; height: 38px; font-size: 15px; font-weight: 700; line-height: 1; color: #fff; background: linear-gradient(135deg, #5b4bff, #00c2a8); }
.avatar > svg, .avatar > img { width: 100%; height: 100%; display: block; object-fit: cover; }
.av-xs { width: 24px; height: 24px; font-size: 11px; } .av-s { width: 32px; height: 32px; font-size: 13px; } .av-m { width: 38px; height: 38px; font-size: 15px; }
.av-l { width: 64px; height: 64px; font-size: 26px; } .av-xl { width: 96px; height: 96px; font-size: 38px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; margin-bottom: 14px; }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 9px; font-size: 14px; font-weight: 500; color: var(--muted); }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.avatar-edit { display: grid; grid-template-columns: 120px 1fr; gap: 22px; align-items: start; }
#avPreview .avatar { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--accent); }
.av-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; padding: 6px 4px 12px; max-width: 460px; }
.av-opt { position: relative; aspect-ratio: 1; border: 0; background: none; border-radius: 50%; padding: 0; display: block; transition: transform .15s, box-shadow .15s; }
.av-opt .avatar { width: 100%; height: 100%; }
.av-opt:hover { transform: scale(1.06); }
.av-opt:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--accent); }
.av-opt.sel { box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--accent); }
.av-opt .tick { position: absolute; right: -2px; bottom: -2px; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: #fff; display: none; place-items: center; font-size: 12px; border: 2px solid var(--surface); }
.av-opt.sel .tick { display: grid; }
.drop { display: grid; place-items: center; text-align: center; gap: 4px; padding: 26px 16px; max-width: 460px; border: 2px dashed var(--line); border-radius: 20px; cursor: pointer; color: var(--muted); transition: .15s; font-size: 14.5px; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.drop b { color: var(--text); font-size: 15.5px; }
.drop input { display: none; }
.cropwrap { display: grid; justify-items: start; gap: 12px; }
#avCanvas { width: 240px; height: 240px; max-width: 100%; border-radius: 20px; touch-action: none; cursor: grab; background: #fff; }
#avCanvas.grab { cursor: grabbing; }
.zoomrow { display: flex; align-items: center; gap: 10px; width: 240px; color: var(--muted); font-size: 13px; }
.zoomrow input { flex: 1; accent-color: var(--accent); }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.pstate { margin: 10px 0 0; color: var(--muted); font-size: 13.5px; }
@media (max-width: 760px) { .avatar-edit { grid-template-columns: 1fr; } .av-grid { grid-template-columns: repeat(4, 1fr); } }

/* แถบบนบนมือถือ: เมนูเลื่อนข้างได้ ไม่ดันหน้าให้กว้างเกินจอ */
@media (max-width: 760px) {
  .topbar .in > .mark, .topbar .who, .topbar .btn { flex: none; }
  .topbar .sp { display: none; }
  .tabs { margin-left: 0; flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { white-space: nowrap; padding: 7px 11px; font-size: 14px; }
}

/* แท็บเข้าสู่ระบบ / สร้างบัญชีใหม่ + แบนเนอร์ข้อความดี */
.tabs2 { display: flex; margin: 0 0 18px; }
.tabs2 button { flex: 1; padding: 9px 12px; }
.banner.good { background: rgba(18,183,106,.13); color: #0b8a50; }
:root[data-theme="dark"] .banner.good { color: #5fdb9c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .banner.good { color: #5fdb9c; } }

#welcome, #profile-picture { scroll-margin-top: 76px; }   /* ไม่ให้แถบบนบังตอนเลื่อนมา */

/* รหัสสิทธิ์ / สิทธิ์เข้าระบบ */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12.5px; font-weight: 600; }
.gen-row { display: grid; grid-template-columns: 1fr 180px; gap: 14px; }
.checks { border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px 6px; margin: 0 0 14px; }
.checks legend { font-size: 14px; font-weight: 600; padding: 0 6px; }
.chk { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 14.5px; cursor: pointer; }
.chk input { width: 18px; height: 18px; accent-color: var(--accent); }
.code-box { margin: 14px 0 0; padding: 14px 16px; border-radius: 16px; background: var(--accent-soft); }
.code-box p { margin: 0 0 10px; font-size: 14px; }
.code-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.code-row code { font: 700 22px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .08em; user-select: all; }
@media (max-width: 760px) { .gen-row { grid-template-columns: 1fr; } }
