.sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  width: 280px;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
}

.sidebar-mobile-bar,
.sidebar-mobile-close {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

.sidebar-head {
  position: relative;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sidebar .brand-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  text-decoration: none;
  color: inherit;
}

.sidebar .logo {
  justify-content: center;
  width: 100%;
}

.sidebar-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9b8993;
  margin: 0;
}

.tenant-switcher {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
  position: relative;
}

.tenant-trigger {
  width: 100%;
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #faf6f7;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  text-align: left;
  transition: all 0.15s ease;
}

.tenant-trigger:hover {
  background: #fff;
  border-color: #dcc5cc;
  box-shadow: 0 1px 2px rgba(43, 17, 25, 0.08);
}

.tenant-trigger:focus-visible,
.tenant-trigger.is-open {
  outline: none;
  border-color: var(--wine);
  box-shadow: 0 0 0 3px rgba(123, 30, 58, 0.15);
  background: #fff;
}

.tenant-trigger.is-readonly {
  cursor: default;
  border-style: dashed;
  background: transparent;
}

.tenant-trigger.is-readonly:hover {
  box-shadow: none;
  border-color: var(--border);
  background: transparent;
}

.tenant-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--gold), #8e5c26);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}

.tenant-meta {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.tenant-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tenant-sub {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tenant-chevron {
  width: 16px;
  height: 16px;
  color: #9b8993;
  flex-shrink: 0;
  transition: transform 0.18s ease;
}

.tenant-trigger.is-open .tenant-chevron {
  transform: rotate(180deg);
  color: var(--wine);
}

.tenant-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #dcc5cc;
  border-radius: 12px;
  box-shadow: 0 8px 24px -8px rgba(43, 17, 25, 0.18), 0 2px 6px rgba(43, 17, 25, 0.06);
  padding: 6px;
  max-height: 320px;
  overflow-y: auto;
  display: none;
  z-index: 40;
}

.tenant-menu.is-open {
  display: block;
}

.tenant-search-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.tenant-search-icon {
  width: 14px;
  height: 14px;
  color: #9b8993;
  flex: 0 0 14px;
}

.tenant-search {
  border: 0;
  border-radius: 0;
  outline: none;
  width: 100%;
  padding: 4px 0;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  box-shadow: none;
}

.tenant-search::placeholder {
  color: #9b8993;
  opacity: 1;
}

.tenant-search:focus,
.tenant-search:focus-visible {
  border: 0;
  border-radius: 0;
  outline: none;
  outline-offset: 0;
  box-shadow: none;
}

.tenant-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  transition: background 0.12s ease;
}

.tenant-item:hover {
  background: #fbf0f3;
}

.tenant-item.is-active {
  background: rgba(123, 30, 58, 0.14);
}

.tenant-item-avatar {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: #f1e1cb;
  color: #651730;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.tenant-item-meta {
  min-width: 0;
  flex: 1;
}

.tenant-item-name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tenant-item-sub {
  display: block;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tenant-item-check {
  width: 16px;
  height: 16px;
  color: var(--wine);
  flex-shrink: 0;
}

.tenant-item:not(.is-active) .tenant-item-check {
  visibility: hidden;
}

.sidebar-nav {
  display: block;
  flex: 1;
  margin: 0;
  padding: 12px;
  list-style: none;
  min-height: 0;
  overflow-y: auto;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 40px;
  padding: 11px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.2;
  color: var(--muted);
  font-weight: 500;
  margin: 0 0 4px;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.sidebar-nav a:hover {
  background: var(--secondary);
  color: var(--text);
  text-decoration: none;
}

.sidebar-nav a.active {
  background: var(--wine);
  color: #fff;
}

.sidebar-nav a svg {
  display: block;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  color: currentColor;
}

.sidebar-nav a.active svg {
  color: #fff;
}

.nav-foot {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  flex: 0 0 auto;
  margin-top: auto;
}

.sidebar-user {
  margin-bottom: 8px;
}

.sidebar-user-card {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  background: #faf6f7;
  border: 1px solid var(--border);
}

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--wine), var(--wine-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.sidebar-user-meta {
  min-width: 0;
  flex: 1;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-email {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-role-badge {
  display: inline-flex;
  align-items: center;
  margin-top: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.4;
  background: rgba(123, 30, 58, 0.14);
  color: #651730;
}

.sidebar-user-actions {
  margin-top: 8px;
  display: flex;
  gap: 6px;
}

.sidebar-action-btn {
  flex: 1;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.12s ease;
}

.sidebar-action-btn svg {
  width: 13px;
  height: 13px;
  flex: 0 0 13px;
}

.sidebar-action-btn:hover {
  background: #fbf0f3;
  border-color: #dcc5cc;
  color: var(--wine);
  text-decoration: none;
}

.sidebar-action-btn.is-danger:hover {
  background: var(--wine);
  border-color: var(--wine);
  color: #fff;
}

.nav-logout {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.2;
  font-weight: 500;
  text-decoration: none;
}

.nav-logout:hover {
  background: var(--secondary);
  color: var(--text);
  text-decoration: none;
}

.nav-logout svg {
  display: block;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  color: currentColor;
}

@media (max-width: 1024px) {
  .sidebar {
    width: 248px;
  }
}

@media (max-width: 760px) {
  body.no-scroll {
    overflow: hidden;
  }

  .app {
    min-height: 100dvh;
    height: auto;
  }

  .main {
    height: auto;
    min-height: 100dvh;
    width: 100%;
    padding: 76px 18px 24px;
    overflow: visible;
  }

  .sidebar-mobile-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1180;
    height: 56px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: #fff;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-mobile-trigger {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 40px;
  }

  .sidebar-mobile-trigger svg {
    width: 20px;
    height: 20px;
  }

  .sidebar-mobile-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
    min-width: 0;
    flex: 1;
  }

  .sidebar-mobile-avatar {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--wine), var(--gold));
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex: 0 0 36px;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(31, 20, 24, 0.48);
    z-index: 1190;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }

  .sidebar-backdrop.is-visible {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(84vw, 320px);
    max-width: 320px;
    height: 100dvh;
    min-height: 100dvh;
    z-index: 1200;
    transform: translateX(-102%);
    transition: transform 0.22s cubic-bezier(.2, .8, .2, 1);
    box-shadow: 12px 0 40px rgba(40, 10, 20, .18);
    display: flex;
  }

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

  .sidebar-mobile-close {
    position: absolute;
    right: 10px;
    top: 10px;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
  }

  .sidebar-mobile-close svg {
    width: 20px;
    height: 20px;
  }
}
