:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --line: #dce3ed;
  --text: #1f2937;
  --muted: #65758b;
  --blue: #2f80ed;
  --blue-dark: #1d63c9;
  --green: #15803d;
  --red: #b42318;
  --shadow: 0 12px 34px rgba(31, 41, 55, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.admin-page {
  max-width: 980px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.button.primary:hover {
  background: var(--blue-dark);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.catalog-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.catalog-node {
  display: grid;
  gap: 8px;
}

.catalog-children {
  display: grid;
  gap: 8px;
}

.catalog-row {
  position: relative;
  display: grid;
  grid-template-columns: 24px 34px 1fr 38px;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 10px 12px 10px calc(12px + var(--depth, 0) * 26px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.tree-toggle,
.tree-spacer {
  width: 24px;
  height: 30px;
}

.tree-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.tree-toggle:hover {
  background: #eef2f7;
  color: var(--text);
}

.folder-icon {
  width: 32px;
  height: 26px;
  color: var(--blue);
}

.catalog-title {
  min-width: 0;
}

.catalog-title strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.catalog-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.permission-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 3px 7px;
  border: 1px solid #c7d7ef;
  border-radius: 999px;
  background: #eef6ff;
  color: #24528f;
  font-size: 12px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-button:hover {
  background: #eef2f7;
  color: var(--text);
}

.row-menu {
  position: absolute;
  top: 48px;
  right: 12px;
  z-index: 3;
  min-width: 210px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.row-menu button {
  width: 100%;
  justify-content: flex-start;
  border: 0;
}

.employee-list {
  display: grid;
  gap: 10px;
}

.employee-card {
  display: grid;
  grid-template-columns: 1fr 34px;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.employee-card strong,
.employee-card span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.employee-card span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.remove-button {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: #fff1f0;
  color: var(--red);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.remove-button:hover {
  background: #ffe3e0;
}

.remove-button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.state {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
}

.state.error {
  color: var(--red);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.48);
}

.modal {
  width: min(560px, 100%);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.modal-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field label {
  color: var(--muted);
  font-size: 13px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.segmented button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.segmented button.active {
  border-color: var(--blue);
  background: #eaf3ff;
  color: var(--blue-dark);
}

.input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
}

.input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 128, 237, 0.14);
}

.user-results {
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.user-result {
  width: 100%;
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.user-result:last-child {
  border-bottom: 0;
}

.user-result.active,
.user-result:hover {
  background: #eef6ff;
}

.user-result span {
  color: var(--muted);
  font-size: 12px;
}

.notice {
  min-height: 18px;
  margin-top: 10px;
  color: var(--green);
  font-size: 13px;
}

@media (max-width: 640px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .catalog-row {
    grid-template-columns: 22px 30px 1fr 34px;
    padding-left: calc(10px + var(--depth, 0) * 18px);
  }
}
