/* VoiceFlow Mini App — гибрид-необрутализм (Ф4).
   критика: Ф4 И4 Исп4 К5 Сд4 Р4
   Необрутализм-язык (жирные обводки, офсет-тени, плоские поп-цвета, bold-типографика,
   малый радиус) поверх Telegram-темы: обводка и текст идут от --tg-theme-*, поэтому
   на светлой теме обводка тёмная, на тёмной — светлая (классический #000-бордер
   необрутализма сломал бы тёмную тему Telegram). Бренд-акцент — коралл, НЕ фиолетовый. */

:root {
  /* Telegram-тема как база */
  --bg: var(--tg-theme-bg-color, #ffffff);
  --surface: var(--tg-theme-secondary-bg-color, #f0f0f3);
  --text: var(--tg-theme-text-color, #14141a);
  --hint: var(--tg-theme-hint-color, #8a8a92);
  --tg-button: var(--tg-theme-button-color, #2ea6ff);
  --tg-button-text: var(--tg-theme-button-text-color, #ffffff);

  /* Бренд: тёплый коралл — характер, не конфликтует с синей кнопкой Telegram */
  --brand: #ff5a4d;
  --brand-ink: #ffffff;

  /* Семантика срочности — плоские поп-цвета (константы, не от темы) */
  --u-high: #ff4d3d;
  --u-mid: #ffb02e;
  --u-low: #3ec46d;

  /* «Чернила» необрутализма — обводки и тени. currentColor темы, чтобы
     адаптироваться к light/dark. На свету тёмные, в дарке светлые. */
  --ink: color-mix(in srgb, var(--text) 78%, transparent);
  --shadow-ink: color-mix(in srgb, var(--text) 90%, transparent);

  --border-w: 2px;
  --shadow-off: 3px;
  --radius: 12px;
  --radius-sm: 8px;

  --z-modal: 100;
}

/* Тёмная тема Telegram: чуть мягче обводки, тени темнее (под светлый текст) */
@media (prefers-color-scheme: dark) {
  :root {
    --ink: color-mix(in srgb, var(--text) 55%, transparent);
    --shadow-ink: rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Public Sans", -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px; /* ≥16px: иначе iOS зумит инпут при фокусе */
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

/* Необрутализм-примитив: блок с обводкой и жёсткой офсет-тенью */
.nb {
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-off) var(--shadow-off) 0 var(--shadow-ink);
  background: var(--bg);
}

h1, h2, h3 {
  font-family: "Lexend Mega", "Public Sans", sans-serif;
  letter-spacing: -0.02em;
}

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 14px 16px 10px;
  z-index: 6;
  border-bottom: var(--border-w) solid var(--ink);
}
.topbar h1 {
  font-size: 22px;
  font-weight: 800;
  margin: 0 0 10px;
  text-transform: uppercase;
}

.tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.tab {
  flex: 1;
  padding: 9px;
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: "Public Sans", sans-serif;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.tab.is-active {
  background: var(--brand);
  color: var(--brand-ink);
  box-shadow: var(--shadow-off) var(--shadow-off) 0 var(--shadow-ink);
}

#search {
  width: 100%;
  padding: 11px 13px;
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: "Public Sans", sans-serif;
  font-size: 16px;
}
#search:focus { outline: none; box-shadow: var(--shadow-off) var(--shadow-off) 0 var(--brand); }

/* ===== Фильтры ===== */
.filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 16px 12px;
}
.filter-group { display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.filter-group::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  padding: 7px 13px;
  border: var(--border-w) solid var(--ink);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.chip.is-active {
  background: var(--text);
  color: var(--bg);
}
/* Цветная точка срочности на чипах фильтра (вместо эмодзи). */
.chip[data-urgency] { display: inline-flex; align-items: center; gap: 6px; }
.chip[data-urgency]::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  flex: none;
}
.chip[data-urgency="high"]::before { background: var(--u-high); }
.chip[data-urgency="mid"]::before { background: var(--u-mid); }
.chip[data-urgency="low"]::before { background: var(--u-low); }

/* ===== Лента ===== */
.list { display: flex; flex-direction: column; gap: 14px; padding: 4px 16px 28px; }

.card {
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-off) var(--shadow-off) 0 var(--shadow-ink);
  background: var(--bg);
  padding: 14px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
  /* место под акцентный угол срочности */
  position: relative;
  overflow: hidden;
}
.card:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow-ink); }
.card.is-done { opacity: 0.62; }

/* Срочность — акцентный УГОЛ-вырез сверху, а не боковая полоса (анти-слоп). */
.card::before {
  content: "";
  position: absolute;
  top: 0; right: 0;
  width: 36px; height: 36px;
  background: var(--card-accent, transparent);
  clip-path: polygon(100% 0, 0 0, 100% 100%);
}
.card.u-high { --card-accent: var(--u-high); }
.card.u-mid { --card-accent: var(--u-mid); }
.card.u-low { --card-accent: var(--u-low); }

.card-head { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--hint); margin-bottom: 7px; }
/* Точка-индикатор срочности (вместо эмодзи): цвет от класса карточки. */
.card-urgency {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--card-accent, var(--hint));
  flex: none;
}
.card-who { font-weight: 700; color: var(--text); }
.card-date { margin-left: auto; font-variant-numeric: tabular-nums; }
.card-summary { margin: 0; font-size: 16px; line-height: 1.4; font-weight: 500; }

