:root {
  --crm-sidebar-width: 260px;
  --crm-sidebar-collapsed-width: 72px;
  --crm-sidebar-bg: #111827;
  --crm-sidebar-text: #e5e7eb;
  --crm-sidebar-muted: #9ca3af;
  --crm-sidebar-active: #1d4ed8;
  --crm-sidebar-active-bg: rgba(29, 78, 216, 0.18);
  --crm-mobile-bar-height: 3.5rem;
}

.crm-app {
  min-height: 100vh;
}

.crm-skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 500;
  padding: 0.75rem 1rem;
  background: #fff;
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: 0.375rem;
}

.crm-skip-link:focus {
  left: 1rem;
  top: 1rem;
}

.crm-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

.crm-sidebar {
  width: var(--crm-sidebar-width);
  flex-shrink: 0;
  background: var(--crm-sidebar-bg);
  color: var(--crm-sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid #1f2937;
  transition: width 0.2s ease, transform 0.2s ease;
}

.crm-sidebar-header {
  padding: 0.85rem 1rem 0.75rem;
  border-bottom: 1px solid #1f2937;
}

.crm-sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  color: #fff;
  font-weight: 700;
  text-decoration: none;
}

.crm-sidebar-brand:hover {
  background: transparent;
  box-shadow: none;
  color: #fff;
  text-decoration: none;
}

.crm-sidebar-brand-logo {
  display: block;
  width: 132px;
  height: auto;
  max-width: 100%;
  object-fit: contain;
  object-position: center center;
  flex-shrink: 0;
  filter: brightness(0) invert(1);
}

.crm-sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.75rem 0.5rem 1rem;
}

.crm-sidebar-section + .crm-sidebar-section {
  margin-top: 1rem;
}

.crm-sidebar-section-title {
  margin: 0 0 0.35rem;
  padding: 0 0.75rem;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--crm-sidebar-muted);
  text-transform: uppercase;
}

.crm-sidebar-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.crm-sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: 0.5rem;
  color: var(--crm-sidebar-text);
  text-decoration: none;
  line-height: 1.3;
}

.crm-sidebar-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  text-decoration: none;
}

.crm-sidebar-link:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.crm-sidebar-link.is-active {
  background: var(--crm-sidebar-active-bg);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--crm-sidebar-active);
}

.crm-sidebar-icon {
  display: inline-flex;
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  align-items: center;
  justify-content: center;
}

.crm-nav-svg {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
}

.crm-sidebar-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crm-sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid #1f2937;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.crm-sidebar-public-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  border-radius: 0.5rem;
  background: var(--crm-sidebar-active);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}

.crm-sidebar-public-link:hover {
  background: var(--primary-dark);
  color: #fff;
  text-decoration: none;
}

.crm-sidebar-public-link:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.crm-sidebar-collapse {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid #374151;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--crm-sidebar-text);
  cursor: pointer;
  font: inherit;
}

.crm-sidebar-collapse:hover {
  background: rgba(255, 255, 255, 0.06);
}

.crm-sidebar-collapse:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.crm-shell {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.crm-mobile-bar {
  display: none;
  align-items: center;
  gap: 0.75rem;
  min-height: var(--crm-mobile-bar-height);
  padding: 0.75rem 1rem;
  background: #111827;
  color: #fff;
  border-bottom: 1px solid #1f2937;
}

.crm-mobile-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid #374151;
  border-radius: 0.5rem;
  background: transparent;
  color: #fff;
  cursor: pointer;
  font: inherit;
}

