/* Custom styles เสริมจาก Tailwind CDN */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.dark ::-webkit-scrollbar-thumb { background: #475569; }

#mainSidebar.collapsed { width: 4.5rem; }
#mainSidebar.collapsed .sidebar-label { display: none; }
#mainSidebar.collapsed #sidebarTitle { display: none; }

.badge { display: inline-flex; align-items: center; padding: 0.125rem 0.625rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 500; }

@media print {
  #mainSidebar, header, #sidebarToggleBtn, .no-print { display: none !important; }
  main { padding: 0 !important; overflow: visible !important; }
  body { background: white !important; }
}

.kanban-scroll { scrollbar-width: thin; }

table.data-table th { cursor: pointer; user-select: none; }
table.data-table th .sort-icon { opacity: 0.4; font-size: 0.7rem; margin-left: 4px; }

/* ============================================================
   Mobile Theme — สไตล์แอปมือถือ (พื้นหลังฟ้าไล่สี, การ์ดโค้งมน, แถบเมนูล่าง)
   ใช้เฉพาะจอ < 768px ไม่กระทบหน้าตาบนคอมพิวเตอร์
   ============================================================ */
.bottom-nav, #mobileOverlay, .stat-icon { display: none; }
.mobile-greet { font-size: 1.15rem; color: #8fa0cf; }
.mobile-greet b { color: #1e2a52; font-weight: 600; }
html.dark .mobile-greet b { color: #e5e9ff; }

/* วงแหวนแสดงเปอร์เซ็นต์ (ใช้ในการ์ดอัตราอนุมัติ) */
.pct-ring { --p: 0; width: 5.5rem; height: 5.5rem; border-radius: 9999px; display: grid; place-items: center; flex-shrink: 0;
        background: conic-gradient(#4f7bf7 calc(var(--p) * 1%), #e3e9ff 0); }
.pct-ring span { width: 76%; height: 76%; border-radius: 9999px; background: #fff; display: grid; place-items: center; font-weight: 600; color: #3b5be0; font-size: .95rem; }
html.dark .pct-ring { background: conic-gradient(#6f93ff calc(var(--p) * 1%), #374151 0); }
html.dark .pct-ring span { background: #1f2937; color: #9db4ff; }

@media screen and (max-width: 767px) {
  :root { --m-blue: #4f7bf7; --m-blue-d: #3b5be0; --m-ink: #1e2a52; --m-shadow: 0 10px 28px -14px rgba(59,91,224,.38); }

  /* พื้นหลังฟ้าไล่สีพร้อมวงกลมตกแต่ง */
  html, body.font-sans { background: linear-gradient(160deg, #7a9cff 0%, #4f7bf7 55%, #3f63e6 100%) fixed; color: var(--m-ink); }
  html.dark, html.dark body.font-sans { background: linear-gradient(160deg, #26356f 0%, #1a2552 55%, #121a3b 100%) fixed; color: #e5e9ff; }
  body.font-sans::before, body.font-sans::after { content: ""; position: fixed; border-radius: 9999px; background: rgba(255,255,255,.13); pointer-events: none; z-index: 0; }
  body.font-sans::before { width: 260px; height: 260px; top: -90px; right: -80px; }
  body.font-sans::after { width: 200px; height: 200px; bottom: -70px; left: -70px; }

  /* กรอบแอปแบบหน้าจอโทรศัพท์ในภาพตัวอย่าง */
  body .app-shell { position: relative; z-index: 1; margin: 8px; height: calc(100vh - 16px); height: calc(100dvh - 16px);
                    border-radius: 2rem; background: rgba(244,247,255,.97); border: 1.5px solid rgba(255,255,255,.8);
                    box-shadow: 0 20px 50px -20px rgba(20,35,110,.55); }
  html.dark body .app-shell { background: rgba(17,24,39,.97); border-color: rgba(255,255,255,.1); }

  /* หัวหน้า: ทักทาย + ปุ่มกลม */
  body .app-shell > div > header { background: transparent; border: 0; height: 4.4rem; padding: 0 1.1rem; }
  html.dark body .app-shell > div > header { background: transparent; }
  header #notifBtn, header #darkModeToggleBtn { background: #fff; box-shadow: var(--m-shadow); border-radius: 9999px; width: 2.5rem; height: 2.5rem; display: flex; align-items: center; justify-content: center; padding: 0; }
  html.dark header #notifBtn, html.dark header #darkModeToggleBtn { background: #1f2937; box-shadow: none; }
  header #profileBtn { padding: 0; }
  header #profileBtn > div { width: 2.5rem; height: 2.5rem; box-shadow: var(--m-shadow); }
  body #notifDropdown { position: fixed; left: 1rem; right: 1rem; top: 4.6rem; width: auto; border-radius: 1.5rem; }
  body #profileDropdown { border-radius: 1.25rem; }

  body .app-shell main { padding: .25rem 1.1rem 6.75rem; }

  /* การ์ดโค้งมน นุ่มๆ */
  body main div.bg-white { border-radius: 1.5rem; border-color: rgba(255,255,255,.9); box-shadow: var(--m-shadow); }
  html.dark body main div.bg-white { border-color: rgba(255,255,255,.06); box-shadow: none; }
  body main input:not([type=checkbox]):not([type=radio]):not([type=file]), body main select, body main textarea { border-radius: .9rem; }
  body main button.bg-teal-500, body main button.bg-teal-600, body main a.bg-teal-500, body main a.bg-teal-600 { border-radius: 9999px; }

  /* โทนสีหลัก teal -> น้ำเงิน */
  body .bg-teal-500, body .bg-teal-600 { background-color: var(--m-blue); background-image: linear-gradient(135deg, var(--m-blue), var(--m-blue-d)); }
  body .hover\:bg-teal-700:hover { background-color: var(--m-blue-d); }
  body .text-teal-300, body .text-teal-400, body .text-teal-600, body .text-teal-700, body .hover\:text-teal-600:hover { color: var(--m-blue-d); }
  body .bg-teal-50 { background-color: #eaf0ff; }
  body .bg-teal-100 { background-color: #dbe6ff; }
  body .border-teal-500, body .border-teal-600 { border-color: var(--m-blue); }
  html.dark body .text-teal-300, html.dark body .text-teal-400, html.dark body .text-teal-600, html.dark body .text-teal-700,
  html.dark body .dark\:text-teal-300, html.dark body .dark\:text-teal-400 { color: #9db4ff; }
  html.dark body .dark\:bg-teal-900\/40, html.dark body .dark\:bg-teal-900\/20, html.dark body .dark\:bg-teal-900 { background-color: rgba(79,123,247,.22); }

  /* เมนูหลักเป็น drawer เลื่อนจากซ้าย */
  body #mainSidebar { position: fixed; z-index: 60; top: 8px; bottom: 8px; left: 8px; width: min(80vw, 19rem); border: 0; border-radius: 2rem;
                      box-shadow: 0 20px 60px -10px rgba(20,35,110,.5); transform: translateX(calc(-100% - 24px)); transition: transform .25s ease; overflow: hidden; }
  body #mainSidebar.mobile-open { transform: translateX(0); }
  body #mainSidebar.collapsed { width: min(80vw, 19rem); }
  body #mainSidebar.collapsed .sidebar-label, body #mainSidebar.collapsed #sidebarTitle { display: revert; }
  body #mainSidebar nav a { border-radius: 9999px; padding: .7rem 1rem; }
  #mobileOverlay { display: block; position: fixed; inset: 0; z-index: 50; background: rgba(20,30,80,.45); backdrop-filter: blur(2px);
                   opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  #mobileOverlay.show { opacity: 1; pointer-events: auto; }

  /* แถบเมนูด้านล่างแบบลอย */
  body .bottom-nav { display: flex; position: absolute; z-index: 30; left: 14px; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom));
                     justify-content: space-around; align-items: center; padding: .4rem .5rem; border-radius: 9999px;
                     background: rgba(255,255,255,.93); backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,.9);
                     box-shadow: 0 12px 30px -10px rgba(59,91,224,.45); }
  html.dark body .bottom-nav { background: rgba(31,41,55,.94); border-color: rgba(255,255,255,.08); }
  .bottom-nav a, .bottom-nav button { width: 3rem; height: 3rem; border-radius: 9999px; display: flex; align-items: center; justify-content: center;
                                      color: #a3b0d6; background: transparent; border: 0; transition: background .15s, color .15s; }
  .bottom-nav .active { color: var(--m-blue-d); background: #e6edff; }
  html.dark .bottom-nav .active { color: #9db4ff; background: rgba(79,123,247,.22); }

  /* การ์ดสถิติแบบไล่สี (แดชบอร์ด) */
  body main .stat-card { position: relative; overflow: hidden; border: 0; min-height: 7.5rem; padding: 1rem;
                         background-image: linear-gradient(145deg, var(--c1), var(--c2)); box-shadow: 0 14px 26px -14px var(--c2); }
  body main .stat-card::after { content: ""; position: absolute; right: -30px; bottom: -36px; width: 112px; height: 112px; border-radius: 9999px; background: rgba(255,255,255,.17); }
  body main .stat-card::before { content: ""; position: absolute; right: 26px; top: -26px; width: 64px; height: 64px; border-radius: 9999px; background: rgba(255,255,255,.12); }
  body main .stat-card > * { position: relative; z-index: 1; }
  body main .stat-card .stat-label { color: rgba(255,255,255,.92); font-size: .78rem; }
  body main .stat-card .stat-value { color: #fff; font-size: 1.9rem; line-height: 1.2; }
  .stat-icon { display: flex; width: 2rem; height: 2rem; border-radius: 9999px; background: rgba(255,255,255,.26); color: #fff; align-items: center; justify-content: center; margin-bottom: .55rem; }
  .stat-blue { --c1: #6b92ff; --c2: #3b5be0; }
  .stat-purple { --c1: #b98af5; --c2: #7c4ddb; }
  .stat-green { --c1: #45dcae; --c2: #12a37f; }
  .stat-pink { --c1: #ff80a1; --c2: #e5486f; }

  /* หน้า login / สมัครสมาชิก */
  body.auth-page { background: transparent; }
  body.auth-page > div { border-radius: 2rem; border-color: rgba(255,255,255,.8); box-shadow: 0 20px 50px -20px rgba(20,35,110,.55); }
}

/* ฟอร์มค้นหา/ตัวกรองบนมือถือ: ช่องกว้างเต็มแถว */
@media screen and (max-width: 767px) {
  body main form.flex-wrap > input[type=text], body main form.flex-wrap > select { flex: 1 1 100%; width: 100%; }
}

/* ปฏิทิน (FullCalendar) บนมือถือ: ย่อขนาด + โทนสีน้ำเงิน */
@media screen and (max-width: 767px) {
  body main .fc { --fc-button-bg-color: #4f7bf7; --fc-button-border-color: #4f7bf7; --fc-button-hover-bg-color: #3b5be0; --fc-button-hover-border-color: #3b5be0;
                  --fc-button-active-bg-color: #3b5be0; --fc-button-active-border-color: #3b5be0; --fc-button-disabled-bg-color: #a9bdf9; --fc-button-disabled-border-color: #a9bdf9;
                  --fc-today-bg-color: rgba(79,123,247,.12); --fc-border-color: #e3e9ff; --fc-page-bg-color: transparent; font-size: .8rem; }
  html.dark body main .fc { --fc-border-color: #374151; --fc-today-bg-color: rgba(79,123,247,.2); }
  body main .fc .fc-toolbar { gap: .5rem; flex-wrap: wrap; justify-content: space-between; }
  body main .fc .fc-footer-toolbar { margin-top: .75rem; justify-content: center; }
  body main .fc .fc-toolbar-title { font-size: 1.05rem; font-weight: 600; }
  body main .fc .fc-button { padding: .35rem .65rem; font-size: .78rem; text-transform: none; }
  body main .fc .fc-today-button { border-radius: 9999px; }
  body main .fc .fc-button-group > .fc-button:first-child { border-radius: 9999px 0 0 9999px; }
  body main .fc .fc-button-group > .fc-button:last-child { border-radius: 0 9999px 9999px 0; }
  body main .fc .fc-button-group > .fc-button:only-child { border-radius: 9999px; }
  body main .fc .fc-col-header-cell-cushion { font-size: .68rem; padding: 4px 0; white-space: nowrap; }
  body main .fc .fc-daygrid-day-number { font-size: .72rem; padding: 2px 4px; }
  body main .fc .fc-daygrid-day-frame { min-height: 3.4rem; }
  body main .fc .fc-event { font-size: .62rem; }
  body main .fc .fc-list-event-title, body main .fc .fc-list-event-time { font-size: .8rem; }
}
