/* ==========================================================================
   Design System & Layout CSS Variables
   ========================================================================== */
:root {
  /* Layout Dimensions */
  --header-height: 135px;
  --welcome-height: 45px;
  --sidebar-width: 280px;
  --sidebar-collapsed-width: 92px;

  /* Colors */
  --primary-teal: #0f766e;
  --accent-teal: #14b8a6;
  --text-color: #1e293b;
  --muted-color: #475569;
  --border-color: #e2e8f0;
  --accent-maroon: #800020;
  --bg-page: #f1f5f9;

  /* Status Colors */
  --color-danger: #b91c1c;
  --color-warning: #b45309;
  --color-success: #166534;
  --color-info: #0f766e;

  /* Gradients */
  --header-gradient: linear-gradient(135deg, #0f766e, #14b8a6);

  /* Typography */
  --font-body: 'Khmer OS Battambang', 'Battambang', 'KhmerOSSiemreapWeb', 'Khmer OS Siemreap', 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  --font-display: 'KhmerOSMuolLightWeb', 'KhmerOSMuolLight', 'Khmer OS Muol Light', 'Moul', 'Hanuman', serif;
}

/* ==========================================================================
   Typography & Webfonts
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Battambang:wght@400;700&display=swap');

@font-face {
  font-family: 'KhmerOSSiemreapWeb';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src:
    local('Khmer OS Siemreap'),
    local('KhmerOS Siemreap'),
    local('KhmerOSSiemreap'),
    url('/media/system_images/KhmerOSSiemreap.ttf') format('truetype'),
    url("/static/fonts/KhmerOSSiemreap.d586f04d96be.ttf") format('truetype');
}

@font-face {
  font-family: 'KhmerOSMuolLightWeb';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src:
    local('Khmer OS Muol Light'),
    local('KhmerOS Muol Light'),
    local('KhmerOSMuolLight'),
    url('/media/system_images/KhmerOSMuolLight.ttf') format('truetype'),
    url("/static/fonts/KhmerOSMuolLight.7b996be20a59.ttf") format('truetype');
}

@font-face {
  font-family: 'KhmerOSMuolLightWeb';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src:
    local('Khmer OS Muol Light'),
    local('KhmerOS Muol Light'),
    local('KhmerOSMuolLight'),
    url('/media/system_images/KhmerOSMuolLight.ttf') format('truetype'),
    url("/static/fonts/KhmerOSMuolLight.7b996be20a59.ttf") format('truetype');
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  font-family: var(--font-body) !important;
  color: var(--text-color);
  background-color: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6,
.kh-muol,
.display-title,
.app-header-title,
.page-title {
  font-family: var(--font-display) !important;
  font-weight: normal;
}

.display-title,
.app-header-title {
  font-size: 24px;
  font-weight: normal;
  line-height: 1.4;
}

button, input, select, textarea,
.btn, .form-control, .form-select, label,
table, th, td,
.nav, .nav-tabs .nav-link, .dropdown-menu, .dropdown-item,
.badge, .alert, .modal, .popover, .tooltip,
.pagination, .breadcrumb {
  font-family: inherit;
}

/* ==========================================================================
   Layout Components (Fixed Shell)
   ========================================================================== */

/* 1. Fixed Top Header Banner (135px tall, teal gradient, white text, z-index 1060) */
.app-header-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: var(--header-height);
  background: var(--header-gradient);
  color: #ffffff;
  z-index: 1060;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 24px;
  box-shadow: 0 2px 10px rgba(15, 118, 110, 0.25);
}

.app-header-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  width: 100%;
  max-width: 1400px;
}

.app-header-logo {
  width: 140px;
  height: auto;
  max-height: 125px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.2));
}

.app-header-title {
  font-family: var(--font-display) !important;
  font-size: 24px;
  font-weight: normal;
  color: #ffffff;
  margin: 0;
  text-align: center;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

/* 2. Fixed White Welcome Bar (45px tall, border-bottom: 1px solid #e2e8f0) */
.app-welcome-bar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  width: 100%;
  height: var(--welcome-height);
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  z-index: 1050;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.app-welcome-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.app-welcome-center {
  flex: 1;
  text-align: center;
  color: var(--accent-maroon);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 16px;
}

.app-welcome-center,
.app-welcome-center * {
  color: var(--accent-maroon) !important;
}

.app-welcome-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  justify-content: flex-end;
}

