
  /* ============ THEME TOKENS (Telegram WebApp vars + fallbacks) ============ */
  /* Тёмная — по умолчанию: это рабочий пульт, в него смотрят вечером.
     Значения взяты из тёмной темы Telegram Desktop, чтобы мини-апп
     не спорил с окном мессенджера вокруг себя. */
  :root{
    --fb-bg:#080b0f;
    --fb-text:#eef3f7;
    --fb-hint:#818e9b;
    --fb-link:#6ab7ff;
    --fb-button:#3d6b99;
    --fb-button-text:#ffffff;
    --fb-secondary-bg:#040608;
    --fb-section-bg:#0f141a;
    --fb-hairline:rgba(255,255,255,.09);
    --fb-bubble-bot:#16232f;
    --fb-bubble-client:#111820;
  }
  /* Светлая остаётся доступной: и системной настройкой, и кнопкой. */
  :root[data-theme="light"]{
    --fb-bg:#ffffff;
    --fb-text:#000000;
    --fb-hint:#6b7378;
    --fb-link:#2481cc;
    --fb-button:#2ea6ff;
    --fb-button-text:#ffffff;
    --fb-secondary-bg:#eef1f4;
    --fb-section-bg:#ffffff;
    --fb-hairline:rgba(60,60,67,.29);
    --fb-bubble-bot:#e3f1ff;
    --fb-bubble-client:#ffffff;
  }
  :root[data-theme="dark"]{
    --fb-bg:#080b0f;
    --fb-text:#eef3f7;
    --fb-hint:#818e9b;
    --fb-link:#6ab7ff;
    --fb-button:#3d6b99;
    --fb-button-text:#ffffff;
    --fb-secondary-bg:#040608;
    --fb-section-bg:#0f141a;
    --fb-hairline:rgba(255,255,255,.09);
    --fb-bubble-bot:#16232f;
    --fb-bubble-client:#111820;
  }
  :root{
    --bg: var(--tg-theme-bg-color, var(--fb-bg));
    --text: var(--tg-theme-text-color, var(--fb-text));
    --hint: var(--tg-theme-hint-color, var(--fb-hint));
    --link: var(--tg-theme-link-color, var(--fb-link));
    --button: var(--tg-theme-button-color, var(--fb-button));
    --button-text: var(--tg-theme-button-text-color, var(--fb-button-text));
    --secondary-bg: var(--tg-theme-secondary-bg-color, var(--fb-secondary-bg));
    --section-bg: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-section-bg)));
    --hairline: var(--fb-hairline);
    --bubble-bot: var(--fb-bubble-bot);
    --bubble-client: var(--fb-bubble-client);

    --sev-critical:#ff3b30;      --sev-critical-rgb:255,59,48;
    --sev-high:#ff9500;          --sev-high-rgb:255,149,0;
    --sev-medium:#c99a00;        --sev-medium-rgb:201,154,0;
    --sev-ok:#34c759;            --sev-ok-rgb:52,199,89;
  }
  :root{ --sev-medium:#e0b400; }
  :root[data-theme="light"]{ --sev-medium:#a87f00; }

  *{ box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
  html,body{ margin:0; padding:0; }
  body{
    background:var(--secondary-bg);
    color:var(--text);
    font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
    -webkit-font-smoothing:antialiased;
    min-height:100vh;
    overflow-x:hidden;
  }
  button{ font-family:inherit; cursor:pointer; }
  a{ color:inherit; text-decoration:none; }

  .app{ max-width:480px; margin:0 auto; padding:0 0 40px; min-width:0; }

  /* ============ TOPBAR ============ */
  .topbar{ display:flex; align-items:flex-start; justify-content:space-between; gap:10px; padding:16px 16px 10px; }
  .topbar-title{ font-size:20px; font-weight:700; letter-spacing:-.01em; }
  .topbar-sub{ font-size:13px; color:var(--hint); margin-top:2px; }
  .status-pill{ display:flex; align-items:center; gap:6px; padding:6px 10px; border-radius:20px; font-size:12.5px; font-weight:600; white-space:nowrap; flex-shrink:0; margin-top:1px; }
  .status-pill .status-dot{ width:7px; height:7px; border-radius:50%; }
  .status-pill.st-critical{ background:rgba(var(--sev-critical-rgb),.14); color:var(--sev-critical); }
  .status-pill.st-critical .status-dot{ background:var(--sev-critical); animation:pulse 1.6s ease-in-out infinite; }
  .status-pill.st-high{ background:rgba(var(--sev-high-rgb),.14); color:var(--sev-high); }
  .status-pill.st-high .status-dot{ background:var(--sev-high); }
  .status-pill.st-medium{ background:rgba(var(--sev-medium-rgb),.16); color:var(--sev-medium); }
  .status-pill.st-medium .status-dot{ background:var(--sev-medium); }
  .status-pill.st-ok{ background:rgba(var(--sev-ok-rgb),.14); color:var(--sev-ok); }
  .status-pill.st-ok .status-dot{ background:var(--sev-ok); }
  @keyframes pulse{ 0%,100%{ opacity:1; } 50%{ opacity:.35; } }

  /* ============ GROUPED CARD ============ */
  .group{ background:var(--section-bg); border-radius:12px; margin:10px 12px 18px; overflow:hidden; }
  .group-caption{ padding:14px 16px 4px; font-size:12.5px; color:var(--hint); text-transform:uppercase; letter-spacing:.04em; }
  .srow{ display:flex; align-items:center; justify-content:space-between; gap:10px; padding:11px 16px; min-height:22px; position:relative; }
  .srow + .srow::before{ content:""; position:absolute; left:16px; right:0; top:0; height:1px; background:var(--hairline); }
  .srow-label{ font-size:14.5px; color:var(--text); }
  .srow-value{ font-size:13.5px; color:var(--hint); text-align:right; }
  .link-row{ display:flex; align-items:center; justify-content:space-between; padding:12px 16px; }
  .link-row span{ font-size:14.5px; color:var(--link); font-weight:500; }
  .link-row svg{ color:var(--hint); flex-shrink:0; }

  .hero{ padding:14px 16px 12px; }
  .hero-top{ display:flex; align-items:baseline; justify-content:space-between; margin-bottom:8px; }
  .hero-num{ font-size:30px; font-weight:700; line-height:1; }
  .hero-cap{ font-size:12.5px; color:var(--hint); text-transform:uppercase; letter-spacing:.04em; margin-bottom:2px; }
  .hero-breakdown{ font-size:13px; color:var(--hint); margin-bottom:9px; }
  .hero-bar{ display:flex; height:6px; border-radius:4px; overflow:hidden; background:var(--secondary-bg); }
  .hero-bar div{ height:100%; }

  /* ============ SEGMENTED FILTER ============ */
  .segmented{ display:flex; gap:2px; background:rgba(120,120,128,.14); border-radius:9px; padding:2px; margin:4px 12px 14px; }
  .segment{ flex:1; border:none; background:none; padding:7px 4px; font-size:12.8px; font-weight:600; color:var(--text); border-radius:7px; transition:background .15s,box-shadow .15s,color .15s; white-space:nowrap; }
  .segment .seg-count{ opacity:.6; font-weight:500; }
  .segment.active{ background:var(--section-bg); box-shadow:0 1px 3px rgba(0,0,0,.18); }
  .segment.sev-tab-critical.active{ color:var(--sev-critical); }
  .segment.sev-tab-high.active{ color:var(--sev-high); }
  .segment.sev-tab-medium.active{ color:var(--sev-medium); }

  /* ============ FEED ============ */
  .date-header{ position:sticky; top:0; z-index:3; background:var(--secondary-bg); padding:16px 20px 6px; font-size:12.5px; font-weight:600; color:var(--hint); text-transform:uppercase; letter-spacing:.04em; }
  .finding{ background:var(--section-bg); padding:12px 14px 0; position:relative; }
  .finding + .finding::before, .finding-first-in-group::before{ content:""; }
  .findings-group{ margin:0 12px 18px; border-radius:12px; overflow:hidden; }
  .findings-group .finding:not(:first-child){ border-top:1px solid var(--hairline); margin-left:14px; padding-left:0; width:calc(100% - 14px); }
  .findings-group .finding:not(:first-child){ margin-left:0; }
  .findings-group .finding + .finding{ position:relative; }
  .findings-group .finding + .finding::before{ content:""; position:absolute; top:0; left:14px; right:0; height:1px; background:var(--hairline); }

  .f-row1{ display:flex; align-items:center; gap:8px; }
  .f-dot{ width:9px; height:9px; border-radius:50%; flex-shrink:0; }
  .f-dot.critical{ background:var(--sev-critical); }
  .f-dot.high{ background:var(--sev-high); }
  .f-dot.medium{ background:var(--sev-medium); }
  .f-title{ font-size:15px; font-weight:600; flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .f-time{ font-size:12.5px; color:var(--hint); flex-shrink:0; }

  .f-row2{ display:flex; align-items:center; gap:5px; margin:4px 0 0 17px; font-size:12.8px; color:var(--hint); flex-wrap:wrap; }
  .f-client{ color:var(--text); font-weight:500; max-width:150px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .f-chatid{ font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; font-size:11.5px;
    appearance:none; background:none; border:0; padding:0; color:inherit; cursor:pointer;
    display:inline-flex; align-items:center; gap:4px; }
  .f-chatid svg{ opacity:.45; flex:none; }
  .f-chatid:active svg{ opacity:1; }
  .f-chatid.copied{ color:var(--sev-ok); }
  .f-user{ font-size:11.5px; color:var(--hint); }
  .f-step{ background:var(--secondary-bg); color:var(--hint); border-radius:5px; padding:1px 6px; font-size:11px; }

  .quote-block{ display:flex; flex-direction:column; gap:1px; margin:9px 0 7px 17px; padding:2px 0 2px 10px; border-left:3px solid var(--acc); }
  .quote-from{ font-size:11.5px; font-weight:700; color:var(--acc); }
  .quote-text{ font-size:13.6px; line-height:1.42; max-height:4.6em; overflow-y:auto; overflow-wrap:anywhere; white-space:pre-wrap; padding-right:4px; }

  .f-detail{ margin:0 0 8px 17px; font-size:12.5px; color:var(--hint); }

  .f-row4{ display:flex; align-items:center; gap:6px; margin:0 0 10px 17px; }
  .chip{ display:inline-flex; align-items:center; font-size:11px; font-weight:700; padding:2.5px 7px; border-radius:20px; }
  .chip.hits{ background:var(--secondary-bg); color:var(--hint); }
  .chip.status-waiting{ background:rgba(142,142,147,.16); color:var(--hint); }
  .chip.status-manual{ background:rgba(var(--sev-high-rgb),.15); color:var(--sev-high); }

  .actions-row{ display:flex; border-top:1px solid var(--hairline); }
  .action-btn{ flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px; padding:9px 2px 10px; background:none; border:none; color:var(--link); font-size:11.3px; font-weight:500; }
  .action-btn:not(:last-child){ border-right:1px solid var(--hairline); }
  .action-btn:active{ background:var(--secondary-bg); }
  .action-btn svg{ display:block; }
  .action-btn.act-mute{ color:var(--hint); }
  .action-btn.act-done{ color:var(--sev-ok); }

  .finding.leaving{ animation:collapse .28s ease forwards; }
  @keyframes collapse{ to{ opacity:0; max-height:0; padding-top:0; padding-bottom:0; margin:0; } }

  .empty-state{ text-align:center; padding:50px 30px; color:var(--hint); }
  .empty-state svg{ margin-bottom:12px; color:var(--sev-ok); }
  .empty-state h3{ margin:0 0 6px; font-size:16px; color:var(--text); }
  .empty-state p{ margin:0; font-size:13.5px; line-height:1.5; }

  /* ============ MODAL ============ */
  .modal-overlay{ position:fixed; inset:0; background:rgba(0,0,0,.44); display:flex; align-items:flex-end; justify-content:center; z-index:50; opacity:0; pointer-events:none; transition:opacity .22s; }
  .modal-overlay.open{ opacity:1; pointer-events:auto; }
  .modal-sheet{ width:100%; max-width:480px; background:var(--bg); border-radius:16px 16px 0 0; max-height:88vh; display:flex; flex-direction:column; transform:translateY(102%); transition:transform .3s cubic-bezier(.32,.72,0,1); }
  .modal-overlay.open .modal-sheet{ transform:translateY(0); }
  .modal-handle{ width:36px; height:4px; background:var(--hairline); border-radius:3px; margin:8px auto 2px; flex-shrink:0; }
  .modal-header{ display:flex; align-items:center; gap:10px; padding:10px 14px 12px; border-bottom:1px solid var(--hairline); flex-shrink:0; }
  .modal-avatar{ width:38px; height:38px; border-radius:50%; background:var(--button); color:var(--button-text); display:flex; align-items:center; justify-content:center; font-weight:700; font-size:15px; flex-shrink:0; }
  .modal-titlewrap{ flex:1; min-width:0; }
  .modal-name{ font-size:15px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .modal-sub{ font-size:12px; color:var(--hint); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; font-family:ui-monospace,Menlo,Consolas,monospace; margin-top:1px; }
  .modal-close{ width:30px; height:30px; border-radius:50%; background:var(--secondary-bg); border:none; display:flex; align-items:center; justify-content:center; color:var(--hint); flex-shrink:0; }
  .modal-messages{ flex:1; overflow-y:auto; padding:14px 12px; display:flex; flex-direction:column; gap:7px; background:var(--secondary-bg); min-height:0; }

  .bubble{ max-width:84%; padding:8px 11px; border-radius:15px; font-size:14px; line-height:1.42; overflow-wrap:anywhere; white-space:pre-wrap; }
  .bubble.client{ align-self:flex-start; background:var(--bubble-client); border:1px solid var(--hairline); border-bottom-left-radius:4px; }
  .bubble.bot{ align-self:flex-end; background:var(--bubble-bot); border-bottom-right-radius:4px; }
  .bubble.placeholder{ align-self:flex-end; background:transparent; border:1.5px dashed var(--acc); color:var(--hint); font-style:italic; font-size:13px; }
  .bubble.flag{ box-shadow:0 0 0 2px var(--acc); position:relative; }
  .flag-chip{ font-size:11px; font-weight:700; letter-spacing:.02em; text-transform:uppercase; color:#fff; background:var(--acc); padding:2.5px 8px; border-radius:20px; margin-bottom:2px; }
  .flag-chip.self-end{ align-self:flex-end; }
  .flag-chip.self-start{ align-self:flex-start; }
  .sys-divider{ align-self:center; font-size:11.5px; color:var(--hint); background:rgba(120,120,128,.18); padding:4px 11px; border-radius:10px; text-align:center; max-width:92%; }

  .modal-actions{ border-top:1px solid var(--hairline); padding:10px 14px calc(10px + env(safe-area-inset-bottom,0px)); flex-shrink:0; }
  .btn-secondary{ width:100%; padding:12px; border-radius:10px; border:none; background:var(--secondary-bg); color:var(--text); font-size:14.5px; font-weight:600; margin-bottom:8px; }
  .btn-secondary:active{ opacity:.7; }
  .btn-main{ width:100%; padding:14px; border-radius:10px; border:none; background:var(--button); color:var(--button-text); font-size:15.5px; font-weight:600; }
  .btn-main:active{ opacity:.85; }

  /* ============ TOAST ============ */
  .toast{ position:fixed; left:16px; right:16px; bottom:16px; max-width:448px; margin:0 auto; background:#222; color:#fff; border-radius:11px; padding:12px 8px 12px 15px; display:flex; align-items:center; justify-content:space-between; gap:10px; font-size:13px; box-shadow:0 6px 20px rgba(0,0,0,.3); z-index:60; transform:translateY(140%); transition:transform .25s ease; }
  .toast.show{ transform:translateY(0); }
  .toast span{ line-height:1.35; }
  .toast button{ background:none; border:none; color:#5ac8fa; font-size:13px; font-weight:700; padding:8px 9px; flex-shrink:0; }

  @media (min-width:481px){
    body{ padding:0; }
  }

  /* переключатель темы — только для просмотра макета вне Telegram;
     внутри мессенджера тему диктует клиент */
  .topbar-right{ display:flex; align-items:center; gap:8px; }
  .theme-toggle{
    appearance:none; width:32px; height:32px; flex:none;
    display:inline-flex; align-items:center; justify-content:center;
    background:var(--secondary-bg); color:var(--hint);
    border:1px solid var(--hairline); border-radius:8px; cursor:pointer;
  }
  .theme-toggle:active{ opacity:.6; }
