/* Закрытый хаб — простые темы через CSS-переменные. Основная разметка остаётся на Tailwind. */

@font-face {
  font-family: "VCROSD Mono RUS by D";
  src: url("/site-font/vcrosdmonorusbyd.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Fallback до измерения #mobile-chrome (шапка на телефоне) */
  --app-mobile-chrome-h: 4.5rem;
  --mobile-bottom-nav-h: 5.45rem;
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --ink-900: #0a0d14;
  --ink-800: #11151f;
  --ink-700: #161b27;
  --ink-600: #1f2535;
  --ink-500: #2a3146;
  --ink-400: #3a4360;
  --ink-300: #7d8597;
  --ink-200: #aab1c0;
  --ink-100: #e6e8ef;
  --ink-900-rgb: 10 13 20;
  --ink-800-rgb: 17 21 31;
  --ink-700-rgb: 22 27 39;
  --ink-600-rgb: 31 37 53;
  --ink-500-rgb: 42 49 70;
  --ink-400-rgb: 58 67 96;
  --ink-300-rgb: 125 133 151;
  --ink-200-rgb: 170 177 192;
  --ink-100-rgb: 230 232 239;

  --bg: #0a0d14;
  --bg-elev: #11151f;
  --bg-elev-2: #161b27;
  --border: #1f2535;
  --border-2: #2a3146;
  --text: #e6e8ef;
  --text-strong: #f6f8ff;
  --muted: #7d8597;
  --accent: #8a9bff;
  --accent-2: #c084fc;
  --accent-rgb: 138 155 255;
  --accent-2-rgb: 192 132 252;
  --accent-soft: rgba(138, 155, 255, 0.16);
  --accent-contrast: #08111f;
  --danger: #f87171;
  --success: #6ee7b7;
  --panel-bg: rgba(17, 21, 31, 0.64);
  --list-bg: rgba(17, 21, 31, 0.5);
  --list-bg-hover: rgba(22, 27, 39, 0.65);
  --field-bg: rgba(10, 13, 20, 0.94);
  --chip-bg: rgba(17, 21, 31, 0.7);
  --bottom-nav-bg: rgba(10, 13, 20, 0.94);
  --scroll-thumb: #1d2333;
  --scroll-thumb-hover: #2a3046;
  --glow-1: #4f46e5;
  --glow-2: #c084fc;
  --btn-primary-start: #6b7bff;
  --btn-primary-end: #4f5fef;
  --btn-primary-shadow: rgba(107, 123, 255, 0.6);
  --soft-shadow: rgba(0, 0, 0, 0.62);
  --focus-ring: rgba(138, 155, 255, 0.34);
  --site-font: "VCROSD Mono RUS by D", "Inter", -apple-system, "SF Pro Text", system-ui, sans-serif;
  color-scheme: dark;
}

html[data-theme="telegram-blue"] {
  --ink-900: #07111d;
  --ink-800: #0d1b2a;
  --ink-700: #12263a;
  --ink-600: #1d3954;
  --ink-500: #2d4d6c;
  --ink-400: #4b6f90;
  --ink-300: #84a3bc;
  --ink-200: #b8cad8;
  --ink-100: #eef7ff;
  --ink-900-rgb: 7 17 29;
  --ink-800-rgb: 13 27 42;
  --ink-700-rgb: 18 38 58;
  --ink-600-rgb: 29 57 84;
  --ink-500-rgb: 45 77 108;
  --ink-400-rgb: 75 111 144;
  --ink-300-rgb: 132 163 188;
  --ink-200-rgb: 184 202 216;
  --ink-100-rgb: 238 247 255;

  --bg: #07111d;
  --bg-elev: #0d1b2a;
  --bg-elev-2: #12263a;
  --border: #1d3954;
  --border-2: #2d6fa3;
  --text: #eef7ff;
  --text-strong: #ffffff;
  --muted: #84a3bc;
  --accent: #35a7ff;
  --accent-2: #5ed6ff;
  --accent-rgb: 53 167 255;
  --accent-2-rgb: 94 214 255;
  --accent-soft: rgba(53, 167, 255, 0.16);
  --accent-contrast: #06111d;
  --panel-bg: rgba(13, 27, 42, 0.76);
  --list-bg: rgba(13, 27, 42, 0.62);
  --list-bg-hover: rgba(18, 38, 58, 0.78);
  --field-bg: rgba(7, 17, 29, 0.94);
  --chip-bg: rgba(13, 27, 42, 0.8);
  --bottom-nav-bg: rgba(7, 17, 29, 0.95);
  --scroll-thumb: #1d3954;
  --scroll-thumb-hover: #2d6fa3;
  --glow-1: #0ea5e9;
  --glow-2: #22d3ee;
  --btn-primary-start: #48b7ff;
  --btn-primary-end: #1585d8;
  --btn-primary-shadow: rgba(53, 167, 255, 0.52);
  --focus-ring: rgba(53, 167, 255, 0.32);
}

html[data-theme="light"] {
  --ink-900: #f6f8fb;
  --ink-800: #ffffff;
  --ink-700: #edf2f7;
  --ink-600: #d8e1ea;
  --ink-500: #c5d0dc;
  --ink-400: #8c9bad;
  --ink-300: #64748b;
  --ink-200: #334155;
  --ink-100: #102033;
  --ink-900-rgb: 246 248 251;
  --ink-800-rgb: 255 255 255;
  --ink-700-rgb: 237 242 247;
  --ink-600-rgb: 216 225 234;
  --ink-500-rgb: 197 208 220;
  --ink-400-rgb: 140 155 173;
  --ink-300-rgb: 100 116 139;
  --ink-200-rgb: 51 65 85;
  --ink-100-rgb: 16 32 51;

  --bg: #f6f8fb;
  --bg-elev: #ffffff;
  --bg-elev-2: #edf2f7;
  --border: #d8e1ea;
  --border-2: #b7c7d8;
  --text: #102033;
  --text-strong: #07111d;
  --muted: #64748b;
  --accent: #248be6;
  --accent-2: #6f7dfb;
  --accent-rgb: 36 139 230;
  --accent-2-rgb: 111 125 251;
  --accent-soft: rgba(36, 139, 230, 0.12);
  --accent-contrast: #ffffff;
  --panel-bg: rgba(255, 255, 255, 0.82);
  --list-bg: rgba(255, 255, 255, 0.9);
  --list-bg-hover: rgba(237, 242, 247, 0.95);
  --field-bg: #ffffff;
  --chip-bg: rgba(255, 255, 255, 0.9);
  --bottom-nav-bg: rgba(255, 255, 255, 0.95);
  --scroll-thumb: #c5d0dc;
  --scroll-thumb-hover: #8c9bad;
  --glow-1: #b6dcff;
  --glow-2: #d7cbff;
  --btn-primary-start: #35a7ff;
  --btn-primary-end: #247de0;
  --btn-primary-shadow: rgba(36, 139, 230, 0.28);
  --soft-shadow: rgba(20, 35, 55, 0.18);
  --focus-ring: rgba(36, 139, 230, 0.24);
  color-scheme: light;
}

html[data-theme="sand"] {
  --ink-900: #14120f;
  --ink-800: #201c17;
  --ink-700: #2b261f;
  --ink-600: #433a2e;
  --ink-500: #5c5141;
  --ink-400: #867765;
  --ink-300: #b3a490;
  --ink-200: #d6c8b6;
  --ink-100: #fff7ed;
  --ink-900-rgb: 20 18 15;
  --ink-800-rgb: 32 28 23;
  --ink-700-rgb: 43 38 31;
  --ink-600-rgb: 67 58 46;
  --ink-500-rgb: 92 81 65;
  --ink-400-rgb: 134 119 101;
  --ink-300-rgb: 179 164 144;
  --ink-200-rgb: 214 200 182;
  --ink-100-rgb: 255 247 237;

  --bg: #14120f;
  --bg-elev: #201c17;
  --bg-elev-2: #2b261f;
  --border: #433a2e;
  --border-2: #6f5f49;
  --text: #fff7ed;
  --text-strong: #ffffff;
  --muted: #b3a490;
  --accent: #f0b35f;
  --accent-2: #8bd3c7;
  --accent-rgb: 240 179 95;
  --accent-2-rgb: 139 211 199;
  --accent-soft: rgba(240, 179, 95, 0.16);
  --accent-contrast: #1b1207;
  --panel-bg: rgba(32, 28, 23, 0.74);
  --list-bg: rgba(32, 28, 23, 0.6);
  --list-bg-hover: rgba(43, 38, 31, 0.78);
  --field-bg: rgba(20, 18, 15, 0.94);
  --chip-bg: rgba(32, 28, 23, 0.78);
  --bottom-nav-bg: rgba(20, 18, 15, 0.95);
  --scroll-thumb: #433a2e;
  --scroll-thumb-hover: #6f5f49;
  --glow-1: #f0b35f;
  --glow-2: #8bd3c7;
  --btn-primary-start: #ffd089;
  --btn-primary-end: #e99c3f;
  --btn-primary-shadow: rgba(240, 179, 95, 0.42);
  --focus-ring: rgba(240, 179, 95, 0.28);
}

html {
  background: var(--bg);
  color: var(--text);
  font-feature-settings: "ss01", "cv11";
  font-family: var(--site-font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

* {
  box-sizing: border-box;
}

a {
  color: inherit;
  text-decoration: none;
}

img,
svg,
video,
canvas,
iframe {
  max-width: 100%;
}

input,
textarea,
select,
button {
  font: inherit;
  color: inherit;
}

input,
textarea,
select {
  font-size: 16px;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
}

.app-main {
  min-width: 0;
  width: 100%;
}

.brand-title {
  font-family: var(--site-font);
  font-weight: 400;
  letter-spacing: 0.06em;
}

textarea {
  resize: vertical;
}

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

/* Тонкий скролл */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 6px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
}

/* Tabular numerals для дат и счётчиков */
.num {
  font-variant-numeric: tabular-nums;
}

/* Утилитарные тени-свечения */
.glow-accent {
  box-shadow: 0 0 0 1px var(--border-2),
    0 8px 30px -12px rgba(138, 155, 255, 0.45);
}

.ring-accent {
  box-shadow: inset 0 0 0 1px rgba(138, 155, 255, 0.5),
    0 8px 30px -16px rgba(138, 155, 255, 0.45);
}

/* Декоративные glow-пятна */
.bg-glow {
  position: relative;
  overflow: hidden;
}
.bg-glow::before,
.bg-glow::after {
  content: "";
  position: absolute;
  z-index: 0;
  filter: blur(80px);
  opacity: 0.55;
  pointer-events: none;
  border-radius: 9999px;
}
.bg-glow::before {
  width: 520px;
  height: 520px;
  background: radial-gradient(circle, var(--glow-1) 0%, transparent 65%);
  top: -180px;
  left: -120px;
}
.bg-glow::after {
  width: 480px;
  height: 480px;
  background: radial-gradient(circle, var(--glow-2) 0%, transparent 65%);
  bottom: -200px;
  right: -120px;
}
.bg-glow > * {
  position: relative;
  z-index: 1;
}

.public-screen {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, var(--safe-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, var(--safe-left));
}

.auth-step {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2rem;
  padding: 0.3rem 0.55rem;
  border-radius: 9999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: color-mix(in srgb, var(--bg-elev) 60%, transparent);
  font-size: 0.75rem;
  white-space: nowrap;
}

.auth-step.active {
  border-color: color-mix(in srgb, var(--accent) 38%, transparent);
  color: var(--text);
  background: var(--accent-soft);
}

.auth-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 9999px;
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 0.7rem;
  font-weight: 600;
}

.auth-step.active .auth-step-num {
  background: var(--accent);
  color: var(--accent-contrast);
}

/* 6 палитр обложек по детерминированному hash от названия */
.cover-bg {
  position: relative;
  isolation: isolate;
}
.cover-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.18) 0%, transparent 50%),
    radial-gradient(circle at 75% 80%, rgba(0, 0, 0, 0.35) 0%, transparent 60%);
  z-index: 0;
}
.cover-bg > * {
  position: relative;
  z-index: 1;
}

