@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@400;500;600;700&family=Outfit:wght@400;500;600;700&display=swap');

/* ========================================
   THEME.CSS — Bootstrap 5 Override
   ระบบ "มือทำเงินพันล้าน"
   ======================================== */

:root {
  /* Brand */
  --bs-primary:             #185FA5;
  --bs-primary-rgb:         24, 95, 165;
  --bs-font-sans-serif:     'Noto Sans Thai', 'Outfit', sans-serif;
  --bs-body-font-size:      18px;
  --bs-border-radius:       12px;
  --bs-border-radius-lg:    16px;
  --bs-border-radius-sm:    8px;
  --sidebar-width:          260px;   /* ความกว้าง sidebar — ลากเส้นแบ่งปรับได้ (JS + localStorage) */

  /* Custom tokens */
  --color-primary:          #185FA5;
  --color-primary-hover:    #0C447C;
  --color-primary-light:    #E8F1FA;
  --color-primary-dark:     #082C52;
  --color-page-bg:          #FFFFFF;
  --color-card-border:      #E5E7EB;
  --color-surface:          #F5F7FA;
  --color-text-primary:     #1A1A2E;
  --color-text-secondary:   #6B7280;
  --color-text-muted:       #9CA3AF;

  /* Role colors — Staff (Blue) */
  --role-staff-bg:          #EFF6FF;
  --role-staff-border:      #3B82F6;
  --role-staff-text:        #1D4ED8;

  /* Role colors — Staff-Owner (Emerald) */
  --role-staff-owner-bg:    #ECFDF5;
  --role-staff-owner-border:#10B981;
  --role-staff-owner-text:  #047857;

  /* Role colors — Owner (Violet) */
  --role-owner-bg:          #F5F3FF;
  --role-owner-border:      #7C3AED;
  --role-owner-text:        #5B21B6;

  /* Role colors — Admin (Amber) */
  --role-admin-bg:          #FFFBEB;
  --role-admin-border:      #D97706;
  --role-admin-text:        #92400E;

  /* Role colors — Super Admin (Rose) */
  --role-super-admin-bg:      #FFF1F2;
  --role-super-admin-border:  #F43F5E;
  --role-super-admin-text:    #E11D48;

  /* Status colors */
  --status-pending-bg:      #FEF3C7;
  --status-pending-text:    #BA7517;
  --status-confirmed-bg:    #D1FAE5;
  --status-confirmed-text:  #1D9E75;
  --status-cancelled-bg:    #FEE2E2;
  --status-cancelled-text:  #E24B4A;
  --status-completed-bg:    #F3F4F6;
  --status-completed-text:  #374151;
}

