/**
 * CRM Sidebar Layout – stil DistroHub / Partner Portal
 * Sidebar FIX înălțime ecran, scroll doar pe content
 */

html:has(.crm-sidebar-layout),
body:has(.crm-sidebar-layout) {
  height: 100%;
  min-height: 100vh;
  min-height: -webkit-fill-available; /* iOS Safari mai vechi */
  overflow: hidden;
  display: block;
}

.crm-sidebar-layout {
  display: flex;
  height: 100vh;
  height: 100dvh; /* iOS Safari: viewport corect, fără tăierea footer-ului */
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  background: #f5f6f8;
  --dash-primary: #2563eb;
}

/* ========== Sidebar ========== */
.crm-sidebar {
  width: 240px;
  min-width: 240px;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  background: #fafbfc;
  border-right: 1px solid #e8eaed;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 100;
  transition: transform 0.3s ease, width 0.3s ease;
  overflow: hidden;
}

.crm-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  height: 64px;
  min-height: 64px;
  padding: 0 20px;
  flex-shrink: 0;
  background: #fff;
  border-bottom: 1px solid #e8eaed;
}

.crm-sidebar-header .navbar-brand {
  margin: 0;
  padding: 0;
  float: none;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  height: 100%;
  min-height: 0;
}

.crm-sidebar-header .navbar-brand img {
  max-height: 32px;
  width: auto;
  display: block;
  object-position: center;
}

.crm-sidebar-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 10px;
}

.crm-sidebar-link {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px 12px 14px;
  margin-bottom: 4px;
  color: #3c4043;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s, color 0.2s;
  border-radius: 10px;
  position: relative;
}

.crm-sidebar-link:hover {
  background: rgba(37, 99, 235, 0.08);
  color: #1e293b;
}

.crm-sidebar-link.active {
  background: rgba(37, 99, 235, 0.1);
  color: #1a56db;
}

.crm-sidebar-link i:first-child {
  width: 24px;
  min-width: 24px;
  text-align: center;
  font-size: 1.25rem;
  color: #6b7280;
  flex-shrink: 0;
}

.crm-sidebar-link:hover i:first-child,
.crm-sidebar-link.active i:first-child {
  color: #2563eb;
}

.crm-sidebar-link span {
  flex: 1;
}

.crm-sidebar-chevron {
  font-size: 0.7rem;
  color: #9ca3af;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.crm-sidebar-dropdown.open .crm-sidebar-chevron {
  transform: rotate(180deg);
}

.crm-sidebar-dropdown {
  position: relative;
}

.crm-sidebar-dropdown > .crm-sidebar-link {
  padding-left: 14px;
}

.crm-sidebar-submenu {
  display: none;
  list-style: none;
  margin: 4px 0;
  padding: 6px 0 6px 12px;
  background: transparent;
  margin-left: 0;
}

/* Submeniul e ascuns întotdeauna, doar .open (la click) îl afișează */
.crm-sidebar-dropdown .crm-sidebar-submenu {
  display: none !important;
}
.crm-sidebar-dropdown.open .crm-sidebar-submenu {
  display: block !important;
}
/* data-collapsed forțează ascunderea la încărcare (prioritate maximă) */
.crm-sidebar-dropdown[data-collapsed="1"] .crm-sidebar-submenu {
  display: none !important;
}
/* Când utilizatorul dă click, scoatem data-collapsed și open afișează submeniul */
.crm-sidebar-dropdown.open .crm-sidebar-submenu {
  display: block !important;
}

.crm-sidebar-submenu li {
  margin: 0;
}

.crm-sidebar-submenu a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 14px;
  margin-bottom: 2px;
  color: #5f6368;
  font-size: 13px;
  text-decoration: none;
  border-radius: 8px;
  position: relative;
}

.crm-sidebar-submenu a i,
.crm-sidebar-submenu a .fa {
  font-size: 1.1rem;
  color: #6b7280;
  flex-shrink: 0;
  width: 20px;
  min-width: 20px;
  text-align: center;
}

.crm-sidebar-submenu a:hover {
  color: #374151;
  background: rgba(37, 99, 235, 0.06);
}