/* 3. Fixed Left Sidebar (280px wide, collapsible to 92px, white bg, border-right: 1px solid #e2e8f0) */
.app-sidebar {
  position: fixed;
  top: calc(var(--header-height) + var(--welcome-height));
  bottom: 0;
  left: 0;
  width: var(--sidebar-width);
  background: #ffffff;
  border-right: 1px solid var(--border-color);
  z-index: 1040;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.25s ease, transform 0.25s ease;
  display: flex;
  flex-direction: column;
}

.app-sidebar-nav {
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  list-style: none;
  margin: 0;
}

.sidebar-nav-item {
  position: relative;
  list-style: none;
}

.sidebar-nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--text-color);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
  border: 1px solid transparent;
  cursor: pointer;
}

.sidebar-nav-link:hover {
  background-color: rgba(15, 118, 110, 0.08);
  color: var(--primary-teal);
}

.sidebar-nav-link.active {
  background-color: rgba(15, 118, 110, 0.12);
  color: var(--primary-teal);
  font-weight: 600;
  border-color: rgba(15, 118, 110, 0.2);
}

.sidebar-nav-icon {
  font-size: 18px;
  min-width: 24px;
  text-align: center;
  color: var(--primary-teal);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-nav-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.sidebar-nav-arrow {
  font-size: 12px;
  color: var(--muted-color);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.sidebar-nav-link[aria-expanded="true"] .sidebar-nav-arrow {
  transform: rotate(180deg);
}

/* Sidebar Submenu */
.sidebar-submenu {
  list-style: none;
  padding: 4px 0 4px 34px;
  margin: 0;
}

.sidebar-submenu-item {
  list-style: none;
  margin-bottom: 2px;
}

.sidebar-submenu-link {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--muted-color);
  font-size: 13.5px;
  text-decoration: none;
  transition: all 0.2s ease;
}

.sidebar-submenu-link:hover {
  color: var(--primary-teal);
  background-color: rgba(15, 118, 110, 0.06);
}

.sidebar-submenu-link.active {
  color: var(--primary-teal);
  font-weight: 600;
  background-color: rgba(15, 118, 110, 0.1);
}

/* Desktop Collapsed Sidebar State (92px) */
body.sidebar-collapsed .app-sidebar {
  width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .app-sidebar .sidebar-nav-text,
body.sidebar-collapsed .app-sidebar .sidebar-nav-arrow {
  display: none !important;
}

body.sidebar-collapsed .app-sidebar .sidebar-nav-link {
  justify-content: center;
  padding: 12px;
}

body.sidebar-collapsed .app-sidebar .sidebar-nav-icon {
  font-size: 22px;
  margin: 0;
}

body.sidebar-collapsed .app-sidebar .sidebar-submenu {
  padding-left: 0;
}

body.sidebar-collapsed .app-sidebar .sidebar-submenu-link {
  text-align: center;
  font-size: 11px;
  padding: 6px 4px;
}

/* 4. Main Content Area (Offset by sidebar width, page background #f1f5f9) */
.app-main-content {
  margin-top: calc(var(--header-height) + var(--welcome-height));
  margin-left: var(--sidebar-width);
  min-height: calc(100vh - var(--header-height) - var(--welcome-height));
  background-color: var(--bg-page);
  padding: 24px;
  transition: margin-left 0.25s ease;
}

body.sidebar-collapsed .app-main-content {
  margin-left: var(--sidebar-collapsed-width);
}

/* ==========================================================================
   UI Components & Elements
   ========================================================================== */

/* 1. Cards (white, border-radius: 12px, box-shadow: 0 1px 3px rgba(0,0,0,0.1), 24px padding, 20px bottom margin) */
.card {
  background: #ffffff !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 12px !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
  padding: 24px !important;
  margin-bottom: 20px !important;
}

.card-body {
  padding: 0 !important;
}

.card-header {
  background: transparent !important;
  border-bottom: 1px solid var(--border-color) !important;
  padding-bottom: 16px !important;
  margin-bottom: 16px !important;
}

/* 2. Icon Buttons (29–38px squares, border-radius: 8–10px, subtle teal tint background rgba(15,118,110,0.1) with 1px teal-tinted border, smooth 0.2s ease hover transitions) */
.icon-btn,
.btn-icon,
.btn-sq-sm,
.fixed-back-btn,
.fixed-logout-btn,
.sidebar-toggle-btn,
#mydeskBackBtn,
#mydeskLogoutBtn,
#mydeskFixedActions .btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 36px !important;
  height: 36px !important;
  min-width: 29px !important;
  max-width: 38px !important;
  min-height: 29px !important;
  max-height: 38px !important;
  border-radius: 8px !important;
  background-color: rgba(15, 118, 110, 0.1) !important;
  border: 1px solid rgba(15, 118, 110, 0.25) !important;
  color: var(--primary-teal) !important;
  text-decoration: none !important;
  padding: 0 !important;
  margin: 0 !important;
  line-height: 1 !important;
  cursor: pointer;
  transition: all 0.2s ease !important;
  flex-shrink: 0;
}

#mydeskFixedActions {
  display: flex !important;
  align-items: center !important;
  gap: 2mm !important;
}

