/* =====================================================================
   SchoolHub — สไตล์หลักทั้งระบบ
   สีหลักเปลี่ยนได้ที่ ตั้งค่าโรงเรียน > สีหลัก (ตัวแปร --brand)
   ===================================================================== */
:root {
  --brand: #2563eb;
  --bg: #ffffff;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e5e8ef;
  --soft: #f1f4f9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --sb-w: 264px;
  --red: #dc2626; --orange: #ea580c; --amber: #d97706; --green: #16a34a; --blue: #2563eb; --violet: #7c3aed; --cyan: #0891b2; --pink: #db2777; --gray: #64748b;
  --brand-soft: color-mix(in srgb, var(--brand) 10%, transparent);
}
/* รูปแบบสี (patch_theme): ตั้งที่ ตั้งค่าโรงเรียน > รูปแบบสี — <html data-theme="light|dark|auto"> */
:root[data-theme="dark"] { --bg: #0b1120; --card: #111a2e; --text: #e2e8f0; --muted: #94a3b8; --line: #1e293b; --soft: #16213a; --shadow: 0 1px 2px rgba(0,0,0,.3); }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] { --bg: #0b1120; --card: #111a2e; --text: #e2e8f0; --muted: #94a3b8; --line: #1e293b; --soft: #16213a; --shadow: 0 1px 2px rgba(0,0,0,.3); } }

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
h1 { font-size: 1.5rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: .3em 0; }
code { background: var(--soft); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.pad { padding: 8px 0; }
.hidden { display: none !important; }
img { max-width: 100%; }

/* ---------- โครงหน้า ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sb-w); background: var(--card); border-right: 1px solid var(--line); position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 40; transition: transform .25s; }
.sb-brand { display: flex; gap: 10px; align-items: center; padding: 18px 18px 14px; color: var(--text); }
.sb-brand img { width: 40px; height: 40px; object-fit: contain; }
.sb-brand b { display: block; font-size: .92rem; line-height: 1.25; }
.sb-brand small { color: var(--muted); font-size: .75rem; }
.sb-logo { width: 40px; height: 40px; border-radius: 12px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 22px; flex: none; }
.sb-logo.lg { width: 56px; height: 56px; font-size: 30px; border-radius: 16px; }
.sb-nav { flex: 1; overflow-y: auto; padding: 4px 10px 16px; }
.sb-group { font-size: .72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 14px 10px 6px; }
.sb-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; color: var(--text); font-size: .9rem; }
.sb-item i { font-size: 19px; color: var(--muted); }
.sb-item:hover { background: var(--soft); }
.sb-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.sb-item.active i { color: var(--brand); }
.sb-item.soon { opacity: .5; cursor: default; }
.sb-item.soon:hover { background: none; }
.sb-item em { margin-left: auto; font-style: normal; font-size: .66rem; background: var(--soft); padding: 1px 6px; border-radius: 6px; color: var(--muted); }
.sb-foot { padding: 10px 18px; font-size: .72rem; color: var(--muted); border-top: 1px solid var(--line); }
.sb-backdrop { display: none; }
.main { flex: 1; margin-left: var(--sb-w); min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top-search { flex: 1; max-width: 460px; position: relative; }
.top-search i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.top-search input { width: 100%; padding: 9px 12px 9px 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.content { padding: 22px 24px 48px; max-width: 1400px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: 4px; font-size: .82rem; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }
.crumbs i { font-size: 11px; }
.only-mobile, .icon-btn.only-mobile { display: none; }

/* ---------- ปุ่ม ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-size: .9rem; font-weight: 500; cursor: pointer; white-space: nowrap; transition: .15s; }
.btn:hover { background: var(--soft); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--brand) 88%, #000); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: color-mix(in srgb, var(--red) 8%, transparent); }
.btn-sm { padding: 5px 10px; font-size: .82rem; border-radius: 8px; }
.btn-lg { padding: 12px 18px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { position: relative; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); display: grid; place-items: center; cursor: pointer; font-size: 19px; }
.icon-btn .dot { position: absolute; top: -5px; right: -5px; background: var(--red); color: #fff; font-size: .65rem; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-size: .85rem; cursor: pointer; }
.user-btn { display: flex; align-items: center; gap: 8px; border: 0; background: none; cursor: pointer; color: var(--text); font: inherit; text-align: left; padding: 2px; }
.user-btn b { display: block; font-size: .85rem; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-btn small { color: var(--muted); font-size: .75rem; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }

/* ---------- dropdown ---------- */
.dropdown { position: relative; }
.dropdown .menu { display: none; position: absolute; top: calc(100% + 6px); left: 0; min-width: 220px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(15,23,42,.12); padding: 6px; z-index: 50; }
.dropdown .menu.right { left: auto; right: 0; }
.dropdown.open .menu { display: block; }
.menu-title { font-size: .75rem; color: var(--muted); padding: 6px 10px; }
.menu-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border-radius: 8px; border: 0; background: none; color: var(--text); font: inherit; font-size: .88rem; text-align: left; cursor: pointer; }
.menu-item:hover { background: var(--soft); }
.menu-item.cur { color: var(--brand); font-weight: 600; }
.menu-item small { margin-left: auto; color: var(--green); font-size: .72rem; }
.menu-item.danger { color: var(--red); }

/* ---------- การ์ด ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h3 { display: flex; align-items: center; gap: 6px; }
.card-head a { font-size: .82rem; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 16px 18px 0; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.col { min-width: 0; }

.welcome { display: flex; justify-content: space-between; align-items: center; background: linear-gradient(120deg, var(--brand), color-mix(in srgb, var(--brand) 60%, #7c3aed)); color: #fff; padding: 22px 26px; border-radius: var(--radius); margin-bottom: 18px; }
.welcome h2 { font-size: 1.3rem; }
.welcome p { opacity: .85; }
.welcome > i { font-size: 56px; opacity: .5; }

/* ---------- สถิติ ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { display: flex; gap: 14px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; color: var(--text); box-shadow: var(--shadow); }
.stat > i { font-size: 30px; width: 52px; height: 52px; display: block; text-align: center; line-height: 52px; border-radius: 14px; background: color-mix(in srgb, var(--tone) 12%, transparent); color: var(--tone); flex: none; }
.stat small { display: block; color: var(--muted); font-size: .8rem; }
.stat b { font-size: 1.6rem; line-height: 1.2; display: block; }
.stat span { font-size: .75rem; color: var(--muted); }
.tone-blue { --tone: var(--blue); } .tone-violet { --tone: var(--violet); } .tone-green { --tone: var(--green); } .tone-orange { --tone: var(--orange); }
.tone-red { --tone: var(--red); } .tone-gray { --tone: var(--gray); } .tone-cyan { --tone: var(--cyan); } .tone-pink { --tone: var(--pink); }

/* ---------- ตาราง ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-weight: 600; font-size: .78rem; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--soft); }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: color-mix(in srgb, var(--soft) 60%, transparent); }
.table .num { text-align: right; }
.table .actions { text-align: right; white-space: nowrap; }
.person { display: flex; align-items: center; gap: 10px; color: var(--text); }
.person b { display: block; font-weight: 600; }
.person small { color: var(--muted); font-size: .78rem; }

/* ---------- ฟอร์ม ---------- */
.form label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: 12px; }
.form input:not([type=checkbox]):not([type=radio]), .form select, .form textarea, .filters input, .filters select {
  display: block; width: 100%; margin-top: 4px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-size: .92rem; }