.crm-mobile-toggle:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.crm-mobile-brand-link {
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.crm-mobile-brand-logo {
  display: block;
  width: 100px;
  height: auto;
  max-width: min(110px, 42vw);
  object-fit: contain;
  object-position: center center;
  flex-shrink: 0;
  filter: brightness(0) invert(1);
}

.crm-mobile-brand {
  font-weight: 700;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crm-mobile-public-link {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.75rem;
  border-radius: 0.5rem;
  background: var(--crm-sidebar-active);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.crm-mobile-public-link:hover {
  background: var(--primary-dark);
  color: #fff;
  text-decoration: none;
}

.crm-main {
  flex: 1;
  padding: 2rem 0 3rem;
}

.crm-main:focus {
  outline: none;
}

.crm-top-bar {
  display: none;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: #fff;
  border-bottom: 1px solid var(--border, #e5e7eb);
}

.crm-top-bar-spacer {
  flex: 1;
}

.crm-user-menu {
  position: relative;
}

.crm-user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.35rem 0.55rem 0.35rem 0.35rem;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 999px;
  background: #fff;
  color: var(--text, #111827);
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.crm-top-bar .crm-user-menu-trigger {
  border-color: #d1d5db;
}

.crm-mobile-bar .crm-user-menu-trigger {
  border-color: #374151;
  background: rgba(255, 255, 255, 0.04);
  color: #fff;
  padding: 0.25rem;
  border-radius: 999px;
}

.crm-mobile-bar .crm-user-menu-text,
.crm-mobile-bar .crm-user-menu-chevron {
  display: none;
}

.crm-user-menu-trigger:hover {
  background: #f9fafb;
}

.crm-mobile-bar .crm-user-menu-trigger:hover {
  background: rgba(255, 255, 255, 0.08);
}

.crm-user-menu-trigger:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.crm-user-menu-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: var(--crm-sidebar-active);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

.crm-user-menu-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}

.crm-user-menu-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 10rem;
}

.crm-user-menu-role {
  font-size: 0.75rem;
  color: var(--muted, #6b7280);
}

.crm-mobile-bar .crm-user-menu-role {
  color: #d1d5db;
}

.crm-user-menu-chevron {
  display: inline-flex;
  width: 1rem;
  height: 1rem;
  transform: rotate(90deg);
  color: var(--muted, #6b7280);
}

.crm-user-menu-panel {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  min-width: 12rem;
  padding: 0.35rem;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 0.65rem;
  background: #fff;
  box-shadow: 0 10px 25px rgba(17, 24, 39, 0.12);
  z-index: 300;
}

.crm-user-menu-item {
  display: block;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 0;
  border-radius: 0.45rem;
  background: transparent;
  color: var(--text, #111827);
  text-decoration: none;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.crm-user-menu-item:hover,
.crm-user-menu-item:focus-visible {
  background: #f3f4f6;
  color: var(--text, #111827);
  text-decoration: none;
  outline: none;
}

.crm-user-menu-logout {
  margin: 0;
  padding: 0;
}

.crm-user-menu-logout-btn {
  color: #b91c1c;
}

.crm-user-menu-logout-btn:hover,
.crm-user-menu-logout-btn:focus-visible {
  background: #fef2f2;
  color: #991b1b;
}

.crm-profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem 1.5rem;
  margin: 0;
}

.crm-profile-item dt {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.crm-profile-item dd {
  margin: 0;
  font-size: 1rem;
}

.crm-sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
  z-index: 150;
}

.crm-app.crm-sidebar-collapsed .crm-sidebar {
  width: var(--crm-sidebar-collapsed-width);
}

.crm-app.crm-sidebar-collapsed .crm-sidebar-header {
  padding: 0.65rem 0.35rem 0.7rem;
}

.crm-app.crm-sidebar-collapsed .crm-sidebar-brand {
  padding: 0;
}

.crm-app.crm-sidebar-collapsed .crm-sidebar-brand-logo {
  width: 44px;
  max-width: 100%;
  height: auto;
  object-position: center center;
}

.crm-app.crm-sidebar-collapsed .crm-sidebar-section-title,
.crm-app.crm-sidebar-collapsed .crm-sidebar-label,
.crm-app.crm-sidebar-collapsed .crm-sidebar-public-link span.crm-sidebar-public-text,
.crm-app.crm-sidebar-collapsed .crm-sidebar-collapse-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.crm-app.crm-sidebar-collapsed .crm-sidebar-link {
  justify-content: center;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.crm-app.crm-sidebar-collapsed .crm-sidebar-public-link,
.crm-app.crm-sidebar-collapsed .crm-sidebar-collapse {
  justify-content: center;
}

.crm-app.crm-sidebar-collapsed .crm-sidebar-collapse-icon {
  transform: rotate(180deg);
}

@media (max-width: 1023px) {
  .crm-mobile-bar {
    display: flex;
  }

  .crm-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    transform: translateX(-100%);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  }

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

  .crm-sidebar-collapse {
    display: none !important;
  }

  .crm-app.crm-sidebar-collapsed .crm-sidebar {
    width: var(--crm-sidebar-width);
  }

  .crm-app.crm-sidebar-collapsed .crm-sidebar-section-title,
  .crm-app.crm-sidebar-collapsed .crm-sidebar-label,
  .crm-app.crm-sidebar-collapsed .crm-sidebar-public-link span.crm-sidebar-public-text,
  .crm-app.crm-sidebar-collapsed .crm-sidebar-collapse-label {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: hidden;
    clip: auto;
    white-space: nowrap;
  }
}

@media (max-width: 768px) {
  .crm-sidebar-brand-logo {
    width: 100px;
    max-width: min(110px, 42vw);
  }
}

@media (min-width: 1024px) {
  .crm-sidebar-collapse {
    display: inline-flex;
  }

  .crm-top-bar {
    display: flex;
  }

  .crm-sidebar-backdrop {
    display: none !important;
  }
}