.cover-1 { background: linear-gradient(135deg, #4f46e5 0%, #c084fc 100%); }
.cover-2 { background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%); }
.cover-3 { background: linear-gradient(135deg, #f43f5e 0%, #f59e0b 100%); }
.cover-4 { background: linear-gradient(135deg, #10b981 0%, #06b6d4 100%); }
.cover-5 { background: linear-gradient(135deg, #db2777 0%, #4f46e5 100%); }
.cover-6 { background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%); }

.company-logo {
  width: 5rem;
  height: 5rem;
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.12),
    0 12px 30px -20px var(--soft-shadow);
}

.company-logo img {
  display: block;
}

/* Карточка по умолчанию */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.card-hover {
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}
.card-hover:hover {
  transform: translateY(-2px);
  border-color: var(--border-2);
  box-shadow: 0 14px 40px -20px rgba(0, 0, 0, 0.6);
}

/* Простые блоки для страниц и списков */
.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 14px 36px -28px var(--soft-shadow);
}

.panel-hover {
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.panel-hover:hover {
  border-color: var(--border-2);
  box-shadow: 0 18px 42px -30px rgba(0, 0, 0, 0.85);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.list-row {
  background: var(--list-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  transition: border-color 120ms ease, background 120ms ease;
}
.list-row:hover {
  background: var(--list-bg-hover);
  border-color: var(--border-2);
}

.feed-list {
  max-width: 56rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.feed-card {
  overflow: hidden;
  display: grid;
  background: color-mix(in srgb, var(--bg-elev) 72%, transparent);
}

.feed-card:hover {
  transform: none;
}

.feed-card-with-media {
  grid-template-columns: 1fr;
}

.feed-media {
  background: color-mix(in srgb, var(--bg) 72%, #000 28%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 11rem;
  max-height: 18rem;
  padding: 0.75rem;
}

.feed-media img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 16.5rem;
  object-fit: contain;
  border-radius: 12px;
}

.feed-body {
  min-width: 0;
  padding: 1rem;
}

.feed-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.72rem;
}

.feed-title {
  margin-top: 0.35rem;
  color: var(--text);
  font-size: 1.02rem;
  line-height: 1.35;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.feed-text {
  margin-top: 0.65rem;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.65;
}

.feed-text a,
.feed-fulltext a {
  color: var(--accent);
  overflow-wrap: anywhere;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 42%, transparent);
  text-underline-offset: 0.16em;
}

.feed-text a:hover,
.feed-fulltext a:hover {
  color: var(--text-strong);
}

.feed-fulltext {
  margin-top: 0.65rem;
}

.feed-fulltext summary {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  user-select: none;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 500;
}

.feed-fulltext summary::-webkit-details-marker {
  display: none;
}

.feed-fulltext div {
  margin-top: 0.65rem;
  color: var(--text);
  white-space: pre-wrap;
  font-size: 0.92rem;
  line-height: 1.65;
}

.feed-actions {
  position: relative;
  margin-top: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 2rem;
}

@media (min-width: 768px) {
  .feed-card-with-media {
    grid-template-columns: minmax(14rem, 0.9fr) minmax(0, 1.2fr);
  }

  .feed-media {
    border-bottom: 0;
    border-right: 1px solid var(--border);
    max-height: 24rem;
  }

  .feed-media img {
    max-height: 22rem;
  }

  .feed-body {
    padding: 1.15rem 1.25rem;
  }
}

.digest-sections {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.digest-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.digest-dot {
  width: 0.42rem;
  height: 0.42rem;
  margin-top: 0.55rem;
  border-radius: 9999px;
  flex-shrink: 0;
  background: var(--accent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 42%, transparent);
}

.digest-title {
  width: 100%;
  display: block;
  text-align: left;
  color: var(--text);
  font-size: 0.96rem;
  line-height: 1.45;
  transition: color 120ms ease;
}

.digest-title:hover {
  color: var(--text-strong);
}

.empty-state {
  background: color-mix(in srgb, var(--bg-elev) 36%, transparent);
  border: 1px dashed var(--border-2);
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
}

.library-folder-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.library-folder-card {
  min-height: 10.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 1rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: color-mix(in srgb, var(--bg-elev) 28%, transparent);
  transition: border-color 120ms ease, background 120ms ease;
}

.library-folder-card:hover {
  border-color: color-mix(in srgb, var(--accent) 38%, var(--border));
  background: color-mix(in srgb, var(--accent-soft) 50%, var(--bg-elev));
}

.library-folder-icon {
  width: 6.7rem;
  height: 6.7rem;
  object-fit: contain;
}

.library-folder-label {
  max-width: 100%;
  color: var(--text);
  font-size: 0.78rem;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
}

.library-folder-empty-icon {
  width: 6rem;
  height: 6rem;
  object-fit: contain;
  margin: 0 auto;
}

@media (min-width: 640px) {
  .library-folder-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .library-folder-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.trust-card {
  background: color-mix(in srgb, var(--bg-elev) 58%, transparent);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.theme-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
}

.theme-option {
  width: 100%;
  min-height: 3.35rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--list-bg);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.theme-option:hover {
  border-color: var(--border-2);
  background: var(--list-bg-hover);
}

.theme-option.active {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 24%, transparent);
}

.theme-swatch {
  width: 2.2rem;
  height: 2.2rem;
  flex-shrink: 0;
  border-radius: 9999px;
  border: 1px solid color-mix(in srgb, var(--border-2) 72%, transparent);
  box-shadow:
    inset 0 0 12px rgba(0, 0, 0, 0.24),
    0 8px 18px -14px var(--soft-shadow);
}

.theme-swatch[data-theme-swatch="telegram-blue"] {
  background: linear-gradient(135deg, #07111d 0%, #0d1b2a 45%, #35a7ff 100%);
}

.theme-swatch[data-theme-swatch="dark"] {
  background: linear-gradient(135deg, #0a0d14 0%, #11151f 45%, #8a9bff 100%);
}

.theme-swatch[data-theme-swatch="light"] {
  background: linear-gradient(135deg, #f6f8fb 0%, #ffffff 45%, #248be6 100%);
}

.theme-swatch[data-theme-swatch="sand"] {
  background: linear-gradient(135deg, #14120f 0%, #2b261f 45%, #f0b35f 100%);
}

/* Информационные сообщения */
.alert {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  line-height: 1.5;
}
.alert-warn {
  border-color: rgba(245, 158, 11, 0.35);
  color: #fde68a;
  background: rgba(245, 158, 11, 0.1);
}
.alert-danger {
  border-color: rgba(248, 113, 113, 0.35);
  color: #fecaca;
  background: rgba(248, 113, 113, 0.1);
}

.danger-panel {
  border: 1px solid rgba(248, 113, 113, 0.25);
  border-radius: 16px;
  background: rgba(248, 113, 113, 0.07);
}

/* Поля ввода */
.field {
  width: 100%;
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  color: var(--text);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.field::placeholder {
  color: var(--muted);
}

/* Базовые кнопки */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-radius: 10px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}
.btn:hover {
  border-color: var(--border-2);
}
.btn:active {
  transform: translateY(1px);
}
.btn-primary {
  background: linear-gradient(180deg, var(--btn-primary-start) 0%, var(--btn-primary-end) 100%);
  border-color: transparent;
  color: var(--accent-contrast);
  box-shadow: 0 8px 24px -10px var(--btn-primary-shadow);
}
.btn-primary:hover {
  filter: brightness(1.06);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--bg-elev);
  border-color: var(--border);
}
.btn-danger {
  border-color: rgba(248, 113, 113, 0.35);
  color: #fecaca;
  background: rgba(248, 113, 113, 0.1);
}
.btn-danger:hover {
  border-color: rgba(248, 113, 113, 0.55);
  background: rgba(248, 113, 113, 0.15);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.62;
  transform: none;
}

html[data-theme="light"] .hover\:text-white:hover,
html[data-theme="light"] .group:hover .group-hover\:text-white {
  color: var(--text-strong) !important;
}

/* Чипы и загрузка файлов */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}
.chip-accent {
  border-color: color-mix(in srgb, var(--accent) 38%, transparent);
  color: var(--accent);
  background: var(--accent-soft);
}

.file-field {
  display: block;
  width: 100%;
  font-size: 0.875rem;
  color: var(--muted);
}
.file-field::file-selector-button {
  cursor: pointer;
  margin-right: 0.75rem;
  border: 0;
  border-radius: 12px;
  padding: 0.62rem 1rem;
  background: var(--bg-elev-2);
  color: var(--text);
  font-weight: 500;
  box-shadow: 0 0 0 1px var(--border-2);
}
.file-field:hover::file-selector-button {
  background: var(--bg-elev);
}

.dropzone {
  display: block;
  cursor: pointer;
  border: 2px dashed var(--border-2);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
  transition: border-color 120ms ease, color 120ms ease;
}
.dropzone:hover {
  border-color: var(--accent);
  color: var(--text);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

.library-scope-tabs {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--bg-elev);
}

.library-scope-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.25rem;
  padding: 0 0.9rem;
  border-radius: 9999px;
  color: var(--muted);
  font-size: 0.88rem;
  transition: background 120ms ease, color 120ms ease;
}

.library-scope-tab:hover,
.library-scope-tab.active {
  color: var(--text);
  background: var(--accent-soft);
}

.library-upload-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  min-height: 4rem;
  border: 1.5px dashed var(--border-2);
  border-radius: 14px;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.library-upload-drop:hover,
.library-upload-drop.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.library-upload-drop.is-busy {
  pointer-events: none;
  opacity: 0.68;
}

.library-upload-draft {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-elev);
}

.library-file-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem;
  border-bottom: 1px solid var(--border);
  border-radius: 13px 13px 0 0;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: blur(14px);
}

.library-file-caption {
  min-width: 0;
  flex: 1;
}

.library-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
}

.library-file-meta {
  margin-top: 0.05rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.library-file-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.library-icon-btn {
  width: 2.4rem;
  height: 2.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--bg-elev-2);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.library-icon-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.library-icon-btn:active {
  transform: translateY(1px);
}

.library-icon-danger {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.1);
}

.library-action-menu {
  position: relative;
}

.library-action-menu > summary {
  list-style: none;
}

.library-action-menu > summary::-webkit-details-marker {
  display: none;
}

.library-action-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 0.5rem);
  z-index: 40;
  width: min(18rem, 80vw);
  display: grid;
  gap: 0.55rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-bg);
  box-shadow: 0 18px 44px -28px var(--soft-shadow);
}

@media (min-width: 640px) {
  .library-upload-draft {
    flex-direction: row;
    align-items: flex-start;
  }
}

/* Бейджи */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  border-radius: 9999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.02);
}
.badge-accent {
  border-color: color-mix(in srgb, var(--accent) 38%, transparent);
  color: var(--accent);
  background: var(--accent-soft);
}
.badge-warn {
  border-color: rgba(245, 158, 11, 0.35);
  color: #fcd34d;
  background: rgba(245, 158, 11, 0.12);
}
.badge-success {
  border-color: rgba(16, 185, 129, 0.35);
  color: #6ee7b7;
  background: rgba(16, 185, 129, 0.12);
}

/* Sidebar nav-item */
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  position: relative;
  transition: color 120ms ease, background 120ms ease;
}
.nav-link:hover {
  color: var(--text);
  background: var(--bg-elev);
}
.nav-link.active {
  color: var(--text);
  background: var(--bg-elev);
}
.nav-link.active::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 25%;
  bottom: 25%;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.sidebar-nav-icon {
  width: 2.5rem;
  height: 2.5rem;
  object-fit: contain;
  flex-shrink: 0;
  opacity: 0.82;
}

