﻿/* ============================================================
   Navigation — BandThai
   SIDEBAR layout
   Desktop (≥1024px) : fixed left sidebar, always visible
   Mobile  (<1024px) : slim topbar + slide-in drawer from left
   ============================================================ */

/* ──────────────────────────────────────────────────────────
   SIDEBAR WIDTH VARIABLE
   ────────────────────────────────────────────────────────── */
:root { --sidebar-width: 260px; --topbar-height: 56px; }

/* ──────────────────────────────────────────────────────────
   LAYOUT SHIFT — push page content
   ────────────────────────────────────────────────────────── */
@media (min-width: 1024px) {
  body { padding-left: var(--sidebar-width) !important; overflow-x: hidden; }
}
@media (max-width: 1023px) {
  body { padding-top: calc(var(--topbar-height) + env(safe-area-inset-top, 0px)) !important; }
}

/* ──────────────────────────────────────────────────────────
   SIDEBAR PANEL
   ────────────────────────────────────────────────────────── */
.nav-sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-width);
  background: #111827;
  border-right: 1px solid #1f2937;
  display: flex;
  flex-direction: column;
  z-index: 300;
  overflow: hidden;
}

/* Mobile: sidebar is a drawer (hidden by default) */
@media (max-width: 1023px) {
  .nav-sidebar {
    top: calc(var(--topbar-height) + env(safe-area-inset-top, 0px));
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1), box-shadow .28s ease;
    box-shadow: none;
  }
  .nav-sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 40px rgba(0,0,0,.55);
  }
}

