.admin-md-page {
  --page-module-accent: #2864d8;
  gap: 18px;
}

.admin-view-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--soft);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--line);
  vertical-align: middle;
}

.admin-view-toggle button {
  padding: 6px 14px;
  font-size: 16px;
  font-weight: 800;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.admin-view-toggle button.is-active {
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.admin-history-container {
  width: 100%;
  margin-top: 20px;
}

.admin-reuse-container {
  width: 100%;
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.admin-reuse-container[hidden] {
  display: none;
}

.admin-md-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-md-search {
  min-width: 260px;
  max-width: 460px;
  flex: 1 1 320px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px 12px;
}

.admin-md-search .app-icon {
  --icon-size: 18px;
  opacity: 0.62;
}

.admin-md-search input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: var(--font-weight-medium);
}

.admin-md-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: var(--font-weight-bold);
  white-space: nowrap;
}

.admin-md-folders {
  display: flex;
  gap: 8px;
  margin: -2px 0 2px;
  overflow-x: auto;
  padding: 2px 0 8px;
  scrollbar-width: thin;
}

.admin-md-folder-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: var(--font-weight-semibold);
  line-height: 1;
  padding: 10px 12px;
}

.admin-md-folder-tab strong {
  min-width: 22px;
  border-radius: 999px;
  background: #eef3f7;
  color: var(--muted);
  font-size: 11px;
  font-weight: var(--font-weight-bold);
  line-height: 1;
  padding: 5px 6px;
  text-align: center;
}

.admin-md-folder-tab:hover,
.admin-md-folder-tab:focus-visible {
  background: var(--soft);
  outline: none;
}

.admin-md-folder-tab.is-active {
  border-color: #b9cff8;
  background: #eaf2ff;
  color: #174caa;
}

.admin-md-folder-tab.is-active strong {
  background: #d8e7ff;
  color: #174caa;
}

.admin-md-layout {
  min-height: 620px;
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(0, 1fr);
  gap: 14px;
}

.admin-md-list,
.admin-md-viewer {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.admin-md-list {
  max-height: 72vh;
  overflow: auto;
  padding: 8px;
}

.admin-md-file {
  width: 100%;
  display: grid;
  gap: 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  padding: 11px 12px;
  text-align: left;
}

.admin-md-file:hover,
.admin-md-file:focus-visible {
  background: var(--soft);
  outline: none;
}

.admin-md-file.is-active {
  background: #eaf2ff;
  color: #174caa;
}

.admin-md-file-name {
  overflow: hidden;
  font-size: 14px;
  font-weight: var(--font-weight-bold);
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-md-file-meta {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: var(--font-weight-semibold);
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-md-viewer {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.admin-md-viewer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 16px 18px;
}

.admin-md-viewer-head h2 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  font-weight: var(--font-weight-heading);
  line-height: 1.3;
}

.admin-md-viewer-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: var(--font-weight-semibold);
  line-height: 1.45;
}

.admin-md-open {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: var(--font-weight-semibold);
  padding: 8px 10px;
  text-decoration: none;
}

.admin-md-open:hover,
.admin-md-open:focus-visible {
  background: var(--soft);
  outline: none;
}

.admin-md-body {
  min-height: 0;
  margin: 0;
  overflow: auto;
  background: #fbfdff;
  color: #1f2d38;
  font-size: 15px;
  font-weight: var(--font-weight-body);
  line-height: 1.75;
  padding: 18px;
}

.admin-md-rendered > :first-child {
  margin-top: 0;
}

.admin-md-rendered > :last-child {
  margin-bottom: 0;
}

.admin-md-rendered h1,
.admin-md-rendered h2,
.admin-md-rendered h3,
.admin-md-rendered h4 {
  color: var(--ink);
  font-weight: var(--font-weight-heading);
  line-height: 1.25;
}

.admin-md-rendered h1 {
  margin: 0 0 18px;
  border-bottom: 1px solid var(--line);
  font-size: 30px;
  padding-bottom: 14px;
}

.admin-md-rendered h2 {
  margin: 28px 0 12px;
  font-size: 22px;
}

.admin-md-rendered h3 {
  margin: 22px 0 10px;
  font-size: 18px;
}

.admin-md-rendered h4 {
  margin: 18px 0 8px;
  font-size: 16px;
}

.admin-md-rendered p,
.admin-md-rendered ul,
.admin-md-rendered ol,
.admin-md-rendered blockquote,
.admin-md-rendered pre,
.admin-md-rendered table {
  margin: 0 0 14px;
}

.admin-md-rendered ul,
.admin-md-rendered ol {
  padding-left: 24px;
}

.admin-md-rendered li + li {
  margin-top: 4px;
}

.admin-md-rendered a {
  color: #1b62cf;
  font-weight: var(--font-weight-bold);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.admin-md-rendered blockquote {
  border-left: 4px solid #b9cff8;
  background: #f3f7ff;
  color: #384955;
  padding: 12px 14px;
}

.admin-md-rendered code {
  border-radius: 6px;
  background: #eef3f7;
  color: #16324a;
  font-family: var(--font-data);
  font-size: 0.92em;
  padding: 2px 5px;
}

.admin-md-rendered pre {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1720;
  color: #e9f0f6;
  padding: 14px;
}

.admin-md-rendered pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.admin-md-rendered table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.admin-md-rendered th,
.admin-md-rendered td {
  border: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

.admin-md-rendered th {
  background: #f2f6f9;
  color: var(--ink);
  font-weight: var(--font-weight-bold);
}

.admin-md-rendered hr {
  height: 1px;
  border: 0;
  background: var(--line);
  margin: 24px 0;
}

.admin-md-loading,
.admin-md-error {
  color: var(--muted);
  font-size: 14px;
  font-weight: var(--font-weight-semibold);
}

.admin-md-error {
  color: #b42318;
}

.admin-md-empty {
  color: var(--muted);
  font-size: 13px;
  font-weight: var(--font-weight-semibold);
  line-height: 1.5;
  padding: 14px;
}

.admin-reuse-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-reuse-search {
  max-width: 520px;
}

.admin-reuse-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-reuse-controls button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: var(--font-weight-bold);
  line-height: 1;
  padding: 9px 10px;
}

.admin-reuse-controls button:hover,
.admin-reuse-controls button:focus-visible {
  background: var(--soft);
  outline: none;
}

.admin-reuse-map-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 14px 16px;
}

.admin-reuse-map-head h2 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  font-weight: var(--font-weight-heading);
  line-height: 1.3;
}