.nav-link.active .sidebar-nav-icon,
.nav-link:hover .sidebar-nav-icon {
  opacity: 1;
}

/* Нижняя навигация на телефоне — ближе к большому пальцу и без налезания текста */
.mobile-bottom-nav {
  /* Нав в потоке flex-колонки (не fixed), прижат к низу 100svh-контейнера */
  flex-shrink: 0;
  height: calc(var(--mobile-bottom-nav-h) + var(--safe-bottom));
  display: flex;
  gap: 0.35rem;
  overflow: hidden;
  padding: 0.42rem max(0.65rem, var(--safe-right)) max(0.42rem, var(--safe-bottom)) max(0.65rem, var(--safe-left));
  background: var(--bottom-nav-bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -16px 40px -26px rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(18px);
  scrollbar-width: none;
}

.mobile-bottom-nav::-webkit-scrollbar {
  display: none;
}

/* Контекстные вкладки в шапке левее ML Hub (Файлы/Ссылки, Новости/Выжимка, Профиль/Люди) */
.mobile-header-tabs {
  display: flex;
  gap: 0.2rem;
  align-items: center;
  /* Резервирует высоту как у нижних вкладок — шапка одинакова на всех страницах */
  min-height: 3.9rem;
}

.mobile-header-tab {
  /* Те же пропорции что .mobile-tab; flex:1 — обе вкладки одинаковой ширины */
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.18rem;
  padding: 0.3rem 0.5rem;
  border-radius: 14px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.1;
  white-space: nowrap;
  min-height: 3.9rem;
  /* Рамка у обеих вкладок — неактивная тоже имеет чёткую границу */
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent);
}

