/* ===== Fagan — Premium Knowledge Base UI ===== */

:root {
  color-scheme: light;

  /* Native Telegram theme (graceful fallbacks) */
  --tg-bg: var(--tg-theme-bg-color, #eef2ee);
  --tg-surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --tg-text: var(--tg-theme-text-color, #1b201c);
  --tg-hint: var(--tg-theme-hint-color, #697568);
  --tg-link: var(--tg-theme-link-color, #2f8f5b);

  /* Brand accent (kept consistent across themes) */
  --accent: #2f8f5b;
  --accent-600: #1f6f44;
  --accent-700: #165236;
  --accent-050: #e7f2eb;
  --accent-glow: rgba(47, 143, 91, 0.26);

  --warn: #e0a128;
  --warn-700: #8a6313;
  --warn-050: #fbf1d6;

  /* Derived tokens */
  --bg: var(--tg-bg);
  --surface: var(--tg-surface);
  --surface-2: color-mix(in srgb, var(--tg-surface) 86%, var(--tg-text) 6%);
  --surface-3: color-mix(in srgb, var(--tg-surface) 78%, var(--tg-text) 10%);
  --text: var(--tg-text);
  --text-soft: color-mix(in srgb, var(--tg-text) 82%, transparent);
  --muted: var(--tg-hint);
  --line: color-mix(in srgb, var(--tg-text) 12%, transparent);
  --line-strong: color-mix(in srgb, var(--tg-text) 20%, transparent);

  --radius-xs: 9px;
  --radius-sm: 12px;
  --radius: 16px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  --shadow-xs: 0 1px 2px rgba(18, 34, 24, 0.06);
  --shadow-sm: 0 2px 6px -2px rgba(18, 34, 24, 0.12), 0 1px 2px rgba(18, 34, 24, 0.05);
  --shadow: 0 10px 26px -12px rgba(18, 34, 24, 0.22), 0 3px 8px -4px rgba(18, 34, 24, 0.10);
  --shadow-lg: 0 22px 48px -18px rgba(18, 34, 24, 0.32);
  --ring: 0 0 0 4px var(--accent-glow);

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --tg-bg: #eef2ee;
  --tg-surface: #ffffff;
  --tg-text: #1b201c;
  --tg-hint: #697568;
  --tg-link: #2f8f5b;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --tg-bg: #171a18;
  --tg-surface: #212522;
  --tg-text: #f2f5f2;
  --tg-hint: #9ca69e;
  --tg-link: #72c996;
  --accent-050: #203d2c;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background-color 0.3s var(--ease), color 0.3s var(--ease);
}

/* Soft ambient gradient at the top for depth */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 320px;
  background:
    radial-gradient(120% 100% at 50% -20%, var(--accent-050) 0%, transparent 60%),
    radial-gradient(80% 100% at 90% -10%, color-mix(in srgb, var(--accent) 18%, transparent) 0%, transparent 55%);
  opacity: 0.9;
  pointer-events: none;
  z-index: 0;
}

::selection {
  background: var(--accent-glow);
  color: var(--text);
}

:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--radius-sm);
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
*::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--tg-text) 18%, transparent);
  border-radius: 8px;
}

h1, h2, h3, p {
  margin: 0;
}

/* ===== Layout shell ===== */

.app-shell {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

/* ===== Top bar ===== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: -8px -16px 16px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  font-size: 22px;
  color: #fff;
  background: linear-gradient(145deg, var(--accent) 0%, var(--accent-700) 100%);
  box-shadow: 0 8px 18px -8px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 1px;
  color: var(--accent-600);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  font-size: 24px;
  line-height: 1.12;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text-soft);
  cursor: pointer;
  flex: 0 0 auto;
  transition: transform 0.15s var(--ease), background-color 0.2s var(--ease),
    border-color 0.2s var(--ease), color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.icon-button:hover {
  color: var(--accent-600);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-xs);
}
.icon-button:active {
  transform: scale(0.92);
}
.icon-button svg {
  width: 20px;
  height: 20px;
  display: block;
}

/* ===== Search ===== */

.search-panel {
  margin-bottom: 14px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 16px;
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
}

.search-panel input {
  width: 100%;
  height: 50px;
  padding: 0 16px 0 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  box-shadow: var(--shadow-xs);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), background-color 0.2s var(--ease);
}
.search-panel input::placeholder {
  color: var(--muted);
}
.search-panel input::-webkit-search-cancel-button {
  display: none;
}
.search-panel input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring), var(--shadow-xs);
}

/* ===== Segmented quick actions ===== */