.icon-btn i,
.btn-icon i,
.btn-sq-sm i,
.fixed-back-btn i,
.fixed-logout-btn i,
.sidebar-toggle-btn i {
  color: var(--primary-teal) !important;
  font-size: 16px;
  line-height: 1;
}

.icon-btn:hover,
.btn-icon:hover,
.btn-sq-sm:hover,
.fixed-back-btn:hover,
.fixed-logout-btn:hover,
.sidebar-toggle-btn:hover {
  background-color: rgba(15, 118, 110, 0.2) !important;
  border-color: var(--primary-teal) !important;
  color: var(--primary-teal) !important;
  transform: translateY(-1px);
}

.icon-btn.text-danger,
.btn-icon.text-danger,
.fixed-logout-btn.text-danger {
  background-color: rgba(185, 28, 28, 0.1) !important;
  border-color: rgba(185, 28, 28, 0.25) !important;
}

.icon-btn.text-danger i,
.btn-icon.text-danger i,
.fixed-logout-btn.text-danger i {
  color: var(--color-danger) !important;
}

.icon-btn.text-danger:hover,
.btn-icon.text-danger:hover,
.fixed-logout-btn.text-danger:hover {
  background-color: rgba(185, 28, 28, 0.2) !important;
  border-color: var(--color-danger) !important;
}

/* 3. Focus States (2px teal outline at 25% opacity with offset) */
*:focus-visible,
.form-control:focus,
.form-select:focus,
.form-check-input:focus,
.btn:focus,
.icon-btn:focus,
.sidebar-nav-link:focus,
a:focus {
  outline: 2px solid rgba(15, 118, 110, 0.25) !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12) !important;
}

/* 4. Modals (Must use z-index 1080, backdrop 1070 to sit above fixed header) */
.modal {
  z-index: 1080 !important;
}

.modal-backdrop {
  z-index: 1070 !important;
}