.admin-reuse-map-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: var(--font-weight-semibold);
  line-height: 1.45;
}

.admin-reuse-status {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  color: var(--muted);
  font-size: 12px;
  font-weight: var(--font-weight-bold);
  line-height: 1.35;
  padding: 8px 10px;
}

.admin-reuse-tree-shell {
  min-height: 620px;
  max-height: 76vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
}

.admin-reuse-tree {
  display: grid;
  gap: 6px;
}

.admin-reuse-tree-branch,
.admin-reuse-tree-leaf {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.admin-reuse-tree-branch[open] {
  background: #fbfdff;
}

.admin-reuse-tree-branch summary,
.admin-reuse-tree-leaf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 9px 11px;
}

.admin-reuse-tree-branch summary {
  cursor: pointer;
  list-style: none;
}

.admin-reuse-tree-branch summary::-webkit-details-marker {
  display: none;
}

.admin-reuse-tree-branch summary::before {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #eef3f7;
  color: var(--muted);
  content: "›";
  font-size: 15px;
  font-weight: var(--font-weight-bold);
  line-height: 1;
  transform: rotate(0deg);
  transition: transform 0.15s ease;
}

.admin-reuse-tree-branch[open] > summary::before {
  transform: rotate(90deg);
}

.admin-reuse-tree-branch summary:hover,
.admin-reuse-tree-branch summary:focus-visible,
.admin-reuse-tree-leaf:hover {
  background: var(--soft);
  outline: none;
}

.admin-reuse-tree-children {
  display: grid;
  gap: 6px;
  margin: 0 0 10px 28px;
  padding: 0 10px 0 13px;
  border-left: 2px solid #e3ebf2;
}

.admin-reuse-node-main {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
}

.admin-reuse-label {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: var(--font-weight-bold);
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-reuse-node-meta {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: var(--font-weight-bold);
}

.admin-reuse-node-meta span {
  border-radius: 999px;
  background: #eef3f7;
  padding: 5px 7px;
}

.admin-reuse-tree-node.is-search-match {
  border-color: #f5c76a;
  background: #fffaf0;
}

.admin-reuse-type {
  flex: 0 0 auto;
  border-radius: 999px;
  background: #eef3f7;
  color: #334155;
  font-size: 11px;
  font-weight: var(--font-weight-bold);
  letter-spacing: 0;
  line-height: 1;
  padding: 6px 8px;
}

.admin-reuse-type-section { background: #eaf2ff; color: #174caa; }
.admin-reuse-type-category { background: #e6f7fb; color: #0e7490; }
.admin-reuse-type-file { background: #e9f8ef; color: #15803d; }
.admin-reuse-type-item { background: #f2ebff; color: #6d28d9; }
.admin-reuse-type-rule { background: #fff4df; color: #b45309; }
.admin-reuse-type-status { background: #fff0ee; color: #b42318; }

.admin-reuse-file-refs {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.admin-reuse-file-refs span {
  border-radius: 999px;
  background: #e9f8ef;
  color: #15803d;
  font-family: var(--font-data);
  font-size: 11px;
  font-weight: var(--font-weight-bold);
  line-height: 1;
  padding: 5px 7px;
}

@media (max-width: 900px) {
  .admin-md-toolbar,
  .admin-md-viewer-head,
  .admin-reuse-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .admin-md-search {
    max-width: none;
  }

  .admin-md-layout {
    grid-template-columns: 1fr;
  }

  .admin-md-list {
    max-height: 260px;
  }

  .admin-reuse-map-head {
    flex-direction: column;
  }

  .admin-reuse-status {
    width: 100%;
  }

  .admin-reuse-tree-shell {
    max-height: none;
  }

  .admin-reuse-tree-children {
    margin-left: 14px;
    padding-left: 10px;
  }

  .admin-reuse-label {
    white-space: normal;
  }
}
