/* ==========================================================================
   Кабинет психолога — оформление
   Цвета берутся из темы Telegram (--tg-*), с запасными значениями,
   чтобы приложение нормально выглядело и в обычном браузере.
   ========================================================================== */

:root {
  --bg: var(--tg-bg, #f4f3f1);
  --card: var(--tg-section-bg, #ffffff);
  --secondary: var(--tg-secondary-bg, #eceae7);
  --text: var(--tg-text, #16181b);
  --subtitle: var(--tg-subtitle, #3d4046);
  --hint: var(--tg-hint, #8b8e94);
  --link: var(--tg-link, #4d6a99);
  --accent: var(--tg-link, #4d6a99);
  --button: var(--tg-button, #3f5b86);
  --button-text: var(--tg-button-text, #ffffff);
  --destructive: var(--tg-destructive, #bb3b30);
  --line: var(--tg-separator, rgba(16, 18, 22, 0.08));
  --shadow: 0 1px 2px rgba(16, 18, 22, 0.04), 0 8px 24px -12px rgba(16, 18, 22, 0.18);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --nav-h: 62px;
  --r: 18px;
}

html[data-tg-theme="dark"] {
  --bg: var(--tg-bg, #16171a);
  --card: var(--tg-section-bg, #212327);
  --secondary: var(--tg-secondary-bg, #2a2d32);
  --text: var(--tg-text, #f2f3f5);
  --subtitle: var(--tg-subtitle, #c6c9ce);
  --hint: var(--tg-hint, #8f939a);
  --line: var(--tg-separator, rgba(255, 255, 255, 0.09));
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px -14px rgba(0, 0, 0, 0.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-tg-theme="light"]) {
    --bg: var(--tg-bg, #16171a);
    --card: var(--tg-section-bg, #212327);
    --secondary: var(--tg-secondary-bg, #2a2d32);
    --text: var(--tg-text, #f2f3f5);
    --subtitle: var(--tg-subtitle, #c6c9ce);
    --hint: var(--tg-hint, #8f939a);
    --line: var(--tg-separator, rgba(255, 255, 255, 0.09));
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px -14px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}

button, input, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
a { color: var(--link); text-decoration: none; }
svg { width: 20px; height: 20px; display: block; }

.app {
  max-width: 620px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg);
}

@media (min-width: 720px) {
  body { padding-top: 28px; }
  .app {
    border-radius: 26px;
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
    min-height: calc(100dvh - 56px);
  }
}

/* ------------------------------ Шапка ---------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 14px) 18px 14px;
}

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

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

.avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  flex: none;
}
.avatar--mono {
  display: grid; place-items: center;
  background: linear-gradient(135deg, #b9c6e6, #93a8d4);
  color: #1d2438;
  font-weight: 650;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.who__name { font-weight: 650; letter-spacing: -0.01em; }
.who__role { color: var(--hint); font-size: 12.5px; }

.topbar__stat { text-align: right; flex: none; }
.topbar__stat strong { display: block; font-size: 17px; font-weight: 650; line-height: 1.1; }
.topbar__stat span { color: var(--hint); font-size: 11.5px; }

.search {
  display: flex; align-items: center; gap: 9px;
  margin-top: 13px;
  padding: 0 13px;
  height: 42px;
  border-radius: 13px;
  background: var(--secondary);
  color: var(--hint);
}
.search input {
  flex: 1; min-width: 0;
  border: 0; background: none; outline: none;
  font-size: 15px;
}
.search input::-webkit-search-cancel-button { display: none; }

.notice {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  margin-top: 11px;
  padding: 10px 14px;
  border-radius: 13px;
  background: var(--secondary);
  background: color-mix(in srgb, var(--accent) 12%, var(--card));
  color: var(--text);
  font-size: 14px;
  font-weight: 550;
}
.notice span { display: flex; align-items: center; gap: 8px; }
.notice svg { width: 17px; height: 17px; opacity: 0.75; }
.pill {
  background: var(--accent);
  color: #fff;
  border-radius: 99px;
  padding: 1px 9px;
  font-size: 12px;
  font-weight: 650;
}

/* ------------------------------ Страница ------------------------------- */
.page { padding: 18px; display: flex; flex-direction: column; gap: 18px; }
.page--post { gap: 14px; }

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--hint);
  font-weight: 600;
  margin: 6px 0 -8px 4px;
}

/* --------------------------- Главная карточка -------------------------- */
.feature {
  background: var(--card);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.feature__cover { height: 132px; background-size: cover; background-position: center; }
.feature__body { padding: 15px 16px 17px; }
.feature__title {
  margin: 9px 0 7px;
  font-size: 20.5px;
  line-height: 1.25;
  font-weight: 680;
  letter-spacing: -0.022em;
}
.feature__text { margin: 0; color: var(--subtitle); font-size: 14.5px; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
  background: rgba(77, 106, 153, 0.14);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  padding: 3px 9px;
  border-radius: 99px;
}

.meta {
  display: flex; align-items: center; gap: 6px;
  color: var(--hint);
  font-size: 12.5px;
  margin-top: 12px;
}
.meta svg { width: 14px; height: 14px; }
.meta i { font-style: normal; opacity: 0.6; }
.meta--sm { font-size: 12px; margin: 0; }

/* ------------------------------- Темы ---------------------------------- */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 18px;
  margin: 0 -18px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }

.chip {
  flex: none;
  display: flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  border-radius: 99px;
  background: var(--secondary);
  color: var(--subtitle);
  font-size: 13.5px;
  font-weight: 550;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.chip.is-active { background: var(--accent); color: #fff; }
.chip__n { opacity: 0.55; font-size: 11.5px; }

/* ------------------------------- Список -------------------------------- */
.list { display: flex; flex-direction: column; gap: 11px; }

.card {
  display: flex;
  gap: 13px;
  padding: 13px;
  background: var(--card);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.card:active { transform: scale(0.985); }
.card__cover {
  width: 74px; height: 74px;
  border-radius: 13px;
  flex: none;
  background-size: cover;
  background-position: center;
}
.card__body { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.card__title {
  margin: 0 0 4px;
  font-size: 15.5px;
  font-weight: 640;
  line-height: 1.3;
  letter-spacing: -0.015em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card__text {
  margin: 0;
  color: var(--hint);
  font-size: 13.5px;
  line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card__foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: auto; padding-top: 9px;
}

.tags { display: flex; gap: 5px; flex-wrap: wrap; overflow: hidden; max-height: 22px; }
.tag {
  font-size: 11.5px;
  color: var(--accent);
  background: rgba(77, 106, 153, 0.13);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  padding: 2.5px 8px;
  border-radius: 99px;
  white-space: nowrap;
}
.tag--link { transition: background 0.15s; }
.tag--link:active { background: rgba(77, 106, 153, 0.26); background: color-mix(in srgb, var(--accent) 26%, transparent); }

/* ------------------------------- Строка -------------------------------- */
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px;
  background: var(--card);
  border-radius: 15px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.row__cover { width: 46px; height: 46px; border-radius: 11px; flex: none; background-size: cover; }
.row__body { min-width: 0; }
.row__title { font-weight: 600; font-size: 14.5px; margin-bottom: 3px; }

/* ------------------------------- Подшапка ------------------------------ */
.subbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.subbar__title {
  font-weight: 640;
  font-size: 15.5px;
  letter-spacing: -0.01em;
  flex: 1;
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.subbar__actions { display: flex; gap: 2px; margin-left: auto; }

.iconbtn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 11px;
  color: var(--subtitle);
  flex: none;
  transition: background 0.15s;
}
.iconbtn:active { background: var(--secondary); }
.iconbtn--danger { color: var(--destructive); }
.iconbtn svg { width: 19px; height: 19px; }

/* -------------------------------- Пост --------------------------------- */
.hero {
  height: 168px;
  border-radius: var(--r);
  background-size: cover;
  background-position: center;
  position: relative;
}
.hero__badge {
  position: absolute; left: 12px; bottom: 12px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 11px; font-weight: 600;
  padding: 4px 10px;
  border-radius: 99px;
}
.post__title {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.028em;
}
.post__meta { margin: 0; }
.post__tags { max-height: none; }

.rich { font-size: 16px; color: var(--subtitle); }
.rich > *:first-child { margin-top: 0; }
.rich > *:last-child { margin-bottom: 0; }
.rich-p { margin: 0 0 14px; }
.rich-h2, .rich-h3 {
  color: var(--text);
  font-weight: 670;
  letter-spacing: -0.02em;
  line-height: 1.3;
  margin: 26px 0 10px;
}
.rich-h2 { font-size: 19.5px; }
.rich-h3 { font-size: 17px; }
.rich-list { margin: 0 0 14px; padding-left: 22px; }
.rich-list li { margin-bottom: 7px; }
.rich-list li::marker { color: var(--accent); }
.rich-quote {
  margin: 0 0 14px;
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  background: rgba(77, 106, 153, 0.07);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  border-radius: 0 12px 12px 0;
  color: var(--text);
  font-style: italic;
}
.rich-hr { border: 0; height: 1px; background: var(--line); margin: 24px 0; }
.rich strong { color: var(--text); font-weight: 640; }
code {
  background: var(--secondary);
  padding: 1.5px 6px;
  border-radius: 6px;
  font-size: 0.88em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ------------------------------- Автор --------------------------------- */
.author, .panel, .profile, .cta {
  background: var(--card);
  border-radius: var(--r);
  padding: 16px;
  box-shadow: var(--shadow);
}
.author { display: flex; align-items: center; gap: 12px; }
.author__avatar { width: 44px; height: 44px; }
.author__name { font-weight: 640; }
.author__role { color: var(--hint); font-size: 12.5px; }
.author .btn { margin-left: auto; }

.panel { display: flex; flex-direction: column; gap: 12px; }
.panel--flush { padding: 0; overflow: hidden; }
.panel--muted { background: var(--secondary); box-shadow: none; }
.panel p { margin: 0; color: var(--subtitle); }

/* -------------------------------- CTA ---------------------------------- */
.cta {
  background: var(--card);
  background: linear-gradient(140deg, color-mix(in srgb, var(--accent) 16%, var(--card)), var(--card));
  display: flex; flex-direction: column; gap: 9px;
}
.cta h3 { margin: 0; font-size: 17.5px; font-weight: 670; letter-spacing: -0.02em; }
.cta p { margin: 0; color: var(--subtitle); font-size: 14.5px; }
.cta__buttons { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 4px; }

/* -------------------------------- Профиль ------------------------------ */
.profile { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 24px 16px 20px; }
.profile__avatar { width: 78px; height: 78px; font-size: 26px; margin-bottom: 8px; }
.profile__name { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.025em; }
.profile__role { margin: 0; color: var(--hint); font-size: 13.5px; }

.facts {
  display: flex; gap: 10px;
  margin-top: 16px;
  width: 100%;
}
.fact {
  flex: 1;
  background: var(--secondary);
  border-radius: 13px;
  padding: 10px 6px;
}
.fact strong { display: block; font-size: 15px; font-weight: 650; }
.fact span { color: var(--hint); font-size: 11.5px; }

.service {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.service:last-child { border-bottom: 0; }
.service__title { font-weight: 600; }
.service__note { color: var(--hint); font-size: 12.5px; }
.service__price { font-weight: 650; white-space: nowrap; }

/* -------------------------------- Темы-сетка --------------------------- */
.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.theme-card {
  background: var(--card);
  border-radius: 15px;
  padding: 15px 14px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px;
  min-height: 82px;
  transition: transform 0.12s ease;
}
.theme-card:active { transform: scale(0.97); }
.theme-card__name { font-weight: 640; letter-spacing: -0.015em; }
.theme-card__n { color: var(--hint); font-size: 12px; }

/* ------------------------------- Кнопки -------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 44px;
  padding: 0 18px;
  border-radius: 13px;
  font-weight: 600;
  font-size: 15px;
  transition: opacity 0.15s, transform 0.12s;
}
.btn:active { opacity: 0.8; transform: scale(0.98); }
.btn--primary { background: var(--button); color: var(--button-text); flex: 1; }
.btn--ghost { background: var(--secondary); color: var(--text); }
.btn--danger { color: var(--destructive); }

.fab {
  position: fixed;
  right: max(18px, calc(50% - 310px + 18px));
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px);
  width: 54px; height: 54px;
  border-radius: 18px;
  background: var(--button);
  color: var(--button-text);
  display: grid; place-items: center;
  box-shadow: 0 10px 26px -8px rgba(63, 91, 134, 0.7);
  box-shadow: 0 10px 26px -8px color-mix(in srgb, var(--button) 70%, transparent);
  z-index: 30;
  transition: transform 0.12s;
}
.fab:active { transform: scale(0.93); }
.fab svg { width: 24px; height: 24px; }

/* ----------------------------- Навигация ------------------------------- */
.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 6px 10px calc(env(safe-area-inset-bottom) + 6px);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
}
@media (min-width: 720px) {
  .nav {
    left: 50%; right: auto;
    transform: translateX(-50%);
    width: 620px;
    bottom: 28px;
    border-radius: 0 0 26px 26px;
    border-top: 1px solid var(--line);
  }
}
.nav__item {
  flex: 1;
  max-width: 132px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px;
  border-radius: 13px;
  color: var(--hint);
  font-size: 10.5px;
  font-weight: 550;
  transition: color 0.15s;
}
.nav__item svg { width: 22px; height: 22px; }
.nav__item.is-active { color: var(--accent); }

/* ------------------------------- Редактор ------------------------------ */
.editor { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field__label {
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--hint);
  padding-left: 3px;
}
.field__label em { font-style: normal; text-transform: none; letter-spacing: 0; opacity: 0.75; font-weight: 500; }
.field input, .field textarea {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
  outline: none;
  width: 100%;
  resize: vertical;
  transition: border-color 0.15s;
  line-height: 1.5;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { font-size: 15px; min-height: 220px; }

.hint {
  background: var(--secondary);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--subtitle);
}
.hint summary { cursor: pointer; font-weight: 600; color: var(--text); }
.hint__grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 14px;
  align-items: center;
  margin-top: 12px;
}
.hint__grid code { justify-self: start; }

.editor__actions { display: flex; flex-direction: column; gap: 9px; margin-top: 4px; }
.editor__actions .btn--ghost { flex: none; }

.btn:disabled { opacity: 0.45; pointer-events: none; }

/* ------------------------------ Скелетон ------------------------------- */
.skeleton {
  position: relative;
  height: 98px;
  border-radius: var(--r);
  background: var(--card);
  overflow: hidden;
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent,
    color-mix(in srgb, var(--hint) 14%, transparent),
    transparent
  );
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton::after { animation: none; }
}

/* -------------------------------- Пусто -------------------------------- */
.empty {
  text-align: center;
  padding: 54px 24px;
  color: var(--hint);
}
.empty__mark { font-size: 26px; color: var(--accent); opacity: 0.5; margin-bottom: 10px; }
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 16.5px; font-weight: 640; }
.empty p { margin: 0; font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
