/* ============================================================
   LAYOUT.CSS — Aviation Accounting System Enterprise Dashboard
   Layout, sidebar, header, navigation, dropdowns, RTL support
   ============================================================ */

/* ============================================================
   1. APP LAYOUT
   ============================================================ */

.app-layout {
  min-height: 100vh;
  width: 100%;
}

/* ============================================================
   2. SIDEBAR
   ============================================================ */

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--primary-dark);
  color: #fff;
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--transition-normal);
}

/* Thin white scrollbar */
.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* Collapsed state */
.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

/* Mobile off-canvas */
.sidebar.mobile-open {
  transform: translateX(0);
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

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

  [dir="rtl"] .sidebar {
    transform: translateX(100%);
  }

  [dir="rtl"] .sidebar.mobile-open {
    transform: translateX(0);
  }
}

/* ============================================================
   3. SIDEBAR LOGO
   ============================================================ */

.sidebar-logo {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding-inline: 20px;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.sidebar-logo .logo-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-logo .logo-icon svg,
.sidebar-logo .logo-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sidebar-logo .company-name {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 1;
  transition: opacity 0.2s;
}

.sidebar.collapsed .sidebar-logo {
  padding-inline: 0;
  justify-content: center;
}

.sidebar.collapsed .sidebar-logo .company-name {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

/* ============================================================
   4. SIDEBAR NAVIGATION
   ============================================================ */

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Nav item */
.nav-item {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  gap: 12px;
  color: rgba(255, 255, 255, 0.65);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  position: relative;
  margin-inline: 8px;
  margin-bottom: 2px;
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
}

/* Nav item hover */
.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

/* Nav item active */
.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-weight: 600;
}

/* Active indicator bar on the left */
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--primary-light, #60a5fa);
  border-radius: 0 3px 3px 0;
}

/* Nav icon */
.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  font-size: 16px;
  opacity: 0.7;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-item:hover .nav-icon,
.nav-item.active .nav-icon {
  opacity: 1;
}

/* Nav text */
.nav-text {
  flex: 1;
  white-space: nowrap;
  opacity: 1;
  transition: opacity 0.2s;
}

/* Collapsed sidebar nav */
.sidebar.collapsed .nav-text {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

.sidebar.collapsed .nav-item {
  padding: 10px;
  justify-content: center;
  margin-inline: 4px;
}

/* Nav section header */
.nav-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.35);
  padding-block: 16px 8px;
  padding-inline: 20px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar.collapsed .nav-section {
  display: none;
}

/* ============================================================
   5. TREEVIEW MENU
   ============================================================ */

/* Treeview container */
.nav-treeview {
  display: none;
  list-style: none;
  padding: 0;
  margin: 0;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 6px;
  margin-inline: 8px;
  margin-bottom: 4px;
  overflow: hidden;
}

/* Treeview items */
.nav-treeview li a {
  display: flex;
  align-items: center;
  padding: 7px 12px 7px 16px;
  gap: 10px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.55);
  text-decoration: none;
  transition: all 0.15s;
  cursor: pointer;
}

[dir="rtl"] .nav-treeview li a {
  padding: 7px 16px 7px 12px;
}

.nav-treeview li a:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
}

.nav-treeview li a.active {
  color: #fff;
  background: rgba(96, 165, 250, 0.12);
}

/* Numbered code */
.nav-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono, monospace);
  color: rgba(255, 255, 255, 0.45);
  letter-spacing: 0.3px;
  flex-shrink: 0;
}

.nav-treeview li a:hover .nav-code {
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.65);
}

.nav-treeview li a.active .nav-code {
  background: rgba(96, 165, 250, 0.2);
  color: #60a5fa;
}

/* Nested subtree (System Setup children) */
.nav-treeitem.has-subtree {
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.nav-treeitem.has-subtree:last-child {
  border-bottom: none;
}

.nav-subtree-toggle {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  gap: 10px;
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
}

.nav-subtree-toggle:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
}