.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 18px;
  padding: 5px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-xs);
}

.quick-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: color 0.2s var(--ease), background-color 0.25s var(--ease),
    box-shadow 0.25s var(--ease), transform 0.15s var(--ease);
}
.quick-actions button svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}
.quick-actions button:hover {
  color: var(--text);
}
.quick-actions button:active {
  transform: scale(0.96);
}
.quick-actions button.active {
  color: var(--accent-700);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

/* ===== Content panel ===== */

.content-panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

h2 {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

#countBadge {
  min-width: 30px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-050);
  color: var(--accent-700);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

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

.section-note {
  padding: 10px 4px 4px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.list-label {
  margin-top: 6px;
  color: var(--accent-600);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ===== Category / generic item cards ===== */

.item {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 13px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  text-align: left;
  transition: transform 0.15s var(--ease), border-color 0.2s var(--ease),
    box-shadow 0.2s var(--ease), background-color 0.2s var(--ease);
}
.item::after {
  content: "›";
  color: var(--muted);
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
  transform: translateY(-1px);
  transition: transform 0.2s var(--ease), color 0.2s var(--ease);
}
.item:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}
.item:hover::after {
  color: var(--accent);
  transform: translate(2px, -1px);
}
.tree-category::after {
  content: "▸";
  font-size: 16px;
}
.tree-category-open::after {
  content: "▾";
  color: var(--accent);
  transform: none;
}
.tree-node {
  display: grid;
  gap: 8px;
  margin-left: calc(var(--tree-depth, 0) * 18px);
}
.tree-documents {
  display: grid;
  gap: 8px;
  margin-left: 20px;
}

.item-button {
  width: 100%;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.item-button:active {
  transform: scale(0.992);
}

.item-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: linear-gradient(150deg, var(--accent-050), color-mix(in srgb, var(--accent) 12%, var(--surface)));
  font-size: 22px;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 16%, transparent);
}

.item-title {
  margin-bottom: 3px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.item-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.empty {
  padding: 28px 12px;
  color: var(--muted);
  text-align: center;
  font-size: 15px;
  animation: fadeIn 0.25s var(--ease);
}

/* ===== Document cards ===== */

.document {
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  transition: transform 0.15s var(--ease), border-color 0.2s var(--ease),
    box-shadow 0.2s var(--ease);
}
.document-button {
  width: 100%;
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.document-button:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}
.document-button:active {
  transform: scale(0.992);
}

.document-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.favorite-mark {
  color: var(--warn);
  font-size: 18px;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(224, 161, 40, 0.4));
}

.document-compact {
  min-height: 42px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.document-compact .item-title {
  margin: 0;
  font-size: 15px;
}

.document-text {
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.document-media {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
}
.media-thumb {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  padding: 0;
  background: var(--surface-2);
  cursor: pointer;
}
.media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.media-list {
  display: grid;
  gap: 8px;
}
.media-link {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  text-align: left;
  overflow-wrap: anywhere;
}
.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 8px;
  padding: 56px 12px 42px;
  background: rgba(0, 0, 0, 0.86);
}
.image-viewer img {
  max-width: 100%;
  max-height: calc(100vh - 120px);
  justify-self: center;
  object-fit: contain;
  border-radius: var(--radius-sm);
}
.image-viewer-close,
.image-viewer-nav {
  border: 0;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 30px;
}
.image-viewer-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 42px;
  height: 42px;
}
.image-viewer-nav {
  width: 44px;
  height: 64px;
}
.image-viewer-nav:disabled {
  opacity: 0.25;
}
.image-viewer-count {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.tag-line {
  margin-top: 12px;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--accent-600);
  font-size: 12px;
  font-weight: 600;
}
.tag-line::before {
  content: "#";
  margin-right: -2px;
  opacity: 0.6;
}

/* ===== Ghost text button (back) ===== */

.text-button {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  padding: 6px 10px 6px 8px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--accent-600);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  transition: background-color 0.2s var(--ease), transform 0.15s var(--ease);
}
.text-button:hover {
  background: var(--accent-050);
}
.text-button:active {
  transform: translateX(-2px);
}

/* ===== Document detail ===== */

.document-detail {
  position: relative;
  overflow: hidden;
  padding: 20px 56px 20px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.detail-heart {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--warn-700);
  cursor: pointer;
  font: inherit;
  font-size: 24px;
  line-height: 1;
  box-shadow: var(--shadow-xs);
  transition: transform 0.15s var(--ease), border-color 0.2s var(--ease), background-color 0.2s var(--ease);
}
.detail-heart:hover {
  border-color: var(--warn);
  background: var(--warn-050);
}
.detail-heart:active {
  transform: scale(0.92);
}
.detail-heart.active {
  border-color: var(--warn);
  background: var(--warn-050);
}
.document-detail::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-600) 100%);
}