.mobile-header-tab img {
  opacity: 0.75;
  transition: opacity 120ms ease;
}

.mobile-header-tab.active {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 32%, transparent);
}

.mobile-header-tab.active img {
  opacity: 1;
}

.mobile-tab {
  flex: 1;
  min-width: 0;
  min-height: 3.9rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.18rem;
  border-radius: 14px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.1;
  white-space: nowrap;
}

.mobile-tab .ic {
  width: 1.25rem;
  height: 1.25rem;
}

.mobile-nav-icon {
  width: 2.05rem;
  height: 2.05rem;
  object-fit: contain;
  flex-shrink: 0;
  opacity: 0.82;
  transition: opacity 120ms ease;
}

.mobile-tab.active .mobile-nav-icon {
  opacity: 1;
}

.mobile-tab.active {
  color: var(--text);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 32%, transparent);
}

@media (max-width: 767px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    /* Растягиваем до самого низа физического экрана, включая safe area */
    min-height: 0;
    height: calc(100svh + env(safe-area-inset-bottom, 0px));
    overflow: hidden;
  }

  .app-main {
    /* Только main скроллится; нав всегда виден снизу */
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding-left: max(1rem, var(--safe-left));
    padding-right: max(1rem, var(--safe-right));
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
    scroll-padding-bottom: 1.5rem;
  }

  .mobile-topbar {
    padding-left: max(1rem, var(--safe-left));
    padding-right: max(1rem, var(--safe-right));
  }

  .mobile-topbar-centered {
    display: grid;
    grid-template-columns: minmax(2.5rem, 1fr) auto minmax(2.5rem, 1fr);
    align-items: center;
  }

  .mobile-brand-link {
    justify-self: center;
  }

  .mobile-topbar-logout {
    justify-self: end;
  }

  .btn,
  .field,
  select,
  input[type="file"]::file-selector-button {
    min-height: 44px;
  }

  .nav-link {
    min-height: 44px;
  }
}

