:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --card: var(--tg-theme-secondary-bg-color, #1a1d23);
  --text: var(--tg-theme-text-color, #f2f4f8);
  --hint: var(--tg-theme-hint-color, #8b93a3);
  --accent: var(--tg-theme-button-color, #2ea6ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --up: #2ecc71;
  --down: #ff5c5c;
  --border: rgba(255,255,255,0.08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 15px; line-height: 1.35;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px; position: sticky; top: 0; z-index: 10;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.brand-title { font-weight: 700; font-size: 18px; }
.brand-sub { color: var(--hint); font-size: 12px; }
.period-label { color: var(--hint); font-size: 12px; text-align: right; max-width: 45%; }

.controls { padding: 12px 16px 6px; display: flex; flex-direction: column; gap: 10px; }
.presets { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.presets button {
  flex: 0 0 auto; padding: 9px 14px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-size: 13px; font-weight: 500;
}
.presets button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.custom-range { display: flex; align-items: center; gap: 6px; }
.custom-range input[type=date] {
  flex: 1; background: var(--card); border: 1px solid var(--border); color: var(--text);
  padding: 8px 10px; border-radius: 10px; font-size: 13px; min-width: 0;
}
.custom-range .apply {
  padding: 8px 14px; border-radius: 10px; border: none; background: var(--accent);
  color: var(--accent-text); font-weight: 600;
}
.cmp-toggle { display: flex; align-items: center; gap: 8px; color: var(--hint); font-size: 13px; }
.cmp-toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.tabs { display: flex; gap: 4px; padding: 6px 12px 0; border-bottom: 1px solid var(--border); }
.tabs button {
  flex: 1; padding: 12px 4px; background: none; border: none; color: var(--hint);
  font-size: 14px; font-weight: 600; border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 14px 12px 60px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kpi {
  background: var(--card); border-radius: 14px; padding: 12px 13px; border: 1px solid var(--border);
}
.kpi-label { color: var(--hint); font-size: 12px; margin-bottom: 4px; }
.kpi-value { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }
.kpi-delta { font-size: 12px; margin-top: 3px; font-weight: 600; }
.kpi-delta.up { color: var(--up); }
.kpi-delta.down { color: var(--down); }
.kpi-delta.flat { color: var(--hint); }

.card {
  background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 12px;
  border: 1px solid var(--border);
}
.card-title { font-weight: 600; font-size: 14px; margin-bottom: 10px; }
canvas { max-width: 100%; }

.legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--hint); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: right; padding: 8px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; white-space: normal; }
th { color: var(--hint); font-weight: 600; font-size: 11px; text-transform: uppercase; }
td.pos { color: var(--up); }
td.neg { color: var(--down); }
.sub { color: var(--hint); font-size: 11px; }
.bar-cell { position: relative; }
.mini-bar { height: 4px; border-radius: 2px; background: var(--accent); margin-top: 3px; }

.loader, .error { text-align: center; padding: 30px; color: var(--hint); }
.error { color: var(--down); }
.hidden { display: none; }

/* Подсказки (инсайты) — сквозная аналитика.
   Фиксированные пастельные фоны + тёмный текст: читается и в светлой, и в тёмной
   теме Telegram (не завязано на themeParams, поэтому текст не сливается с фоном). */
.insights { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.insights:empty { display: none; }
.insights-title { font-weight: 700; font-size: 16px; margin: 4px 2px 2px; }
.insights-hint { color: var(--hint); font-size: 12px; margin: 0 2px 4px; }
.insight {
  display: flex; gap: 12px; align-items: flex-start;
  border-radius: 14px; padding: 12px 14px; border-left: 5px solid;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.insight.good { background: #e7f7ec; border-left-color: #1faf54; }
.insight.warn { background: #fff3dd; border-left-color: #f5920b; }
.insight.info { background: #e7f1ff; border-left-color: #2e8bff; }
.insight.diggable { cursor: pointer; }
.insight.diggable:active { filter: brightness(0.97); }
.insight-icon {
  font-size: 22px; line-height: 1.1; flex: 0 0 auto;
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.65); border-radius: 10px;
}
.insight-body { min-width: 0; flex: 1; }
.insight-title { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.insight.good .insight-title { color: #0f5a2c; }
.insight.warn .insight-title { color: #7a4a00; }
.insight.info .insight-title { color: #0a3f80; }
.insight-detail { font-size: 12.5px; margin-top: 3px; line-height: 1.4; }
.insight.good .insight-detail { color: #245c39; }
.insight.warn .insight-detail { color: #6e4f18; }
.insight.info .insight-detail { color: #2b5590; }
.insight .chev { font-size: 12px; opacity: 0.7; transition: transform 0.15s; margin-left: auto; }
.insight.open .chev { transform: rotate(90deg); }
.insight-drill {
  margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(0,0,0,0.12);
}
.drill-title { font-weight: 700; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: 0.3px; margin: 8px 0 4px; opacity: 0.85; }
.insight.good .insight-drill, .insight.good .drill-title { color: #245c39; }
.insight.warn .insight-drill, .insight.warn .drill-title { color: #6e4f18; }
.insight.info .insight-drill, .insight.info .drill-title { color: #2b5590; }
.insight-drill table { width: 100%; border-collapse: collapse; font-size: 12px; }
.insight-drill th, .insight-drill td {
  text-align: right; padding: 5px 6px; border-bottom: 1px solid rgba(0,0,0,0.10); white-space: nowrap;
}
.insight-drill th:first-child, .insight-drill td:first-child { text-align: left; white-space: normal; }
.insight-drill th { font-size: 10px; text-transform: uppercase; opacity: 0.75; }

/* Фильтр по услуге + аккордеон врачей */
.filter-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.filter-row label { color: var(--hint); font-size: 12px; flex: 0 0 auto; }
.filter-row select {
  flex: 1; min-width: 0; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 13px;
}
/* Ранжированные карточки врачей */
#doctors-list { display: flex; flex-direction: column; gap: 10px; }
.doc-card {
  background: var(--card); border: 1px solid var(--border); border-left: 5px solid var(--accent);
  border-radius: 12px; padding: 11px 13px;
}
.doc-card.expandable { cursor: pointer; }
.doc-card.expandable:active { filter: brightness(0.97); }
.doc-card-head { display: flex; align-items: flex-start; gap: 10px; }
.doc-rank {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: 7px;
  background: rgba(255,255,255,0.08); color: var(--hint);
  font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.doc-main { flex: 1; min-width: 0; }
.doc-name { font-weight: 600; font-size: 14px; }
.doc-spec { color: var(--hint); font-weight: 400; font-size: 12px; margin-left: 6px; }
.doc-rev { font-size: 19px; font-weight: 700; letter-spacing: -0.3px; margin-top: 2px; }
.doc-figures { color: var(--hint); font-size: 12px; margin-top: 1px; }
.doc-bar { height: 6px; border-radius: 3px; background: rgba(255,255,255,0.07); margin-top: 8px; overflow: hidden; }
.doc-bar-fill { height: 100%; border-radius: 3px; }
.doc-card .chev { color: var(--hint); flex: 0 0 auto; transition: transform 0.15s; }
.doc-card.open .chev { transform: rotate(90deg); }
.doc-card .doc-services { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border); }
.doc-card.other .doc-rev { color: var(--hint); }
.sub-table { width: 100%; margin-top: 2px; }
.sub-table th { font-size: 10px; }
.sub-table td, .sub-table th { padding: 6px 6px; }

/* Вкладка «Общее» — портрет базы */
.general-note {
  color: var(--hint); font-size: 12.5px; margin: 2px 2px 12px; line-height: 1.4;
}
.card-hint { color: var(--hint); font-size: 12px; margin: -4px 0 10px; line-height: 1.4; }
.cov-badge {
  font-weight: 500; font-size: 11px; color: var(--hint);
  background: rgba(255,255,255,0.07); border-radius: 8px; padding: 2px 7px; margin-left: 6px;
  white-space: nowrap;
}
.cov-badge.warn { color: #f5920b; background: rgba(245,146,11,0.14); }
#gen-base.kpi-grid { grid-template-columns: 1fr 1fr; margin-bottom: 0; }
#tab-general .kpi-value { font-size: 18px; }

/* Вкладка «Отзывы» */
#rev-kpi.kpi-grid { margin-bottom: 0; }
#tab-reviews .kpi-value { font-size: 18px; }
#rev-list { display: flex; flex-direction: column; gap: 10px; }
.review {
  background: var(--bg); border: 1px solid var(--border); border-left: 4px solid #2ecc71;
  border-radius: 10px; padding: 10px 12px;
}
.review.neg { border-left-color: #ff5c5c; }
/* Алерт «новые негативные за период» */
.neg-alert {
  border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: 13px;
  line-height: 1.4; border-left: 5px solid; box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.neg-alert.warn { background: #ffe2e0; border-left-color: #e23b34; color: #7a1c17; }
.neg-alert.ok { background: #e7f7ec; border-left-color: #1faf54; color: #14562c; }
.neg-alert b { font-weight: 700; }
.neg-alert-icon { margin-right: 4px; }
#rev-branch-filter {
  flex: 1; min-width: 0; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 13px;
}
.review-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.review-stars { font-size: 14px; letter-spacing: 1px; flex: 0 0 auto; }
.review-meta { color: var(--hint); font-size: 11.5px; text-align: right; }
.review-text { font-size: 13px; line-height: 1.4; }

/* Отзывы: блок «Проблемы и что делать» */
.rev-advice {
  background: #fff3dd; color: #7a4a00; border-radius: 10px; padding: 10px 12px;
  font-size: 12.5px; line-height: 1.4; margin-bottom: 12px;
}
.rev-advice-icon { margin-right: 4px; }
#rev-problems { display: flex; flex-direction: column; gap: 12px; }
.problem { }
.problem-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.problem-name { font-weight: 600; font-size: 13.5px; }
.problem-count {
  flex: 0 0 auto; font-weight: 700; font-size: 13px; color: var(--down);
  background: rgba(255,92,92,0.14); border-radius: 8px; padding: 1px 8px;
}
.problem-bar { background: var(--down); margin: 6px 0 6px; }
.problem-rec { color: var(--hint); font-size: 12px; line-height: 1.4; }
