/* ==========================================
   STOCK MANAGEMENT SYSTEM - WHITE & FOREST GREEN THEME
   Version 4.2 - Natural, Professional & Modern
   ========================================== */
@import url('loader2.css');
@import url('animate-ui.css');

/* ==========================================
   CSS VARIABLES - White with Forest Green
   ========================================== */
:root {
  /* Corporate Olive Colors - Custom Deep */
  --primary-green: #3a5a40;
  --primary-green-dark: #2c4c3b;
  --primary-green-darker: #1a2e22;
  --primary-green-light: #588157;
  --green-50: #f0f7f4;
  --green-100: #d8e5dc;
  --green-200: #b0ccb9;
  --green-300: #88b396;
  --green-400: #588157;
  --green-500: #3a5a40;
  --green-600: #2c4c3b;
  --green-700: #1a2e22;
  --green-800: #122118;
  --green-900: #0a110c;

  --accent-sage: #8a9a5b;
  --accent-moss: #7e8f4f;
  --accent-clay: #9c7a5e;

  --accent-warm: #c9a57b;
  --accent-warm-light: #e0cfb8;
  --accent-warm-dark: #a88b60;
  --accent-cool: #7c8e98;
  --accent-cool-light: #99acb5;
  --accent-earth: #8b7d6b;
  --accent-earth-light: #a69989;

  --gradient-primary: linear-gradient(135deg, #3a5a40 0%, #2c4c3b 100%);
  --gradient-success: linear-gradient(135deg, #588157 0%, #3a5a40 100%);
  --gradient-light: linear-gradient(135deg, #f0f7f4 0%, #d8e5dc 100%);

  --gradient-forest-rich: linear-gradient(135deg, #3a5a40 0%, #1a2e22 100%);
  --gradient-warm-forest: linear-gradient(135deg, #588157 0%, #3a5a40 100%);
  --gradient-sidebar: linear-gradient(180deg, #2c4c3b 0%, #1a2e22 100%);
  --bg-gradient-subtle: linear-gradient(135deg, #ffffff 0%, #f6f7f5 100%);

  /* Themed menu dropdown (dropdown2) */
  --dropdown2-trigger-bg: rgba(0, 0, 0, 0.22);
  --dropdown2-menu-bg: #243d30;
  --dropdown2-menu-bg-light: var(--white);
  --dropdown2-text: #ffffff;
  --dropdown2-text-muted: rgba(255, 255, 255, 0.72);
  --dropdown2-link-text: var(--gray-800);
  --dropdown2-accent: var(--green-300);
  --dropdown2-border: rgba(255, 255, 255, 0.14);
  --dropdown2-shadow: 0 8px 24px rgba(10, 17, 12, 0.35);

  --white: #ffffff;
  --neutral-warm-bg: #fdfdfc;
  --neutral-50: #fbfbfc;
  --neutral-100: #f5f5f4;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  --bg-main: radial-gradient(125% 125% at 50% 10%, #ffffff 55%, #b7dcc0 100%);
  --bg-card: rgba(255, 255, 255, 0.99);
  --bg-glass: rgba(255, 255, 255, 0.6);

  --shadow-xs: 0 1px 2px rgba(82, 96, 66, 0.06);
  --shadow-sm: 0 2px 8px rgba(82, 96, 66, 0.1);
  --shadow-md: 0 4px 12px rgba(82, 96, 66, 0.12);
  --shadow-lg: 0 10px 25px rgba(82, 96, 66, 0.15);
  --shadow-xl: 0 20px 40px rgba(82, 96, 66, 0.18);
  --shadow-glow: 0 0 20px rgba(82, 96, 66, 0.25);

  --shadow-soft: 0 2px 8px rgba(82, 96, 66, 0.08), 0 1px 3px rgba(82, 96, 66, 0.06);
  --shadow-medium: 0 4px 12px rgba(82, 96, 66, 0.12), 0 2px 6px rgba(82, 96, 66, 0.08);
  --shadow-strong: 0 8px 24px rgba(82, 96, 66, 0.15), 0 4px 12px rgba(82, 96, 66, 0.1);
  --shadow-premium: 0 20px 60px rgba(82, 96, 66, 0.18), 0 8px 24px rgba(82, 96, 66, 0.12);
  --shadow-warm: 0 4px 16px rgba(201, 165, 123, 0.1);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-2xl: 32px;

  --transition-fast: 0.2s cubic-bezier(0.33, 1, 0.68, 1);
  --transition-normal: 0.35s cubic-bezier(0.33, 1, 0.68, 1);
  --transition-slow: 0.5s cubic-bezier(0.33, 1, 0.68, 1);
}

/* ==========================================
   DARK MODE THEME
   ========================================== */
[data-theme='dark'] {
  --primary-green: #6b7d56;
  --primary-green-dark: #526042;
  --primary-green-darker: #3e4a32;
  --primary-green-light: #8a9e75;

  --white: #1a1c18;
  --neutral-warm-bg: #141612;
  --neutral-50: #222620;
  --neutral-100: #2d3329;

  --gray-50: #1a1d18;
  --gray-100: #262b24;
  --gray-200: #333a30;
  --gray-300: #4a5446;
  --gray-400: #889482;
  --gray-500: #9bad6f;
  --gray-600: #c1ccab;
  --gray-700: #e2e8d5;
  --gray-800: #f4f7f0;
  --gray-900: #ffffff;

  --bg-main: linear-gradient(135deg, #141612 0%, #1a1c18 100%);
  --bg-card: rgba(34, 38, 32, 0.95);
  --bg-glass: rgba(34, 38, 32, 0.8);

  --gradient-sidebar: linear-gradient(180deg, #1a1c18 0%, #141612 100%);
  --bg-gradient-subtle: linear-gradient(135deg, #1a1c18 0%, #222620 100%);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.6);
  --shadow-soft: 0 2px 8px rgba(0, 0, 0, 0.3);

  --input-bg: #222620;
}

/* ==========================================
   RESET & BASE
   ========================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Kanit', 'Sarabun', 'Noto Sans Thai', 'Leelawadee UI', Tahoma, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-main);
  background-attachment: fixed;
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ฟอร์มคอนโทรลไม่สืบทอด font-family เองโดยดีฟอลต์ของเบราว์เซอร์
   → บังคับให้ปุ่มแท็บ/แท็บย่อย (<button>), input, select, textarea ใช้ Kanit ตาม body */
button, input, select, textarea, optgroup {
  font-family: inherit;
}

html {
  scroll-behavior: smooth;
}

/* ==========================================
   APP CONTAINER & SIDEBAR LAYOUT
   ========================================== */
.app-container {
  display: flex;
  min-height: 100vh;
  position: relative;
}

.sidebar {
  width: 250px;
  min-width: 250px;
  background: var(--gradient-sidebar);
  color: white;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: width 0.3s ease, min-width 0.3s ease;
  z-index: 1000;
}

.sidebar.collapsed {
  width: 80px;
  min-width: 80px;
}

/* ★ จุดที่ 1: ไม่ต้องแก้ - overflow-y: auto อยู่แล้ว */
.main-content {
  flex: 1;
  padding: 24px;
  background: var(--bg-main);
  min-width: 0;
  overflow-x: auto;
  overflow-y: auto;
}

.app-container.sidebar-collapsed .main-content {
  margin-left: 0;
}

/* Mobile Sidebar */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -250px;
    width: 250px;
    z-index: 1100;
    transition: left 0.3s ease;
  }

  .sidebar.mobile-open {
    left: 0;
  }

  .main-content {
    margin-left: 0 !important;
  }

  .app-container {
    flex-direction: column;
  }
}

/* Sidebar Components */
.sidebar-toggle-btn {
  position: absolute;
  right: 10px;
  top: 20px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  z-index: 100;
}

.sidebar-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 2rem;
  line-height: 1;
}

.logo-text {
  flex: 1;
  min-width: 0;
}

.logo-title {
  font-size: 1.125rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logo-subtitle {
  font-size: 0.8125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Animated gradient — sidebar brand (theme forest greens + white) */
.sidebar-header .logo-title,
.sidebar-header .logo-subtitle,
.animate-character {
  background-image: linear-gradient(
    -225deg,
    #ffffff 0%,
    var(--green-50) 18%,
    var(--green-100) 38%,
    var(--green-200) 52%,
    var(--green-300) 68%,
    var(--accent-warm-light) 82%,
    var(--green-100) 94%,
    #ffffff 100%
  );
  background-size: 200% auto;
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: logo-textclip 6s ease-in-out infinite;
  display: inline-block;
  max-width: 100%;
}

[data-theme='dark'] .sidebar-header .logo-title,
[data-theme='dark'] .sidebar-header .logo-subtitle,
[data-theme='dark'] .animate-character {
  background-image: linear-gradient(
    -225deg,
    var(--gray-800) 0%,
    var(--gray-700) 22%,
    var(--gray-600) 42%,
    var(--gray-500) 58%,
    var(--accent-warm-light) 76%,
    var(--gray-700) 92%,
    var(--gray-800) 100%
  );
}

.sidebar-header .logo-icon {
  display: inline-block;
  animation: logo-icon-float 6s ease-in-out infinite;
}

@keyframes logo-textclip {
  to {
    background-position: 200% center;
  }
}

@keyframes logo-icon-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-3px);
  }
}

.sidebar.collapsed .logo-text {
  display: none;
}

.sidebar-menu {
  flex: 1;
  padding: 10px 0;
  overflow-y: auto;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  transition: all 0.3s ease;
  cursor: pointer;
  border-left: 3px solid transparent;
}

.menu-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border-left-color: rgba(255, 255, 255, 0.5);
}

.menu-item.active {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border-left-color: white;
  font-weight: 600;
}

.menu-icon {
  font-size: 1.25rem;
  min-width: 24px;
  text-align: center;
}

.menu-section-title {
  padding: 16px 20px 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.5);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.user-info {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.user-info-name {
  font-weight: 600;
  color: white;
  font-size: 0.875rem;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-info-role {
  font-size: 0.8125rem;
  color: rgba(255, 255, 255, 0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.footer-btn {
  flex: none;
  width: 100%;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
}

.footer-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.footer-btn-icon {
  font-size: 1rem;
}

.sidebar.collapsed .footer-btn-text,
.sidebar.collapsed .user-info-name,
.sidebar.collapsed .user-info-role,
.sidebar.collapsed .menu-section-title {
  display: none;
}

/* ==========================================
   ANIMATIONS
   ========================================== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px) translateZ(0);
  }

  to {
    opacity: 1;
    transform: translateY(0) translateZ(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-30px) translateZ(0);
  }

  to {
    opacity: 1;
    transform: translateX(0) translateZ(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateZ(0);
  }

  to {
    opacity: 1;
    transform: scale(1) translateZ(0);
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg) translateZ(0);
  }

  100% {
    transform: rotate(360deg) translateZ(0);
  }
}

@keyframes pulse {

  0%,
  100% {
    transform: scale(1) translateZ(0);
    opacity: 1;
  }

  50% {
    transform: scale(1.05) translateZ(0);
    opacity: 0.9;
  }
}

@keyframes shimmer {
  0% {
    background-position: -1000px 0;
  }

  100% {
    background-position: 1000px 0;
  }
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0px) translateZ(0);
  }

  50% {
    transform: translateY(-10px) translateZ(0);
  }
}

/* ==========================================
   CONTAINER & LAYOUT
   ========================================== */
.container {
  max-width: 95%;
  margin: 0 auto;
  padding: 24px 20px;
  opacity: 1 !important;
  visibility: visible !important;
}

/* ==========================================
   HEADER
   ========================================== */
.header {
  background: var(--site-surface, rgba(255, 255, 255, 0.98));
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  padding: 32px;
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg);
  margin-bottom: 24px;
  border: 1px solid rgba(88, 129, 87, 0.1);
  position: relative;
  overflow: hidden;
  animation: fadeIn 0.4s ease;
}

.header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--gradient-primary);
}

.header h1 {
  color: var(--primary-green);
  font-size: 2rem;
  margin-bottom: 8px;
  font-weight: 800;
  letter-spacing: -0.025em;
}

.header p {
  color: var(--gray-600);
  font-size: 0.9375rem;
  font-weight: 500;
}

/* ==========================================
   NAVIGATION
   ========================================== */
.nav {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 20px;
}

.nav-btn {
  padding: 12px 24px;
  background: var(--white);
  color: var(--primary-green);
  border: 2px solid var(--green-200);
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all var(--transition-normal);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.nav-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--gradient-primary);
  opacity: 0;
  transition: opacity var(--transition-normal);
  z-index: -1;
}

.nav-btn:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-green);
  color: var(--white);
}

.nav-btn:hover::before {
  opacity: 1;
}

.nav-btn:active {
  transform: translateY(-1px);
}

.back-link {
  padding: 12px 24px;
  background: var(--site-surface, rgba(255, 255, 255, 0.95));
  color: var(--gray-700);
  border: 2px solid var(--gray-300);
  text-decoration: none;
  border-radius: var(--radius-lg);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-sm);
}

.back-link:hover {
  background: var(--white);
  border-color: var(--primary-green);
  transform: translateX(-5px);
  box-shadow: var(--shadow-md);
}

/* ==========================================
   CARDS
   ========================================== */
.card {
  background: linear-gradient(to bottom, var(--site-surface, rgba(255, 255, 255, 0.95)), rgba(253, 251, 247, 0.95));
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  padding: 32px;
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-soft), 0 10px 30px rgba(58, 90, 64, 0.05), inset 0 -1px 0 rgba(58, 90, 64, 0.04);
  border: 1px solid rgba(58, 90, 64, 0.1);
  margin-bottom: 24px;
  animation: scaleIn 0.5s cubic-bezier(0.25, 0.8, 0.25, 1);
  transition: transform var(--transition-normal),
    box-shadow var(--transition-normal),
    border-color var(--transition-normal);
  position: relative;
  overflow: hidden;
  transform: translateZ(0);
  will-change: transform;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--gradient-primary);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--transition-normal);
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-medium), 0 20px 40px rgba(58, 90, 64, 0.08);
  border-color: rgba(58, 90, 64, 0.15);
}

