:root {
  --fw-primary: #4338ca;
  --fw-primary-rgb: 67, 56, 202;
  --fw-accent: #d4a017;
  --fw-sidebar: #1c1a36;
  --fw-sidebar-text: #b9b6d9;
  --fw-bg: #f4f5fb;
  --fw-card: #ffffff;
  --fw-border: #e6e7f0;
  --fw-radius: 14px;
  --bs-primary: var(--fw-primary);
  --bs-primary-rgb: var(--fw-primary-rgb);
  --bs-body-font-family: 'IBM Plex Sans Thai', system-ui, sans-serif;
  --bs-link-color: var(--fw-primary);
  --bs-link-color-rgb: var(--fw-primary-rgb);
}
[data-bs-theme="dark"] {
  --fw-bg: #12111f;
  --fw-card: #1b1a2e;
  --fw-border: #2c2a45;
  --fw-sidebar: #0d0c19;
  --bs-body-bg: #12111f;
  --fw-primary: #8b85ff;
  --fw-primary-rgb: 139, 133, 255;
  --bs-primary: var(--fw-primary);
  --bs-primary-rgb: var(--fw-primary-rgb);
}

body { background: var(--fw-bg); font-size: .95rem; }
.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 264px; flex-shrink: 0; background: var(--fw-sidebar); color: var(--fw-sidebar-text);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 1rem .75rem; z-index: 1040;
  transition: transform .25s ease;
}
/* หัวเมนูล็อกไว้ด้านบน เลื่อนเมนูแล้วยังเห็นชื่อระบบ (margin ติดลบชดเชย padding ของ .sidebar) */
.brand {
  display: flex; align-items: center; gap: .75rem; text-decoration: none;
  position: sticky; top: -1rem; z-index: 2; background: var(--fw-sidebar);
  margin: -1rem -.75rem .5rem; padding: 1.5rem 1.25rem 1rem; border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-icon {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 1.35rem;
  background: linear-gradient(135deg, var(--fw-accent), #f3cf63); color: #2a1d00;
}
.brand-logo { background: #fff; border-radius: 50%; padding: 2px; flex-shrink: 0; }
.brand-logo img { width: 38px; height: 38px; object-fit: contain; }
.brand-title { display: block; color: #fff; font-weight: 600; line-height: 1.2; }
.brand-sub { display: block; font-size: .75rem; color: var(--fw-sidebar-text); max-width: 170px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-heading { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: #7d79a8; padding: 1rem .75rem .35rem; }
.sidebar .nav-link {
  color: var(--fw-sidebar-text); border-radius: 10px; padding: .55rem .75rem; display: flex; align-items: center; gap: .7rem; margin-bottom: 2px;
}
.sidebar .nav-link i { font-size: 1.1rem; width: 1.25rem; text-align: center; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar .nav-link.active { background: linear-gradient(90deg, #4f46e5, #6d5ef0); color: #fff; box-shadow: 0 6px 16px rgba(79,70,229,.35); }
.sidebar-backdrop { display: none; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .75rem; padding: .85rem 1.5rem; background: var(--fw-card);
  border-bottom: 1px solid var(--fw-border); position: sticky; top: 0; z-index: 1020;
}
.page-title { font-size: 1.2rem; font-weight: 600; margin: 0; }
.content { padding: 1.5rem; flex: 1; }
.footer { padding: 1rem 1.5rem; font-size: .8rem; color: var(--bs-secondary-color); }
.btn-icon { width: 38px; height: 38px; border-radius: 10px; display: inline-grid; place-items: center; border: 1px solid var(--fw-border); background: transparent; color: var(--bs-body-color); }
.btn-user { display: flex; align-items: center; gap: .5rem; border: 1px solid var(--fw-border); border-radius: 999px; padding: .25rem .75rem .25rem .25rem; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--fw-primary); color: #fff; font-weight: 600; }

@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1035; }
  .content { padding: 1rem; }
  .topbar { padding: .75rem 1rem; }
}

/* ---------- Components ---------- */
.card { border: 1px solid var(--fw-border); border-radius: var(--fw-radius); background: var(--fw-card); box-shadow: 0 1px 2px rgba(20,20,60,.04); }
.card-header { background: transparent; border-bottom: 1px solid var(--fw-border); padding: 1rem 1.25rem; font-weight: 600; }
.card-body { padding: 1.25rem; }
.btn { border-radius: 10px; }
.btn-primary { --bs-btn-bg: var(--fw-primary); --bs-btn-border-color: var(--fw-primary); --bs-btn-hover-bg: #3730a3; --bs-btn-hover-border-color: #3730a3; --bs-btn-active-bg: #312e81; }
.form-control, .form-select { border-radius: 10px; }
.form-control:focus, .form-select:focus { border-color: var(--fw-primary); box-shadow: 0 0 0 .2rem rgba(var(--fw-primary-rgb), .15); }
.form-label { font-weight: 500; font-size: .875rem; }
.table { --bs-table-bg: transparent; }
.table > :not(caption) > * > * { padding: .7rem .75rem; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--bs-secondary-color); font-weight: 600; background: var(--fw-bg); border-bottom: 0; }
.table-hover tbody tr:hover > * { background: rgba(var(--fw-primary-rgb), .04); }

.stat-card { position: relative; overflow: hidden; }
.stat-card .stat-icon { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; font-size: 1.4rem; }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat-card .stat-label { color: var(--bs-secondary-color); font-size: .85rem; }
.bg-soft-primary { background: rgba(67,56,202,.1); color: #4338ca; }
.bg-soft-success { background: rgba(16,185,129,.12); color: #059669; }
.bg-soft-warning { background: rgba(245,158,11,.14); color: #b45309; }
.bg-soft-danger  { background: rgba(239,68,68,.12); color: #dc2626; }
.bg-soft-info    { background: rgba(14,165,233,.12); color: #0284c7; }

.badge-soft-success { background: rgba(16,185,129,.14) !important; color: #047857 !important; }
.badge-soft-warning { background: rgba(245,158,11,.18) !important; color: #92400e !important; }
.badge-soft-danger  { background: rgba(239,68,68,.14) !important; color: #b91c1c !important; }
.badge-soft-info    { background: rgba(14,165,233,.14) !important; color: #0369a1 !important; }
.badge-soft-secondary { background: rgba(100,116,139,.15) !important; color: #475569 !important; }
.badge-soft-dark    { background: rgba(30,27,58,.85) !important; color: #fff !important; }
.badge { font-weight: 500; padding: .4em .75em; }

.progress { height: 8px; border-radius: 99px; background: var(--fw-border); }
.money { font-variant-numeric: tabular-nums; }
.text-money-lg { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.member-search { position: relative; }
.member-search .results {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 1050; margin-top: 4px; max-height: 320px; overflow-y: auto;
  background: var(--fw-card); border: 1px solid var(--fw-border); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.12);
}
.member-search .results a { display: block; padding: .6rem .9rem; text-decoration: none; color: inherit; border-bottom: 1px solid var(--fw-border); }
.member-search .results a:hover, .member-search .results a.active { background: rgba(var(--fw-primary-rgb), .07); }

.pay-item { border: 1px solid var(--fw-border); border-radius: 12px; padding: .75rem 1rem; margin-bottom: .5rem; cursor: pointer; transition: .15s; }
.pay-item:hover { border-color: var(--fw-primary); }
.pay-item.checked { border-color: var(--fw-primary); background: rgba(var(--fw-primary-rgb), .05); }

.method-option input { display: none; }
.method-option label { border: 1px solid var(--fw-border); border-radius: 12px; padding: .75rem; width: 100%; text-align: center; cursor: pointer; }
.method-option label i { display: block; font-size: 1.5rem; margin-bottom: .25rem; }
.method-option input:checked + label { border-color: var(--fw-primary); background: rgba(var(--fw-primary-rgb), .07); color: var(--fw-primary); font-weight: 600; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--bs-secondary-color); }
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .5rem; opacity: .5; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background: radial-gradient(circle at 20% 20%, #3b2f8f 0, transparent 45%), radial-gradient(circle at 80% 80%, #6d4b00 0, transparent 40%), #15132b; }
.login-card { width: 100%; max-width: 420px; border-radius: 20px; border: 0; box-shadow: 0 30px 60px rgba(0,0,0,.35); }

/* ---------- Home (หน้าแรกสาธารณะ) ---------- */
.home { --home-hero-a: #eceafd; --home-hero-b: #fbf4e2; }
[data-bs-theme="dark"] .home { --home-hero-a: #1d1b38; --home-hero-b: #241f14; }
.min-w-0 { min-width: 0; }
.home-nav { position: sticky; top: 0; z-index: 1020; padding: .7rem 0; background: color-mix(in srgb, var(--fw-card) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--fw-border); }
.home-logo-sm { width: 40px; height: 40px; border-radius: 50%; background: #fff; padding: 2px; object-fit: contain; flex-shrink: 0; }
.home-nav-sub { max-width: 46vw; }
.home-hero { background: linear-gradient(135deg, var(--home-hero-a), var(--home-hero-b)); padding: 3.5rem 0 5.5rem; }
.home-date { display: inline-block; font-size: .85rem; padding: .3rem .8rem; border-radius: 999px; margin-bottom: 1rem;
  background: var(--fw-card); border: 1px solid var(--fw-border); color: var(--bs-secondary-color); }
.home-title { font-size: clamp(1.6rem, 3.2vw, 2.4rem); font-weight: 700; line-height: 1.3; margin-bottom: .75rem; }
.home-lead { font-size: 1.05rem; color: var(--bs-secondary-color); max-width: 36rem; margin-bottom: 1.5rem; line-height: 1.8; }
.home-emblem { width: 240px; height: 240px; margin: 0 auto; border-radius: 50%; background: #fff; display: grid; place-items: center;
  box-shadow: 0 20px 50px rgba(67,56,202,.15), 0 0 0 12px rgba(255,255,255,.45); }
.home-emblem img { width: 82%; height: auto; }
.home-main { margin-top: -3.5rem; padding-bottom: 3rem; }
.home-stats .card { box-shadow: 0 10px 30px rgba(20,20,60,.06); }
.home-section { margin-top: 2.5rem; }
.home-section-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem 1rem; margin-bottom: 1rem; }
.home-section-head h2 { font-size: 1.25rem; font-weight: 600; margin: 0; }
.announce-card { transition: transform .15s ease, box-shadow .15s ease; border-top: 3px solid var(--fw-accent); }
.announce-card:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(20,20,60,.08); }
.announce-facts { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: 0 0 1rem; padding: .75rem; border-radius: 12px; background: var(--fw-bg); }
.announce-facts dt { font-size: .75rem; font-weight: 400; color: var(--bs-secondary-color); }
.announce-facts dd { margin: 0; font-weight: 600; }
.rate-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0;
  background: rgba(var(--fw-primary-rgb), .1); color: var(--fw-primary); }
.pay-box { border: 1px solid var(--fw-border); border-radius: 12px; padding: .9rem 1rem; background: var(--fw-bg); }
.pay-account { font-size: 1.35rem; font-weight: 700; letter-spacing: .04em; }
.house-row { display: grid; grid-template-columns: minmax(0, 11rem) 1fr 2.5rem; align-items: center; gap: .75rem; padding: .3rem 0; font-size: .9rem; }
.house-bar { height: 10px; border-radius: 99px; background: var(--fw-border); overflow: hidden; }
.house-bar span { display: block; height: 100%; border-radius: 99px; background: var(--fw-primary); }
.house-cnt { text-align: right; font-weight: 600; }
.stat-card-link { transition: transform .15s ease, box-shadow .15s ease; }
.stat-card-link:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(20,20,60,.1) !important; }
.stat-card-link .stat-go { color: var(--bs-secondary-color); transition: transform .15s ease; }
.stat-card-link:hover .stat-go { transform: translateX(3px); color: var(--fw-primary); }
.home-page-head { background: linear-gradient(135deg, var(--home-hero-a), var(--home-hero-b)); padding: 2rem 0 4.5rem; }
.home-page-head h1 { font-size: clamp(1.4rem, 2.6vw, 1.9rem); font-weight: 700; margin: .25rem 0 .35rem; }
.home-crumb { font-size: .85rem; }
.home-crumb a { text-decoration: none; }
.house-card { transition: transform .15s ease, box-shadow .15s ease; }
.house-card:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(20,20,60,.08); }
.home-footer { padding: 1.25rem 0; font-size: .85rem; color: var(--bs-secondary-color); border-top: 1px solid var(--fw-border); background: var(--fw-card); }
[data-bs-theme="dark"] .bg-soft-primary { color: #a5a0ff; }
[data-bs-theme="dark"] .bg-soft-success { color: #34d399; }
[data-bs-theme="dark"] .bg-soft-warning { color: #fbbf24; }
[data-bs-theme="dark"] .bg-soft-info { color: #38bdf8; }
@media (max-width: 575.98px) {
  .home-hero { padding: 2rem 0 4.5rem; }
  .home-stats .stat-value { font-size: 1.3rem; }
}

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .footer, .no-print, .d-print-none { display: none !important; }
  body, .content { background: #fff !important; padding: 0 !important; }
  .card { border: 0; box-shadow: none; }
  .table thead th { background: #eee !important; }
  a { text-decoration: none; color: #000; }
}