/* 5. Status & Brand Colors */
.text-teal { color: var(--primary-teal) !important; }
.bg-teal { background-color: var(--primary-teal) !important; color: #fff !important; }

.text-danger { color: var(--color-danger) !important; }
.text-warning { color: var(--color-warning) !important; }
.text-success { color: var(--color-success) !important; }
.text-info { color: var(--color-info) !important; }

.bg-danger { background-color: var(--color-danger) !important; color: #fff !important; }
.bg-warning { background-color: var(--color-warning) !important; color: #fff !important; }
.bg-success { background-color: var(--color-success) !important; color: #fff !important; }
.bg-info { background-color: var(--color-info) !important; color: #fff !important; }

.border-danger { border-color: var(--color-danger) !important; }
.border-warning { border-color: var(--color-warning) !important; }
.border-success { border-color: var(--color-success) !important; }
.border-info { border-color: var(--color-info) !important; }

/* Primary Button in Brand Teal */
.btn-primary,
.btn-teal {
  background-color: var(--primary-teal) !important;
  border-color: var(--primary-teal) !important;
  color: #ffffff !important;
  transition: all 0.2s ease !important;
}

.btn-primary:hover,
.btn-teal:hover {
  background-color: #0d655e !important;
  border-color: #0d655e !important;
  color: #ffffff !important;
  transform: translateY(-1px);
}

.btn-outline-primary,
.btn-outline-teal {
  color: var(--primary-teal) !important;
  border-color: var(--primary-teal) !important;
  background-color: transparent !important;
  transition: all 0.2s ease !important;
}

.btn-outline-primary:hover,
.btn-outline-teal:hover {
  background-color: var(--primary-teal) !important;
  border-color: var(--primary-teal) !important;
  color: #ffffff !important;
}

/* Oval action button style */
.btn-oval-lg {
  border-radius: 50px !important;
  padding: 8px 20px !important;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-custom-grey {
  background-color: #f8fafc;
  border: 1px solid var(--border-color);
  color: var(--text-color);
}

.btn-custom-grey:hover {
  background-color: rgba(15, 118, 110, 0.08);
  border-color: var(--primary-teal);
  color: var(--primary-teal);
}

/* System-wide Required Asterisk (Red) */
.req-star {
  color: var(--color-danger) !important;
  margin-left: 3px;
  font-weight: 700;
  line-height: 1;
}

/* Notification Popup */
.alert.important-info-popup {
  position: fixed;
  top: calc(var(--header-height) + var(--welcome-height) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  width: auto;
  max-width: min(90vw, 560px);
  min-width: min(320px, 90vw);
  box-shadow: 0 0.75rem 1.5rem rgba(0, 0, 0, 0.2);
}

.alert.important-info-popup.is-fading-out {
  opacity: 0;
  transition: opacity 0.35s ease;
}

/* Export Notification Popup */
.export-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  animation: fadeIn 0.3s ease-in;
}

.popup-content {
  background: white;
  padding: 2rem 2.5rem;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  text-align: center;
  max-width: 400px;
}

.popup-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.popup-message strong {
  display: block;
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
  color: var(--primary-teal);
}

.popup-message small {
  color: #666;
  font-size: 0.9rem;
}

/* Table styling */
.table {
  border-color: var(--border-color) !important;
}

.table > :not(caption) > * > * {
  padding: 10px 14px;
}

.table thead th {
  background-color: #f8fafc;
  color: var(--muted-color);
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
}

/* Forms styling */
.form-control,
.form-select {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--text-color);
}

/* Keep space for the dropdown arrow so text does not overlap it */
.form-select {
  padding-right: 2.25rem;
}

/* ==========================================================================
   Responsive Shell (Mobile & Tablet)
   ========================================================================== */
@media (max-width: 991.98px) {
  .app-header-banner {
    height: 100px;
    padding: 0 16px;
  }

  .app-header-logo {
    width: 70px;
    max-height: 70px;
  }

  .app-header-title {
    font-size: 16px;
  }

  .app-welcome-bar {
    top: 100px;
    padding: 0 12px;
  }

  .app-sidebar {
    top: calc(100px + var(--welcome-height));
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
  }

  body.mobile-sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  .app-main-content {
    margin-top: calc(100px + var(--welcome-height)) !important;
    margin-left: 0 !important;
    padding: 16px;
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    top: calc(100px + var(--welcome-height));
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1035;
    backdrop-filter: blur(2px);
  }

  body.mobile-sidebar-open .sidebar-backdrop {
    display: block;
  }

  .app-welcome-left,
  .app-welcome-right {
    min-width: auto;
  }

  .app-welcome-center {
    font-size: 12px;
    padding: 0 8px;
  }
}