.card:hover::before {
  transform: scaleX(1);
}

.card h2 {
  color: var(--primary-green);
  margin-bottom: 24px;
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.01em;
}

/* ==========================================
   STATS GRID
   ========================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  background: var(--white);
  padding: 28px;
  border-radius: var(--radius-xl);
  text-align: center;
  transition: transform var(--transition-normal),
    box-shadow var(--transition-normal);
  animation: scaleIn 0.5s cubic-bezier(0.25, 0.8, 0.25, 1);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--neutral-100);
  border-top: 3px solid var(--primary-green);
  transform: translateZ(0);
  will-change: transform;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  background: linear-gradient(135deg, rgba(58, 90, 64, 0.03) 0%, transparent 100%);
  opacity: 0;
  transition: opacity var(--transition-normal);
  z-index: 0;
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, rgba(88, 129, 87, 0.08) 0%, transparent 70%);
  transform: translate(-50%, -50%) scale(0) translateZ(0);
  transition: transform var(--transition-normal);
  border-radius: 50%;
  z-index: 0;
}

.stat-card:hover {
  transform: translateY(-8px) translateZ(0);
  box-shadow: var(--shadow-medium), 0 12px 28px rgba(58, 90, 64, 0.08);
}

.stat-card:hover::before {
  opacity: 1;
}

.stat-card:hover::after {
  transform: translate(-50%, -50%) scale(1) translateZ(0);
}

.stat-card:nth-child(4n+1) {
  border-top-color: var(--primary-green);
  background: linear-gradient(135deg, var(--site-raised, #f0f7f4) 0%, var(--site-surface, #ffffff) 100%);
}

.stat-card:nth-child(4n+2) {
  border-top-color: #2f7cb0;
  background: linear-gradient(135deg, var(--site-raised, #eef5f9) 0%, var(--site-surface, #ffffff) 100%);
}

.stat-card:nth-child(4n+3) {
  border-top-color: var(--primary-green);
  background: linear-gradient(135deg, var(--site-raised, #f0f7f4) 0%, var(--site-surface, #ffffff) 100%);
}

.stat-card:nth-child(4n) {
  border-top-color: #2f7cb0;
  background: linear-gradient(135deg, var(--site-raised, #eef5f9) 0%, var(--site-surface, #ffffff) 100%);
}

.stat-value {
  font-size: 2.5rem;
  font-weight: 800;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
  position: relative;
  z-index: 1;
}

.stat-label {
  color: var(--gray-600);
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  position: relative;
  z-index: 1;
}

/* ==========================================
   BUTTONS
   ========================================== */
