/* ==========================================================================
   PLG CMMS - Layouts & App Shell
   1:1 Match with lib/widgets/custom_drawer.dart & home_screen.dart
   ========================================================================== */

/* ─── TOP DEMO CONTROL BAR ─── */
.demo-bar {
  min-height: var(--demo-bar-height, 42px);
  background: linear-gradient(90deg, #071526 0%, #0F2E4E 50%, #1E4D78 100%);
  border-bottom: 1px solid rgba(0, 229, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px;
  font-size: 12px;
  z-index: 1100;
  position: sticky;
  top: 0;
  flex-wrap: wrap;
  gap: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.demo-bar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.back-portal-link {
  color: #00E5FF;
  text-decoration: none;
  font-size: 11.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(0, 229, 255, 0.08);
  border: 1px solid rgba(0, 229, 255, 0.25);
  transition: all 0.2s ease;
}
.back-portal-link:hover {
  background: rgba(0, 229, 255, 0.18);
  border-color: #00E5FF;
  transform: translateX(-2px);
  color: #FFFFFF;
}

.demo-bar-sep {
  color: rgba(255, 255, 255, 0.2);
  font-size: 12px;
}

.demo-bar-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #10B981;
  border-radius: 20px;
  font-weight: 700;
  font-size: 10.5px;
  letter-spacing: 0.3px;
}

.demo-bar-badge .pulse-dot {
  width: 6px;
  height: 6px;
  background-color: #10B981;
  border-radius: 50%;
  box-shadow: 0 0 8px #10B981;
  animation: demoPulse 2s infinite;
}

@keyframes demoPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

.demo-bar-title {
  font-weight: 700;
  color: #FFFFFF;
  font-size: 12px;
  letter-spacing: 0.2px;
}
.demo-bar-version {
  color: #8EA0B4;
  font-weight: 500;
  font-size: 11px;
}

.demo-bar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.demo-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 3px 8px;
  border-radius: 6px;
  color: #E2ECF5;
  font-size: 11.5px;
}

.demo-pill select {
  background: transparent;
  border: none;
  color: #FFFFFF;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  font-size: 11.5px;
}

.demo-pill select option {
  background-color: #0F2E4E;
  color: #FFFFFF;
}

.demo-btn-action {
  background: rgba(42, 107, 173, 0.3);
  border: 1px solid rgba(0, 229, 255, 0.35);
  color: #FFFFFF;
  padding: 3px 9px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  transition: all 0.2s ease;
}
.demo-btn-action:hover {
  background: rgba(0, 229, 255, 0.2);
  border-color: #00E5FF;
  color: #00E5FF;
}
.demo-btn-action.is-offline {
  background: rgba(229, 57, 53, 0.25);
  border-color: #E53935;
  color: #FF8A80;
}
.demo-btn-reset:hover {
  border-color: #F59E0B;
  color: #F59E0B;
}

@media (max-width: 768px) {
  .demo-bar {
    padding: 6px 12px;
  }
  .demo-bar-sep, .demo-bar-title {
    display: none;
  }
  .demo-bar-controls {
    width: 100%;
    justify-content: space-between;
  }
}

.app-shell {
  display: flex;
  min-height: calc(100vh - var(--demo-bar-height, 42px));
  width: 100vw;
  background-color: var(--color-bg);
  overflow-x: hidden;
  position: relative;
}

/* --- Responsive Drawer / Sidebar (1:1 with Flutter CustomDrawer) --- */
.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 46, 78, 0.4);
  backdrop-filter: blur(2px);
  z-index: 990;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.drawer-backdrop.active {
  display: block;
  opacity: 1;
}

.app-drawer {
  width: var(--sidebar-width);
  background-color: var(--color-bg);
  border-right: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--demo-bar-height, 42px));
  position: fixed;
  top: var(--demo-bar-height, 42px);
  left: 0;
  z-index: 1000;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 4px 0 20px rgba(15, 46, 78, 0.06);
}