.crm-sidebar-submenu a.active i,
.crm-sidebar-submenu a.active .fa {
  color: var(--dash-primary, #2563eb);
}

.crm-sidebar-submenu a span {
  flex: 1;
}

.crm-sidebar-submenu a .badge {
  flex: none;
  flex-shrink: 0;
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--dash-primary, #2563eb);
  color: #fff;
  border-radius: 10px;
}

.crm-sidebar-submenu a.active {
  background: rgba(37, 99, 235, 0.1);
  color: #1a56db;
  font-weight: 500;
}

.crm-sidebar-submenu a .qty_total {
  font-size: 11px;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--dash-primary, #2563eb);
  color: #fff;
  border-radius: 10px;
}

.crm-sidebar-submenu a .qty_total:empty {
  display: none;
}

/* Linkuri omni_sales din customers_navigation_end (Catalog, Comenzi, Coș) – afișate direct în sidebar */
.crm-sidebar-nav > li {
  margin: 0 0 4px 0;
  list-style: none;
}

.crm-sidebar-nav > li > a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px 12px 14px;
  color: #3c4043;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s, color 0.2s;
  border-radius: 10px;
}

.crm-sidebar-nav > li > a:hover {
  background: rgba(37, 99, 235, 0.08);
  color: #1e293b;
}

.crm-sidebar-nav > li > a.active {
  background: rgba(37, 99, 235, 0.1);
  color: #1a56db;
}

.crm-sidebar-nav > li > a i,
.crm-sidebar-nav > li > a .fa {
  width: 24px;
  min-width: 24px;
  text-align: center;
  font-size: 1.25rem;
  color: #6b7280;
  flex-shrink: 0;
}

.crm-sidebar-nav > li > a:hover i,
.crm-sidebar-nav > li > a.active i,
.crm-sidebar-nav > li > a.active .fa {
  color: #2563eb;
}

.crm-sidebar-nav > li > a .qty_total {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--dash-primary, #2563eb);
  color: #fff;
  border-radius: 10px;
}

.crm-sidebar-nav > li > a .qty_total:empty {
  display: none;
}

/* Sidebar footer – profil jos */
.crm-sidebar-footer {
  flex-shrink: 0;
  padding: 12px 10px 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0));
  border-top: 1px solid #e8eaed;
}

.crm-sidebar-profile {
  position: relative;
}

.crm-sidebar-profile-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: transparent;
  border-radius: 8px;
  text-decoration: none;
  color: #202124;
  transition: background 0.15s;
  border: none;
}

.crm-sidebar-profile-toggle:hover {
  background: #e8eaed;
  color: #202124;
}

.crm-sidebar-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  background: #e8a64c;
  color: #fff;
}

.crm-sidebar-avatar-img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.crm-sidebar-profile-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.crm-sidebar-profile-name {
  font-size: 13px;
  font-weight: 600;
  color: #202124;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crm-sidebar-profile-company {
  font-size: 11px;
  color: #5f6368;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crm-sidebar-profile-chevron,
.crm-sidebar-profile-toggle .fa-chevron-right {
  font-size: 0.7rem;
  color: #9ca3af;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.crm-sidebar-profile.crm-sidebar-profile-dropdown .dropdown-menu {
  min-width: 320px;
  padding: 18px 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  z-index: 1050;
  overflow: visible;
}

.crm-sidebar-profile .img-header img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: block;
  margin: 0 auto 8px;
}

.crm-sidebar-profile .nume-header,
.crm-sidebar-profile .email-header {
  font-size: 14px;
  margin-bottom: 12px;
}

.crm-sidebar-profile .email-header {
  color: #64748b;
  font-size: 13px;
}

.crm-sidebar-profile .li-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 2px 0;
  border-radius: 6px;
}

.crm-sidebar-profile .li-header:hover {
  background: rgba(37, 99, 235, 0.06);
}

.crm-sidebar-profile .dropdown-submenu {
  position: relative;
}

.crm-sidebar-profile .dropdown-submenu > .dropdown-menu {
  position: absolute;
  bottom: 0;
  top: auto;
  left: 100%;
  margin-left: 4px;
  display: none;
  min-width: 180px;
  z-index: 1051;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  border-radius: 8px;
}

.crm-sidebar-profile .dropdown-submenu:hover > .dropdown-menu {
  display: block;
}

.crm-sidebar-toggle {
  display: none;
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border: 1px solid #e2e8f0;
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  color: #64748b;
}

.crm-sidebar-toggle .crm-sidebar-toggle-icon-close {
  display: none;
}

/* ========== Main + Header ========== */
.crm-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.crm-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
  min-height: 64px;
  padding: 0 20px;
  background: #fff;
  border-bottom: 1px solid #e8eaed;
  flex-shrink: 0;
}

.crm-topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
}