.card-action {
  margin: 10px 0 0;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--u-mid) 18%, var(--bg));
}
.card-badges { display: flex; gap: 8px; margin-top: 9px; font-size: 13px; }
.badge-done { color: var(--u-low); font-weight: 700; }
.badge-starred { color: var(--hint); font-weight: 600; }

.empty, .loader { text-align: center; color: var(--hint); padding: 44px 24px; font-size: 16px; }

/* ===== Детали (bottom-sheet) ===== */
.detail { position: fixed; inset: 0; z-index: var(--z-modal); display: flex; align-items: flex-end; }
.detail-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); }
.detail-card {
  position: relative;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg);
  border-top: var(--border-w) solid var(--ink);
  border-radius: 18px 18px 0 0;
  padding: 22px 16px calc(26px + env(safe-area-inset-bottom));
  animation: slideUp .22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.detail-close {
  position: absolute;
  top: 14px; right: 14px;
  border: var(--border-w) solid var(--ink);
  background: var(--bg);
  color: var(--text);
  width: 34px; height: 34px;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
#detail-body h2 { margin: 0 44px 18px 0; font-size: 19px; font-weight: 800; }
/* Цветной акцент срочности слева от заголовка детали (вместо эмодзи в тексте). */
.detail-title { display: flex; align-items: center; gap: 9px; }
.detail-title::before {
  content: "";
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--hint);
  flex: none;
}
.detail-title.u-high::before { background: var(--u-high); }
.detail-title.u-mid::before { background: var(--u-mid); }
.detail-title.u-low::before { background: var(--u-low); }

.d-row { margin-bottom: 14px; }
.d-label { display: block; font-size: 12px; font-weight: 700; color: var(--hint); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 3px; }
.d-value { font-size: 16px; line-height: 1.4; }

.d-actions { display: flex; flex-wrap: wrap; gap: 9px; margin: 18px 0; }
.btn {
  padding: 10px 14px;
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: var(--brand-ink);
  font-family: "Public Sans", sans-serif;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-off) var(--shadow-off) 0 var(--shadow-ink);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow-ink); }
.btn-muted { background: var(--surface); color: var(--text); }
.btn-subtext { background: var(--u-mid); color: #1a1208; width: 100%; }
.btn-danger { background: var(--u-high); color: #fff; width: 100%; margin-top: 8px; }
.btn:disabled { opacity: 0.6; }

/* Субтекст в детали */
.d-subtext {
  margin: 18px 0;
  padding: 14px;
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--brand) 8%, var(--bg));
}
.d-subtext .d-label { margin-bottom: 12px; }
.st-row { margin-bottom: 10px; }
.st-label { display: block; font-size: 12px; font-weight: 700; color: var(--brand); margin-bottom: 2px; }
.st-value { font-size: 15px; line-height: 1.4; }

/* Дайджест */
.widget.digest { background: var(--surface); }
.digest-line { margin: 0; font-size: 16px; font-weight: 600; line-height: 1.5; }

.d-note { margin: 18px 0; }
.d-note label { display: block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--hint); margin-bottom: 7px; }
.d-note textarea {
  width: 100%;
  min-height: 66px;
  padding: 11px;
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: "Public Sans", sans-serif;
  font-size: 16px;
  resize: vertical;
  margin-bottom: 9px;
}
.d-note textarea:focus { outline: none; box-shadow: var(--shadow-off) var(--shadow-off) 0 var(--brand); }

.d-transcript { margin-top: 18px; border-top: var(--border-w) solid var(--ink); padding-top: 14px; }
.d-transcript summary { cursor: pointer; color: var(--brand); font-size: 14px; font-weight: 700; }
.d-transcript p { font-size: 15px; line-height: 1.55; color: var(--text); margin-top: 12px; }