/* Profile Header inside Drawer (1:1 with DrawerProfileHeader) */
.drawer-profile-header {
  background: linear-gradient(135deg, #0F2E4E 0%, #1E4D78 50%, #2A6BAD 100%);
  padding: 16px 18px 12px;
  color: #FFFFFF;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  transition: filter 0.2s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 200px;
}
.drawer-profile-header:hover {
  filter: brightness(1.04);
}
.drawer-profile-decor {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
  pointer-events: none;
}
.drawer-profile-decor.d1 {
  width: 170px;
  height: 170px;
  top: -60px;
  right: -40px;
}
.drawer-profile-decor.d2 {
  width: 120px;
  height: 120px;
  bottom: -35px;
  left: -25px;
}

.drawer-header-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 2;
  margin-bottom: 8px;
}
.drawer-version-pill {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 2px 10px;
  border-radius: 99px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 10px;
  font-weight: 600;
}
.drawer-env-pill {
  background: #FFCDD2;
  color: #B71C1C;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.drawer-profile-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 2;
  margin: 4px 0 6px;
}
.drawer-avatar-badge-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 2px;
}
.drawer-avatar-circle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2.5px solid #FFFFFF;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  background: var(--color-primary-mid);
  color: #FFFFFF;
  font-size: 20px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}
.drawer-role-pill {
  position: relative;
  margin-top: -12px;
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.35);
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 700;
  color: #FFFFFF;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
.drawer-user-fullname {
  font-size: 16px;
  font-weight: 800;
  color: #FFFFFF;
  text-align: center;
  letter-spacing: 0.2px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 6px;
}

.drawer-profile-hint-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 10.5px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.6);
  z-index: 2;
}

/* Nav Menu List (1:1 with Flutter CustomDrawer body) */
.drawer-nav-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
}
.nav-section-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.1px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  padding: 8px 6px 6px;
  margin-top: 4px;
}
.nav-section-label:first-child {
  margin-top: 0;
}

/* Flutter Nav Tile Card (1:1 with _buildNavTile) */
.flutter-nav-tile {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(30, 77, 120, 0.04);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  margin-bottom: 6px;
  transition: all 0.2s ease;
  user-select: none;
}
.flutter-nav-tile:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-primary-mid);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(30, 77, 120, 0.08);
}
.flutter-nav-tile.active {
  border-color: var(--color-primary);
  background: var(--color-surface-active);
  box-shadow: 0 3px 8px rgba(30, 77, 120, 0.1);
}
.flutter-nav-tile .nav-icon-box {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--color-surface-active);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  transition: all 0.2s;
}
.flutter-nav-tile.active .nav-icon-box {
  background: var(--color-primary);
  color: #FFFFFF;
}
.flutter-nav-tile .nav-tile-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary);
  flex: 1;
  letter-spacing: 0.1px;
}
.flutter-nav-tile.active .nav-tile-title {
  color: var(--color-primary);
  font-weight: 700;
}
.flutter-nav-tile .nav-tile-chevron {
  font-size: 12px;
  color: var(--color-border);
  transition: transform 0.2s, color 0.2s;
}
.flutter-nav-tile:hover .nav-tile-chevron {
  color: var(--color-primary-mid);
}

/* Flutter Expandable Tile (1:1 with _buildExpandableTile) */
.flutter-expandable-card {
  margin-bottom: 6px;
}
.flutter-expandable-header {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(30, 77, 120, 0.04);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}
.flutter-expandable-header:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-primary-mid);
}
.flutter-expandable-card.open .flutter-expandable-header {
  border-color: rgba(42, 107, 173, 0.4);
  box-shadow: 0 3px 10px rgba(30, 77, 120, 0.08);
}
.flutter-expandable-header .nav-icon-box {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--color-surface-active);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  transition: all 0.2s;
}
.flutter-expandable-card.open .flutter-expandable-header .nav-icon-box {
  background: rgba(42, 107, 173, 0.15);
  color: var(--color-primary-mid);
}
.flutter-expandable-header .nav-tile-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary);
  flex: 1;
}
.flutter-expandable-card.open .flutter-expandable-header .nav-tile-title {
  color: var(--color-primary-mid);
  font-weight: 700;
}
.flutter-expandable-header .arrow-down-icon {
  font-size: 14px;
  color: var(--color-text-secondary);
  transition: transform 0.25s ease;
}
.flutter-expandable-card.open .arrow-down-icon {
  transform: rotate(180deg);
  color: var(--color-primary-mid);
}

