/* ============================================
   Psychodynamic.ru — Энциклопедия психоанализа
   и психодинамической терапии
   ============================================ */

:root {
  /* Основные */
  --psy-bg: #f5f3ee;
  --psy-white: #fefdfb;
  --psy-text: #1e1e1e;
  --psy-text-secondary: #555;

  /* Акцент — глубокий синий */
  --psy-accent: #1a3a5c;
  --psy-accent-light: #e8edf3;
  --psy-accent-lighter: #f2f5f8;

  /* Ссылки */
  --psy-link: #1a4a7a;
  --psy-link-hover: #0d2f52;
  --psy-link-visited: #4a3a7a;

  /* Границы */
  --psy-border: #c5bfb2;
  --psy-border-light: #ddd8ce;

  /* Заголовки */
  --psy-heading: #1a2d3d;

  /* Инфобокс */
  --psy-infobox-title: #d5dde6;

  /* TOC */
  --psy-toc-bg: #f7f4ed;

  /* Таблица */
  --psy-table-header: #e8e3d8;
  --psy-table-stripe: #f9f6f0;

  /* Амбоксы */
  --psy-ambox-bg: #fef9f0;
  --psy-ambox-border: #e0c870;
  --psy-ambox-green-bg: #f2f7f4;
  --psy-ambox-green-border: #8cbfa0;

  /* Акцент доказательности */
  --psy-evidence: #1a6b4a;
  --psy-evidence-bg: #edf7f2;

  /* Навбокс */
  --psy-navbox-title: #dce2e8;

  /* Футер */
  --psy-footer-text: #6b6560;

  /* Кнопки */
  --psy-btn-primary: #1a3a5c;
  --psy-btn-primary-hover: #0f2a45;
}

