/* =========================================================================
   AGRINEX ADMIN UNIFIED SHELL & CROSS-MODULE INTERLINK STYLES
   Persistent Collapsible Sidebar, Command Palette (Ctrl+K),
   AgriNexBus Toast Alerts, and Contextual Deep-Link Animations
   ========================================================================= */

/* --- 1. COLLAPSIBLE SIDEBAR RULES --- */
.sidebar {
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              min-width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              padding 0.25s ease !important;
  position: sticky !important;
  top: 0;
  height: 100vh;
  overflow-x: hidden !important;
}

/* Sidebar Toggle Button */
.sidebar-toggle-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ffffff;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  margin-left: auto;
}

.sidebar-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: #4ade80;
  color: #4ade80;
  transform: scale(1.05);
}

.sidebar-toggle-btn svg {
  transition: transform 0.25s ease;
}

/* Collapsed State */
.sidebar.collapsed {
  width: 68px !important;
  min-width: 68px !important;
  padding: 16px 8px !important;
}

.sidebar.collapsed .brand-title,
.sidebar.collapsed .brand-tagline,
.sidebar.collapsed .sidebar-menu-heading,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .connected-portals-box,
.sidebar.collapsed .nav-item-badge {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none;
}

.sidebar.collapsed .sidebar-brand {
  justify-content: center !important;
  padding: 0 0 14px 0 !important;
}

.sidebar.collapsed .sidebar-toggle-btn {
  margin: 8px auto 0 auto;
}

.sidebar.collapsed .sidebar-toggle-btn svg {
  transform: rotate(180deg);
}

.sidebar.collapsed .nav-item {
  justify-content: center !important;
  padding: 10px 0 !important;
  position: relative;
}

.sidebar.collapsed .nav-item-left {
  justify-content: center !important;
  width: auto !important;
}

.sidebar.collapsed .nav-icon {
  margin: 0 !important;
  width: 22px;
  height: 22px;
}

/* Tooltip on hover when collapsed */
.sidebar.collapsed .nav-item:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 72px;
  top: 50%;
  transform: translateY(-50%);
  background: #0f172a;
  color: #f8fafc;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.15);
  z-index: 9999;
  pointer-events: none;
  animation: tooltipFadeIn 0.15s ease-out forwards;
}

@keyframes tooltipFadeIn {
  from { opacity: 0; transform: translateY(-50%) translateX(-6px); }
  to { opacity: 1; transform: translateY(-50%) translateX(0); }
}

/* Adjust Main Content when sidebar is collapsed */
.main-wrapper {
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  flex: 1;
  min-width: 0;
}

/* --- 2. COMMAND PALETTE (CTRL+K) STYLES --- */
.command-palette-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10000;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 80px 16px 20px;
  animation: backdropFadeIn 0.15s ease-out;
}

.command-palette-backdrop.active {
  display: flex !important;
}

@keyframes backdropFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.command-palette-modal {
  background: #ffffff;
  width: 100%;
  max-width: 660px;
  border-radius: 16px;
  box-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(15, 23, 42, 0.08);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 560px;
  animation: modalPopDown 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPopDown {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.command-palette-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}

.command-palette-icon {
  color: #059669;
  flex-shrink: 0;
}

.command-palette-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 1.05rem;
  font-weight: 600;
  color: #0f172a;
  font-family: inherit;
}

.command-palette-input::placeholder {
  color: #94a3b8;
  font-weight: 500;
}

.command-palette-esc-badge {
  background: #e2e8f0;
  color: #475569;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
}

.command-palette-results {
  overflow-y: auto;
  padding: 10px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.command-group-title {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  padding: 8px 10px 4px 10px;
}

.command-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.12s ease;
  user-select: none;
}

.command-item:hover,
.command-item.selected {
  background: #ecfdf5;
  color: #065f46;
}

.command-item.selected {
  outline: 2px solid #059669;
}

.command-item-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f5f9;
  color: #0c5a36;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.command-item:hover .command-item-icon,
.command-item.selected .command-item-icon {
  background: #d1fae5;
  color: #047857;
}

.command-item-info {
  flex: 1;
  min-width: 0;
}

.command-item-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.command-item:hover .command-item-title,
.command-item.selected .command-item-title {
  color: #065f46;
}

.command-item-desc {
  font-size: 0.74rem;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.command-item-badge {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 6px;
  background: #f1f5f9;
  color: #475569;
  white-space: nowrap;
}

.command-palette-footer {
  padding: 10px 18px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.74rem;
  color: #64748b;
}

.command-palette-shortcuts {
  display: flex;
  align-items: center;
  gap: 12px;
}

.command-palette-shortcuts kbd {
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
  padding: 2px 5px;
  border-radius: 4px;
  font-weight: 700;
  font-family: inherit;
  font-size: 0.68rem;
  color: #334155;
}

/* --- 3. CONTEXTUAL DEEP-LINK ANIMATIONS --- */
.deep-link-highlight {
  animation: deepLinkPulse 2.5s ease-out forwards;
}

@keyframes deepLinkPulse {
  0% {
    background-color: rgba(5, 150, 105, 0.35) !important;
    box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.4);
    transform: scale(1.01);
  }
  50% {
    background-color: rgba(5, 150, 105, 0.2) !important;
    box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.2);
  }
  100% {
    background-color: transparent;
    box-shadow: none;
    transform: scale(1);
  }
}

/* Quick Jump Pill Button in Tables */
.deep-jump-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 800;
  color: #0369a1;
  background: #e0f2fe;
  border: 1px solid #bae6fd;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.deep-jump-btn:hover {
  background: #0284c7;
  color: #ffffff;
  border-color: #0284c7;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(2, 132, 199, 0.25);
}