/* Tree-style Children Branch (1:1 with treeIndent & border-left) */
.flutter-tree-children {
  display: none;
  margin-top: 4px;
  margin-left: 20px;
  padding-left: 10px;
  border-left: 2px solid rgba(42, 107, 173, 0.25);
  animation: fadeIn 0.2s ease;
}
.flutter-expandable-card.open .flutter-tree-children {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Flutter Sub Tile (1:1 with _buildSubTile) */
.flutter-sub-tile {
  background: var(--color-bg);
  border-radius: 10px;
  padding: 7px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.18s;
  user-select: none;
}
.flutter-sub-tile:hover, .flutter-sub-tile.active {
  background: var(--color-surface-active);
}
.flutter-sub-tile .sub-icon-box {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: rgba(30, 77, 120, 0.08);
  color: var(--color-primary-mid);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.flutter-sub-tile .sub-tile-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
  flex: 1;
}
.flutter-sub-tile.active .sub-tile-title {
  color: var(--color-primary);
  font-weight: 700;
}
.flutter-sub-tile .sub-chevron {
  font-size: 11px;
  color: var(--color-border);
}

/* Flutter Logout Tile (1:1 with _buildLogoutTile) */
.flutter-logout-tile {
  background: var(--color-danger-bg);
  border: 1px solid rgba(229, 57, 53, 0.20);
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  margin-top: 6px;
  transition: all 0.2s;
  user-select: none;
}
.flutter-logout-tile:hover {
  background: #FFE5E5;
  border-color: rgba(229, 57, 53, 0.40);
  transform: translateY(-1px);
}
.flutter-logout-tile .logout-icon-box {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(229, 57, 53, 0.10);
  color: var(--color-danger);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.flutter-logout-tile .logout-tile-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-danger);
  letter-spacing: 0.1px;
}

/* --- Main App Body & Top Bar --- */
.app-main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  width: calc(100vw - var(--sidebar-width));
  transition: margin-left 0.3s cubic-bezier(0.16, 1, 0.3, 1), width 0.3s;
}

.app-topbar {
  height: var(--topbar-height);
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 800;
  box-shadow: 0 2px 10px rgba(15, 46, 78, 0.03);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}
.drawer-toggle-btn {
  background: var(--color-input-bg);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary-dark);
  cursor: pointer;
  transition: all 0.2s;
}
.drawer-toggle-btn:hover {
  background: var(--color-surface-active);
  color: var(--color-primary);
}

.topbar-title-group {
  display: flex;
  flex-direction: column;
}
.topbar-page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: -0.2px;
}
.topbar-page-crumb {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-secondary);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Offline Mode Demo Switcher */
.offline-toggle-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--color-success-bg);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 6px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-success);
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}
.offline-toggle-badge.offline-mode {
  background: var(--color-danger-bg);
  border-color: rgba(229, 57, 53, 0.3);
  color: var(--color-danger);
}
.offline-toggle-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
}

.topbar-user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--color-input-bg);
  border: 1px solid var(--color-border);
  padding: 5px 12px 5px 6px;
  border-radius: 99px;
  cursor: pointer;
  transition: all 0.2s;
}
.topbar-user-chip:hover {
  background: var(--color-surface-active);
  border-color: var(--color-primary-mid);
}
.topbar-user-chip .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #FFFFFF;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.topbar-user-chip .info {
  text-align: left;
  line-height: 1.2;
}
.topbar-user-chip .name {
  font-size: 12px;
  font-weight: 700;
  color: var(--color-text-primary);
}
.topbar-user-chip .role {
  font-size: 10px;
  color: var(--color-text-secondary);
}

/* Content Container */
.app-content-container {
  flex: 1;
  padding: 28px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* Offline Alert Banner */
.offline-banner {
  display: none;
  background: var(--grad-danger);
  color: #FFFFFF;
  padding: 10px 24px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 2px 8px rgba(229, 57, 53, 0.25);
  animation: fadeIn 0.3s ease;
}
.offline-banner.active {
  display: flex;
}

/* Tablet & Mobile Responsiveness */
@media (max-width: 1024px) {
  .app-drawer {
    transform: translateX(-100%);
  }
  .app-drawer.open {
    transform: translateX(0);
  }
  .app-main-wrapper {
    margin-left: 0;
    width: 100vw;
  }
}

@media (max-width: 640px) {
  .app-topbar {
    padding: 0 16px;
    height: 60px;
  }
  .app-content-container {
    padding: 16px 12px;
  }
  .topbar-user-chip .info {
    display: none;
  }
}