body {
  background: var(--psy-bg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Liberation Sans', 'Helvetica Neue', sans-serif;
  color: var(--psy-text);
  line-height: 1.6;
  margin: 0;
  padding: 0;
}

/* ===== WIKI PAGE WRAPPER ===== */
.wiki-page {
  background: var(--psy-white);
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  min-height: 100vh;
  overflow-x: clip;
}

@media (min-width: 1200px) {
  .wiki-page {
    max-width: 1120px;
    margin: 0 auto;
  }
}

.wiki-content {
  padding: 1.5rem 2rem 3rem;
  max-width: 960px;
  margin: 0 auto;
}

/* ===== STICKY HEADER ===== */
.wiki-header-sticky {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: #ede8df;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* ===== WIKI TABS ===== */
.wiki-tabs {
  display: flex;
  gap: 0;
  font-size: 0.82rem;
  padding: 0 1.5rem;
  background: #ede8df;
  border-bottom: 1px solid var(--psy-border);
  overflow-x: auto;
  overflow-y: hidden;
  flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #bbb transparent;
  overscroll-behavior-x: contain;
}

.wiki-tabs::-webkit-scrollbar { height: 4px; }
.wiki-tabs::-webkit-scrollbar-track { background: transparent; }
.wiki-tabs::-webkit-scrollbar-thumb { background: #bbb; border-radius: 2px; }

.wiki-tab {
  padding: 0.5rem 1.2rem;
  color: #5a5550;
  white-space: nowrap;
  cursor: default;
  position: relative;
  bottom: -1px;
  text-decoration: none;
  flex-shrink: 0;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.wiki-tab.active {
  background: var(--psy-white);
  border: 1px solid var(--psy-border);
  border-bottom: 1px solid var(--psy-white);
  color: var(--psy-heading);
  font-weight: 700;
}

.wiki-tab:not(.active) {
  background: #e0dbd1;
  border: 1px solid var(--psy-border);
  border-bottom: 1px solid var(--psy-border);
  color: var(--psy-link);
}
.wiki-tab:not(.active):hover {
  background: #ede8df;
  text-decoration: none;
  color: var(--psy-link-hover);
}

/* ===== ACTION BAR ===== */
.wiki-action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.6rem 1.5rem;
  background: #ede8df;
  border-bottom: 1px solid var(--psy-border);
  justify-content: flex-end;
}

.wiki-header-sticky .wiki-action-bar {
  background: #ede8df;
  border-bottom: 1px solid var(--psy-border);
}

.wiki-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.3rem 0.7rem;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.15s;
  color: #fff;
}

.wiki-action-btn i { font-size: 0.85rem; }
.wiki-action-btn:hover { text-decoration: none; color: #fff; filter: brightness(1.1); }

.wiki-action-book { background: var(--psy-accent); }
.wiki-action-telegram { background: #0088cc; }
.wiki-action-max { background: #6c5ce7; }
.wiki-action-whatsapp { background: #25D366; }

@media (max-width: 480px) {
  .wiki-action-bar {
    gap: 0.25rem;
    padding: 0.5rem 0.4rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: center;
  }
  .wiki-action-btn { padding: 0.3rem 0.4rem; font-size: 0.68rem; gap: 0.2rem; border-radius: 5px; flex-shrink: 0; }
  .wiki-action-btn i { font-size: 0.75rem; }
}

/* ===== HEADINGS ===== */
.wiki-content h1 {
  font-family: 'Linux Libertine', 'Georgia', 'Times', serif;
  font-size: 2rem;
  font-weight: 400;
  border-bottom: 1px solid var(--psy-border);
  padding-bottom: 0.35rem;
  margin: 0.25rem 0 1rem;
  color: var(--psy-heading);
  letter-spacing: -0.3px;
}

.wiki-content h2 {
  font-family: 'Linux Libertine', 'Georgia', 'Times', serif;
  font-size: 1.55rem;
  font-weight: 400;
  border-bottom: 1px solid var(--psy-border);
  padding-bottom: 0.18rem;
  margin: 2rem 0 0.75rem;
  color: var(--psy-heading);
}

.wiki-content h3 {
  font-family: 'Linux Libertine', 'Georgia', 'Times', serif;
  font-size: 1.2rem;
  font-weight: 700;
  margin: 1.5rem 0 0.5rem;
  color: var(--psy-heading);
}

.wiki-content h4 {
  font-size: 1rem;
  font-weight: 700;
  margin: 1.2rem 0 0.4rem;
  color: var(--psy-heading);
}

.wiki-content p { margin: 0.5rem 0 1rem; font-size: 0.9375rem; }
.wiki-content ul, .wiki-content ol { margin: 0.3rem 0 1rem 1.6rem; padding: 0; font-size: 0.9375rem; }
.wiki-content li { margin-bottom: 0.25rem; }

.wiki-content a { color: var(--psy-link); text-decoration: none; }
.wiki-content a:hover { text-decoration: underline; color: var(--psy-link-hover); }
.wiki-content a:visited { color: var(--psy-link-visited); }

/* ===== HATNOTE ===== */
.wiki-hatnote {
  font-style: italic;
  padding: 0.4rem 0;
  font-size: 0.875rem;
  color: #777;
  margin-bottom: 0.5rem;
}

/* ===== INFOBOX ===== */
.wiki-infobox {
  float: right;
  width: 275px;
  background: #fdfcf9;
  border: 1px solid var(--psy-border);
  padding: 0.5em;
  margin: 0.5rem 0 1.5rem 1.5rem;
  font-size: 0.8rem;
  line-height: 1.5;
  clear: right;
  border-radius: 3px;
}

.wiki-infobox .infobox-title {
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  padding: 0.35em 0;
  background: var(--psy-infobox-title);
  margin: -0.5em -0.5em 0.5em;
  color: var(--psy-heading);
  letter-spacing: 0.3px;
}

.wiki-infobox .infobox-image { text-align: center; padding: 0.5em 0; }
.wiki-infobox .infobox-image img { max-width: 100%; height: auto; border-radius: 2px; }
.wiki-infobox table { width: 100%; }
.wiki-infobox th { text-align: left; vertical-align: top; padding: 0.2em 0.4em; font-weight: 400; color: #888; width: 40%; white-space: nowrap; }
.wiki-infobox td { vertical-align: top; padding: 0.2em 0.4em; color: #333; }

/* ===== TABLE OF CONTENTS ===== */
.wiki-toc {
  background: var(--psy-toc-bg);
  border: 1px solid var(--psy-border);
  font-size: 0.875rem;
  padding: 0.6em 1.2em;
  margin: 1.2rem 0 1.5rem;
  display: inline-block;
  min-width: 280px;
  border-radius: 2px;
}

.wiki-toc .toc-title {
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.4em;
  color: var(--psy-heading);
  font-size: 0.95rem;
}

.wiki-toc ul { list-style: none; margin: 0; padding: 0; }
.wiki-toc > ul { margin-left: 0; }
.wiki-toc ul ul { margin-left: 1.5em; }
.wiki-toc .toc-number { color: #888; }

/* ===== QUOTE BOX ===== */
.wiki-quote {
  background: var(--psy-toc-bg);
  border-left: 4px solid var(--psy-accent);
  padding: 0.85rem 1.35rem;
  margin: 1.2rem 0;
  font-size: 0.9rem;
  border-radius: 0 3px 3px 0;
}

/* ===== WIKI TABLE ===== */
.wiki-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.875rem;
}

.wiki-table th {
  background: var(--psy-table-header);
  text-align: left;
  padding: 0.5em 0.7em;
  border: 1px solid var(--psy-border);
  font-weight: 700;
  color: var(--psy-heading);
}

.wiki-table td {
  padding: 0.5em 0.7em;
  border: 1px solid var(--psy-border);
  vertical-align: top;
}

.wiki-table tr:nth-child(even) td { background: var(--psy-table-stripe); }

/* ===== TABLE RESPONSIVE WRAPPER ===== */
.table-responsive-wrapper {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0;
}
.table-responsive-wrapper .wiki-table { min-width: 600px; margin: 0; }

/* ===== AMBOX ===== */
.wiki-ambox {
  display: flex;
  background: var(--psy-ambox-bg);
  border: 1px solid var(--psy-ambox-border);
  padding: 0.6rem 1.1rem;
  margin: 0.5rem 0 1rem;
  font-size: 0.875rem;
  align-items: flex-start;
  gap: 0.6rem;
  border-radius: 3px;
}

.wiki-ambox.ambox-green {
  background: var(--psy-ambox-green-bg);
  border-color: var(--psy-ambox-green-border);
}

.wiki-ambox.ambox-blue {
  background: var(--psy-accent-lighter);
  border-color: #a0b8d0;
}

/* ===== EVIDENCE BADGE ===== */
.evidence-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--psy-evidence-bg);
  color: var(--psy-evidence);
  border: 1px solid #8cbfa0;
  padding: 0.15em 0.55em;
  border-radius: 3px;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.evidence-star { color: var(--psy-evidence); font-weight: 700; }

/* ===== PORTAL CARDS (главная-портал) ===== */
.portal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  margin: 2rem 0;
}

.portal-card {
  background: #fdfcf9;
  border: 1px solid var(--psy-border);
  border-radius: 4px;
  padding: 1.5rem;
  transition: box-shadow 0.2s, border-color 0.2s;
  text-decoration: none !important;
  display: block;
  color: var(--psy-text) !important;
}

.portal-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  border-color: var(--psy-accent);
  text-decoration: none !important;
}

.portal-card-icon {
  font-size: 2rem;
  color: var(--psy-accent);
  margin-bottom: 0.75rem;
}

.portal-card h3 {
  font-family: 'Linux Libertine', 'Georgia', 'Times', serif;
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: var(--psy-heading) !important;
  border: none;
}

.portal-card p {
  font-size: 0.875rem;
  color: #666;
  margin: 0;
  line-height: 1.5;
}

.portal-card .evidence-badge { margin-top: 0.75rem; }

/* ===== HERO PORTAL (главная) ===== */
.hero-portal {
  text-align: center;
  padding: 2rem 1rem 1.5rem;
  border-bottom: 1px solid var(--psy-border);
}

.hero-portal h1 {
  font-family: 'Linux Libertine', 'Georgia', 'Times', serif;
  font-size: 2.2rem;
  font-weight: 400;
  color: var(--psy-heading);
  margin: 0 0 0.5rem;
  border: none;
}

.hero-portal .hero-subtitle {
  font-size: 1rem;
  color: #777;
  font-style: italic;
  max-width: 640px;
  margin: 0 auto;
}

/* ===== SECTION HEADER (хабы) ===== */
.section-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 2.5rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--psy-accent);
}

.section-header h2 {
  font-family: 'Linux Libertine', 'Georgia', 'Times', serif;
  font-size: 1.4rem;
  color: var(--psy-heading);
  margin: 0;
  border: none;
  padding: 0;
  font-weight: 700;
}

.section-header i {
  font-size: 1.5rem;
  color: var(--psy-accent);
}

/* ===== METHOD LIST (для хабов) ===== */
.method-list {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.5rem;
}

.method-list li {
  margin: 0;
}

.method-list a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--psy-accent-lighter);
  border-radius: 3px;
  font-size: 0.9rem;
  color: var(--psy-link) !important;
  text-decoration: none !important;
  transition: background 0.15s;
}

.method-list a:hover {
  background: var(--psy-accent-light);
  color: var(--psy-link-hover) !important;
}

.method-list a i { font-size: 0.75rem; color: var(--psy-accent); opacity: 0.6; }

/* ===== NAVBOX ===== */
.wiki-navbox {
  border: 1px solid var(--psy-border);
  font-size: 0.85rem;
  margin: 2rem 0 1rem;
  clear: both;
  border-radius: 2px;
}

.wiki-navbox .navbox-title {
  background: var(--psy-navbox-title);
  text-align: center;
  padding: 0.35rem;
  font-weight: 700;
  color: var(--psy-heading);
}

.wiki-navbox .navbox-body { padding: 0.5rem 1rem; }

/* ===== CATEGORIES ===== */
.wiki-categories {
  background: var(--psy-toc-bg);
  border: 1px solid var(--psy-border);
  padding: 0.6rem 1.1rem;
  margin: 1.5rem 0;
  font-size: 0.85rem;
  border-radius: 2px;
}

/* ===== BUTTONS ===== */
.wiki-btn {
  display: inline-block;
  background: #f5f2ec;
  border: 1px solid var(--psy-border);
  color: var(--psy-link);
  font-weight: 600;
  padding: 0.45rem 1.1rem;
  font-size: 0.875rem;
  text-decoration: none;
  transition: all 0.15s;
  border-radius: 3px;
}

.wiki-btn:hover {
  background: #fff;
  text-decoration: none;
  color: var(--psy-link-hover);
  border-color: var(--psy-accent);
}

.wiki-btn-primary,
a.wiki-btn.wiki-btn-primary,
button.wiki-btn.wiki-btn-primary {
  background: var(--psy-btn-primary);
  border-color: var(--psy-btn-primary);
  color: #fff;
}

.wiki-btn-primary:hover,
a.wiki-btn.wiki-btn-primary:hover,
button.wiki-btn.wiki-btn-primary:hover {
  background: var(--psy-btn-primary-hover);
  color: #fff;
}

/* ===== FORM ===== */
.wiki-form .form-control {
  border: 1px solid var(--psy-border);
  border-radius: 3px;
  padding: 0.55rem 0.8rem;
  font-size: 0.9rem;
  background: #fefdfb;
  transition: border-color 0.15s;
}

.wiki-form .form-control:focus {
  border-color: var(--psy-accent);
  box-shadow: 0 0 0 2px rgba(26,58,92,0.1);
  outline: none;
}

.wiki-form label {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--psy-heading);
  margin-bottom: 0.3rem;
}