/* --- 4. AGRINEXBUS TOAST NOTIFICATION STACK --- */
#agrinex-toast-stack {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10005;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.agrinex-toast {
  pointer-events: auto;
  background: #ffffff;
  border-left: 4px solid #059669;
  border-radius: 10px;
  box-shadow: 0 10px 30px -5px rgba(15, 23, 42, 0.2), 0 0 0 1px rgba(15, 23, 42, 0.06);
  padding: 12px 16px;
  min-width: 320px;
  max-width: 440px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  animation: toastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: all 0.25s ease;
}

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

.agrinex-toast.toast-alert {
  border-left-color: #e11d48;
}

.agrinex-toast.toast-info {
  border-left-color: #0284c7;
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.agrinex-toast.fade-out {
  opacity: 0;
  transform: translateX(40px);
}

.toast-icon {
  font-size: 1.25rem;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 1px;
}

.toast-body {
  flex: 1;
}

.toast-title {
  font-size: 0.82rem;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 2px;
}

.toast-message {
  font-size: 0.74rem;
  color: #475569;
  line-height: 1.35;
}

.toast-close {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  transition: color 0.15s ease;
}

.toast-close:hover {
  color: #0f172a;
}

/* Command Palette trigger badge in top search */
.search-ctrl-k-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.68rem;
  font-weight: 800;
  color: #64748b;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  padding: 2px 6px;
  margin-left: auto;
  cursor: pointer;
  transition: all 0.15s ease;
}

.search-ctrl-k-badge:hover {
  background: #e2e8f0;
  color: #0f172a;
}

/* =========================================================================
   5. MOBILE RESPONSIVE DRAWER & ADAPTIVE SHELL RULES
   ========================================================================= */

/* Mobile Hamburger Toggle Button (Navbar) */
.mobile-sidebar-toggle {
  display: none;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #0f172a;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  font-weight: 800;
  flex-shrink: 0;
  transition: all 0.15s ease;
  margin-right: 8px;
}

.mobile-sidebar-toggle:hover {
  background: #e2e8f0;
  color: #064e3b;
}

/* Sidebar Backdrop Overlay on Mobile */
.sidebar-mobile-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1050;
  animation: backdropFadeIn 0.2s ease-out;
}

.sidebar-mobile-backdrop.active {
  display: block !important;
}

/* Tablet & Mobile Breakpoints (< 1024px) */
@media (max-width: 1024px) {
  .mobile-sidebar-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1100 !important;
    width: 270px !important;
    min-width: 270px !important;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25) !important;
  }

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

  .sidebar-toggle-btn {
    display: none !important;
  }

  .sidebar.collapsed {
    transform: translateX(-100%) !important;
    width: 270px !important;
    min-width: 270px !important;
  }

  .sidebar.collapsed .brand-title,
  .sidebar.collapsed .brand-tagline,
  .sidebar.collapsed .sidebar-menu-heading,
  .sidebar.collapsed .nav-item span,
  .sidebar.collapsed .connected-portals-box {
    display: block !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  .sidebar.collapsed .nav-item {
    justify-content: flex-start !important;
    padding: 8px 10px !important;
  }

  .sidebar.collapsed .nav-item-left {
    justify-content: flex-start !important;
    width: 100% !important;
  }

  .cockpit-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  .cockpit-panel-queue,
  .cockpit-panel-pulse {
    width: 100% !important;
  }
}

/* Mobile Screens (< 768px) */
@media (max-width: 768px) {
  .top-navbar {
    padding: 0 14px !important;
    height: auto !important;
    min-height: 56px !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    padding-top: 6px !important;
    padding-bottom: 6px !important;
  }

  .navbar-left {
    max-width: 100% !important;
    flex: 1 1 auto !important;
    gap: 8px !important;
  }

  .navbar-left div:last-child {
    display: none !important; /* Hide long badge on small mobile */
  }

  .navbar-search {
    padding: 6px 12px !important;
    min-width: 140px !important;
  }

  .search-ctrl-k-badge {
    display: none !important;
  }

  .navbar-right {
    gap: 6px !important;
    margin-left: auto !important;
  }

  .navbar-right .btn-outline {
    font-size: 0.72rem !important;
    padding: 5px 8px !important;
  }

  .navbar-right a[title*="Switch to another stakeholder portal"] {
    display: none !important;
  }

  .profile-widget .profile-info {
    display: none !important;
  }

  .profile-widget {
    padding: 2px !important;
  }

  .executive-status-bar {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
    padding: 14px !important;
  }

  .executive-actions-right {
    width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .executive-actions-right .status-pill-btn {
    flex: 1 1 auto !important;
    justify-content: center !important;
  }

  .executive-kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }

  .dashboard-content {
    padding: 14px !important;
  }

  .filter-pills-bar {
    overflow-x: auto !important;
    white-space: nowrap !important;
    padding-bottom: 6px !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .listings-table-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .modal-box-lg,
  .modal-content,
  .modal-card,
  .tribunal-modal {
    width: 95vw !important;
    max-width: 95vw !important;
    max-height: 88vh !important;
    margin: 12px auto !important;
    border-radius: 12px !important;
  }

  #apmc-gis-map {
    height: 340px !important;
  }
}

/* Extra Small Mobile (< 520px) */
@media (max-width: 520px) {
  .executive-kpi-grid {
    grid-template-columns: 1fr !important;
  }

  .executive-name-row {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 4px !important;
  }

  .executive-subtext {
    flex-wrap: wrap !important;
    font-size: 0.72rem !important;
  }

  .pulse-tabs-bar {
    overflow-x: auto !important;
    white-space: nowrap !important;
    -webkit-overflow-scrolling: touch !important;
  }
}