.nav-icon-sub {
  width: 16px;
  font-size: 13px;
  opacity: 0.6;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-arrow-sub {
  margin-inline-start: auto;
  font-size: 10px;
  transition: transform 0.2s;
  opacity: 0.5;
}

.nav-treeitem.has-subtree.expanded .nav-arrow-sub {
  transform: rotate(90deg);
}

/* Sub treeview (nested inside subtree) */
.nav-subtreeview {
  display: none;
  list-style: none;
  padding: 0;
  margin: 0;
  padding-inline-start: 20px;
}

.nav-subtreeview li a {
  display: flex;
  align-items: center;
  padding: 5px 10px;
  gap: 8px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
  text-decoration: none;
  transition: all 0.15s;
  cursor: pointer;
}

.nav-subtreeview li a:hover {
  color: #fff;
}

.nav-subtreeview li a .nav-code {
  min-width: 28px;
  padding: 1px 4px;
  font-size: 10px;
}

/* Arrow rotation for treeview items */
.nav-arrow {
  font-size: 12px;
  transition: transform 0.2s;
  flex-shrink: 0;
  margin-inline-start: auto;
}

.nav-item.has-treeview.expanded .nav-arrow {
  transform: rotate(90deg);
}

.sidebar.collapsed .nav-arrow {
  display: none;
}

/* ============================================================
   6. SIDEBAR FOOTER
   ============================================================ */

.sidebar-footer {
  padding-block: 12px;
  padding-inline: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.sidebar-footer .version-info,
.sidebar-version {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.35);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar.collapsed .sidebar-footer {
  padding: 12px;
  text-align: center;
}

.sidebar.collapsed .sidebar-footer .version-info,
.sidebar.collapsed .sidebar-version {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

/* ============================================================
   7. SIDEBAR OVERLAY (Mobile)
   ============================================================ */

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: calc(var(--z-sidebar) - 1);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
  pointer-events: none;
}

.sidebar-overlay.overlay-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ============================================================
   8. MAIN CONTENT AREA
   ============================================================ */

.main-content {
  margin-inline-start: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-inline-start var(--transition-normal);
  background: var(--background);
}

/* When sidebar is collapsed */
.main-content.sidebar-collapsed {
  margin-inline-start: var(--sidebar-collapsed-width);
}

@media (max-width: 768px) {
  .main-content {
    margin-inline-start: 0;
  }
}

/* ============================================================
   9. TOP HEADER
   ============================================================ */

.top-header {
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  padding-inline: 24px;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

/* ============================================================
   10. HEADER SECTIONS
   ============================================================ */

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-center {
  flex: 1;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Sidebar toggle button */
.sidebar-toggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.sidebar-toggle:hover {
  background: var(--background);
  color: var(--text-primary);
}

/* ============================================================
   11. SEARCH BAR
   ============================================================ */

.header-search {
  position: relative;
  max-width: 320px;
  width: 100%;
}

.header-search .search-input,
.header-search .form-control {
  padding-inline-start: 40px;
  padding-inline-end: 50px;
  height: 36px;
  width: 100%;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.header-search .search-input::placeholder,
.header-search .form-control::placeholder {
  color: var(--text-secondary);
}

.header-search .search-input:focus,
.header-search .form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.header-search .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 14px;
  pointer-events: none;
}

/* ============================================================
   12. BREADCRUMB
   ============================================================ */

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  list-style: none;
  margin: 0;
  padding: 0;
}

.breadcrumb-item {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

.breadcrumb-item:hover {
  color: var(--primary);
}

.breadcrumb-separator {
  color: var(--text-muted);
  opacity: 0.5;
}

.breadcrumb-item.active {
  color: var(--text-primary);
  font-weight: 500;
}

/* ============================================================
   13. HEADER ACTIONS
   ============================================================ */

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Notification bell */
.notification-btn {
  position: relative;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.notification-btn:hover {
  background: var(--background);
  color: var(--text-primary);
}

.notification-badge {
  position: absolute;
  top: 4px;
  inset-inline-end: 4px;
  min-width: 18px;
  height: 18px;
  background: var(--danger, #ef4444);
  color: #fff;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}

/* Quick actions */
.quick-actions-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.quick-actions-btn:hover {
  background: var(--background);
  color: var(--text-primary);
}

/* Language selector */
.language-selector,
.currency-selector {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.language-selector:hover,
.currency-selector:hover {
  background: var(--background);
  color: var(--text-primary);
}

/* User profile */
.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.2s;
}

.user-profile:hover {
  background: var(--background);
}

/* User avatar */
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

/* User info */
.user-info {
  display: flex;
  flex-direction: column;
}

.user-info .user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}

.user-info .user-role {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.2;
}

/* Dropdown arrow */
.dropdown-arrow {
  font-size: 10px;
  color: var(--text-secondary);
  transition: transform 0.2s;
}

@media (max-width: 768px) {
  .user-info {
    display: none;
  }
}

/* ============================================================
   14. CONTENT AREA
   ============================================================ */

.page-content {
  padding-block: 24px;
  padding-inline: 32px;
  flex: 1;
}

/* Page header */
.page-header {
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Page actions */
.page-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

@media (max-width: 640px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .page-content {
    padding: 16px;
  }
}

/* ============================================================
   15. FOOTER
   ============================================================ */

.app-footer {
  padding-block: 16px;
  padding-inline: 32px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.footer-links {
  display: flex;
  gap: 16px;
}

.footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-links a:hover {
  color: var(--primary);
}

@media (max-width: 640px) {
  .app-footer {
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }
}

/* ============================================================
   16. DROPDOWN MENUS
   ============================================================ */

.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md, 0 4px 24px rgba(0, 0, 0, 0.12));
  min-width: 200px;
  padding: 6px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.15s ease;
  z-index: var(--z-dropdown);
  display: block !important;
}

/* Open state */
.dropdown.open .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Dropdown items */
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  border: none;
  background: transparent;
  width: 100%;
  text-align: start;
}

.dropdown-item:hover {
  background: var(--background);
}

.dropdown-item.danger {
  color: var(--danger, #ef4444);
}

.dropdown-item.danger:hover {
  background: rgba(239, 68, 68, 0.08);
}

/* Dropdown divider */
.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* Dropdown header (notification) */
.dropdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
}

.dropdown-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.dropdown-link {
  font-size: 12px;
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
}

.dropdown-link:hover {
  text-decoration: underline;
}

.dropdown-footer-link {
  justify-content: center;
  color: var(--primary);
  font-weight: 500;
  font-size: 13px;
}

/* Search shortcut kbd */
.search-shortcut {
  position: absolute;
  inset-inline-end: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: inherit;
  color: var(--text-muted);
  pointer-events: none;
  line-height: 1.4;
}

/* Header time */
.header-time {
  font-size: 13px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Logo link and text */
.logo-link {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: #fff;
}

.logo-text {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 1;
  transition: opacity 0.2s;
}

.sidebar.collapsed .logo-text {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

.sidebar.collapsed .logo-link {
  justify-content: center;
}

.sidebar-version {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.35);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar.collapsed .sidebar-version {
  opacity: 0;
  width: 0;
}

/* Notification menu */
.notification-menu {
  min-width: 340px;
  max-height: 420px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.notification-list {
  overflow-y: auto;
  max-height: 320px;
}

.notification-item {
  padding: 10px 12px !important;
  gap: 12px !important;
}

.notification-item.unread {
  background: #f8fafc;
}

.notification-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}

.notification-icon.success {
  background: #f0fdf4;
  color: var(--success);
}

.notification-icon.warning {
  background: #fffbeb;
  color: var(--warning);
}

.notification-icon.danger {
  background: #fef2f2;
  color: var(--danger);
}

.notification-icon.info {
  background: #eff6ff;
  color: var(--primary);
}

.notification-content {
  flex: 1;
  min-width: 0;
}

.notification-text {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.4;
}

.notification-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ============================================================
   17. RTL SUPPORT
   ============================================================ */

[dir="rtl"] .sidebar {
  left: auto;
  right: 0;
}

[dir="rtl"] .main-content {
  margin-inline-start: auto;
  margin-inline-end: var(--sidebar-width);
}

[dir="rtl"] .main-content.sidebar-collapsed {
  margin-inline-end: var(--sidebar-collapsed-width);
}

[dir="rtl"] .header-search .search-input,
[dir="rtl"] .header-search .form-control {
  padding-left: 12px;
  padding-right: 50px;
}

[dir="rtl"] .header-search .search-icon {
  left: auto;
  right: 12px;
}

[dir="rtl"] .dropdown-menu {
  right: auto;
  left: 0;
}

[dir="rtl"] .nav-item.active::before {
  left: auto;
  right: -8px;
  border-radius: 3px 0 0 3px;
}

[dir="rtl"] .submenu-item::before {
  left: auto;
  right: 34px;
}

/* Nav arrow rotation in RTL */
[dir="rtl"] .nav-item.expanded .nav-arrow {
  transform: rotate(-90deg);
}

/* "View All" and directional arrows */
[dir="rtl"] .btn .fa-arrow-right,
[dir="rtl"] a .fa-arrow-right {
  transform: scaleX(-1);
}

/* Footer in RTL should also flip */
[dir="rtl"] .app-footer {
  flex-direction: row-reverse;
}

@media (max-width: 768px) {
  [dir="rtl"] .main-content {
    margin-inline-end: 0;
  }
}