/* Inline SVG-иконки одинакового размера */
.ic {
  width: 1.1em;
  height: 1.1em;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ic-lg {
  width: 1.5em;
  height: 1.5em;
}

/* OTP-окошки */
.otp-wrap {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.45rem;
  max-width: 16rem;
}
.otp-wrap input {
  text-align: center;
  font-size: 1.25rem;
  letter-spacing: 0;
  padding: 0.65rem 0;
  font-variant-numeric: tabular-nums;
}

/* Просмотрщик (overflow не hidden — иначе ломается position:sticky внутри, в т.ч. в iOS PWA) */
.viewer {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-elev);
  overflow: visible;
  display: flex;
  flex-direction: column;
}
.viewer-frame-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 0 0 13px 13px;
}
.viewer-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #0d0f14;
  min-height: 60vh;
}
.viewer img {
  width: 100%;
  height: auto;
  max-height: 70vh;
  object-fit: contain;
  background: #0d0f14;
  display: block;
}

/* Библиотека: на телефоне картинка может быть выше экрана — скролл, без обрезки */
@media (max-width: 767px) {
  .library-preview-img {
    max-height: none;
    touch-action: pan-x pan-y pinch-zoom;
  }
}

/* Вспомогательные ограничения текста */
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Приятный focus-ring для интерактива на клавиатуре */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}