/* ===== FOOTER ===== */
.wiki-footer {
  border-top: 1px solid var(--psy-border);
  padding: 1.5rem 2rem;
  font-size: 0.78rem;
  color: var(--psy-footer-text);
  max-width: 960px;
  margin: 0 auto;
}

.wiki-footer a { color: var(--psy-link); }
.wiki-footer ul {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.5rem;
}

.wiki-footer li { margin-bottom: 0.25rem; }

/* ===== TOAST ===== */
.custom-toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--psy-heading);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.9rem;
  z-index: 9999;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  animation: slideUp 0.4s ease, fadeOut 0.4s ease 3.5s forwards;
}

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

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ===== REFERENCES ===== */
.wiki-references {
  font-size: 0.85rem;
  column-count: 2;
  column-gap: 2rem;
}

.wiki-references ol { margin: 0.3rem 0 1rem 1.6rem !important; }
.wiki-references li { margin-bottom: 0.4rem; }

/* ===== SIDEBAR (десктоп) ===== */
.wiki-sidebar {
  float: left;
  width: 170px;
  font-size: 0.8rem;
  padding: 1rem 0.75rem;
  margin-right: 2rem;
  display: none;
}

@media (min-width: 992px) {
  .wiki-sidebar { display: block; }
}

.wiki-sidebar .sidebar-logo { text-align: center; margin-bottom: 1rem; }
.wiki-sidebar .sidebar-logo img { max-width: 135px; }
.wiki-sidebar ul { list-style: none; margin: 0; padding: 0; }
.wiki-sidebar li { padding: 0.3rem 0; }
.wiki-sidebar a { color: var(--psy-link); text-decoration: none; }
.wiki-sidebar a:hover { text-decoration: underline; }
.wiki-sidebar .sidebar-section {
  font-weight: 700;
  color: #888;
  margin-top: 0.8rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--psy-border-light);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ===== MAIN WITH SIDEBAR ===== */
.wiki-main { overflow: hidden; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .wiki-infobox { float: none; width: 100%; margin: 1rem 0; }
  .wiki-references { column-count: 1; }
  .wiki-content { padding: 1rem; }
  .wiki-footer ul { flex-direction: column; gap: 0.25rem; }
  .portal-grid { grid-template-columns: 1fr; }
  .method-list { grid-template-columns: 1fr; }
  .hero-portal { padding: 1.5rem 0.5rem 1rem; }
  .hero-portal h1 { font-size: 1.6rem; }
}

html { scroll-behavior: smooth; }