.menu-permission-layout {
  display: grid;
  flex: 1;
  grid-template-columns: 340px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.menu-tree-panel,
.menu-detail-panel {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: var(--bg-card);
}

.menu-tree-panel {
  border-right: 1px solid var(--border);
}

.menu-tree-panel__header,
.menu-detail-header,
.menu-access-card,
.menu-permission-picker__header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.menu-tree-panel__header,
.menu-permission-picker__header {
  display: grid;
  gap: var(--space-3);
}

.menu-panel-title {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.menu-panel-title h2,
.menu-panel-title h3,
.menu-detail-title h2 {
  margin: 0;
  color: var(--text-primary);
  font-size: var(--admin-font-size);
  font-weight: 760;
}

.menu-panel-title span,
.menu-detail-title span,
.menu-detail-field span {
  color: var(--text-tertiary);
  font-size: var(--admin-font-size);
}

.menu-tree-list,
.menu-permission-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.menu-tree-item {
  display: grid;
  width: 100%;
  min-height: 58px;
  align-items: center;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: var(--space-3);
  padding-top: var(--space-2);
  padding-right: var(--space-4);
  padding-bottom: var(--space-2);
  border: 0;
  border-bottom: 1px solid var(--row-border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition:
    background var(--motion-fast) var(--ease-standard),
    box-shadow var(--motion-fast) var(--ease-standard),
    color var(--motion-fast) var(--ease-standard);
}

.menu-tree-item:hover {
  background: var(--bg-card-strong);
}

.menu-tree-item--active,
.menu-tree-item--active:hover {
  background: var(--primary-surface);
  box-shadow: inset 3px 0 0 var(--primary);
  color: var(--text-primary);
}

.menu-tree-item__drag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
}

.menu-tree-item__content {
  display: grid;
  min-width: 0;
  gap: var(--space-1);
}

.menu-tree-item__name,
.menu-tree-item__meta {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-tree-item__name {
  color: inherit;
  font-weight: 700;
}

.menu-tree-item__meta {
  color: var(--text-tertiary);
  font-size: var(--admin-font-size);
}

.menu-tree-status {
  display: inline-flex;
  height: 24px;
  align-items: center;
  justify-content: center;
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--neutral-surface);
  color: var(--stopped);
  font-size: var(--admin-font-size);
  font-weight: 650;
  white-space: nowrap;
}

.menu-tree-status.is-visible {
  border-color: var(--success-border);
  background: var(--success-surface);
  color: var(--success);
}

.menu-tree-status.is-hidden {
  color: var(--stopped);
}

.menu-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.menu-detail-title {
  display: grid;
  min-width: 0;
  gap: var(--space-2);
}

.menu-detail-title h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-detail-fields {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--border);
}

.menu-detail-field {
  display: grid;
  min-width: 0;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-right: 1px solid var(--row-border);
}

.menu-detail-field:last-child {
  border-right: 0;
}

.menu-detail-field strong {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text-primary);
  font-size: var(--admin-font-size);
  font-weight: 700;
}

.menu-access-card {
  display: grid;
  gap: var(--space-3);
}

.menu-access-card__header {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.menu-bound-permission {
  display: grid;
  align-items: center;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.2fr) auto;
  gap: var(--space-3);
  min-height: var(--control-height);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--bg-card-strong);
  color: var(--text-secondary);
  font-size: var(--admin-font-size);
}

.menu-bound-permission span,
.menu-bound-permission code {
  min-width: 0;
  overflow-wrap: anywhere;
}

.menu-bound-permission span:first-child {
  color: var(--text-primary);
  font-weight: 700;
}

.menu-bound-permission code,
.menu-permission-option code {
  color: var(--text-tertiary);
  font-family: inherit;
  font-size: var(--admin-font-size);
}

.menu-permission-picker {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.menu-permission-option {
  display: grid;
  width: 100%;
  min-height: 56px;
  align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border: 0;
  border-bottom: 1px solid var(--row-border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition:
    background var(--motion-fast) var(--ease-standard),
    color var(--motion-fast) var(--ease-standard);
}

.menu-permission-option:hover {
  background: var(--bg-card-strong);
}

.menu-permission-option:disabled {
  cursor: default;
}

.menu-permission-option--active,
.menu-permission-option--active:hover {
  background: var(--primary-surface);
  color: var(--text-primary);
}

.menu-permission-option > span {
  display: grid;
  min-width: 0;
  gap: var(--space-1);
}

.menu-permission-option strong {
  min-width: 0;
  overflow: hidden;
  color: inherit;
  font-size: var(--admin-font-size);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-permission-option em {
  display: inline-flex;
  height: 24px;
  align-items: center;
  padding: 0 var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--neutral-surface);
  color: var(--text-tertiary);
  font-style: normal;
  font-size: var(--admin-font-size);
  font-weight: 650;
  white-space: nowrap;
}

.menu-detail-empty,
.empty-state--compact {
  display: grid;
  flex: 1;
  min-height: 180px;
  place-items: center;
}

.permission-library-drawer {
  width: min(920px, 100vw);
}

.permission-library-drawer__body {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
}

.permission-library-drawer__body .search-box {
  flex: 0 0 auto;
}

.permission-library-drawer__body .table-frame {
  flex: 1;
  min-height: 0;
}

@media (max-width: 980px) {
  .menu-permission-layout {
    grid-template-columns: 1fr;
  }

  .menu-tree-panel {
    min-height: 320px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 720px) {
  .menu-detail-header,
  .menu-access-card__header {
    align-items: stretch;
    flex-direction: column;
  }

  .menu-detail-fields,
  .menu-bound-permission {
    grid-template-columns: 1fr;
  }

  .menu-detail-field {
    border-right: 0;
    border-bottom: 1px solid var(--row-border);
  }

  .menu-detail-field:last-child {
    border-bottom: 0;
  }
}
