/* ---------------------------------------------
  Base typography & spacing
  --------------------------------------------- */
html { font-size: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: #212529;
}

h1, h2, h3, h4, h5, h6 { color: #111; line-height: 1.25; margin-top: 0; margin-bottom: .75rem; }
h1 { font-size: 2rem; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.3rem; }
h4 { font-size: 1.15rem; }
h5 { font-size: 1rem; }
h6 { font-size: .95rem; }

small, .text-muted { color: #6c757d !important; }

/* Navbar polish */
.navbar { font-size: .95rem; }
.navbar-brand { font-weight: 600; letter-spacing: .2px; }
.navbar .nav-link { padding: .4rem .75rem; }

/* ---------------------------------------------
  Filter dropdown & forms
  --------------------------------------------- */
/* Custom styles for scrollable dropdown menus in filters */
.scrollable-dropdown-menu {
  max-height: 200px; /* Adjust as needed */
  overflow-y: auto;
  overflow-x: auto; /* allow horizontal scroll when labels are long */
  padding: .25rem 0; /* keep content away from top/bottom border */
  white-space: nowrap; /* keep items on a single line */
}

/* Optional: Style for the container of the filter dropdowns if needed */
.filter-dropdown-container .dropdown-toggle {
  text-align: left; /* Align text to the left for a cleaner look */
}

/* Ensure labels within dropdowns are clickable and properly aligned */
.scrollable-dropdown-menu .form-check-label {
  display: inline-block;
  cursor: pointer;
  margin: 0;
}

.scrollable-dropdown-menu .form-check-input {
  cursor: pointer;
  margin-left: 0;           /* avoid clipping against left border */
  margin-right: .5rem;      /* space before label */
  margin-top: .1rem;        /* slight vertical alignment */
}

/* Tighten list item spacing so controls don't touch borders */
.scrollable-dropdown-menu .dropdown-item-text.form-check {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .3rem 1rem;      /* horizontal padding matches px-3, add vertical space */
  margin: 0;                /* prevent extra gaps that can clip at edges */
}

/* Prevent dropdown menu from being too narrow if button text is short */
.filter-dropdown-container .dropdown-menu {
    min-width: 100%; /* Ensure it's at least as wide as the button */
}

/* Relation filter: cluster list with hover submenu */
.cluster-dropdown-menu { padding: .25rem 0; }
.cluster-item { position: relative; }
.cluster-toggle { cursor: default; padding-right: 1.5rem; }
.cluster-toggle::after { content: "\203A"; position: absolute; right: .75rem; }
.cluster-submenu {
  display: none;
  position: absolute;
  top: 0;
  left: 100%;
  min-width: 16rem;
  margin: 0;
  padding: .25rem 0;
  list-style: none;
  background: #fff;
  border: 1px solid rgba(0,0,0,.15);
  border-radius: .375rem;
  box-shadow: 0 .5rem 1rem rgba(0,0,0,.15);
  z-index: 1060;
}
.cluster-item:hover { z-index: 2; }
.cluster-item:hover > .cluster-submenu,
.cluster-toggle:focus + .cluster-submenu { display: block; }

/* Keep filter dropdowns above the results column */
aside.col-lg-3 { position: relative; z-index: 1050; }
.filter-panel { position: relative; z-index: 1050; }
.cluster-submenu { background-color: #fff !important; }

/* Search page polish */
.search-header { margin-top: 6px; margin-bottom: 18px; }

.filter-panel { border-radius: 8px; }
.filter-panel .card-title { font-size: 1.05rem; margin-bottom: 0.75rem; }

.results-list { display: flex; flex-direction: column; gap: 16px; }

/* Style individual dialogue cards (align with video.css) */
.dialogue-card { padding: 0; border-color: #e6e8eb; }

/* Make the filter form controls more compact and aligned */
.filter-panel .form-group, .filter-panel .form-check { margin-bottom: 0.5rem; }

/* Search input size tuned for readability */
.form-control-lg { padding: .7rem 1rem; font-size: 1.05rem; }

/* Active filters badges */
.badge.bg-light.text-dark.border { font-weight: 500; padding: .4rem .6rem; border-radius: .5rem; }
.badge.bg-secondary { font-weight: 500; }
.badge a { color: inherit; }

/* Small screens: ensure good spacing */
@media (max-width: 768px) {
  .search-header .col-md-9, .search-header .col-md-3 { width: 100%; }
}

/* Hover elevation for dialogue cards and filter card */
.dialogue-card { transition: box-shadow 160ms ease, transform 160ms ease; }
.dialogue-card:hover { box-shadow: 0 8px 24px rgba(0,0,0,0.10); transform: translateY(-2px); }
.filter-panel { transition: box-shadow 160ms ease, transform 160ms ease; }
.filter-panel:hover { box-shadow: 0 8px 20px rgba(0,0,0,0.06); transform: translateY(-2px); }

/* Statistics cards layout */
.stats-cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
@media (min-width: 992px) { /* >= lg */
  .stats-cards { grid-template-columns: repeat(5, 1fr); }
}
.stats-cards .card .card-body { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; }
.stats-cards .card .card-title { 
  text-align: center; 
  margin-bottom: .25rem; 
  min-height: clamp(2.4rem, 3vw, 3.6rem); /* reserve space for up to ~2 lines */
  display: flex; align-items: center; justify-content: center; gap: .25rem;
}
.stat-value { font-weight: 700; font-size: clamp(1.25rem, 2vw, 1.75rem); margin: .1rem 0 0; }
.stats-help { cursor: help; font-size: .95em; margin-left: .35rem; color: #6c757d; }

/* Show-more toggle for long dialogue texts */
.dialogue-content { position: relative; line-height: 1.6; }
.dialogue-content.collapsed {
  max-height: 6.5rem; /* ~4 lines depending on font-size */
  overflow: hidden;
}
.dialogue-content.expanded {
  max-height: none;
}
.show-more-btn {
  display: inline-block;
  margin-top: 2px;       /* even closer to dialogue text */
  margin-bottom: 12px;   /* more space before metadata/participants */
  padding: 0;
  border: none;
  background: none;
  color: #0d6efd; /* bootstrap primary */
  font-size: .95rem;
  font-weight: 500;
  cursor: pointer;
}
.show-more-btn:hover { color: #0a58ca; text-decoration: underline; }
.show-more-btn:focus { outline: none; text-decoration: underline; }

/* Dialogue metadata tweaks */
.dialogue-header { margin-bottom: .5rem; }
.dialogue-types { margin-bottom: .6rem; }
.dialogue-meta { margin-top: .2rem; }

/* Pagination compact spacing */
.pagination .page-link { padding: .4rem .6rem; }
.pagination { margin-top: 1rem; }

/* Pagination typography to match layout */
.pagination .page-link {
  font-size: .95rem;
  font-weight: 500;
  color: #0d6efd;
  border-radius: .5rem;
  border-color: #dee2e6;
}
.pagination .page-link:hover {
  color: #0a58ca;
  background-color: #eef5ff;
  border-color: #cfe2ff;
}
.pagination .page-item.active .page-link {
  background-color: #0d6efd;
  border-color: #0d6efd;
  color: #fff;
}
.pagination .page-item.disabled .page-link {
  color: #adb5bd;
}

/* ---------------------------------------------
  Dialogue metadata chips & badges
  --------------------------------------------- */
.participant-badge {
  background: #f8f9fa;
  color: #212529;
  border: 1px solid #e2e6ea;
  border-radius: .6rem;
  padding: .25rem .5rem;
  margin-right: .5rem;   /* slightly more space between participant tags */
  margin-bottom: .35rem; /* better wrap spacing */
}
.participant-badge .participant-name { font-weight: 600; }
.chip {
  display: inline-block;
  font-size: .75rem;
  line-height: 1;
  padding: .25rem .4rem;
  margin-left: .35rem;
  border-radius: .5rem;
  vertical-align: middle;
  border: 1px solid transparent;
}
.sex-chip.sex-m { background: #e7f1ff; color: #0b5ed7; border-color: #cfe2ff; }
.sex-chip.sex-f { background: #fde7f1; color: #d63384; border-color: #f8c2d7; }
.sex-chip.sex-u { background: #f1f3f5; color: #495057; border-color: #e9ecef; }

.age-chip { background: #f8f9fa; color: #495057; border-color: #e9ecef; }
/* Common Russian age tags; unknown strings will use the default .age-chip */
.age-chip.age-tag-молодой { background: #e9f7ef; color: #0f5132; border-color: #c7eed8; }
.age-chip.age-tag-зрелый-1 { background: #fff3cd; color: #664d03; border-color: #ffe69c; }
.age-chip.age-tag-зрелый-2 { background: #ffe5d0; color: #99582a; border-color: #ffd1a7; }
.age-chip.age-tag-неизвестно { background: #f1f3f5; color: #6c757d; border-color: #e9ecef; }

/* Participant characteristics toggle and panel */
.participant-toggle {
  display: inline-block;
  width: .9rem;
  height: .9rem;
  margin-left: .35rem;
  padding: 0;
  vertical-align: middle;
  border: 0;
  background: none;
  cursor: pointer;
  opacity: .7;
}
.participant-toggle::before {
  content: "";
  display: block;
  width: .4rem;
  height: .4rem;
  margin: .2rem auto 0;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-135deg);
  transition: transform .15s ease;
}
.participant-toggle.collapsed::before { transform: rotate(45deg); margin-top: .1rem; }
.participant-toggle:hover { opacity: 1; }
.participant-traits {
  margin: .25rem 0 .5rem;
  padding: .4rem .6rem;
  background: #f8f9fa;
  border-left: 3px solid #dee2e6;
  border-radius: .25rem;
}
.participant-traits-name { font-weight: 600; color: #495057; }

.rel-badge {
  background: #e0e7ff; /* more vivid indigo */
  color: #1f2a68;
  border: 1px solid #c7d2fe;
  font-weight: 600; /* match familiarity badge */
  font-size: .75rem; /* align with other small chips */
  line-height: 1;    /* compact like chips */
  border-radius: .5rem;
  padding: .2rem .5rem;
  margin-right: .5rem;   /* slightly increase spacing between relation tags */
  margin-bottom: .35rem; /* better wrap spacing */
}

/* ---------------------------------------------
  Navbar logo
  --------------------------------------------- */
.navbar-logo {
  max-height: 80px;
  height: auto;
  width: auto;
  object-fit: contain;
}
@media (max-width: 768px) {
  .navbar-logo { max-height: 48px; }
}

/* Familiarity badge (e.g., degree_of_familiarity) */
.fam-badge {
  background: #ffe5e0; /* warm vivid */
  color: #7a1d12;
  border: 1px solid #ffc9c0;
  font-weight: 600;
  font-size: .75rem; /* align with relation badge */
  line-height: 1;    /* compact like chips */
  border-radius: .5rem;
  padding: .2rem .5rem;
  /* keep a touch of left spacing but add right/bottom for flow */
  margin: 0 .5rem .35rem .35rem;
}

/* Familiarity variants (fallback is .fam-badge) */
.fam-badge.fam-незнакомые { background: #e9ecef; color: #343a40; border-color: #dee2e6; }
.fam-badge.fam-малознакомые { background: #e0f7fa; color: #0b7285; border-color: #b2f2ff; }
.fam-badge.fam-знакомые { background: #e6f4ea; color: #2b8a3e; border-color: #c3e6cb; }
.fam-badge.fam-близкие { background: #f3e8ff; color: #5f3dc4; border-color: #e5dbff; }

/* Relation category variants (fallback is .rel-badge) */
.rel-badge.rel-семья { background: #ffe8cc; color: #7f4f24; border-color: #ffd8a8; }
.rel-badge.rel-друзья { background: #e7f5ff; color: #0b66a1; border-color: #cfe8ff; }
.rel-badge.rel-коллеги { background: #e6fcf5; color: #087f5b; border-color: #c3fae8; }
.rel-badge.rel-начальник-подчинённый, .rel-badge.rel-начальник-подчиненный { background: #fff0f6; color: #a61e4d; border-color: #ffc9de; }
.rel-badge.rel-романтические { background: #ffe3e9; color: #a61e4d; border-color: #ffccd5; }
.rel-badge.rel-соседи { background: #fff3bf; color: #8a5d07; border-color: #ffe69c; }
.rel-badge.rel-партнёры, .rel-badge.rel-партнеры { background: #e6f0ff; color: #1c4ed8; border-color: #c7d2fe; }


/* ---------------------------------------------
  In-text highlight (<mark>)
  --------------------------------------------- */
mark {
  background-color: #fff3bf; /* soft yellow, good contrast */
  color: inherit;
  padding: 0 .15em;
  border-radius: .2em;
}

/* ---------------------------------------------
  Manual page helpers (tight images & spacing)
  --------------------------------------------- */
.manual-section { margin-bottom: 12px; }
.manual-toc .btn { padding: .15rem .5rem; }
.manual-figure { margin: 0; }
.manual-caption { margin-top: .25rem; font-size: .85rem; color: #6c757d; }
/* Cap image width to keep layout tight on large screens */
.manual-img { width: 100%; height: auto; max-width: 640px; }
/* Дополнительный класс для длинных скриншотов (делает их визуально меньше) */
.manual-img-small { max-width: 520px; }