/* ── Global ── */
* {
  -webkit-tap-highlight-color: transparent;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Noto Sans Thai', 'Outfit', sans-serif;
  background-color: var(--color-page-bg);
  color: var(--color-text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Typography ── */
h1, .h1 { font-size: 24px; font-weight: 600; }
h2, .h2 { font-size: 20px; font-weight: 600; }
h3, .h3 { font-size: 18px; font-weight: 600; }
.text-subtitle { font-size: 16px; color: var(--color-text-secondary); }
.text-label { font-size: 14px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.text-small { font-size: 16px; color: var(--color-text-muted); }
.fw-600 { font-weight: 600; }

/* ── Primary Button ── */
.btn-primary {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
  font-weight: 500;
  border-radius: var(--bs-border-radius);
  padding: 10px 20px;
  transition: all 0.2s ease;
}
.btn-primary:hover,
.btn-primary:focus {
  background-color: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(24, 95, 165, 0.3);
}
.btn-primary:active {
  transform: translateY(0);
}

.btn-outline-primary {
  color: var(--color-primary);
  border-color: var(--color-primary);
  font-weight: 500;
}
.btn-outline-primary:hover,
.btn-outline-primary:focus {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.btn-light-primary {
  background-color: var(--color-primary-light);
  color: var(--color-primary);
  border: none;
  font-weight: 500;
}
.btn-light-primary:hover {
  background-color: #d2e4f5;
  color: var(--color-primary-hover);
}

/* ── Card ── */
.card {
  border: 1px solid var(--color-card-border);
  border-radius: var(--bs-border-radius-lg);
  box-shadow: none;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
  background: #fff;
}
.card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.card-body {
  padding: 14px 16px;
}

/* ── Status Badges ── */
.badge-status {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.badge-pending   { background: var(--status-pending-bg);   color: var(--status-pending-text); }
.badge-confirmed { background: var(--status-confirmed-bg); color: var(--status-confirmed-text); }
.badge-cancelled { background: var(--status-cancelled-bg); color: var(--status-cancelled-text); }
.badge-completed { background: var(--status-completed-bg); color: var(--status-completed-text); }

/* ── Role Badges ── */
.badge-role {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
}
.badge-role-staff       { background: var(--role-staff-bg);       color: var(--role-staff-text);       border: 1px solid var(--role-staff-border); }
.badge-role-staff-owner { background: var(--role-staff-owner-bg); color: var(--role-staff-owner-text); border: 1px solid var(--role-staff-owner-border); }
.badge-role-owner       { background: var(--role-owner-bg);       color: var(--role-owner-text);       border: 1px solid var(--role-owner-border); }
.badge-role-admin       { background: var(--role-admin-bg);       color: var(--role-admin-text);       border: 1px solid var(--role-admin-border); }
.badge-role-super-admin { background: var(--role-super-admin-bg); color: var(--role-super-admin-text); border: 1px solid var(--role-super-admin-border); }

/* ── Package Badge (top-header ฝั่งคลินิก) — สีตาม tier ── */
.badge-package {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.badge-package i { font-size: 15px; }
.badge-package-basic  { background: #F1F5F9; color: #475569; border: 1px solid #CBD5E1; }
.badge-package-silver { background: linear-gradient(135deg, #E5E9F0, #C7CFDB); color: #3A4453; border: 1px solid #A9B4C4; }
.badge-package-gold   { background: linear-gradient(135deg, #FEF3C7, #FDE68A); color: #92400E; border: 1px solid #F0C24B; }

/* ── Top Header ── */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 2px solid var(--color-card-border);
  position: sticky;
  top: 0;
  z-index: 99;
}
.top-header[data-role="staff"]       { border-bottom-color: var(--role-staff-border); }
.top-header[data-role="staff_owner"] { border-bottom-color: var(--role-staff-owner-border); }
.top-header[data-role="owner"]       { border-bottom-color: var(--role-owner-border); }
.top-header[data-role="admin"]       { border-bottom-color: var(--role-admin-border); }
.top-header[data-role="super_admin"] { border-bottom-color: var(--role-super-admin-border); }

.top-header .header-title {
  font-size: 19px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin: 0;
  line-height: 1.3;
}
.top-header .header-subtitle {
  font-size: 15px;
  color: var(--color-text-muted);
  margin: 0;
}

/* ── Bottom Navigation ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--color-card-border);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.04);
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 4px;
  min-height: 44px;
  justify-content: center;
  transition: color 0.2s ease;
  position: relative;
}
.bottom-nav-item i { font-size: 25px; }
.bottom-nav-item:hover { color: var(--color-text-secondary); text-decoration: none; }

/* Active states per role */
.bottom-nav[data-role="staff"] .bottom-nav-item.active       { color: var(--role-staff-text); }
.bottom-nav[data-role="staff_owner"] .bottom-nav-item.active { color: var(--role-staff-owner-text); }
.bottom-nav[data-role="owner"] .bottom-nav-item.active       { color: var(--role-owner-text); }
.bottom-nav[data-role="admin"] .bottom-nav-item.active       { color: var(--role-admin-text); }
.bottom-nav[data-role="super_admin"] .bottom-nav-item.active { color: var(--role-super-admin-text); }

.bottom-nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: currentColor;
}

/* Page content padding for fixed bottom nav */
.page-content {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

/* ── Forms ── */
.form-control, .form-select {
  border: 1px solid var(--color-card-border);
  border-radius: var(--bs-border-radius);
  padding: 10px 14px;
  font-size: 18px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.form-control:focus, .form-select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(13, 158, 122, 0.15);
}
.form-label {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 4px;
}

/* ── Animations ── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to   { opacity: 1; transform: scale(1); }
}

.animate-fadeInUp {
  animation: fadeInUp 0.35s ease forwards;
}
.animate-fadeIn {
  animation: fadeIn 0.3s ease forwards;
}
.animate-scaleIn {
  animation: scaleIn 0.25s ease forwards;
}

/* Staggered animation delays */
.delay-1 { animation-delay: 0.05s; opacity: 0; }
.delay-2 { animation-delay: 0.10s; opacity: 0; }
.delay-3 { animation-delay: 0.15s; opacity: 0; }
.delay-4 { animation-delay: 0.20s; opacity: 0; }
.delay-5 { animation-delay: 0.25s; opacity: 0; }
.delay-6 { animation-delay: 0.30s; opacity: 0; }

/* ── Responsive ── */

/* Tablet (768px–991px) */
@media (min-width: 768px) and (max-width: 991.98px) {
  .page-content { max-width: 680px; margin: 0 auto; }
  .bottom-nav { max-width: 680px; left: 50%; transform: translateX(-50%); border-radius: 16px 16px 0 0; }
}

/* Desktop (≥992px) */
@media (min-width: 992px) {
  /* Hide bottom nav on desktop */
  .bottom-nav { display: none !important; }

  /* Sidebar visible */
  .sidebar {
    display: flex !important;
  }

  /* Layout shift for sidebar */
  .top-header {
    margin-left: var(--sidebar-width);
    position: sticky;
  }
  .page-content {
    margin-left: var(--sidebar-width);
    max-width: 900px;
    padding: 24px 32px;
    padding-bottom: 32px;
  }

  /* Cards can be wider */
  .card-body { padding: 18px 22px; }
  .booking-card { padding: 16px 20px; }
  .customer-card { padding: 16px 20px; }
  .admin-card { padding: 16px 20px; }
  .promo-card { padding: 16px 20px; }

  /* FAB repositioned */
  .fab {
    bottom: 32px;
    right: 32px;
  }

  /* Forms wider */
  .form-control, .form-select {
    padding: 12px 16px;
  }
}

/* Large Desktop (≥1200px) */
@media (min-width: 1200px) {
  .page-content {
    max-width: 1000px;
  }
}

/* ── Sidebar (Desktop only) ── */
.sidebar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: #fff;
  border-right: 1px solid var(--color-card-border);
  flex-direction: column;
  z-index: 101;
  overflow-y: auto;
}

/* ── เส้นแบ่ง sidebar ปรับขนาดได้ (ลากด้วยเมาส์ · desktop ≥992px) ── */
.sidebar-resizer {
  display: none;
  position: fixed;
  top: 0;
  bottom: 0;
  left: var(--sidebar-width);
  width: 8px;
  margin-left: -4px;            /* ให้ตัวจับคร่อมบนเส้นขอบพอดี */
  cursor: col-resize;
  z-index: 102;
  background: transparent;
  transition: background 0.15s ease;
}
.sidebar-resizer::before {      /* เส้นบาง ๆ ให้เห็นว่าลากได้ตอน hover */
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  background: transparent;
  transition: background 0.15s ease;
}
.sidebar-resizer:hover::before,
.sidebar-resizer.dragging::before {
  background: var(--color-primary);
}
@media (min-width: 992px) {
  .sidebar-resizer { display: block; }
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--color-card-border);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo .logo-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--color-primary-light);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.sidebar-logo .logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: 1.2;
}
.sidebar-logo .logo-sub {
  font-size: 14px;
  color: var(--color-text-muted);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
}
.sidebar-section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 8px 12px 6px;
  margin-top: 8px;
}
.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--color-text-secondary);
  font-size: 17px;
  font-weight: 500;
  transition: all 0.2s ease;
  margin-bottom: 2px;
}
.sidebar-nav-item i {
  font-size: 23px;
  width: 24px;
  text-align: center;
}
.sidebar-nav-item:hover {
  background: var(--color-page-bg);
  color: var(--color-text-primary);
  text-decoration: none;
}

/* Sidebar active states per role */
.sidebar[data-role="staff"] .sidebar-nav-item.active {
  background: var(--role-staff-bg);
  color: var(--role-staff-text);
}
.sidebar[data-role="staff_owner"] .sidebar-nav-item.active {
  background: var(--role-staff-owner-bg);
  color: var(--role-staff-owner-text);
}
.sidebar[data-role="owner"] .sidebar-nav-item.active {
  background: var(--role-owner-bg);
  color: var(--role-owner-text);
}
.sidebar[data-role="admin"] .sidebar-nav-item.active {
  background: var(--role-admin-bg);
  color: var(--role-admin-text);
}
.sidebar[data-role="super_admin"] .sidebar-nav-item.active {
  background: var(--role-super-admin-bg);
  color: var(--role-super-admin-text);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--color-card-border);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  flex-shrink: 0;
}
.sidebar-user-info {
  flex: 1;
  min-width: 0;
}
.sidebar-user-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 14px;
  color: var(--color-text-muted);
}
.sidebar-logout {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--color-page-bg);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.sidebar-logout:hover {
  background: #FEE2E2;
  color: #991B1B;
}

/* ── Sidebar Submenu (Collapsible) ── */
.sidebar-nav-group {
  margin-bottom: 2px;
}

/* Parent row — flex container: link + chevron btn */
.sidebar-nav-parent-row {
  display: flex;
  align-items: stretch;
  border-radius: 10px;
  overflow: hidden;
}

/* Parent link (navigates to page) */
.sidebar-nav-parent-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 10px 12px;
  text-decoration: none;
  color: var(--color-text-secondary);
  font-size: 17px;
  font-weight: 500;
  transition: all 0.2s ease;
  flex: 1;
  min-width: 0;
}
.sidebar-nav-parent-link i.ti {
  font-size: 23px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}
.sidebar-nav-parent-link:hover {
  background: var(--color-page-bg);
  color: var(--color-text-primary);
  text-decoration: none;
}
.sidebar[data-role="admin"] .sidebar-nav-parent-link.active {
  background: var(--role-admin-bg);
  color: var(--role-admin-text);
}
.sidebar[data-role="super_admin"] .sidebar-nav-parent-link.active {
  background: var(--role-super-admin-bg);
  color: var(--role-super-admin-text);
}

/* Chevron toggle button */
.sidebar-chevron-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  flex-shrink: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: background 0.2s, color 0.2s;
  border-radius: 0 10px 10px 0;
  padding: 0;
}
.sidebar-chevron-btn:hover {
  background: var(--color-page-bg);
  color: var(--color-text-primary);
}