.crm-sidebar-open-btn {
  display: none;
  padding: 8px 12px;
  border: 1px solid #e2e8f0;
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 20px;
  color: #64748b;
  flex-shrink: 0;
}

.crm-topbar-title {
  min-width: 0;
}

.crm-topbar-page-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: #202124;
  line-height: 1.3;
}

.crm-topbar-welcome {
  margin: 2px 0 0;
  font-size: 12px;
  color: #5f6368;
}

.crm-topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
  gap: 12px;
}

.crm-topbar-cart .nav-cart-btn {
  white-space: nowrap;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #2563eb !important;
  border-color: #2563eb !important;
  color: #fff !important;
}
.crm-topbar-cart .nav-cart-btn:hover,
.crm-topbar-cart .nav-cart-btn:focus {
  background: #1d4ed8 !important;
  border-color: #1d4ed8 !important;
  color: #fff !important;
}
.crm-topbar-cart .nav-cart-btn .qty_total {
  margin-left: 2px;
}

/* În layout sidebar, „Comanda curentă” e doar în topbar, nu și în meniul lateral */
.crm-sidebar-nav .nav-cart-menu-item {
  display: none !important;
}

.crm-topbar-search {
  width: 260px;
  max-width: 100%;
}

.crm-topbar-search .search-box-inner {
  position: relative;
  margin-top: 0;
}

.crm-topbar-search .search-field-input {
  width: 100%;
  height: 34px;
  padding: 0 36px 0 32px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 13px;
  background: #f8fafc;
  transition: border-color 0.2s, background 0.2s;
}

.crm-topbar-search .search-field-input:focus {
  outline: none;
  border-color: #2563eb;
  background: #fff;
}

.crm-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  color: #94a3b8;
  pointer-events: none;
}

.crm-topbar-search .ad-search-content-holder {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  z-index: 100;
  background: #fff;
}