.detail-title {
  margin: 6px 0 14px;
  font-size: 23px;
  font-weight: 800;
  line-height: 1.18;
  letter-spacing: -0.02em;
}

.detail-text {
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* ===== Buttons (file / favorite / submit) ===== */

.favorite-button {
  width: 100%;
  min-height: 48px;
  margin-top: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  transition: transform 0.15s var(--ease), background-color 0.2s var(--ease),
    border-color 0.2s var(--ease), color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.favorite-button:hover {
  border-color: var(--accent);
  color: var(--accent-700);
}
.favorite-button:active {
  transform: scale(0.985);
}

/* Primary CTA: get file */
.favorite-button[data-action="open-file"] {
  background: linear-gradient(145deg, var(--accent) 0%, var(--accent-700) 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 10px 22px -10px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.favorite-button[data-action="open-file"]:hover {
  color: #fff;
  filter: brightness(1.05);
}

/* Favorite active (warn) */
.favorite-button.active {
  border-color: var(--warn);
  background: var(--warn-050);
  color: var(--warn-700);
}

/* Form submit as primary */
.request-form .favorite-button {
  background: linear-gradient(145deg, var(--accent) 0%, var(--accent-700) 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 10px 22px -10px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.request-form .favorite-button:hover {
  color: #fff;
  filter: brightness(1.05);
}

/* ===== Request form ===== */

.request-form {
  display: grid;
  gap: 12px;
}

.request-form textarea {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  color: var(--text);
  background: var(--surface);
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  box-shadow: var(--shadow-xs);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.request-form textarea::placeholder {
  color: var(--muted);
}
.request-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring), var(--shadow-xs);
}

.form-status {
  color: var(--accent-600);
  font-size: 14px;
  font-weight: 600;
}

/* ===== Chat ===== */

.chat-thread-title {
  padding: 4px 2px 8px;
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
}

.chat-messages {
  display: grid;
  gap: 10px;
}

.chat-message {
  justify-self: start;
  max-width: min(88%, 520px);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 16px 16px 16px 6px;
  background: var(--surface-2);
  color: var(--text);
  box-shadow: var(--shadow-xs);
  white-space: pre-wrap;
}

.chat-message.own {
  justify-self: end;
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
  border-radius: 16px 16px 6px 16px;
  background: var(--accent-050);
}

.chat-author {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chat-form {
  display: grid;
  gap: 10px;
  margin-top: 4px;
}

.chat-form textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  color: var(--text);
  background: var(--surface);
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
}

/* ===== Admin panel ===== */

.admin-head {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.admin-subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.admin-tab {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: color 0.2s var(--ease), background-color 0.2s var(--ease),
    border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.admin-tab:hover {
  color: var(--text);
  border-color: var(--line-strong);
}
.admin-tab.active {
  color: var(--accent-700);
  background: var(--accent-050);
  border-color: var(--accent);
  box-shadow: var(--shadow-xs);
}

.admin-body {
  display: grid;
  gap: 12px;
}

.admin-notice {
  margin: 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
}
.admin-notice.info {
  background: var(--surface-2);
  color: var(--muted);
}
.admin-notice.ok {
  background: var(--accent-050);
  color: var(--accent-700);
}
.admin-notice.error {
  background: #fdecec;
  color: #b3261e;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  text-align: center;
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent-700);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.admin-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  display: grid;
  gap: 10px;
}

.admin-item-archived {
  opacity: 0.55;
  border-style: dashed;
}

.admin-item-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.admin-item-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.admin-item-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.admin-item-text {
  margin-top: 4px;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.5;
}

.admin-tree-title {
  cursor: pointer;
  min-width: 0;
}

.admin-filters {
  display: grid;
  grid-template-columns: minmax(150px, 0.7fr) 1fr;
  gap: 10px;
}

.admin-single-filter {
  grid-template-columns: 1fr;
}

.admin-role-select {
  width: min(240px, 100%);
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.admin-user-card {
  padding: 12px 14px;
}

.admin-user-row {
  align-items: center;
}

.admin-user-avatar {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent-050), color-mix(in srgb, var(--accent) 18%, var(--surface)));
  color: var(--accent-700);
  font-weight: 800;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent);
}

.admin-user-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.admin-user-main {
  flex: 1 1 auto;
  min-width: 0;
}

.admin-user-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.admin-user-controls .admin-role-select {
  width: 168px;
}

.admin-item-meta a {
  color: var(--accent-700);
  font-weight: 600;
  text-decoration: none;
}

.admin-item-meta a:hover {
  text-decoration: underline;
}

.admin-icon-actions {
  flex: 0 0 auto;
  gap: 6px;
}

.icon-action {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 16px;
  transition: transform 0.15s var(--ease), border-color 0.2s var(--ease),
    background-color 0.2s var(--ease);
}

.icon-action:hover {
  border-color: var(--line-strong);
  background: var(--surface);
}

.icon-action:active {
  transform: scale(0.94);
}

.icon-action-danger:hover {
  border-color: #ef9a9a;
  background: #fff5f5;
}

.admin-filters input,
.admin-filters select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  box-shadow: var(--shadow-xs);
}

.admin-asset-list {
  display: grid;
  gap: 8px;
}

.admin-asset-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.admin-asset-row span {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: lowercase;
}
.pill-ok {
  background: var(--accent-050);
  color: var(--accent-700);
}
.pill-warn {
  background: var(--warn-050);
  color: var(--warn-700);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.15s var(--ease);
}
.chip:hover {
  color: var(--text);
  border-color: var(--line-strong);
}
.chip-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.admin-actions {
  display: flex;
  gap: 8px;
}

.btn {
  flex: 1;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.15s var(--ease), background-color 0.2s var(--ease),
    border-color 0.2s var(--ease), color 0.2s var(--ease);
}
.btn:active {
  transform: scale(0.985);
}
.btn-sm {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.btn-primary {
  background: linear-gradient(145deg, var(--accent) 0%, var(--accent-700) 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 18px -10px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.btn-primary:hover {
  color: #fff;
  filter: brightness(1.05);
}

.btn-ghost {
  background: var(--surface);
  color: var(--muted);
}
.btn-ghost:hover {
  color: #b3261e;
  border-color: #f1c0bd;
}

.admin-form {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  display: grid;
  gap: 10px;
  box-shadow: var(--shadow-xs);
}

.admin-form-title {
  cursor: pointer;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}

/* Кнопки-переключатели ролей в форме раздела */
.role-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.role-toggle {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  transition: background-color 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease);
}
.role-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.role-toggle-on {
  background: linear-gradient(145deg, var(--accent) 0%, var(--accent-700) 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 14px -8px var(--accent-glow);
}
.role-toggle-on:hover {
  color: #fff;
  filter: brightness(1.05);
}

.admin-form input,
.admin-form select,
.admin-form textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  box-shadow: var(--shadow-xs);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.admin-form input::placeholder,
.admin-form textarea::placeholder {
  color: var(--muted);
}
.admin-form input:focus,
.admin-form select:focus,
.admin-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring), var(--shadow-xs);
}
.admin-form textarea {
  min-height: 80px;
  resize: vertical;
  line-height: 1.5;
}

/* ===== Animations ===== */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.content-list > * {
  animation: fadeIn 0.28s var(--ease) both;
}
.content-list > *:nth-child(2) { animation-delay: 0.03s; }
.content-list > *:nth-child(3) { animation-delay: 0.06s; }
.content-list > *:nth-child(4) { animation-delay: 0.09s; }
.content-list > *:nth-child(5) { animation-delay: 0.12s; }
.content-list > *:nth-child(n + 6) { animation-delay: 0.15s; }

/* ===== Responsive ===== */

@media (max-width: 520px) {
  .app-shell {
    padding: 14px 14px 40px;
  }
  .topbar {
    margin: -8px -14px 14px;
    padding: 10px 14px;
  }
  h1 {
    font-size: 21px;
  }
  .detail-title {
    font-size: 20px;
  }
  .detail-text {
    font-size: 15px;
  }
  .quick-actions button {
    font-size: 0;
    gap: 0;
  }
  .quick-actions button svg {
    width: 20px;
    height: 20px;
  }
  .quick-actions button.active {
    font-size: 13px;
    gap: 6px;
  }
  .admin-filters {
    grid-template-columns: 1fr;
  }
  .admin-user-row {
    align-items: flex-start;
  }
  .admin-user-controls {
    justify-content: flex-start;
    width: 100%;
  }
  .admin-user-controls .admin-role-select {
    flex: 1 1 170px;
  }
  .tree-node {
    margin-left: calc(var(--tree-depth, 0) * 10px);
  }
  .tree-documents {
    margin-left: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
