/* Тёмная тема и та же шкала размеров, что в музыкальном приложении: два своих
   приложения в одном Telegram должны выглядеть роднёй, а не случайными людьми. */
:root {
  --bg: #0d0d10;
  --bg-elev: #16161c;
  --bg-hover: #1e1e26;
  --text: #f2f2f5;
  --muted: #8f8fa0;
  --accent: #4b9bff;
  --accent-soft: rgba(75, 155, 255, .22);
  --line: rgba(255, 255, 255, .07);

  --t-meta: 12px;
  --t-sub: 14px;
  --t-body: 16px;
  --t-lead: 20px;
  --t-head: 26px;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: var(--t-body); line-height: 1.45;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── шапка ─────────────────────────────────────────────────────────────── */

.top {
  position: sticky; top: 0; z-index: 10;
  padding: calc(var(--safe-top) + var(--s3)) var(--s4) var(--s2);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.search { position: relative; }
.search-icon {
  position: absolute; left: var(--s3); top: 50%; transform: translateY(-50%);
  color: var(--muted); width: 18px; height: 18px;
}
#q {
  width: 100%; padding: var(--s3) var(--s3) var(--s3) 40px;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); font-size: var(--t-body); outline: none;
}
#q:focus { border-color: var(--accent); }
#q::-webkit-search-cancel-button { filter: invert(.6); }

.applied {
  margin-top: var(--s2); font-size: var(--t-meta); color: var(--accent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.chips { display: flex; gap: var(--s2); margin-top: var(--s3); overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: var(--s1) var(--s3); border-radius: 999px;
  background: var(--bg-elev); border: 1px solid var(--line);
  color: var(--muted); font-size: var(--t-sub); font-weight: 600; cursor: pointer;
}
.chip.active { background: var(--text); border-color: var(--text); color: #000; }

.bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: var(--s2); font-size: var(--t-meta); color: var(--muted);
}
.link-btn {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--accent); font-size: var(--t-meta); font-weight: 600;
}

/* ── результаты ────────────────────────────────────────────────────────── */

main { padding: var(--s2) var(--s2) calc(var(--safe-bottom) + var(--s5)); }

.hit {
  padding: var(--s3); border-radius: 12px; cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.hit:active { background: var(--bg-hover); }

.hit-head {
  display: flex; align-items: baseline; gap: var(--s2);
  font-size: var(--t-meta); color: var(--muted); margin-bottom: var(--s1);
}
.hit-chat { color: var(--accent); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hit-date { margin-left: auto; flex: none; }

.hit-body {
  font-size: var(--t-sub); line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.hit.open .hit-body { -webkit-line-clamp: unset; }

mark {
  background: var(--accent-soft); color: var(--text);
  border-radius: 3px; padding: 0 2px;
}

.hit-file {
  display: inline-flex; align-items: center; gap: var(--s1);
  margin-top: var(--s1); font-size: var(--t-meta); color: var(--muted);
}
.hit-kind {
  flex: none; font-size: var(--t-meta); color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px; padding: 0 5px;
}

.empty { text-align: center; color: var(--muted); padding: 56px var(--s5); }
.empty .big { font-size: 40px; margin-bottom: var(--s3); }
.empty h2 { color: var(--text); font-size: var(--t-lead); margin: 0 0 var(--s2); }
.empty p { margin: 0; font-size: var(--t-sub); }

.skel { height: 76px; margin: var(--s2); border-radius: 12px; background: var(--bg-elev); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.more { padding: var(--s4); text-align: center; }
.more button {
  padding: var(--s2) var(--s5); border-radius: 999px;
  background: var(--bg-elev); border: 1px solid var(--line);
  color: var(--text); font-size: var(--t-sub); font-weight: 600; cursor: pointer;
}

/* ── выбор чата ────────────────────────────────────────────────────────── */

.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.sheet-card {
  position: relative; width: 100%; max-height: 78vh; overflow-y: auto;
  background: var(--bg-elev); border-radius: 18px 18px 0 0;
  padding: var(--s2) var(--s2) calc(var(--safe-bottom) + var(--s3));
  animation: rise .24s cubic-bezier(.2, .8, .3, 1);
}
@keyframes rise { from { transform: translateY(100%); } }
.sheet-head {
  padding: var(--s3) var(--s3) var(--s2);
  font-weight: 700; border-bottom: 1px solid var(--line); margin-bottom: var(--s1);
}
.sheet-item {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%; padding: var(--s3); border: 0; border-radius: 10px;
  background: none; color: var(--text); font-size: var(--t-sub); text-align: left; cursor: pointer;
}
.sheet-item:active { background: var(--bg-hover); }
.sheet-item.active { color: var(--accent); font-weight: 600; }
.sheet-item .n { margin-left: auto; color: var(--muted); font-size: var(--t-meta); }