.btn {
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 600;
  transition: transform var(--transition-normal),
    box-shadow var(--transition-normal),
    background-color var(--transition-normal),
    color var(--transition-normal);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
  transform: translateZ(0);
}

.btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width var(--transition-normal), height var(--transition-normal);
}

.btn:hover::before {
  width: 300px;
  height: 300px;
}

.btn:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.btn:active {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--gradient-forest-rich);
  color: white;
  box-shadow: var(--shadow-soft), inset 0 1px 0 rgba(255, 255, 255, 0.2), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

.btn-success {
  background: var(--gradient-success);
  color: white;
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: white;
}

.btn-secondary {
  background: linear-gradient(135deg, var(--site-surface, rgba(255, 255, 255, 0.95)), rgba(250, 250, 249, 0.95));
  color: var(--gray-700);
  border: 2px solid rgba(58, 90, 64, 0.2);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.btn-secondary:hover {
  background: linear-gradient(135deg, var(--site-raised, #fdfbf7) 0%, var(--site-raised, #f5f5f4) 100%);
  border-color: var(--primary-green);
  box-shadow: var(--shadow-soft), var(--shadow-warm);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ==========================================
   TABLES
   ========================================== */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

thead {
  background: linear-gradient(135deg, #588157 0%, #3a5a40 50%, #2c4c3b 100%);
  color: white;
  box-shadow: var(--shadow-soft), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

thead th {
  padding: 16px 18px;
  text-align: left;
  font-weight: 700;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tbody tr {
  border-bottom: 1px solid var(--gray-100);
  transition: background-color var(--transition-fast), transform var(--transition-fast);
  transform: translateZ(0);
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:hover {
  background: linear-gradient(90deg, rgba(88, 129, 87, 0.05) 0%, rgba(58, 90, 64, 0.05) 100%);
}

tbody td {
  padding: 16px 18px;
  color: var(--gray-700);
  font-size: 0.9375rem;
}

tbody td strong {
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 700;
}

/* ==========================================
   BADGES
   ========================================== */
.badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  box-shadow: var(--shadow-sm);
}

.badge-success {
  background: var(--gradient-success);
  color: white;
}

.badge-danger {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: white;
}

.badge-warning {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: white;
}

.badge-info {
  background: var(--gradient-warm-forest);
  color: white;
}

.badge-normal {
  background: var(--gray-200);
  color: var(--gray-700);
}

.badge-primary {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: white;
}

.badge-secondary {
  background: linear-gradient(135deg, #64748b 0%, #475569 100%);
  color: white;
}

.badge-staff {
  background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
  color: white;
}

/* ==========================================
   FORMS
   ========================================== */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: var(--gray-700);
  font-weight: 600;
  font-size: 0.875rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius-lg);
  font-size: 0.9375rem;
  transition: all var(--transition-normal);
  background: var(--white);
  color: var(--gray-800);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-green);
  box-shadow: 0 0 0 4px rgba(58, 90, 64, 0.12), var(--shadow-soft), inset 0 1px 2px rgba(212, 165, 116, 0.05);
  transform: translateY(-1px) translateZ(0);
  background: rgba(253, 251, 247, 0.5);
}

.form-group textarea {
  resize: vertical;
  min-height: 100px;
  font-family: inherit;
}

/* ==========================================
   SEARCH BOX
   ========================================== */
.search-box {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-box input,
.search-box select {
  padding: 14px 16px;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius-lg);
  font-size: 0.9375rem;
  transition: all var(--transition-normal);
  background: var(--white);
}

.search-box input {
  flex: 1;
  min-width: 250px;
}

.search-box input:focus,
.search-box select:focus {
  outline: none;
  border-color: var(--primary-green);
  box-shadow: 0 0 0 4px rgba(88, 129, 87, 0.1);
}

/* ==========================================
   MODALS
   ========================================== */
.modal {
  display: none;
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(26, 107, 26, 0.4);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal.show {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  animation: fadeIn 0.3s ease-out;
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: linear-gradient(to bottom, var(--site-surface, rgba(255, 255, 255, 0.98)), rgba(253, 251, 247, 0.98));
  -webkit-backdrop-filter: blur(40px);
  backdrop-filter: blur(40px);
  padding: 36px;
  border-radius: var(--radius-2xl);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-premium), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(58, 90, 64, 0.15);
  animation: scaleIn 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
  position: relative;
  transform: translateZ(0);
  scrollbar-gutter: stable;
}

.modal-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--gradient-primary);
}

.modal-content h2 {
  color: var(--primary-green);
  margin-bottom: 24px;
  font-size: 1.75rem;
  font-weight: 700;
  margin-right: 44px;
}

/* Compact styling for cycle-count round creation options */
.count-round-panel {
  background: var(--green-50);
  border: 2px solid var(--primary-green);
  border-radius: 10px;
  padding: 12px;
  margin-top: 12px;
}

.simple-choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 8px;
}

.simple-choice-card {
  display: block;
  padding: 10px 12px;
  background: var(--ds-surface, #ffffff);
  border: 2px solid var(--gray-200, #e5e7eb);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.simple-choice-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
  margin: 0;
}

input[name="simpleScope"],
input[name="simpleAssign"],
input[name="simpleDistribution"] {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  width: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  pointer-events: none !important;
}

.simple-choice-card:hover {
  border-color: var(--site-info-border, #93c5fd);
  background: var(--site-raised, #f8fbff);
}

.simple-choice-card:has(input:checked) {
  border-color: #588157;
  background: linear-gradient(180deg, var(--site-raised, #f0f7f4) 0%, var(--site-raised, #f0f7f4) 100%);
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.35), 0 0 0 6px rgba(34, 197, 94, 0.12);
}

.modal-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(58, 90, 64, 0.25);
  background: var(--site-raised, #f7faf7);
  color: var(--site-text, #1a2e22);
  font-size: 1.35rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.modal-close-btn:hover {
  transform: translateY(-1px);
  background: var(--ds-surface, #ffffff);
  color: var(--site-text, #1a2e22);
  box-shadow: 0 8px 16px rgba(20, 83, 45, 0.18);
}

.modal-close-btn:focus-visible {
  outline: 3px solid rgba(22, 101, 52, 0.3);
  outline-offset: 2px;
}

/* ==========================================
   TABS
   ========================================== */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  background: var(--gray-100);
  padding: 6px;
  border-radius: var(--radius-xl);
}

.tab {
  padding: 12px 24px;
  background: transparent;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--gray-600);
  transition: background-color var(--transition-normal),
    color var(--transition-normal);
  transform: translateZ(0);
}

.tab:hover {
  background: rgba(255, 255, 255, 0.5);
  color: var(--gray-800);
}

.tab.active {
  background: var(--white);
  color: var(--primary-green);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.4s ease;
}

/* ==========================================
   LOADING SPINNER
   ========================================== */
/* Legacy .spinner — upgraded to .loader2 via Utils.upgradeAllLoaders() in utils.js */
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--gray-200);
  border-top: 4px solid var(--primary-green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

#loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-main);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
}

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.8);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.loading-overlay.hidden {
  display: none;
}

/* ==========================================
   CHARTS
   ========================================== */
.chart-container {
  position: relative;
  height: 300px;
  margin: 20px 0;
}

/* ==========================================
   UTILITIES
   ========================================== */
.text-center {
  text-align: center;
}

.overflow-auto {
  overflow-x: auto;
}

.hidden {
  display: none !important;
}

/* ==========================================
   FORM GRID
   ========================================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 18px;
}

/* ==========================================
   WORKFLOW STEPS (Receiving)
   ========================================== */
.workflow-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin: 20px 0;
}

.workflow-step {
  background: var(--white);
  padding: 24px;
  border-radius: var(--radius-xl);
  border: 2px solid var(--gray-200);
  text-align: center;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-sm);
}

.workflow-step.active {
  border-color: var(--primary-green);
  background: linear-gradient(135deg, rgba(88, 129, 87, 0.05) 0%, rgba(58, 90, 64, 0.05) 100%);
  box-shadow: var(--shadow-md);
}

.workflow-step .step-number {
  width: 48px;
  height: 48px;
  background: var(--gray-200);
  color: var(--gray-700);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  font-weight: 800;
  font-size: 1.25rem;
  transition: all var(--transition-normal);
}

.workflow-step.active .step-number {
  background: var(--gradient-primary);
  color: white;
  animation: pulse 2s infinite;
}

/* ==========================================
   SEARCH DROPDOWN (Receiving)
   ========================================== */
.search-results-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--white);
  border: 2px solid var(--primary-green);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  max-height: 300px;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
  margin-top: -12px;
}

.search-result-item {
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--gray-100);
  transition: all var(--transition-fast);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: linear-gradient(90deg, rgba(88, 129, 87, 0.08) 0%, rgba(58, 90, 64, 0.08) 100%);
  transform: translateX(5px);
}

.search-result-item div:first-child {
  font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}

.search-result-item div:nth-child(2) {
  font-size: 0.875rem;
  color: var(--gray-700);
  margin-bottom: 2px;
}

.search-result-item div:nth-child(3) {
  font-size: 0.8125rem;
  color: var(--gray-500);
}

/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 768px) {
  .container {
    padding: 16px 12px;
  }

  .header {
    padding: 24px 20px;
  }

  .header h1 {
    font-size: 1.5rem;
  }

  .nav {
    flex-direction: column;
  }

  .nav-btn {
    width: 100%;
    justify-content: center;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 24px;
  }

  .tabs {
    flex-direction: column;
  }

  .tab {
    width: 100%;
  }

  .search-box {
    flex-direction: column;
  }

  .search-box input,
  .search-box select {
    width: 100%;
  }

  .workflow-steps {
    grid-template-columns: 1fr;
  }

  table {
    font-size: 0.8125rem;
  }

  thead th,
  tbody td {
    padding: 12px 14px;
  }
}

@media (max-width: 480px) {
  .stat-value {
    font-size: 2rem;
  }

  .header h1 {
    font-size: 1.25rem;
  }

  .modal-content {
    padding: 24px;
  }
}

/* ==========================================
   COLLAPSIBLE SIDEBAR STYLES - REFINED
   ========================================== */

/* Sidebar Toggle Button - Floating Action Style */
.sidebar-toggle-btn {
  position: absolute;
  top: 24px;
  right: -16px;
  width: 32px;
  height: 32px;
  background: var(--gradient-primary);
  border: 2px solid white;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.2rem;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all var(--transition-normal);
}

.sidebar-toggle-btn:hover {
  transform: scale(1.15) rotate(180deg);
  box-shadow: 0 6px 16px rgba(58, 90, 64, 0.3);
  background: var(--primary-green-dark);
}

.sidebar-toggle-btn:active {
  transform: scale(0.95);
}

/* Base Sidebar */
.app-container {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

.app-container .sidebar {
  width: 260px;
  background: var(--gradient-sidebar);
  color: white;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  position: relative;
  transition: width var(--transition-slow);
  z-index: 50;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
  overflow: visible;
  min-height: 0;
}

.app-container .sidebar::before {
  display: none;
}

/* Header */
.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all var(--transition-normal);
}

.logo-img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  filter: brightness(0) invert(1);
  transition: all var(--transition-normal);
}