/* Chevron rotation */
.sidebar-chevron {
  font-size: 15px !important;
  width: auto !important;
  transition: transform 0.25s ease;
  opacity: 0.5;
}
.sidebar-nav-group.open .sidebar-chevron {
  transform: rotate(90deg);
  opacity: 1;
}

/* Submenu container — animated collapse */
.sidebar-submenu {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease, opacity 0.25s ease;
  opacity: 0;
}
.sidebar-nav-group.open .sidebar-submenu {
  max-height: 300px;
  opacity: 1;
}

/* Sub-item */
.sidebar-sub-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 8px 44px;  /* indent: 44px = icon width + gap */
  border-radius: 8px;
  text-decoration: none;
  color: var(--color-text-secondary);
  font-size: 15px;
  font-weight: 500;
  transition: all 0.2s ease;
  margin-bottom: 1px;
  position: relative;
}
.sidebar-sub-item::before {
  content: '';
  position: absolute;
  left: 28px;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
  transition: background 0.2s;
}
.sidebar-sub-item i {
  display: none; /* ซ่อน icon ใช้ dot แทน */
}
.sidebar-sub-item:hover {
  background: var(--color-page-bg);
  color: var(--color-text-primary);
  text-decoration: none;
}
.sidebar-sub-item:hover::before {
  background: var(--color-text-secondary);
}
.sidebar[data-role="admin"] .sidebar-sub-item.active {
  background: var(--role-admin-bg);
  color: var(--role-admin-text);
}
.sidebar[data-role="admin"] .sidebar-sub-item.active::before {
  background: var(--role-admin-text);
}
.sidebar[data-role="super_admin"] .sidebar-sub-item.active {
  background: var(--role-super-admin-bg);
  color: var(--role-super-admin-text);
}
.sidebar[data-role="super_admin"] .sidebar-sub-item.active::before {
  background: var(--role-super-admin-text);
}