/* ===== Дашборд ===== */
.dashboard { padding: 6px 16px 28px; display: flex; flex-direction: column; gap: 14px; }

/* Bento-вариация: первая плитка шире — разрывает монотонную 2-колонку (анти-слоп) */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat {
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-off) var(--shadow-off) 0 var(--shadow-ink);
  background: var(--bg);
  padding: 16px;
}
.stat:first-child { grid-column: span 2; background: var(--surface); }
.stat-accent { background: var(--u-high); border-color: var(--u-high); color: #fff; }
.stat-value { font-family: "Lexend Mega", sans-serif; font-size: 30px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 13px; font-weight: 600; color: var(--hint); margin-top: 6px; }
.stat-accent .stat-label { color: rgba(255, 255, 255, 0.9); }

.widget {
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-off) var(--shadow-off) 0 var(--shadow-ink);
  background: var(--bg);
  padding: 16px;
}
.widget h3 { margin: 0 0 13px; font-size: 14px; font-weight: 800; text-transform: uppercase; letter-spacing: -0.01em; }
.widget-sub { margin: 9px 0 0; font-size: 13px; color: var(--hint); font-variant-numeric: tabular-nums; }

.progress { height: 14px; border: var(--border-w) solid var(--ink); border-radius: 999px; background: var(--surface); overflow: hidden; }
.progress-fill { height: 100%; background: var(--brand); }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.bar-label { width: 72px; font-size: 13px; font-weight: 600; color: var(--hint); }
.bar-label.u-high { color: var(--u-high); }
.bar-label.u-mid { color: var(--u-mid); }
.bar-label.u-low { color: var(--u-low); }
.bar-track { flex: 1; height: 14px; border: var(--border-w) solid var(--ink); border-radius: 999px; background: var(--surface); overflow: hidden; }
.bar-fill { height: 100%; }
.bar-fill.u-high { background: var(--u-high); }
.bar-fill.u-mid { background: var(--u-mid); }
.bar-fill.u-low { background: var(--u-low); }
.bar-count { width: 24px; text-align: right; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }

.spark { display: flex; align-items: flex-end; gap: 4px; height: 66px; }
.spark-col { flex: 1 1 0; max-width: 26px; min-width: 4px; background: var(--brand); border: var(--border-w) solid var(--ink); border-bottom: none; border-radius: 4px 4px 0 0; }

.contact-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-bottom: var(--border-w) solid color-mix(in srgb, var(--ink) 40%, transparent); }
.contact-row:last-child { border-bottom: none; }
.contact-name { font-size: 16px; font-weight: 600; }
.contact-meta { font-size: 13px; color: var(--hint); font-variant-numeric: tabular-nums; }

/* --- Досье контакта --- */
/* Имя-ссылка в детали карточки: подчёркнуто, чтобы читалось как переход. */
.contact-link {
  font: inherit;
  font-weight: 800;
  color: var(--brand);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 2px;
}
.contact-link::after { content: " →"; text-decoration: none; }

.dossier-facts { margin: -2px 0 16px; font-size: 14px; color: var(--hint); font-variant-numeric: tabular-nums; }
.dossier-bars { margin: 14px 0; }
.dossier-trend {
  margin: 14px 0;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 12px;
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.dossier-tails { margin: 16px 0; }
.tail-item {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-weight: 600;
  margin-bottom: 8px;
  padding: 11px 12px;
  border: var(--border-w) solid var(--u-high);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--u-high) 10%, transparent);
  color: var(--text);
  cursor: pointer;
}
.tail-item:active { transform: translate(1px, 1px); }

.relationship-text { margin: 0; font-size: 15px; line-height: 1.5; }

.dossier-cards { margin-top: 18px; }
.dcard {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  font: inherit;
  padding: 11px 0;
  border: none;
  border-bottom: var(--border-w) solid color-mix(in srgb, var(--ink) 35%, transparent);
  background: none;
  color: var(--text);
  cursor: pointer;
}
.dcard:last-child { border-bottom: none; }
.dcard.u-high { --card-accent: var(--u-high); }
.dcard.u-mid { --card-accent: var(--u-mid); }
.dcard.u-low { --card-accent: var(--u-low); }
.dcard.is-done { opacity: 0.55; }
.dcard-summary { flex: 1; font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dcard-date { font-size: 13px; color: var(--hint); font-variant-numeric: tabular-nums; flex: none; }

/* Reduce Motion: уважаем системную настройку */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