.crm-main #wrapper {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* ========== Mobile ========== */
@media (max-width: 991px) {
  .crm-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 240px;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    /* Doar nav face scroll, footer cu profil rămâne vizibil jos */
  }

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

  .crm-sidebar.open + .crm-sidebar-overlay {
    display: block;
  }

  .crm-sidebar.open {
    z-index: 102;
  }

  .crm-sidebar-overlay {
    z-index: 101;
  }

  .crm-sidebar-header {
    padding-left: 14px;
  }

  /* Toggle – săgeată stânga mică, centrată pe axa Y în zona header */
  .crm-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    bottom: auto;
    top: 32px;
    right: 12px;
    left: auto;
    transform: translateY(-50%);
    padding: 6px 10px;
    font-size: 14px;
  }

  .crm-sidebar-toggle .crm-sidebar-toggle-icon-open {
    display: none;
  }

  .crm-sidebar-toggle .crm-sidebar-toggle-icon-close {
    display: inline-block;
    font-size: 0.8rem;
  }

  .crm-sidebar-open-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  body.crm-sidebar-open .crm-sidebar-open-btn {
    visibility: hidden;
  }

  .crm-main {
    margin-left: 0;
  }

  /* Topbar mobile – layout pe 2 rânduri, fără overlap */
  .crm-topbar {
    min-height: 64px;
    height: auto;
    padding: 12px 16px 16px;
    flex-wrap: wrap;
    gap: 12px;
  }

  .crm-topbar-left {
    flex: 0 1 auto;
    min-width: 0;
    order: 1;
  }

  .crm-topbar-title {
    min-width: 0;
    overflow: hidden;
  }

  .crm-topbar-page-title {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .crm-topbar-welcome {
    font-size: 11px;
  }

  .crm-topbar-right {
    order: 2;
    width: 100%;
    flex: 1 1 100%;
    margin-top: 0;
  }

  .crm-topbar-search {
    width: 100%;
    max-width: 100%;
  }

  /* Profile – collapsible normal pe mobile (ca Comercial/Suport), NU dropdown */
  .crm-sidebar-profile {
    display: flex;
    flex-direction: column;
    margin: 0 -10px 0 -10px;
  }

  .crm-sidebar-profile .crm-sidebar-profile-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px 12px 14px;
    color: #3c4043;
    text-decoration: none;
    border-radius: 10px;
    margin-bottom: 4px;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
  }

  .crm-sidebar-profile .crm-sidebar-profile-toggle:hover {
    background: rgba(37, 99, 235, 0.08);
    color: #1e293b;
  }

  .crm-sidebar-profile.crm-sidebar-profile-expanded .crm-sidebar-profile-toggle {
    background: rgba(37, 99, 235, 0.1);
    color: #1a56db;
  }

  .crm-sidebar-profile .crm-sidebar-profile-chevron {
    transition: transform 0.2s;
    margin-left: auto;
  }

  .crm-sidebar-profile.crm-sidebar-profile-expanded .crm-sidebar-profile-chevron {
    transform: rotate(180deg);
  }

  .crm-sidebar-profile .dropdown-menu {
    display: none !important;
    position: static !important;
    float: none !important;
    width: 100% !important;
    min-width: 100% !important;
    margin: 0 !important;
    padding: 6px 14px 6px 12px !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    max-height: 60vh;
    overflow-y: auto;
    list-style: none;
  }

  .crm-sidebar-profile.crm-sidebar-profile-expanded .dropdown-menu {
    display: block !important;
  }

  .crm-sidebar-profile .dropdown-menu .img-header,
  .crm-sidebar-profile .dropdown-menu .nume-header,
  .crm-sidebar-profile .dropdown-menu .email-header {
    padding: 6px 12px 6px 24px;
    margin: 0;
    font-size: 13px;
    color: #5f6368;
  }

  .crm-sidebar-profile .dropdown-menu .img-header {
    display: none;
  }

  .crm-sidebar-profile .dropdown-menu .nume-header {
    font-weight: 600;
    color: #202124;
  }

  .crm-sidebar-profile .dropdown-menu .email-header {
    font-size: 12px;
    color: #64748b;
  }

  .crm-sidebar-profile .dropdown-menu hr {
    margin: 8px 12px;
    border-color: #e8eaed;
  }

  .crm-sidebar-profile .dropdown-menu li {
    margin: 0;
    list-style: none;
  }

  .crm-sidebar-profile .dropdown-menu .li-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px 10px 24px;
    margin-bottom: 2px;
    color: #5f6368;
    font-size: 13px;
    text-decoration: none;
    border-radius: 8px;
    transition: background 0.15s, color 0.15s;
  }

  .crm-sidebar-profile .dropdown-menu .li-header:hover {
    background: rgba(37, 99, 235, 0.06);
    color: #374151;
  }

  .crm-sidebar-profile .dropdown-menu .li-header i {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
    color: #6b7280;
    flex-shrink: 0;
  }

  /* Language – collapsible nested (ca submeniu), arrow Font Awesome */
  .crm-sidebar-profile .dropdown-submenu > a.li-header::after {
    display: none !important;
  }

  .crm-sidebar-profile .dropdown-submenu > a.li-header .crm-lang-arrow {
    display: inline-block;
  }

  .crm-sidebar-profile .dropdown-submenu > a.li-header {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .crm-sidebar-profile .crm-lang-arrow {
    margin-left: auto;
    font-size: 0.8rem;
    color: #6b7280;
    flex-shrink: 0;
    transition: transform 0.2s;
  }

  .crm-sidebar-profile .dropdown-submenu.crm-profile-submenu-expanded .crm-lang-arrow {
    transform: rotate(-90deg);
  }

  .crm-sidebar-profile .dropdown-submenu:hover > .dropdown-menu {
    display: none !important;
  }

  .crm-sidebar-profile .dropdown-submenu > .dropdown-menu {
    display: none !important;
    position: static !important;
    float: none !important;
    padding: 6px 14px 6px 12px !important;
    margin: 0 0 0 12px !important;
    border: none !important;
    box-shadow: none !important;
    list-style: none;
    background: transparent !important;
  }

  .crm-sidebar-profile .dropdown-submenu.crm-profile-submenu-expanded > .dropdown-menu {
    display: block !important;
  }

  .crm-sidebar-profile .dropdown-submenu .dropdown-menu li a {
    display: flex;
    align-items: center;
    padding: 8px 14px 8px 24px;
    font-size: 13px;
    color: #5f6368;
    text-decoration: none;
    border-radius: 6px;
  }

  .crm-sidebar-profile .dropdown-submenu .dropdown-menu li a:hover {
    background: rgba(37, 99, 235, 0.06);
    color: #374151;
  }
}

@media (min-width: 992px) {
  .crm-sidebar-profile .dropdown-submenu > a.li-header::after {
    display: none !important;
  }

  .crm-sidebar-profile .dropdown-submenu > a.li-header {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .crm-sidebar-profile .crm-lang-arrow {
    display: inline-block !important;
    margin-left: auto;
    font-size: 0.7rem;
    color: #6b7280;
    flex-shrink: 0;
  }
}

.crm-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
  cursor: pointer;
}