.logo-text {
  display: flex;
  flex-direction: column;
  transition: opacity 0.2s ease;
}

.logo-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.2;
}

.logo-subtitle {
  font-size: 0.8125rem;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Menu Section */
.sidebar-menu {
  flex: 1;
  padding: 10px 12px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.menu-section-title {
  padding: 12px 16px 8px;
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.5);
  margin-top: 8px;
  white-space: nowrap;
  transition: opacity 0.2s ease;
}

/* Menu Items */
.menu-item {
  padding: 12px 16px;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 12px;
  color: rgba(255, 255, 255, 0.8);
  border-radius: 10px;
  text-decoration: none;
  font-size: 0.925rem;
  font-weight: 500;
  margin-bottom: 4px;
  border: 1px solid transparent;
}

.menu-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  transform: translateX(4px);
}

.menu-item.active {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border: none;
  border-left: 3px solid #85a836;
}

.menu-icon {
  font-size: 1.25rem;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition-normal);
}

/* Footer Section */
.user-info {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.user-info-name {
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
}

.user-info-role {
  font-size: 0.8125rem;
  opacity: 0.7;
  white-space: nowrap;
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: transparent;
}

/* ★ จุดที่ 2: แก้ overflow-x: hidden → auto */
.main-content {
  flex: 1;
  height: 100%;
  overflow-y: auto;
  overflow-x: auto;
  /* ★ FIXED: changed from hidden to auto */
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Footer Buttons */
.footer-btn {
  flex: none;
  width: 100%;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: white;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 0 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.footer-btn-icon {
  font-size: 1.1rem;
}

.footer-btn-refresh:hover {
  background: rgba(88, 129, 87, 0.25);
  border-color: rgba(88, 129, 87, 0.5);
}

.footer-btn-logout:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: rgba(239, 68, 68, 0.5);
}

/* ==========================================
   COLLAPSED STATE
   ========================================== */
.app-container .sidebar.collapsed {
  width: 80px;
}

.app-container .sidebar.collapsed .logo-text,
.app-container .sidebar.collapsed .logo-subtitle,
.app-container .sidebar.collapsed .menu-item span:not(.menu-icon),
.app-container .sidebar.collapsed .menu-section-title,
.app-container .sidebar.collapsed .user-info-name,
.app-container .sidebar.collapsed .user-info-role,
.app-container .sidebar.collapsed .footer-btn-text,
.app-container .sidebar.collapsed .sidebar-header p {
  opacity: 0;
  visibility: hidden;
  width: 0;
  height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  position: absolute;
  transition: opacity 0.2s cubic-bezier(0.33, 1, 0.68, 1), width 0s linear 0.2s, height 0s linear 0.2s, padding 0s linear 0.2s, margin 0s linear 0.2s;
}

.app-container .sidebar.collapsed .sidebar-header {
  padding: 24px 0;
  display: flex;
  justify-content: center;
}

.app-container .sidebar.collapsed .logo-container {
  gap: 0;
  justify-content: center;
}

.app-container .sidebar.collapsed .logo-img {
  width: 44px;
  height: 44px;
}

.app-container .sidebar.collapsed .menu-item {
  padding: 14px 0;
  justify-content: center;
  margin-bottom: 8px;
  border-radius: 12px;
}

.app-container .sidebar.collapsed .menu-item:hover {
  background: var(--green-100);
  transform: none;
}

.app-container .sidebar.collapsed .menu-icon {
  font-size: 1.6rem;
  margin: 0;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

/* Tooltips */
.app-container .sidebar.collapsed .menu-item {
  position: relative;
}

.app-container .sidebar.collapsed .menu-item::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 70px;
  top: 50%;
  transform: translateY(-50%) translateX(-10px);
  background: var(--gray-900);
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 1001;
}

.app-container .sidebar.collapsed .menu-item:hover::after {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
  visibility: visible;
}

/* Transition Logic for Sidebar Content */
.sidebar-header h1,
.sidebar-header p,
.logo-text,
.menu-item span:not(.menu-icon),
.menu-section-title,
.user-info-name,
.user-info-role,
.footer-btn-text {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s cubic-bezier(0.33, 1, 0.68, 1) 0.2s;
}

.menu-item span,
.logo-text,
.user-info-name {
  white-space: nowrap;
}

/* Footer Adjustments — collapsed: icon-only circles */
.app-container .sidebar.collapsed .sidebar-footer {
  padding: 12px 8px;
  gap: 8px;
  align-items: center;
}

.app-container .sidebar.collapsed .footer-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  justify-content: center;
}

.app-container .sidebar.collapsed .footer-btn-icon {
  font-size: 1.3rem;
}

.app-container .sidebar.collapsed .user-info {
  display: flex !important;
  justify-content: center;
  padding: 16px 0;
}

.app-container .sidebar.collapsed .user-info::before {
  content: '👤';
  font-size: 1.5rem;
  opacity: 0.8;
}

/* Responsive adjustment */
@media (max-width: 768px) {
  .app-container .sidebar {
    position: fixed;
    height: 100%;
    left: -280px;
    transform: none;
  }

  .app-container .sidebar.mobile-open {
    left: 0;
    transform: none;
  }

  .app-container .sidebar.collapsed {
    width: min(85vw, 280px);
    left: -280px;
    padding: 0;
    overflow: hidden;
  }
}

/* ==========================================
   RESPONSIVE OVERRIDES - ENHANCED
   ========================================== */

/* --- Tablet (768px - 1024px) --- */
@media (min-width: 769px) and (max-width: 1024px) {
  .container {
    padding: 20px;
    max-width: 95%;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }

  .chart-grid {
    grid-template-columns: 1fr;
  }

  .workflow-steps {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }

  .workflow-step {
    padding: 16px;
  }
}

/* --- Large Desktop (> 1600px) --- */
@media (min-width: 1601px) {
  .container {
    max-width: 1800px;
    padding: 30px;
  }

  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 30px;
  }

  .chart-container {
    height: 400px;
  }

  .card {
    padding: 40px;
  }

  html {
    font-size: 18px;
  }
}