.form textarea { min-height: 100px; resize: vertical; }
.form input:focus, .form select:focus, .form textarea:focus, .top-search input:focus, .filters input:focus, .filters select:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
.form .check, label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
.form fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px 4px; margin: 0 0 16px; }
.form legend { font-weight: 600; padding: 0 6px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.req::after { content: " *"; color: var(--red); }
.hint { font-size: .78rem; color: var(--muted); font-weight: 400; }
.input-icon { position: relative; margin-top: 4px; }
.input-icon > i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.input-icon input { padding-left: 36px !important; margin-top: 0 !important; }
.input-addon { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input, .filters select { width: auto; margin: 0; min-width: 140px; }
.filters .grow { flex: 1; min-width: 200px; }
.row-between { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.photo-pick { display: flex; align-items: center; gap: 14px; }

/* ---------- ป้าย / avatar ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: .74rem; font-weight: 600; background: color-mix(in srgb, var(--c) 12%, transparent); color: var(--c); white-space: nowrap; }
.badge-gray { --c: var(--gray); } .badge-green { --c: var(--green); } .badge-red { --c: var(--red); } .badge-orange { --c: var(--orange); }
.badge-blue { --c: var(--blue); } .badge-violet { --c: var(--violet); } .badge-cyan { --c: var(--cyan); } .badge-amber { --c: var(--amber); }
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex: none; display: inline-grid; place-items: center; font-weight: 600; font-size: .9rem; background: hsl(var(--h, 220) 70% 92%); color: hsl(var(--h, 220) 55% 35%); }
.avatar-sm { width: 32px; height: 32px; font-size: .8rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.3rem; }
.avatar-xl { width: 96px; height: 96px; font-size: 2.2rem; }

/* ---------- แจ้งเตือน ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-size: .9rem; background: color-mix(in srgb, var(--c) 9%, var(--card)); color: color-mix(in srgb, var(--c) 75%, var(--text)); border: 1px solid color-mix(in srgb, var(--c) 25%, transparent); }
.alert i { font-size: 20px; flex: none; }
.alert-success { --c: var(--green); } .alert-error { --c: var(--red); } .alert-info { --c: var(--blue); } .alert-warning { --c: var(--amber); }
.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty-state > i { font-size: 56px; color: var(--muted); opacity: .6; }
.empty-state h3 { color: var(--text); margin: 8px 0; }

/* ---------- รายการ ---------- */
.list { list-style: none; padding: 0; margin: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list li:last-child { border: 0; }
.list li a, .list.compact li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 9px 0; color: var(--text); }
.list li b { font-weight: 500; flex: 1 1 60%; }
.list li small { color: var(--muted); font-size: .75rem; width: 100%; }
.list.compact li { justify-content: space-between; font-size: .85rem; flex-wrap: nowrap; }
.list.compact li small { width: auto; white-space: nowrap; }
.list li.unread b { font-weight: 700; }
.events { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.events li { display: flex; gap: 12px; align-items: center; }
.events li b { display: block; font-weight: 500; font-size: .9rem; }
.events li small { color: var(--muted); font-size: .75rem; }
.ev-date { width: 46px; flex: none; text-align: center; border-radius: 10px; padding: 4px 0; background: color-mix(in srgb, var(--tone) 12%, transparent); color: var(--tone); }
.ev-date b { font-size: 1.1rem; line-height: 1.1; }
.ev-date small { color: inherit !important; }

/* ---------- ข่าว ---------- */
.news-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.news-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.news-card { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; color: var(--text); background: var(--card); transition: .15s; }
.news-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.news-cover { aspect-ratio: 16/9; background: var(--brand-soft) center/cover; display: grid; place-items: center; font-size: 42px; color: var(--brand); }
.news-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.news-body b { font-weight: 600; font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.news-body small { color: var(--muted); font-size: .75rem; }
.news-body p { color: var(--muted); font-size: .84rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.article { max-width: 820px; }
.article .cover { width: 100%; border-radius: 12px; margin-bottom: 16px; }
.article .body { white-space: pre-line; font-size: 1rem; line-height: 1.8; }

/* ---------- ห้องเรียน / โปรไฟล์ ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.room-chip { display: flex; flex-direction: column; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); color: var(--text); min-width: 90px; }
.room-chip small { color: var(--muted); }
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.room-card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; color: var(--text); box-shadow: var(--shadow); }
.room-card h3 { font-size: 1.25rem; }
.room-card .meta { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.room-card .bar { height: 6px; border-radius: 3px; background: var(--soft); margin-top: 10px; overflow: hidden; display: flex; }
.room-card .bar span { background: var(--blue); } .room-card .bar span + span { background: var(--pink); }
.profile-card { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.profile-card > div:nth-child(2) { flex: 1; min-width: 200px; }
.profile-card h3 { font-size: 1.25rem; }
.score-ring { width: 110px; height: 110px; border-radius: 50%; display: grid; place-content: center; text-align: center; background: radial-gradient(closest-side, var(--card) 78%, transparent 80% 100%), conic-gradient(var(--green) calc(var(--p) * 1%), var(--soft) 0); }
.score-ring b { font-size: 1.6rem; line-height: 1; }
.score-ring small { font-size: .62rem; color: var(--muted); max-width: 70px; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kid-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.kid { display: flex; gap: 12px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); }
.kid b { display: block; } .kid small, .kid span { display: block; color: var(--muted); font-size: .8rem; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-size: .9rem; }
.tabs a.active { color: var(--brand); border-color: var(--brand); font-weight: 600; }
.org { display: grid; gap: 14px; }
.org-dept { border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.org-people { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.org-people a { display: flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; background: var(--soft); border-radius: 20px; font-size: .82rem; color: var(--text); }

/* ---------- ปฏิทิน ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal > div { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); min-height: 104px; padding: 6px; font-size: .8rem; }
.cal .dow { min-height: 0; text-align: center; font-weight: 600; color: var(--muted); background: var(--soft); }
.cal .out { background: color-mix(in srgb, var(--soft) 50%, transparent); color: var(--muted); }
.cal .today .d { background: var(--brand); color: #fff; border-radius: 50%; width: 24px; height: 24px; display: inline-grid; place-items: center; }
.cal .ev { display: block; margin-top: 3px; padding: 2px 6px; border-radius: 5px; font-size: .72rem; background: color-mix(in srgb, var(--tone) 14%, transparent); color: color-mix(in srgb, var(--tone) 80%, var(--text)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; border: 0; width: 100%; text-align: left; font-family: inherit; }

/* ---------- แบ่งหน้า ---------- */
.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 0 0; }
.pager-info { font-size: .82rem; color: var(--muted); padding-top: 10px; }
.pager .pager-info { padding: 0; }
.pager nav { display: flex; gap: 4px; }
.pager nav a, .pager nav b, .pager nav span { min-width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--line); font-size: .85rem; color: var(--text); padding: 0 6px; }
.pager nav b { background: var(--brand); color: #fff; border-color: var(--brand); }
.pager nav span { border: 0; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .15s; }
.modal { background: var(--card); border-radius: 16px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px 20px; }
@keyframes fade { from { opacity: 0; } }
.toast-wrap { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 200; }
.toast { background: var(--text); color: var(--card); padding: 10px 16px; border-radius: 10px; font-size: .88rem; animation: fade .2s; }

/* ---------- หน้าเข้าสู่ระบบ / ติดตั้ง ---------- */
body.bare { background: var(--bg); }
.login { display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; }
.login-hero { background: linear-gradient(145deg, var(--brand), color-mix(in srgb, var(--brand) 55%, #4c1d95)); color: #fff; padding: 40px 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-hero::after { content: ""; position: absolute; width: 520px; height: 520px; border-radius: 50%; background: rgba(255,255,255,.07); right: -160px; bottom: -160px; }
.lh-brand { display: flex; gap: 14px; align-items: center; }
.lh-brand img { width: 56px; height: 56px; object-fit: contain; background: #fff; border-radius: 14px; padding: 4px; }
.lh-brand .sb-logo { background: rgba(255,255,255,.18); }
.lh-brand h2 { font-size: 1.2rem; } .lh-brand p { opacity: .8; font-size: .9rem; }
.lh-body h1 { font-size: 2.3rem; margin-bottom: 12px; }
.lh-body p { opacity: .85; max-width: 480px; }
.lh-stats { display: flex; gap: 36px; margin-top: 32px; position: relative; z-index: 1; }
.lh-stats b { display: block; font-size: 2rem; }
.lh-stats span { opacity: .8; font-size: .85rem; }
.login-panel { display: grid; place-items: center; padding: 32px 20px; background: var(--card); }
.login-box { width: 100%; max-width: 420px; }
.login-box h2 { font-size: 1.6rem; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--soft); border-radius: 12px; padding: 4px; margin: 18px 0; }
.seg button { border: 0; background: none; padding: 9px; border-radius: 9px; font: inherit; font-size: .88rem; color: var(--muted); cursor: pointer; display: flex; justify-content: center; align-items: center; gap: 6px; }
.seg button.active { background: var(--card); color: var(--brand); font-weight: 600; box-shadow: var(--shadow); }
.demo { margin-top: 22px; border-top: 1px dashed var(--line); padding-top: 16px; }
.demo-title { font-size: .8rem; color: var(--muted); margin-bottom: 10px; }
.demo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.demo-grid button { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 8px; padding: 6px 4px; font: inherit; font-size: .76rem; cursor: pointer; }
.demo-grid button:hover { border-color: var(--brand); color: var(--brand); }
.login-foot { text-align: center; color: var(--muted); font-size: .75rem; margin-top: 24px; }
.install { max-width: 640px; margin: 40px auto; padding: 0 16px; }
.install-head { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; }
.install h3 { margin: 18px 0 10px; }
.checklist { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.checklist li { display: flex; gap: 8px; align-items: center; }
.checklist .ok i { color: var(--green); } .checklist .bad i { color: var(--red); }

/* ---------- พิมพ์ ---------- */
@media print {
  .sidebar, .topbar, .page-actions, .filters, .pager nav, .no-print { display: none !important; }
  .main { margin: 0; } .content { padding: 0; } .card { box-shadow: none; border: 0; }
}

/* ---------- มือถือ / แท็บเล็ต ---------- */
@media (max-width: 1100px) {
  .grid-main { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  body.sb-open .sidebar { transform: none; }
  body.sb-open .sb-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
  .main { margin-left: 0; }
  .only-mobile, .icon-btn.only-mobile { display: grid; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px 16px 40px; }
  .grid-2, .grid-3, .news-row { grid-template-columns: 1fr; }
  .login { grid-template-columns: 1fr; }
  .login-hero { padding: 28px 22px; }
  .lh-body h1 { font-size: 1.6rem; }
  .lh-stats { gap: 22px; margin-top: 18px; }
  .kv { grid-template-columns: 120px 1fr; }
  .cal > div { min-height: 64px; padding: 3px; }
  .cal .ev { font-size: .62rem; padding: 1px 3px; }
}
@media (max-width: 560px) {
  .hide-sm { display: none; }
  .stats, .grid-4 { grid-template-columns: 1fr; }
  .top-search { max-width: none; }
  .welcome > i { display: none; }
  .demo-grid { grid-template-columns: repeat(2, 1fr); }
  .filters input, .filters select { flex: 1 1 100%; }
}

/* ---------- รายการที่ไม่มีลิงก์ (โมดูลเพิ่มเติม) ---------- */
.list li:not(:has(> a)):not(:has(> span)) { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 9px 0; }
.list li > span { display: block; padding: 9px 0; flex: 1; }
.list li > span small { display: block; }

/* ===== เมนูผู้ใช้ (patch_acct) ===== */
.dropdown .menu.um { min-width: 270px; padding: 8px; border-radius: 16px; }
.um-head { display: flex; align-items: center; gap: 12px; padding: 10px 10px 12px; }
.um-head b { display: block; font-size: .95rem; line-height: 1.3; }
.um-role { display: inline-block; margin-top: 4px; padding: 2px 10px; border-radius: 999px; background: var(--brand-soft, #eef2ff); color: var(--brand); font-size: .75rem; font-weight: 600; }
.um-sep { height: 1px; background: var(--line); margin: 4px 6px; }
.menu.um .menu-item { padding: 10px 12px; font-size: .9rem; gap: 12px; }
.menu.um .menu-item i { font-size: 1.15rem; color: var(--muted); }
.menu.um .menu-item.danger, .menu.um .menu-item.danger i { color: var(--red, #dc2626); }
.um-caret { color: var(--muted); font-size: .9rem; margin-left: 2px; }
.login-lang { display: flex; justify-content: flex-end; margin: -6px 0 10px; }
.login-lang button { border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 999px; padding: 4px 12px; font: inherit; font-size: .8rem; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.login-lang button:hover { color: var(--brand); border-color: var(--brand); }
.sess-list li { display: flex; align-items: center; gap: 12px; }
.list.sess-list li { padding: 10px 0; }
.list.sess-list li > .sess-ico { display: grid; flex: none; padding: 0; }
.sess-ico { width: 40px; height: 40px; border-radius: 12px; background: var(--soft); display: grid; place-items: center; font-size: 1.3rem; color: var(--muted); flex: none; }
.sess-list .grow { flex: 1; min-width: 0; }
.sess-list small { display: block; color: var(--muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.np-row { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.np-row:last-child { border-bottom: 0; }
.np-row .grow { flex: 1; }
.np-row > i { font-size: 1.3rem; color: var(--brand); width: 28px; text-align: center; }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; margin: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::before { transform: translateX(18px); }

/* ===== กล่องแจ้งเตือน (patch_nbox) ===== */
.dropdown .menu.nb-panel { width: 400px; max-width: calc(100vw - 24px); padding: 0; border-radius: 18px; overflow: hidden; }
.nb-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px 10px; }
.nb-head b { font-size: 1.05rem; }
.nb-readall { border: 0; background: none; color: var(--brand); font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer; padding: 4px 8px; border-radius: 8px; display: inline-flex; gap: 4px; align-items: center; }
.nb-readall:hover { background: var(--brand-soft); }
.nb-list { max-height: min(62vh, 520px); overflow-y: auto; padding: 0 8px 6px; overscroll-behavior: contain; }
.nb-item { display: flex; align-items: flex-start; gap: 12px; padding: 10px 10px; border-radius: 14px; color: var(--text); text-decoration: none; position: relative; }
.nb-item:hover { background: var(--soft); }
.nb-item.unread { background: color-mix(in srgb, var(--brand) 5%, transparent); }
.nb-item.unread:hover { background: color-mix(in srgb, var(--brand) 9%, transparent); }
.nb-ico { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 1.3rem; flex: none; --tc: var(--gray); color: var(--tc); background: color-mix(in srgb, var(--tc) 13%, transparent); }
.nb-ico.tone-red { --tc: var(--red); } .nb-ico.tone-amber { --tc: var(--amber); } .nb-ico.tone-orange { --tc: var(--orange); }
.nb-ico.tone-green { --tc: var(--green); } .nb-ico.tone-blue { --tc: var(--blue); } .nb-ico.tone-violet { --tc: var(--violet); }
.nb-ico.tone-indigo { --tc: #4f46e5; } .nb-ico.tone-sky { --tc: #0284c7; } .nb-ico.tone-teal { --tc: #0d9488; }
.nb-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding-right: 14px; }
.nb-txt b { font-weight: 600; font-size: .9rem; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.nb-item:not(.unread) .nb-txt b { font-weight: 500; }
.nb-txt span { font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nb-txt small { font-size: .75rem; color: var(--muted); opacity: .85; }
.nb-dot { position: absolute; right: 12px; top: 50%; width: 9px; height: 9px; margin-top: -4px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
.nb-empty { padding: 34px 16px; text-align: center; color: var(--muted); }
.nb-empty i { font-size: 2rem; display: block; margin-bottom: 6px; }
.nb-empty .ph-spinner { animation: nbspin 1s linear infinite; display: inline-block; }
@keyframes nbspin { to { transform: rotate(360deg); } }
.nb-foot { display: block; text-align: center; padding: 12px; border-top: 1px solid var(--line); font-weight: 600; font-size: .88rem; color: var(--text); }
.nb-foot:hover { background: var(--soft); color: var(--brand); }
.list li.nb-li { border: 0; }
.list li.nb-li .nb-item { display: flex; flex-wrap: nowrap; gap: 14px; padding: 12px; margin: 2px 0; }
.list li.nb-li .nb-txt b { flex: none; }
.nb-readall[hidden] { display: none; }
.nb-list .nb-item + .nb-item { margin-top: 2px; }
@media (max-width: 640px) { .dropdown .menu.nb-panel { position: fixed; top: 62px; left: 8px; right: 8px; width: auto; max-width: none; } }

/* ===== ปุ่มลัดแถบด้านบน (patch_topbar) ===== */
.tb-lang { display: contents; }
.tb-lang .chip { font-weight: 600; letter-spacing: .02em; }
.tb-lang .chip i { font-size: 1.05rem; }
@media (max-width: 640px) { .tb-lang .chip { padding-left: 8px; padding-right: 8px; } }

/* ===== ชื่อระบบ + ลิขสิทธิ์ (patch_brand) ===== */
.sb-foot { line-height: 1.45; }
.sb-foot-name { font-weight: 600; color: var(--text); }
.site-copy { margin-top: 28px; padding: 16px 0 6px; border-top: 1px solid var(--line); text-align: center; color: var(--muted); font-size: .8rem; }
@media print { .site-copy { display: none; } }

/* ===== ตัวเลือกสี (patch_theme) ===== */
.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.swatch { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--text); font: inherit; font-size: .8rem; cursor: pointer; }
.swatch i { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(15,23,42,.18); display: inline-block; }
.swatch:hover { border-color: var(--brand); }

/* ===== ภาพพื้นหลังหน้าเข้าสู่ระบบ (patch_loginbg) ===== */
.login-hero.has-bg { background-image: linear-gradient(145deg, color-mix(in srgb, var(--brand) 70%, transparent), color-mix(in srgb, #1e1b4b 72%, transparent)), var(--login-bg); background-size: cover; background-position: center; }
.login-hero.has-bg .lh-body, .login-hero.has-bg .lh-brand { text-shadow: 0 1px 3px rgba(0,0,0,.35); }