/* ── Sidebar header ── */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid #1f2937;
  flex-shrink: 0;
}
.sidebar-brand {
  font-family: var(--font-family-display, 'Kanit', sans-serif);
  font-size: 17px;
  font-weight: 700;
  color: var(--premium-gold, #f6ad55);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 185px;
}
.sidebar-brand:hover { color: #ecc94b; }

/* Close button — mobile only */
.sidebar-close {
  display: none;
  background: #1f2937;
  border: none;
  color: #9ca3af;
  font-size: 17px;
  width: 32px; height: 32px;
  border-radius: 6px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background .14s, color .14s;
}
.sidebar-close:hover { background: #374151; color: #fff; }
@media (max-width: 1023px) {
  .sidebar-close { display: flex; }
}

/* ── User info block ── */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 20px;
  border-bottom: 1px solid #1f2937;
  flex-shrink: 0;
}
.sidebar-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2d3748, #4a5568);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  border: 2px solid #374151;
}
.sidebar-user-info { min-width: 0; }
.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: #f3f4f6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 11px;
  color: #6b7280;
  margin-top: 1px;
}
.sidebar-user-instrument {
  font-size: 10px;
  color: var(--premium-gold, #d4af37);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-province {
  font-size: 11px;
  opacity: 0.65;
  font-weight: normal;
}

/* ── Nav list (scrollable) ── */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0 16px;
  scrollbar-width: thin;
  scrollbar-color: #374151 transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #374151; border-radius: 4px; }

.nav-menu {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Section label */
.nav-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #4b5563;
  padding: 16px 20px 5px;
  margin-top: 4px;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.nav-section-title:first-child { margin-top: 0; padding-top: 8px; }
.nav-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #1f2937;
  margin-left: 4px;
}

/* Nav item link */
.nav-menu li a {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 8px 20px;
  color: #9ca3af;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-family-body, 'Sarabun', sans-serif);
  transition: background .13s, color .13s, border-color .13s;
  border-left: 3px solid transparent;
  overflow: hidden;
  border-radius: 0 8px 8px 0;
  margin-right: 10px;
}
.nav-menu li a:hover {
  background: #1f2937;
  color: #e5e7eb;
  border-left-color: #374151;
}
.nav-menu li a.active {
  background: linear-gradient(90deg, rgba(246,173,85,.14), rgba(246,173,85,.03));
  color: var(--premium-gold, #f6ad55);
  font-weight: 600;
  border-left-color: var(--premium-gold, #f6ad55);
}

/* label row (emoji + text) */
.nav-menu li a > span:not(.nav-link-desc) {
  display: inline;
}

/* Description line */
.nav-link-desc {
  display: block;
  font-size: 10.5px;
  font-weight: 400;
  color: #4b5563;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  padding-left: 22px;
  transition: color .13s;
}
.nav-menu li a:hover .nav-link-desc {
  color: #6b7280;
}
.nav-menu li a.active .nav-link-desc {
  color: rgba(246,173,85,.65);
}

/* ── Sidebar footer: lang + logout ── */
.sidebar-footer {
  flex-shrink: 0;
  border-top: 1px solid #1f2937;
  padding: 13px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.nav-logout {
  font-size: 12px;
  color: #f87171;
  text-decoration: none;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid rgba(248,113,113,.4);
  transition: background .13s, color .13s;
  white-space: nowrap;
}
.nav-logout:hover { background: #f87171; color: #fff; text-decoration: none; }

/* ──────────────────────────────────────────────────────────
   TOPBAR — mobile/tablet only
   ────────────────────────────────────────────────────────── */
.nav-topbar {
  display: none;
}
@media (max-width: 1023px) {
  .nav-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: calc(var(--topbar-height) + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    background: #111827;
    border-bottom: 1px solid #1f2937;
    box-shadow: 0 2px 10px rgba(0,0,0,.4);
    padding-left: 16px;
    padding-right: 16px;
    padding-bottom: 0;
    z-index: 301;
  }
}

/* Hamburger */
.nav-hamburger {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: #1f2937;
  border: 1px solid #374151;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
  transition: background .14s;
  flex-shrink: 0;
}
.nav-hamburger:hover { background: #374151; }
.nav-hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--premium-gold, #f6ad55);
  border-radius: 2px;
  transition: transform .22s ease, opacity .18s ease;
}
.nav-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-hamburger.open span:nth-child(2) { opacity: 0; }
.nav-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Brand in topbar */
.nav-topbar-brand {
  font-family: var(--font-family-display, 'Kanit', sans-serif);
  font-size: 15px;
  font-weight: 700;
  color: var(--premium-gold, #f6ad55);
  text-decoration: none;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-topbar-brand:hover { color: #ecc94b; }

/* Right area in topbar */
.nav-topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.nav-user-name {
  font-size: 12px;
  color: #6b7280;
  white-space: nowrap;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ──────────────────────────────────────────────────────────
   BACKDROP — mobile only
   ────────────────────────────────────────────────────────── */
.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 299;
  -webkit-tap-highlight-color: transparent;
}
.nav-backdrop.open { display: block; }

/* ──────────────────────────────────────────────────────────
   LEGACY: .main-nav kept as no-op so old pages don't break
   ────────────────────────────────────────────────────────── */
.main-nav { /* no-op legacy class */ }

/* ──────────────────────────────────────────────────────────
   FAQ CHATBOT
   ────────────────────────────────────────────────────────── */
#faqBotBtn {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  right: 20px;
  z-index: 1200;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #d4a843, #b7791f);
  border: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.28);
  cursor: pointer;
  font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  transition: transform .2s, box-shadow .2s;
  color: #fff;
}
#faqBotBtn:hover { transform: scale(1.1); box-shadow: 0 6px 24px rgba(0,0,0,.35); }
#faqBotBtn .faq-badge {
  position: absolute; top: -4px; right: -4px;
  background: #e53e3e; color: #fff;
  border-radius: 50%; width: 18px; height: 18px;
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
}
#faqBotPanel {
  position: fixed;
  bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  right: 16px;
  z-index: 1200;
  width: 340px; max-width: calc(100vw - 24px);
  max-height: 70vh;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(0,0,0,.22);
  display: flex; flex-direction: column;
  overflow: hidden;
  transform: scale(.85) translateY(16px);
  transform-origin: bottom right;
  opacity: 0;
  pointer-events: none;
  transition: all .22s cubic-bezier(.4,0,.2,1);
}
#faqBotPanel.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}
.faqbot-header {
  background: linear-gradient(135deg, #1e293b, #334155);
  color: #fff;
  padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}
.faqbot-header .faqbot-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #d4a843, #b7791f);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.faqbot-header h4 { margin: 0; font-size: .9rem; font-weight: 700; }
.faqbot-header p  { margin: 2px 0 0; font-size: .72rem; color: #94a3b8; }
.faqbot-header-close {
  margin-left: auto; background: none; border: none;
  color: #94a3b8; cursor: pointer; font-size: 18px; padding: 0 4px;
  line-height: 1; transition: color .15s;
}
.faqbot-header-close:hover { color: #fff; }
.faqbot-body {
  flex: 1; overflow-y: auto;
  padding: 14px 12px;
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}
.faqbot-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: .82rem;
  line-height: 1.55;
  word-break: break-word;
}
.faqbot-bubble.bot {
  background: #f1f5f9;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  color: #1e293b;
}
.faqbot-bubble.user {
  background: linear-gradient(135deg, #d4a843, #b7791f);
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}
.faqbot-qs {
  display: flex; flex-direction: column; gap: 6px;
  margin-top: 2px;
}
.faqbot-q {
  background: #fff;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: .78rem;
  font-family: inherit;
  color: #1e40af;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all .15s;
  line-height: 1.4;
}
.faqbot-q:hover { background: #eff6ff; border-color: #93c5fd; }
.faqbot-footer {
  padding: 10px 12px;
  border-top: 1px solid #f1f5f9;
  flex-shrink: 0;
}
.faqbot-back {
  background: none; border: none;
  color: #64748b; font-size: .75rem;
  cursor: pointer; font-family: inherit;
  padding: 4px 0;
  display: flex; align-items: center; gap: 4px;
  transition: color .15s;
}
.faqbot-back:hover { color: #1e293b; }
@media (max-width: 400px) {
  #faqBotPanel { right: 8px; width: calc(100vw - 16px); }
}


/* ============================================
   Collapsible Sidebar Submenu
   ============================================ */
.nav-submenu-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 20px; color: #9ca3af; font-size: 14px; font-weight: 500;
  font-family: var(--font-family-body, 'Sarabun', sans-serif);
  cursor: pointer; border-left: 3px solid transparent;
  border-radius: 0 8px 8px 0; margin-right: 10px;
  transition: background .13s, color .13s;
  user-select: none; -webkit-tap-highlight-color: transparent;
}
.nav-submenu-toggle:hover { background: #1f2937; color: #e5e7eb; }
.nav-submenu-toggle.open { color: var(--premium-gold, #f6ad55); border-left-color: var(--premium-gold, #f6ad55); background: rgba(246,173,85,.08); }
.nav-submenu-toggle .arrow { transition: transform .2s; font-size: 11px; }
.nav-submenu-toggle.open .arrow { transform: rotate(180deg); }
.nav-submenu-toggle .nav-link-desc { display: block; font-size: 10.5px; font-weight: 400; color: #4b5563; }
.nav-submenu-items { display: none; padding: 2px 0 6px 16px; }
.nav-submenu-items.open { display: block; }
.nav-submenu-items li a { font-size: 13px; padding: 6px 16px; }
.nav-submenu-items li a .nav-link-desc { font-size: 10px; padding-left: 18px; }

/* ============================================
   Accessibility — Nav link size override
   ============================================ */
body.text-scale-lg .nav-link { padding: 14px 20px; font-size: 1.1rem; }
body.text-scale-lg .nav-link-desc { font-size: 0.85rem; }
body.text-scale-lg .sidebar-user-name { font-size: 1.15rem; }

body.text-scale-xl .nav-link { padding: 16px 20px; font-size: 1.3rem; }
body.text-scale-xl .nav-link-desc { font-size: 1rem; }
body.text-scale-xl .sidebar-user-name { font-size: 1.35rem; }