/* --- Mobile Improvements (< 768px) --- */
@media (max-width: 768px) {
  .container {
    padding: 16px 12px;
    width: 100%;
    margin: 0;
  }

  .app-container .sidebar {
    z-index: 1000;
  }

  /* ★ จุดที่ 4: แก้ overflow-x: hidden → auto */
  .main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: auto;
    /* ★ FIXED: changed from hidden to auto */
    height: 100%;
    position: relative;
  }

  /* Better Table Scrolling */
  .table-responsive,
  .overflow-auto,
  div[style*="overflow-x: auto"] {
    max-width: 100vw;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 20px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
  }

  /* Stack Filters */
  .search-box {
    flex-direction: column;
    gap: 10px;
  }

  .search-box input,
  .search-box select,
  .search-box button {
    width: 100%;
    min-width: 0;
  }

  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  .btn,
  button,
  .nav-btn {
    min-height: 48px;
  }

  .card {
    padding: 20px;
    margin-bottom: 16px;
  }
}

/* --- Print Styles --- */
@media print {

  .sidebar,
  .footer,
  .btn,
  .no-print {
    display: none !important;
  }

  .main-content {
    margin-left: 0 !important;
    padding: 0 !important;
  }

  .card {
    box-shadow: none;
    border: 1px solid var(--site-border, #ddd);
  }

  body {
    background: var(--ds-surface, #ffffff);
  }
}

::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: var(--gray-100);
  border-radius: 6px;
}

::-webkit-scrollbar-thumb {
  background: var(--gradient-primary);
  border-radius: 6px;
  transition: all var(--transition-normal);
}

::-webkit-scrollbar-thumb:hover {
  box-shadow: var(--shadow-glow);
}

/* ==========================================
   PRINT STYLES
   ========================================== */
@media print {
  body {
    background: var(--ds-surface, #ffffff);
  }

  .nav,
  .nav-btn,
  button,
  .btn {
    display: none !important;
  }

  .card {
    box-shadow: none;
    border: 1px solid var(--gray-300);
    break-inside: avoid;
  }
}

/* ==========================================
   BUTTONS & INPUTS STANDARDIZATION
   ========================================== */

/* Base Button */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 1.25rem;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.9375rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  gap: 8px;
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn:active {
  transform: translateY(0);
}

/* Button Variants */
.btn-primary {
  background: var(--gradient-primary);
  color: white;
  border: none;
}

.btn-primary:hover {
  background: var(--gradient-success);
  box-shadow: 0 4px 12px rgba(58, 90, 64, 0.25);
}

.btn-secondary {
  background: var(--ds-surface, #ffffff);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}

.btn-secondary:hover {
  background: var(--gray-50);
  border-color: var(--gray-400);
  color: var(--gray-900);
}

.btn-danger {
  background: var(--site-danger-bg, #fee2e2);
  color: var(--site-danger, #991b1b);
  border: 1px solid var(--site-danger-border, #fecaca);
}

.btn-danger:hover {
  background: var(--site-danger-bg, #fecaca);
  color: var(--site-danger, #7f1d1d);
}

.btn-success {
  background: var(--site-raised, #d8e5dc);
  color: var(--site-text, #1a2e22);
  border: 1px solid var(--site-border, #b0ccb9);
}

.btn-success:hover {
  background: var(--site-raised, #b0ccb9);
  color: var(--site-text, #1a2e22);
}

/* Button Sizes */
.btn-sm {
  height: 32px;
  padding: 0 0.75rem;
  font-size: 0.875rem;
}

.btn-lg {
  height: 48px;
  padding: 0 1.5rem;
  font-size: 1rem;
}

/* Form Inputs */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="datetime-local"],
select,
.form-control {
  height: 40px;
  padding: 0 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-300);
  background: var(--ds-surface, #ffffff);
  color: var(--gray-900);
  font-size: 0.9375rem;
  transition: all var(--transition-fast);
  width: 100%;
}

/* dropdown ภาษาไทย: height ตายตัว + ไม่มี padding แนวตั้ง ตัดสระบน-ล่าง/วรรณยุกต์
   (ยิ่งชัดกับ Kanit) → ให้สูงยืดตามเนื้อหา คง 40px เป็นพื้น + line-height มีที่หายใจ.
   ตัว compact ที่ตั้ง min-height เองไว้ (เช่น toolbar 32px) จะชนะ specificity ต่อไป */
select:not([multiple]) {
  height: auto;
  min-height: 40px;
  padding-top: 4px;
  padding-bottom: 4px;
  line-height: 1.4;
}

input:focus,
select:focus,
.form-control:focus {
  outline: none;
  border-color: var(--primary-green);
  box-shadow: 0 0 0 3px rgba(58, 90, 64, 0.15);
}

/* Input Group Utility */
.input-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Layout Utilities */
.d-flex {
  display: flex !important;
}

.align-center {
  align-items: center !important;
}

.justify-between {
  justify-content: space-between !important;
}

.justify-center {
  justify-content: center !important;
}

.gap-2 {
  gap: 0.5rem !important;
}

.gap-4 {
  gap: 1rem !important;
}

.gap-6 {
  gap: 1.5rem !important;
}

.mt-4 {
  margin-top: 1rem !important;
}

.mb-4 {
  margin-bottom: 1rem !important;
}

/* ==========================================
   DASHBOARD LAYOUT & COMPONENTS
   ========================================== */

/* ★ จุดที่ 3: แก้ overflow: hidden → overflow-y/x: auto */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  /* ★ FIXED: changed from 'overflow: hidden' to auto */
  overflow-x: auto;
  /* ★ FIXED: changed from 'overflow: hidden' to auto */
  background-color: var(--gray-100, #f3f4f6);
}

.top-bar {
  background: var(--ds-surface, #ffffff);
  padding: 16px 32px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
}

.content-area {
  flex: 1;
  padding: 24px 32px;
  overflow-y: auto;
}

/* Grid Systems */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

/* Executive KPI row (app.html) — 5 cards, ไม่ให้การ์ดที่ 5 หลุดแถวเดียวแปลก ๆ */
.dash-exec-kpi {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.dash-exec-kpi .stat-card {
  text-align: left;
  padding: 20px 22px;
  margin-bottom: 0;
  animation: none;
}

.dash-exec-kpi .stat-card::before,
.dash-exec-kpi .stat-card::after {
  display: none;
}

.dash-exec-kpi .stat-card:hover {
  transform: translateY(-3px);
}

.dash-exec-kpi .stat-card:nth-child(4n+1),
.dash-exec-kpi .stat-card:nth-child(4n+2),
.dash-exec-kpi .stat-card:nth-child(4n+3),
.dash-exec-kpi .stat-card:nth-child(4n) {
  background: var(--ds-surface, #ffffff);
  border-top-color: transparent;
}

.dash-exec-kpi .stat-value,
.dash-exec-kpi .stat-label {
  text-align: left;
}

.dash-exec-kpi .stat-card--link {
  cursor: pointer;
}

.dash-exec-kpi .stat-card--link:hover {
  box-shadow: 0 4px 14px rgba(153, 27, 27, 0.12);
}

@media (max-width: 1280px) {
  .dash-exec-kpi {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .dash-exec-kpi {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .dash-exec-kpi {
    grid-template-columns: 1fr;
  }
}

/* Card Styling */
.card {
  background: var(--ds-surface, #ffffff);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
  border: 1px solid var(--gray-200, #e5e7eb);
}

.card h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gray-800, #1f2937);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card canvas {
  width: 100% !important;
  max-height: 300px;
}

/* Stat Cards */
.stat-card {
  background: var(--ds-surface, #ffffff);
  padding: 24px;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  border: 1px solid var(--gray-200, #e5e7eb);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-green);
  line-height: 1;
  margin-bottom: 8px;
}

.stat-label {
  color: var(--gray-500, #6b7280);
  font-size: 0.875rem;
  font-weight: 500;
}

/* Search Box & Filters */
.search-box {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-box input {
  flex: 1;
  min-width: 200px;
  padding: 10px 16px;
  border: 1px solid var(--gray-300, #d1d5db);
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-box input:focus {
  border-color: var(--primary-green);
  box-shadow: 0 0 0 3px rgba(58, 90, 64, 0.1);
}

.search-box select {
  padding: 10px 16px;
  border: 1px solid var(--gray-300, #d1d5db);
  border-radius: 8px;
  background-color: var(--ds-surface, #ffffff);
  cursor: pointer;
  outline: none;
}

/* Table Styling Override */
table {
  width: 100%;
  border-collapse: collapse;
}

th {
  background: var(--gray-50, #f9fafb);
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--gray-700, #374151);
  border-bottom: 2px solid var(--gray-200, #e5e7eb);
  font-size: 0.875rem;
  white-space: nowrap;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-200, #e5e7eb);
  color: var(--gray-800, #1f2937);
  font-size: 0.9rem;
}

tr:hover {
  background-color: var(--gray-50, #f9fafb);
}

/* Utility */
.overflow-auto {
  overflow-x: auto;
}

/* ==========================================
   TOAST NOTIFICATIONS
   ========================================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.toast {
  background: var(--white);
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 8px 16px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 300px;
  max-width: 400px;
  pointer-events: auto;
  border-left: 5px solid var(--primary-green);
  animation: slideInToast 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  transition: all 0.3s ease;
  cursor: pointer;
}

.toast.toast-success {
  border-left-color: var(--primary-green-light);
}

.toast.toast-error {
  border-left-color: #ef4444;
}

.toast.toast-warning {
  border-left-color: #f59e0b;
}

.toast-icon {
  font-size: 1.25rem;
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--gray-800);
  margin-bottom: 2px;
}

.toast-message {
  font-size: 0.875rem;
  color: var(--gray-600);
}

.toast.hiding {
  opacity: 0;
  transform: translateX(100%);
}

@keyframes slideInToast {
  from {
    opacity: 0;
    transform: translateX(100%);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ==========================================
   TABLES & RESPONSIVE CONTAINERS
   ========================================== */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1rem;
  border-radius: var(--radius-md);
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.02);
}

/* Custom Scrollbar for Horizontal Tables */
.table-responsive::-webkit-scrollbar {
  height: 8px;
}

.table-responsive::-webkit-scrollbar-track {
  background: var(--gray-100);
  border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb {
  background: var(--green-300);
  border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
  background: var(--green-500);
}

/* ==========================================
   PREMIUM TABS & FORMS
   ========================================== */
.tab-container {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  padding: 6px;
  background: var(--gray-100);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  border: 1px solid var(--gray-200);
}

.tab-btn {
  flex: 1;
  padding: 12px 20px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-weight: 600;
  color: var(--gray-500);
  border-radius: var(--radius-md);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  text-align: center;
  position: relative;
  overflow: hidden;
  font-size: 0.95rem;
}

.tab-btn:hover {
  color: var(--primary-green);
  background: rgba(255, 255, 255, 0.5);
}

.tab-btn.active {
  background: var(--white);
  color: var(--primary-green);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  font-weight: 700;
}

/* Form Section Visibility Control */
.form-section {
  display: none;
  animation: fadeIn 0.3s ease;
}

.form-section.active {
  display: block;
}

.form-subsection {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-top: 24px;
  margin-bottom: 24px;
  position: relative;
}

.form-subsection::before {
  content: '';
  position: absolute;
  top: 24px;
  bottom: 24px;
  left: 0;
  width: 4px;
  color: var(--primary-green);
  background: var(--primary-green);
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}

.form-subsection h3 {
  margin-top: 0;
  margin-bottom: 20px;
  color: var(--primary-green);
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.submit-btn {
  width: 100%;
  margin-top: 24px;
  padding: 16px;
  font-size: 1.1rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: var(--gradient-forest-rich);
  position: relative;
  overflow: hidden;
  color: white;
  font-weight: 700;
  border-radius: var(--radius-lg);
}

.submit-btn:hover {
  box-shadow: 0 8px 20px rgba(58, 90, 64, 0.3);
  transform: translateY(-2px);
}

@media (min-width: 768px) {
  .submit-btn {
    width: auto;
    min-width: 250px;
    display: block;
    margin-left: auto;
  }

  /* ==========================================
     PREMIUM CHECKLIST
     ========================================== */
  .checklist-group {
    background: var(--white);
    padding: 24px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
  }

  .checklist-group:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary-green-light);
  }

  .checklist-group h3 {
    margin-top: 0;
    margin-bottom: 16px;
    color: var(--primary-green);
    font-size: 1.1rem;
    font-weight: 700;
    border-bottom: 2px solid var(--gray-100);
    padding-bottom: 12px;
  }

  .checklist-item {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
    padding: 12px 16px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    user-select: none;
  }

  .checklist-item:hover {
    background: var(--white);
    border-color: var(--primary-green);
    transform: translateX(4px);
    box-shadow: var(--shadow-xs);
  }

  .checklist-item input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
  }

  .checklist-item span::before {
    content: '';
    display: inline-block;
    width: 22px;
    height: 22px;
    border: 2px solid var(--gray-400);
    border-radius: 6px;
    margin-right: 12px;
    vertical-align: middle;
    background: var(--white);
    transition: all 0.2s ease;
    flex-shrink: 0;
  }

  .checklist-item input[type="checkbox"]:checked+span::before {
    background: var(--primary-green);
    border-color: var(--primary-green);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='var(--site-surface, white)' width='16px' height='16px'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z'/%3E%3C/svg%3E");
    background-position: center;
    background-repeat: no-repeat;
    box-shadow: 0 4px 6px rgba(88, 129, 87, 0.2);
  }

  .checklist-item input[type="checkbox"]:checked+span {
    color: var(--primary-green-dark);
    font-weight: 600;
  }

  .checklist-item span {
    display: flex;
    align-items: center;
    font-size: 0.95rem;
    color: var(--gray-700);
    width: 100%;
  }

  /* ==========================================
     INPUT VALIDATION STYLING
     ========================================== */
  .input-error {
    border-color: #ef4444 !important;
    background-color: var(--ds-danger-soft, #fef2f2) !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
  }

  @keyframes shake {

    0%,
    100% {
      transform: translateX(0);
    }

    25% {
      transform: translateX(-5px);
    }

    75% {
      transform: translateX(5px);
    }
  }

  .input-error {
    animation: shake 0.3s ease-in-out;
  }

  .input-valid {
    border-color: #588157 !important;
    background-color: var(--green-50, #f0f7f4) !important;
  }

  .error-message {
    color: var(--site-danger, #ef4444);
    font-size: 0.8125rem;
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
  }

  .error-message::before {
    content: '⚠';
    font-size: 1rem;
  }

  .success-message {
    color: var(--site-text, #588157);
    font-size: 0.8125rem;
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
  }

  .success-message::before {
    content: '✔';
    font-size: 1rem;
  }

  .readonly-input {
    background-color: var(--gray-100) !important;
    cursor: not-allowed;
    color: var(--gray-600);
  }

  .form-group.has-validation {
    position: relative;
  }

  .validation-icon {
    position: absolute;
    right: 14px;
    top: 42px;
    font-size: 1.25rem;
    pointer-events: none;
  }

  .validation-icon.valid {
    color: var(--site-text, #588157);
  }

  .validation-icon.invalid {
    color: var(--site-danger, #ef4444);
  }

  /* ==========================================
     AUTOCOMPLETE DROPDOWN STYLES
     ========================================== */
  .autocomplete-container {
    position: relative;
  }

  .autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--ds-surface, #ffffff);
    border: 2px solid var(--primary-green);
    border-top: none;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    max-height: 250px;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: none;
    margin-top: -2px;
  }

  .autocomplete-dropdown.active {
    display: block;
    animation: slideDown 0.2s ease;
  }

  @keyframes slideDown {
    from {
      opacity: 0;
      transform: translateY(-10px);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .autocomplete-item {
    padding: 12px 16px;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .autocomplete-item:last-child {
    border-bottom: none;
  }

  .autocomplete-item:hover,
  .autocomplete-item.selected {
    background: linear-gradient(90deg, rgba(58, 90, 64, 0.08) 0%, rgba(58, 90, 64, 0.05) 100%);
    color: var(--primary-green);
    font-weight: 600;
  }

  .autocomplete-item-main {
    font-weight: 500;
    color: var(--gray-800);
  }

  .autocomplete-item-secondary {
    font-size: 0.8125rem;
    color: var(--gray-500);
    font-weight: 500;
  }

  .autocomplete-item:hover .autocomplete-item-main {
    color: var(--primary-green);
  }

  .autocomplete-empty {
    padding: 16px;
    text-align: center;
    color: var(--gray-500);
    font-size: 0.875rem;
  }

  .autocomplete-dropdown::-webkit-scrollbar {
    width: 8px;
  }

  .autocomplete-dropdown::-webkit-scrollbar-track {
    background: var(--gray-100);
    border-radius: 0 0 var(--radius-lg) 0;
  }

  .autocomplete-dropdown::-webkit-scrollbar-thumb {
    background: var(--primary-green);
    border-radius: 4px;
  }

  .autocomplete-dropdown::-webkit-scrollbar-thumb:hover {
    background: var(--primary-green-dark);
  }

  /* ==========================================
     SAFETY EQUIPMENT FORM - EMPLOYEE CHECKLIST
     ========================================== */
  .employee-checklist {
    max-height: 400px;
    overflow-y: auto;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 16px;
    background: var(--white);
  }

  .employee-checklist-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin-bottom: 8px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
  }

  .employee-checklist-item:hover {
    background: var(--white);
    border-color: var(--primary-green);
    transform: translateX(4px);
    box-shadow: var(--shadow-xs);
  }

  .employee-checklist-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary-green);
  }

  .employee-checklist-item label {
    flex: 1;
    cursor: pointer;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .employee-checklist-item .emp-main {
    font-weight: 600;
    color: var(--gray-800);
    font-size: 0.95rem;
  }

  .employee-checklist-item .emp-secondary {
    font-size: 0.8125rem;
    color: var(--gray-500);
  }

  .employee-checklist-item:has(input:checked) {
    background: linear-gradient(90deg, rgba(58, 90, 64, 0.08) 0%, rgba(58, 90, 64, 0.04) 100%);
    border-color: var(--primary-green);
  }

  .employee-checklist-item:has(input:checked) .emp-main {
    color: var(--primary-green-dark);
  }

  /* ==========================================
     INCOMPLETE EMPLOYEE ENTRIES
     ========================================== */
  .incomplete-entry {
    background: linear-gradient(135deg, var(--site-raised, #fef2f2) 0%, var(--site-surface, #ffffff) 100%);
    border: 2px solid var(--site-danger-border, #fecaca);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
    position: relative;
    animation: scaleIn 0.3s ease;
  }

  .incomplete-entry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
  }

  .incomplete-entry-header h4 {
    color: var(--site-danger, #dc2626);
    font-size: 1rem;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .incomplete-entry .remove-btn {
    background: var(--site-danger-bg, #fee2e2);
    color: var(--site-danger, #dc2626);
    border: 2px solid var(--site-danger-border, #fecaca);
    padding: 6px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: all 0.2s ease;
  }

  .incomplete-entry .remove-btn:hover {
    background: #dc2626;
    color: white;
    border-color: #dc2626;
    transform: scale(1.05);
  }

  .incomplete-entry .form-group {
    margin-bottom: 16px;
  }

  .equipment-missing-group {
    margin-top: 12px;
  }

  .equipment-missing-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--gray-700);
    font-weight: 600;
    font-size: 0.875rem;
  }

  .equipment-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .equipment-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--white);
    border: 2px solid var(--gray-300);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
  }

  .equipment-chip:hover {
    border-color: #dc2626;
    background: var(--ds-danger-soft, #fef2f2);
  }

  .equipment-chip input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #dc2626;
  }

  .equipment-chip:has(input:checked) {
    background: #dc2626;
    border-color: #dc2626;
    color: white;
  }

  .equipment-chip label {
    cursor: pointer;
    margin: 0;
    font-size: 0.875rem;
    font-weight: 600;
  }

  /* ==========================================
     RESPONSIVE DESIGN
     ========================================== */
  @media (max-width: 768px) {
    .employee-checklist {
      max-height: 300px;
    }

    .equipment-chips {
      flex-direction: column;
    }

    .equipment-chip {
      justify-content: flex-start;
      width: 100%;
    }
  }
}

/* ==========================================
   CRITICAL MOBILE LAYOUT FIXES (White Screen Fix)
   ========================================== */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
    min-width: 0 !important;
    flex: none !important;
    display: block !important;
    padding-top: 70px !important;
  }

  .sidebar {
    position: fixed !important;
    left: -260px !important;
    width: 250px !important;
    height: 100% !important;
    z-index: 2000 !important;
    transition: left 0.3s ease !important;
  }

  .sidebar.mobile-open {
    left: 0 !important;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
  }

  .container {
    width: 100% !important;
    max-width: 100% !important;
    padding: 10px !important;
  }
}

/* ==========================================
   GLOBAL SCROLLBAR & OVERFLOW FIXES
   ========================================== */
/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--site-raised, #f1f1f1);
  border-radius: 5px;
}

::-webkit-scrollbar-thumb {
  background: var(--site-raised, #c1ccab);
  border-radius: 5px;
  border: 2px solid var(--site-border, #f1f1f1);
}

::-webkit-scrollbar-thumb:hover {
  background: #8a9a5b;
}

/* Dark mode scrollbar support */
[data-theme='dark'] ::-webkit-scrollbar-track {
  background: #2d3329;
  border-color: #2d3329;
}

[data-theme='dark'] ::-webkit-scrollbar-thumb {
  background: #526042;
  border-color: #2d3329;
}

[data-theme='dark'] ::-webkit-scrollbar-thumb:hover {
  background: #6b7d56;
}

/* Ensure smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Fix for Layout Scrolling */
@media (min-width: 769px) {
  .app-container {
    height: 100vh;
    overflow: hidden;
    /* Prevent body scroll */
  }

  .main-content {
    height: 100%;
    overflow: auto;
    /* Enable scrolling in both directions when content overflows */
    scrollbar-gutter: stable both-edges;
  }

  .sidebar {
    height: 100%;
    overflow-y: auto;
  }
}

/* Ensure tables are responsive */
.table-responsive,
.overflow-auto {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Fix for specific modals or cards that might cut off */
.modal-content {
  max-height: 90vh;
  overflow-y: auto;
}

/* ==========================================
   GLOBAL POPUP & OVERLAY Z-INDEX FIX
   ========================================== */
/* Ensure all modals and sweet alerts come to the very front */
.modal {
  z-index: 99999 !important;
}

.swal2-container {
  z-index: 100000 !important;
}

.loading-overlay {
  z-index: 100001 !important;
}

#loading {
  z-index: 100001 !important;
}

/* ==========================================
   THEMED DROPDOWN (dropdown2) — system-wide
   ========================================== */
.dropdown2 {
  font-family: 'Kanit', 'Sarabun', 'Noto Sans Thai', 'Leelawadee UI', Tahoma, system-ui, sans-serif;
  position: relative;
  width: 100%;
}

.dropdown2 > ul {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
}

.dropdown2 > ul > li {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
  display: block;
  width: 100%;
  cursor: pointer;
}

.dropdown2-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 50px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--dropdown2-text);
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--dropdown2-border);
  background-color: var(--dropdown2-trigger-bg);
  cursor: pointer;
  text-align: left;
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
  box-sizing: border-box;
}

.dropdown2-link:hover,
.dropdown2.is-open > ul > li > .dropdown2-link {
  background-color: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.22);
}

.dropdown2-link-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.dropdown2-user-name,
.user-info-name {
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown2-user-role,
.user-info-role {
  font-size: 0.8125rem;
  color: var(--dropdown2-text-muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown2 a {
  text-decoration: none;
}

.dropdown2 .dropdown-links {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  opacity: 0;
  visibility: hidden;
  display: none;
  width: 100%;
  margin: 0;
  padding: 10px 0 6px;
  list-style: none;
  background-color: var(--dropdown2-menu-bg);
  border: 1px solid var(--dropdown2-border);
  border-radius: 10px;
  box-shadow: var(--dropdown2-shadow);
  z-index: 1100;
  box-sizing: border-box;
}

.dropdown2 .dropdown-links li {
  width: 100%;
  text-align: left;
  margin: 0;
  padding: 0;
  border: none;
  display: block;
}

.dropdown2 .dropdown-links a,
.dropdown2 .dropdown-links button.dropdown-menu-action {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  color: var(--dropdown2-text);
  text-decoration: none;
  background: none;
  border: none;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.3s ease;
  box-sizing: border-box;
}

.dropdown2 .dropdown-links li a:hover,
.dropdown2 .dropdown-links li button.dropdown-menu-action:hover {
  padding-left: 18px;
  color: var(--dropdown2-accent);
  border-left: 3px solid var(--dropdown2-accent);
  background: rgba(255, 255, 255, 0.06);
}

.dropdown2-link .arrow-down {
  flex-shrink: 0;
  margin-left: 8px;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--dropdown2-text);
  transition: transform ease-in-out 0.3s;
}

.dropdown2 li:hover > .dropdown-links,
.dropdown2 .dropdown-links:hover,
.dropdown2.is-open > ul > li > .dropdown-links {
  visibility: visible;
  opacity: 1;
  display: block;
}

.dropdown2 li:hover .arrow-down,
.dropdown2.is-open .arrow-down {
  transform: rotate(180deg);
}

.dropdown-links-lang {
  padding: 4px 14px 10px !important;
  border-bottom: 1px solid var(--dropdown2-border);
  margin-bottom: 4px !important;
}

.dropdown-links-lang .lang-toggle-wrap {
  justify-content: center;
}

.dropdown-links-item--danger:hover,
.dropdown-links a.dropdown-links-item--danger:hover {
  color: #fca5a5 !important;
  border-left-color: var(--site-danger-border, #f87171) !important;
  background: rgba(239, 68, 68, 0.12) !important;
}

/* Light surface (main content forms, filters) */
.main-content .dropdown2 .dropdown2-link,
.dropdown2--light .dropdown2-link {
  background-color: var(--white);
  color: var(--gray-800);
  border-color: var(--gray-200);
}

.main-content .dropdown2 .dropdown2-user-role,
.dropdown2--light .dropdown2-user-role {
  color: var(--gray-500);
}

.main-content .dropdown2 .dropdown-links,
.dropdown2--light .dropdown-links {
  background-color: var(--dropdown2-menu-bg-light);
  border-color: var(--gray-200);
  box-shadow: var(--shadow-lg);
}

.main-content .dropdown2 .dropdown-links a,
.main-content .dropdown2 .dropdown-links button.dropdown-menu-action,
.dropdown2--light .dropdown-links a,
.dropdown2--light .dropdown-links button.dropdown-menu-action {
  color: var(--dropdown2-link-text);
}

.main-content .dropdown2 .dropdown-links li a:hover,
.dropdown2--light .dropdown-links li a:hover {
  color: var(--primary-green);
  border-left-color: var(--primary-green);
  background: var(--green-50);
}

.main-content .dropdown2-link .arrow-down,
.dropdown2--light .dropdown2-link .arrow-down {
  border-top-color: var(--gray-600);
}

/* Sidebar account dropdown */
.sidebar-footer--dropdown {
  padding: 10px 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  gap: 0;
}

.sidebar-footer--dropdown .dropdown2 .dropdown-links {
  bottom: calc(100% + 8px);
}

.app-container .sidebar.collapsed .sidebar-footer--dropdown {
  padding: 10px 8px 14px;
}

.app-container .sidebar.collapsed .dropdown2-link {
  min-height: 42px;
  width: 42px;
  padding: 0;
  justify-content: center;
  border-radius: 50%;
}

.app-container .sidebar.collapsed .dropdown2-link-label,
.app-container .sidebar.collapsed .dropdown2-link .arrow-down {
  display: none;
}

.app-container .sidebar.collapsed .dropdown2 .dropdown-links {
  left: 70px;
  bottom: 0;
  width: 220px;
  min-width: 200px;
}

/* Native & form selects — same accent language */
select:not([multiple]),
.form-select,
.search-box select {
  border-radius: var(--radius-md, 8px);
  border: 1px solid var(--gray-300);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

select:not([multiple]):focus,
.form-select:focus,
.search-box select:focus {
  outline: none;
  border-color: var(--primary-green);
  box-shadow: 0 0 0 3px rgba(58, 90, 64, 0.15);
}

/* Autocomplete / search panels — dropdown2 hover feel */
.autocomplete-item:hover,
.autocomplete-item.selected,
.search-result-item:hover {
  padding-left: 18px !important;
  border-left: 3px solid var(--primary-green);
  color: var(--primary-green) !important;
}

/* ซ่อนปุ่มลบถาวรสำหรับผู้ใช้ที่ไม่ใช่ Admin */
body.user-cannot-delete [data-admin-delete-only],
body.user-cannot-delete .js-admin-delete-only {
  display: none !important;
}

/* Godanix enterprise: sidebar brand — solid, no shimmer (was animated gradient) */
.sidebar-header .logo-title,
[data-theme='dark'] .sidebar-header .logo-title {
  background: none; background-image: none;
  -webkit-text-fill-color: #ffffff; color: #ffffff;
  animation: none; font-weight: 700; letter-spacing: -0.01em;
}
.sidebar-header .logo-subtitle,
[data-theme='dark'] .sidebar-header .logo-subtitle {
  background: none; background-image: none;
  -webkit-text-fill-color: rgba(255,255,255,0.62); color: rgba(255,255,255,0.62);
  animation: none; font-weight: 400;
}

/* Shared sidebar identity: one brand and a clear page context on every app page */
.sidebar-brand-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  border-radius: 8px;
  outline-offset: 4px;
}

.sidebar-brand-link .logo-title,
.sidebar-brand-link .logo-subtitle {
  display: block;
}

.sidebar-brand-link .logo-text {
  min-width: 0;
  line-height: 1.2;
}

.sidebar-brand-mark {
  display: block;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  transition: transform .22s cubic-bezier(.2,.8,.2,1), filter .22s ease;
}

.sidebar-brand-icon,
.app-container .sidebar-brand-icon {
  display: block;
  width: 44px;
  height: 44px;
  margin: 0;
  flex: 0 0 auto;
  animation: none !important;
  filter: none;
}

.sidebar-brand-link .logo-title {
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.sidebar-brand-link .logo-subtitle {
  margin-top: 3px;
  font-size: 0.68rem;
  line-height: 1.3;
  letter-spacing: 0.015em;
}

.sidebar-brand-link:hover .sidebar-brand-mark {
  transform: translateY(-1px) scale(1.035);
  filter: brightness(1.06);
}

.sidebar-page-context {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 16px;
  padding: 9px 34px 9px 11px;
  border-left: 2px solid var(--site-info-border, #70bce8);
  background: linear-gradient(90deg, rgba(112, 188, 232, 0.075), transparent 88%);
}

.sidebar-page-kicker {
  color: rgba(255, 255, 255, 0.42);
  font-size: 0.57rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.16em;
}

.sidebar-page-title {
  overflow: hidden;
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.35;
  text-overflow: ellipsis;
}

.sidebar.collapsed .sidebar-page-context {
  display: none;
}

/* Compact identity for authenticated utility pages that do not use a sidebar */
.page-brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 22px;
  padding: 8px 12px 8px 8px;
  color: var(--primary-dark, #2c4c3b);
  text-align: left;
  text-decoration: none;
  border: 1px solid rgba(58, 90, 64, 0.16);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.76);
  transition: border-color .15s ease, background .15s ease;
}

.page-brand:hover {
  border-color: rgba(58, 90, 64, 0.34);
  background: var(--ds-surface, #ffffff);
}

.page-brand__icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
}

.page-brand__text,
.page-brand__text strong,
.page-brand__text small {
  display: block;
}

.page-brand__text strong {
  font-size: 0.98rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.page-brand__text small {
  margin-top: 3px;
  color: var(--gray-500, #64748b);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}


/* Godanix: consistent button interaction — additive, no color/radius change */
button, .btn, .btn-primary, .btn-secondary, .login-btn, .search-btn, .btn-green, .btn-success {
  transition: filter .15s ease, box-shadow .15s ease, transform .06s ease;
}
button:focus-visible, .btn:focus-visible, .login-btn:focus-visible,
.search-btn:focus-visible, [role="button"]:focus-visible {
  outline: 2px solid #2f7cb0;
  outline-offset: 2px;
}
.btn:active, button.btn:active, .login-btn:active, .search-btn:active,
.btn-primary:active, .btn-green:active { transform: translateY(1px); }
.btn:hover, .btn-primary:hover, .btn-green:hover, .login-btn:hover, .search-btn:hover { filter: brightness(1.04); }
