/* ==========================================================================
   admin-ui.css — Design System หลังบ้าน (v2)
   แรงบันดาลใจจาก Bento Grid: การ์ดมุมโค้งใหญ่ สีพื้นอบอุ่น ตัวอักษรชัด ลำดับข้อมูลชัดเจน
   โหลดผ่าน sidebar_template.php จึงมีผลกับทุกหน้าหลังบ้านโดยไม่ต้องแก้ทีละหน้า
   ========================================================================== */
/* ฟอนต์หลังบ้าน: Google Sans (ไฟล์ในเครื่อง ชุดเดียวกับหน้าบ้าน มีอักษรไทยในตัว) */
@font-face { font-family: 'Google Sans'; src: url('../fonts/GoogleSans-Regular.woff2') format('woff2'); font-weight: 300 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Google Sans'; src: url('../fonts/GoogleSans-Medium.woff2') format('woff2'); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'Google Sans'; src: url('../fonts/GoogleSans-Bold.woff2') format('woff2'); font-weight: 600 900; font-style: normal; font-display: swap; }

:root {
  --brand: var(--bs-primary, #4f46e5);
  --brand-ink: #ffffff;
  --brand-soft: color-mix(in srgb, var(--brand) 12%, #ffffff);
  --brand-softer: color-mix(in srgb, var(--brand) 6%, #ffffff);
  --accent: #ffce73;          /* Bento yellow */
  --accent-soft: #fcf1e6;
  --lavender: #e0d7fc;
  --ui-bg: #f4f4f2;
  --ui-surface: #ffffff;
  --ui-surface-2: #fafaf9;
  --ui-border: #e7e5e4;
  --ui-text: #1c1917;
  --ui-muted: #6b6560;
  --ui-success: #15803d;
  --ui-warning: #b45309;
  --ui-danger: #b91c1c;
  --ui-radius: 14px;
  --ui-radius-lg: 20px;
  --ui-radius-xl: 26px;
  --ui-shadow: 0 1px 2px rgba(28, 25, 23, .04), 0 2px 8px rgba(28, 25, 23, .04);
  --ui-shadow-lg: 0 10px 30px rgba(28, 25, 23, .08), 0 2px 6px rgba(28, 25, 23, .04);
  --ui-font: 'Google Sans', system-ui, -apple-system, 'Segoe UI', 'Leelawadee UI', 'Noto Sans Thai', sans-serif;
  --ui-mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  /* ชื่อตัวแปรเดิมของแต่ละหน้า ชี้มาที่ฟอนต์ชุดเดียวกัน */
  --font-family: var(--ui-font);
  --font-main: var(--ui-font);
  --admin-sidebar-width: 268px;
}

/* ฟอนต์ชุดเดียวทั้งหลังบ้าน: ปุ่ม ฟอร์ม ตาราง เมนู หน้าต่าง และวิดเจ็ตภายนอก ใช้ฟอนต์เดียวกับ body */
button, input, select, textarea, optgroup, label, table, h1, h2, h3, h4, h5, h6,
.btn, .form-control, .form-select, .form-label, .nav-link, .dropdown-menu, .modal, .offcanvas, .tooltip, .popover, .badge, .card, .alert, .toast,
.sidebar, .fc, .flatpickr-calendar, .select2-container, .ql-editor, .ql-container, .note-editor, .dataTables_wrapper, .apexcharts-canvas text, .apexcharts-tooltip, .apexcharts-legend-text {
  font-family: var(--ui-font) !important;
}
/* ไอคอนของวิดเจ็ตภายนอก: ไม่ให้กฎฟอนต์ไปทับฟอนต์ไอคอน และใช้ไอคอน SVG ชุดเดียวกับทั้งระบบ (หลักเดียวกับ .bi) */
.fc .fc-icon { font-family: fcicons !important; }
.fc .fc-icon-chevron-left, .fc .fc-icon-chevron-right {
  display: inline-block; width: 1em; height: 1em; vertical-align: -.125em; background-color: currentColor;
  -webkit-mask: var(--fc-bi) center/100% 100% no-repeat; mask: var(--fc-bi) center/100% 100% no-repeat;
}
.fc .fc-icon-chevron-left::before, .fc .fc-icon-chevron-right::before { content: none !important; }
.fc .fc-icon-chevron-left { --fc-bi: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.25' stroke-linecap='round' stroke-linejoin='round'%3E %3Cg transform='rotate(180 8 8)'%3E %3Cpath d='M5.875 3.75 L10.125 8 L5.875 12.25'/%3E %3C/g%3E %3C/svg%3E"); }
.fc .fc-icon-chevron-right { --fc-bi: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.25' stroke-linecap='round' stroke-linejoin='round'%3E %3Cg%3E %3Cpath d='M5.875 3.75 L10.125 8 L5.875 12.25'/%3E %3C/g%3E %3C/svg%3E"); }

code, pre, kbd, samp, .font-monospace, .user-select-all.font-monospace { font-family: var(--ui-mono) !important; }

body { font-family: var(--ui-font) !important; background: var(--ui-bg) !important; color: var(--ui-text); -webkit-font-smoothing: antialiased; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent) !important; outline-offset: 2px; }

/* ---------- Layout ---------- */
.main-content { margin-left: var(--admin-sidebar-width) !important; padding: 28px clamp(16px, 3vw, 36px) !important; min-height: 100vh; }
@media (max-width: 991.98px) {
  .main-content { margin-left: 0 !important; padding: 76px 16px 24px !important; }
}

/* ---------- Sidebar ---------- */
.sidebar.ui-sidebar { position: fixed !important; top: 0; left: 0; height: 100vh; height: 100dvh; width: var(--admin-sidebar-width) !important; background: var(--ui-surface) !important; border-right: 1px solid var(--ui-border) !important;
  display: flex; flex-direction: column; box-shadow: none !important; z-index: 1045 !important; }
.ui-sidebar .ui-brand { padding: 20px 20px 14px; display: flex; align-items: center; gap: 12px; }
.ui-sidebar .ui-brand img, .ui-icon-badge { width: 40px; height: 40px; border-radius: 12px; object-fit: contain; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-size: 1.15rem; flex: 0 0 auto; }
.ui-sidebar .ui-brand .name { font-weight: 700; font-size: .95rem; line-height: 1.2; }
.ui-sidebar .ui-brand .sub { color: var(--ui-muted); font-size: .75rem; }
.ui-sidebar .ui-nav { padding: 6px 12px 12px; overflow-y: auto; flex: 1; }
.ui-sidebar .ui-nav-label { font-size: .7rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #a8a29e; padding: 14px 12px 6px; }
.ui-sidebar .nav-link { color: #44403c !important; padding: 9px 12px !important; border-radius: 12px !important; font-weight: 500; font-size: .93rem !important; display: flex; align-items: center; gap: 12px; margin: 1px 0 !important; transform: none !important; }
.ui-sidebar .nav-link i { font-size: 1.05rem !important; width: 22px; margin: 0 !important; color: #78716c; }
.ui-sidebar .nav-link:hover { background: var(--ui-surface-2) !important; color: var(--ui-text) !important; }
.ui-sidebar .nav-link.active { background: var(--brand) !important; color: var(--brand-ink) !important; box-shadow: 0 6px 16px color-mix(in srgb, var(--brand) 30%, transparent) !important; }
.ui-sidebar .nav-link.active i { color: var(--brand-ink); }
.ui-sidebar .nav-link .badge-new { margin-left: auto; font-size: .65rem; background: var(--accent); color: #422006; border-radius: 999px; padding: 2px 7px; font-weight: 600; }
.ui-sidebar .ui-user { margin: 10px 12px 14px; padding: 10px; border-radius: 16px; background: var(--ui-surface-2); border: 1px solid var(--ui-border); display: flex; align-items: center; gap: 10px; }
.ui-sidebar .ui-user img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.ui-sidebar .ui-user .meta { min-width: 0; flex: 1; }
.ui-sidebar .ui-user .meta b { display: block; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ui-sidebar .ui-user .meta small { color: var(--ui-muted); font-size: .72rem; }
.ui-topbar { display: none; }
.ui-backdrop { display: none; }
@media (max-width: 991.98px) {
  .sidebar.ui-sidebar { transform: translateX(-100%); transition: transform .25s ease; }
  .sidebar.ui-sidebar.active { transform: translateX(0); box-shadow: var(--ui-shadow-lg) !important; }
  .ui-topbar { display: flex; position: fixed; inset: 0 0 auto 0; height: 60px; z-index: 1040; background: color-mix(in srgb, var(--ui-surface) 92%, transparent);
    backdrop-filter: blur(10px); border-bottom: 1px solid var(--ui-border); align-items: center; gap: 10px; padding: 0 12px; padding-top: env(safe-area-inset-top); }
  .ui-topbar .title { font-weight: 700; font-size: .98rem; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ui-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(28,25,23,.35); z-index: 1042; }
}
.ui-icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--ui-border); background: var(--ui-surface); display: grid; place-items: center; color: var(--ui-text); }

/* ---------- Cards (Bento) ---------- */
.card { border-radius: var(--ui-radius-lg) !important; border: 1px solid var(--ui-border) !important; box-shadow: var(--ui-shadow) !important; }
.card.border-0 { border: 1px solid var(--ui-border) !important; }
.ui-card { background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: var(--ui-radius-lg); box-shadow: var(--ui-shadow); padding: 22px; }
.ui-card-title { font-weight: 700; font-size: 1.02rem; margin: 0; }
.ui-card-sub { color: var(--ui-muted); font-size: .85rem; }
.ui-bento { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.ui-bento > * { min-width: 0; }
.ui-span-3 { grid-column: span 3; } .ui-span-4 { grid-column: span 4; } .ui-span-5 { grid-column: span 5; }
.ui-span-6 { grid-column: span 6; } .ui-span-7 { grid-column: span 7; } .ui-span-8 { grid-column: span 8; } .ui-span-12 { grid-column: span 12; }
@media (max-width: 1199.98px) { .ui-span-3 { grid-column: span 6; } .ui-span-4, .ui-span-5 { grid-column: span 6; } .ui-span-7, .ui-span-8 { grid-column: span 12; } }
@media (max-width: 767.98px) { .ui-bento > * { grid-column: span 12 !important; } }
.ui-tile-brand { background: var(--brand); color: #fff; border-color: transparent; }
.ui-tile-brand .ui-card-sub { color: rgba(255,255,255,.78); }
.ui-tile-accent { background: var(--accent); border-color: transparent; color: #2a1a03; }
.ui-tile-cream { background: var(--accent-soft); border-color: transparent; }
.ui-tile-lavender { background: var(--lavender); border-color: transparent; }
.ui-kpi { font-size: clamp(1.7rem, 3vw, 2.3rem); font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }

/* ---------- Page header ---------- */
.ui-page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.ui-page-head h1 { font-size: clamp(1.35rem, 2.2vw, 1.75rem); font-weight: 700; margin: 0; letter-spacing: -.01em; }
.ui-page-head p { margin: 4px 0 0; color: var(--ui-muted); }

/* ---------- Buttons ---------- */
.btn { border-radius: 12px; font-weight: 500; }
.ui-btn-primary, .btn-primary { background: var(--brand) !important; border-color: var(--brand) !important; color: var(--brand-ink) !important; }
.ui-btn-primary:hover, .btn-primary:hover { filter: brightness(.94); }
.ui-btn-soft { background: var(--brand-soft); color: var(--brand); border: 0; }
.ui-btn-soft:hover { background: color-mix(in srgb, var(--brand) 18%, #fff); color: var(--brand); }
.btn-line { background: #06C755 !important; color: #fff !important; border: 0 !important; }
.btn-line:hover { background: #05b34c !important; }

/* ---------- Forms ---------- */
.form-control, .form-select { border-radius: 12px; border-color: var(--ui-border); }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--brand) 18%, transparent); }
.ui-input { background: var(--ui-surface-2); }
.form-label { color: #44403c; }

/* ---------- Tables ---------- */
.table { --bs-table-bg: transparent; }
.table > thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ui-muted) !important; font-weight: 600; background: var(--ui-surface-2) !important; border-bottom: 1px solid var(--ui-border) !important; }
.table > tbody td { border-color: #f1efed !important; vertical-align: middle; }
.table-hover > tbody > tr:hover > * { background: var(--brand-softer) !important; }

/* ---------- Badges / Pills ---------- */
.ui-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.ui-pill.ok { background: #dcfce7; color: #166534; }
.ui-pill.warn { background: #fef3c7; color: #92400e; }
.ui-pill.bad { background: #fee2e2; color: #991b1b; }
.ui-pill.muted { background: #f1efed; color: #57534e; }
.ui-pill.brand { background: var(--brand-soft); color: var(--brand); }

/* ---------- Modals / Swal ---------- */
.modal-content { border-radius: var(--ui-radius-lg) !important; }
.swal2-popup { border-radius: var(--ui-radius-lg) !important; font-family: var(--ui-font) !important; }

/* ---------- Empty state ---------- */
.ui-empty { text-align: center; padding: 36px 16px; color: var(--ui-muted); }
.ui-empty i { font-size: 2rem; display: block; margin-bottom: 8px; color: #a8a29e; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ==========================================================================
   v3 — ทำให้ทุกหน้าหลังบ้านหน้าตาเหมือนกัน (Normalization layer)
   ใช้ได้กับ markup เดิมของทุกหน้า โดยไม่ต้องแก้ทีละหน้า
   ========================================================================== */
.ui-sidebar .ui-brand > div { min-width: 0; }
.ui-sidebar .ui-brand .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* หัวข้อหน้า: บล็อกแรกใน main ของทุกหน้า */
main.main-content > .d-flex:first-child { margin-bottom: 24px !important; flex-wrap: wrap; gap: 12px; align-items: flex-end !important; }
main.main-content > .d-flex:first-child h4,
main.main-content > .d-flex:first-child h3,
.ui-page-head h1 { font-size: clamp(1.3rem, 2.1vw, 1.7rem) !important; font-weight: 700 !important; letter-spacing: -.01em; color: var(--ui-text) !important; margin: 0 !important; }
main.main-content > .d-flex:first-child h4 i { color: var(--brand); }
main.main-content > .d-flex:first-child small,
main.main-content > .d-flex:first-child p { color: var(--ui-muted) !important; font-size: .88rem !important; margin-top: 4px !important; display: block !important; }

/* การ์ดทุกแบบของแต่ละหน้า → สไตล์เดียว */
.card, .card-custom, .card-settings, .card-profile, .stats-card, .user-card, .room-card, .stat-card,
.main-content .bg-white.rounded-4, .main-content .bg-white.shadow-sm, .main-content .bg-white.rounded-3 {
  background: var(--ui-surface) !important; border: 1px solid var(--ui-border) !important;
  border-radius: var(--ui-radius-lg) !important; box-shadow: var(--ui-shadow) !important;
}
.card-header, .card-header-settings { background: transparent !important; border-bottom: 1px solid var(--ui-border) !important; font-weight: 700; }
.card-footer { background: transparent !important; border-top: 1px solid var(--ui-border) !important; }
.stats-card:hover, .user-card:hover, .room-card:hover { box-shadow: var(--ui-shadow-lg) !important; }

/* ปุ่ม: รูปทรงเดียวกันทั้งระบบ */
.main-content .btn:not(.btn-close):not(.btn-action):not(.btn-circle):not(.btn-bell) { border-radius: 12px !important; font-weight: 600; }
.main-content .btn-sm:not(.btn-action) { border-radius: 10px !important; }
.btn-white { background: var(--ui-surface) !important; border: 1px solid var(--ui-border) !important; color: var(--ui-text) !important; }
.btn-light { background: var(--ui-surface-2); border-color: var(--ui-border); }
.btn-outline-primary { color: var(--brand) !important; border-color: var(--brand) !important; }
.btn-outline-primary:hover { background: var(--brand) !important; color: #fff !important; }
.text-primary { color: var(--brand) !important; }
.bg-primary { background-color: var(--brand) !important; }
.border-primary { border-color: var(--brand) !important; }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.nav-pills .nav-link.active, .nav-pills-custom .nav-link.active, .nav-pills-settings .nav-link.active { background: var(--brand) !important; color: #fff !important; }
.nav-pills .nav-link, .nav-pills-settings .nav-link { border-radius: 12px !important; }
.page-link { color: var(--brand); border-radius: 10px !important; margin: 0 2px; }
.page-item.active .page-link { background: var(--brand); border-color: var(--brand); }
.btn-action { border-radius: 10px !important; }

/* ฟอร์ม */
.main-content .form-control, .main-content .form-select { border-radius: 12px !important; border: 1px solid var(--ui-border) !important; background-color: var(--ui-surface-2); }
.main-content .form-control:focus, .main-content .form-select:focus { background-color: #fff; }
.main-content .form-control.rounded-pill, .main-content .form-select.rounded-pill { border-radius: 12px !important; }
.input-group > .form-control:not(:last-child) { border-top-right-radius: 0 !important; border-bottom-right-radius: 0 !important; }
.input-group > .form-control:not(:first-child), .input-group > .input-group-text + .form-control { border-top-left-radius: 0 !important; border-bottom-left-radius: 0 !important; }
.input-group-text { border-color: var(--ui-border); background: var(--ui-surface-2); border-radius: 12px; }

/* ป้ายสถานะ */
.badge { border-radius: 999px; font-weight: 600; padding: .38em .75em; }
.badge-soft, .status-badge, .badge-status { border-radius: 999px !important; font-weight: 600; }

/* ตาราง: ทุกหน้า */
.main-content .table { margin-bottom: 0; }
.main-content .table > tbody > tr > td { padding-top: 12px; padding-bottom: 12px; }

/* Modal ทุกหน้า */
.modal-header { border-bottom: 1px solid var(--ui-border); }
.modal-footer { border-top: 1px solid var(--ui-border); }
.modal-title { font-weight: 700; }

/* Avatar มาตรฐาน */
.ui-avatar { background: var(--ui-surface-2); }
.avatar-box, .user-avatar, .avatar-table, .avatar-sm { border-radius: 50% !important; object-fit: cover; }
/* bg-primary + bg-opacity-* (ป้าย/ไอคอนแบบสีอ่อน) */
.bg-primary.bg-opacity-10 { background-color: rgba(var(--bs-primary-rgb), .1) !important; }
.bg-primary.bg-opacity-25 { background-color: rgba(var(--bs-primary-rgb), .25) !important; }
.bg-primary.bg-opacity-50 { background-color: rgba(var(--bs-primary-rgb), .5) !important; }
.bg-primary.bg-opacity-75 { background-color: rgba(var(--bs-primary-rgb), .75) !important; }
.bg-primary-subtle { background-color: rgba(var(--bs-primary-rgb), .1) !important; }
.text-primary-emphasis { color: var(--bs-primary) !important; }
.badge { white-space: nowrap; }
