/* Почтовый агент — дизайн-токены и компоненты новой панели (HTMX + шаблоны) */
:root {
    --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f1f5f9; --line: #e2e8f0;
    --ink: #0f172a; --ink-2: #334155; --muted: #64748b;
    --brand: #4f46e5; --brand-ink: #ffffff; --brand-soft: #eef2ff;
    --nav-bg: #0f172a; --nav-ink: #cbd5e1; --nav-on: rgba(255,255,255,0.10);
    --st-new: #1d4ed8; --st-new-bg: #dbeafe;
    --st-wait: #92400e; --st-wait-bg: #fef3c7;
    --st-sent: #166534; --st-sent-bg: #dcfce7;
    --st-rej: #475569; --st-rej-bg: #f1f5f9;
    --st-snz: #6d28d9; --st-snz-bg: #ede9fe;
    --st-err: #b91c1c; --st-err-bg: #fee2e2;
    --pj-allfoods: #16a34a; --pj-allcargo: #2563eb; --pj-flora: #db2777; --pj-cargoflowers: #ea580c; --pj-winwin: #7c3aed; --pj-other: #64748b;
    --r: 10px; --r-sm: 7px;
    --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
    --focus: 0 0 0 3px rgb(79 70 229 / 0.35);
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1120; --surface: #111827; --surface-2: #1e293b; --line: #273244;
        --ink: #e5e7eb; --ink-2: #cbd5e1; --muted: #94a3b8;
        --brand: #818cf8; --brand-ink: #0b1120; --brand-soft: #1e1b4b;
        --nav-bg: #060a14;
        --st-new: #93c5fd; --st-new-bg: #172554; --st-wait: #fcd34d; --st-wait-bg: #3a2a07;
        --st-sent: #86efac; --st-sent-bg: #052e16; --st-rej: #cbd5e1; --st-rej-bg: #1e293b;
        --st-snz: #c4b5fd; --st-snz-bg: #2e1065; --st-err: #fca5a5; --st-err-bg: #450a0a;
        color-scheme: dark;
    }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
a { color: var(--brand); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); font-size: 0.86rem; }
.hint { color: var(--muted); font-size: 0.8rem; margin: 0; }

/* ---- оболочка ---- */
.shell { display: flex; height: 100vh; }
.nav { width: 228px; flex: 0 0 228px; background: var(--nav-bg); color: var(--nav-ink); display: flex; flex-direction: column; gap: 1.1rem; padding: 1.1rem 0.75rem; overflow-y: auto; }
.brand { display: grid; gap: 2px; padding: 0 0.5rem; }
.brand b { color: #fff; font-size: 1.02rem; }
.brand span { font-size: 0.72rem; color: #94a3b8; }
.nav-links { display: grid; gap: 2px; }
.nav-link { display: flex; align-items: center; justify-content: space-between; padding: 0.55rem 0.75rem; border-radius: var(--r-sm); color: var(--nav-ink); text-decoration: none; font-weight: 600; font-size: 0.92rem; }
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.on { background: var(--nav-on); color: #fff; }
.nav-count { background: #f59e0b; color: #1f1300; border-radius: 999px; padding: 0 0.45rem; font-size: 0.72rem; font-weight: 700; }
.nav-sep { height: 1px; background: rgba(255,255,255,0.08); margin: 0.5rem 0.4rem; }
.nav-foot { margin-top: auto; padding: 0 0.5rem; }
.nav-logout { margin: 0; }
.nav-logout .nav-link { width: 100%; background: none; border: 0; font: inherit; font-weight: 600; font-size: 0.92rem; cursor: pointer; text-align: left; }
.nav-logout .nav-link:focus-visible { outline: none; box-shadow: var(--focus); }
.mode { display: inline-block; background: #15803d; color: #fff; border-radius: 999px; padding: 0.3rem 0.8rem; font-size: 0.76rem; font-weight: 600; }
.mode-test { background: #b45309; }
.mode-stop { background: #b91c1c; }
a.mode, a.mode:hover { color: #fff; text-decoration: none; }
.content { flex: 1; min-width: 0; overflow-y: auto; }
.content-inbox { overflow: hidden; }

/* ---- кнопки, поля ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: var(--r-sm); padding: 0.45rem 0.85rem; font: inherit; font-size: 0.86rem; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #94a3b8; }
.btn:disabled, .btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--brand); }
.btn-danger-ghost { color: var(--st-err); border-color: color-mix(in srgb, var(--st-err) 35%, transparent); }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.btn-icon { padding: 0.4rem 0.6rem; }
.btn.armed { background: var(--st-err); border-color: var(--st-err); color: #fff; }
.btn-primary.armed { background: #166534; border-color: #166534; }
.input { width: 100%; padding: 0.5rem 0.65rem; border: 1px solid var(--line); border-radius: var(--r-sm); font: inherit; font-size: 0.9rem; background: var(--surface); color: var(--ink); }
textarea.input { resize: vertical; line-height: 1.5; }
.push { margin-left: auto; }

/* ---- бейджи ---- */
.st { display: inline-block; font-size: 0.74rem; font-weight: 600; border-radius: 999px; padding: 0.12rem 0.55rem; white-space: nowrap; }
.st-lg { font-size: 0.84rem; padding: 0.3rem 0.8rem; }
.st-new { background: var(--st-new-bg); color: var(--st-new); } .st-wait { background: var(--st-wait-bg); color: var(--st-wait); }
.st-sent { background: var(--st-sent-bg); color: var(--st-sent); } .st-rej { background: var(--st-rej-bg); color: var(--st-rej); }
.st-snz { background: var(--st-snz-bg); color: var(--st-snz); } .st-err { background: var(--st-err-bg); color: var(--st-err); }
.chip-test { font-size: 0.7rem; font-weight: 600; border: 1px dashed var(--muted); color: var(--ink-2); border-radius: 999px; padding: 0.02rem 0.45rem; }
.pj-allfoods_market { --pc: var(--pj-allfoods); } .pj-allcargo_market { --pc: var(--pj-allcargo); }
.pj-flora_market { --pc: var(--pj-flora); } .pj-cargo_flowers { --pc: var(--pj-cargoflowers); }
.pj-winwin_market { --pc: var(--pj-winwin); } .pj-other { --pc: var(--pj-other); }
.pj { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.76rem; color: var(--muted); }
.pj::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--pc, var(--pj-other)); flex: none; }

/* ---- страницы ---- */
.page { display: grid; gap: 1.25rem; max-width: 1180px; padding: 1.75rem 2rem 3rem; }
.page-h { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.page-h h1 { font-size: 1.45rem; }
.lead { margin: -0.5rem 0 0; }
.back { font-size: 0.86rem; text-decoration: none; justify-self: start; }
.sec { display: grid; gap: 0.7rem; }
.sec h2 { font-size: 1rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 0.95rem 1.05rem; display: grid; gap: 0.7rem; min-width: 0; align-content: start; }
.card-h { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.card-h h2 { font-size: 0.95rem; }
.card-h .btn-icon:last-child { margin-left: auto; }
h3.sub { font-size: 0.86rem; margin-top: 0.3rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.empty { display: grid; gap: 0.35rem; justify-items: center; text-align: center; padding: 2.5rem 1.25rem; color: var(--muted); }
.empty b { color: var(--ink); }
.need { border-radius: 8px; padding: 0.65rem 0.85rem; font-size: 0.9rem; font-weight: 500; }
.need-wait { background: var(--st-wait-bg); color: var(--st-wait); } .need-err { background: var(--st-err-bg); color: var(--st-err); }
.need-new { background: var(--st-new-bg); color: var(--st-new); }
.note { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; background: var(--st-wait-bg); color: var(--st-wait); border-radius: 8px; padding: 0.6rem 0.8rem; font-size: 0.86rem; }

/* ---- обзор ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.75rem; }
.tile { display: grid; gap: 0.1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0.9rem 1rem; color: inherit; text-decoration: none; }
.tile:hover { border-color: #94a3b8; }
.tile-l { font-size: 0.82rem; color: var(--muted); }
.tile-v { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.tile-s { font-size: 0.76rem; color: var(--muted); }
.tile-wait { border-color: #fcd34d; } .tile-wait .tile-v { color: var(--st-wait); }
.tile-err { border-color: #fca5a5; } .tile-err .tile-v { color: var(--st-err); }
.alerts { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.45rem; }
.al { display: flex; gap: 0.75rem; align-items: center; background: var(--surface); border: 1px solid var(--line); border-left-width: 4px; border-radius: 8px; padding: 0.55rem 0.8rem; font-size: 0.88rem; }
.al-crit { border-left-color: #dc2626; } .al-warn { border-left-color: #d97706; } .al-info { border-left-color: #64748b; }
.al-lvl { font-size: 0.74rem; font-weight: 700; color: var(--muted); min-width: 82px; }
.al-crit .al-lvl { color: var(--st-err); } .al-warn .al-lvl { color: var(--st-wait); }
.al-text { flex: 1; min-width: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.6rem; margin: 0; }
.kpis div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0.65rem 0.85rem; }
.kpis dt { font-size: 0.8rem; color: var(--muted); } .kpis dd { margin: 0.15rem 0 0; font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- проекты ---- */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 0.75rem; }
.pcard { background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--pc); border-radius: 10px; padding: 0.85rem 1rem; display: grid; gap: 0.6rem; color: inherit; text-decoration: none; }
.pcard:hover { border-color: #94a3b8; border-top-color: var(--pc); }
.pcard-h { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.pj-name { font-size: 0.98rem; font-weight: 700; color: var(--ink); }
.pj-title { display: flex; align-items: center; gap: 0.55rem; }
.pj-title::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--pc, var(--pj-other)); }
.pstats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem 0.75rem; margin: 0; }
.pstats dt { font-size: 0.76rem; color: var(--muted); } .pstats dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.25rem; font-size: 0.82rem; }
.checks li { display: flex; gap: 0.45rem; }
.checks li > span:last-child { display: grid; }
.checks small { color: var(--muted); font-size: 0.76rem; }
.checks .ok > span:first-child { color: #16a34a; } .checks .no { color: var(--st-wait); } .checks .no > span:first-child { color: var(--st-err); }
.checks.big { font-size: 0.9rem; gap: 0.5rem; }
.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.row-item { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem 0.75rem; }
.row-item > div:first-child { flex: 1; min-width: 220px; display: grid; gap: 0.12rem; }
.row-item small { color: var(--muted); font-size: 0.78rem; }
.query-edit { flex-basis: 100%; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.query-edit label { font-size: 0.8rem; color: var(--muted); }
.query-edit .input { flex: 1; min-width: 200px; }
.preview { margin: 0.2rem 0 0; font-size: 0.82rem; color: var(--ink-2); white-space: pre-wrap; max-height: 4.6em; overflow: hidden; }
.col-btns { display: flex; flex-direction: column; gap: 0.35rem; }
.linklist { list-style: none; margin: 0; padding: 0; display: grid; }
.linklist a { display: grid; grid-template-columns: 1fr auto auto; gap: 0.6rem; align-items: center; padding: 0.4rem 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; font-size: 0.86rem; }
.linklist a span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linklist a:hover span:first-child { color: var(--brand); }
.linklist time { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.addrow { display: grid; grid-template-columns: 1.3fr 1fr auto; gap: 0.5rem; }
.steps { list-style: none; display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0; padding: 0; counter-reset: s; }
.steps li { counter-increment: s; font-size: 0.82rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0.2rem 0.7rem; background: var(--surface); }
.steps li::before { content: counter(s) ". "; }
.steps li.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.form { max-width: 660px; gap: 0.85rem; }
.form label { display: grid; gap: 0.25rem; font-size: 0.86rem; font-weight: 600; color: var(--ink-2); }
.form small { font-weight: 400; color: var(--muted); }

/* ---- входящие ---- */
.inbox { display: flex; height: 100vh; }
.inbox-side { width: 390px; flex: 0 0 390px; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--surface); min-height: 0; }
.inbox-main { flex: 1; min-width: 0; overflow-y: auto; }
.inbox-bar { padding: 0.75rem 0.75rem 0.4rem; display: grid; gap: 0.5rem; }
.inbox-bar .row { display: flex; gap: 0.4rem; }
.inbox-list { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.qchips { display: flex; flex-wrap: wrap; gap: 0.35rem; padding: 0.2rem 0.75rem 0.65rem; border-bottom: 1px solid var(--line); }
.qchip { border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: 0.22rem 0.65rem; font: inherit; font-size: 0.79rem; cursor: pointer; }
.qchip b { font-weight: 700; }
.qchip.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.qchip.hot:not(.on) b { color: var(--st-wait); }
.tlist { overflow-y: auto; flex: 1; min-height: 0; }
.trow { display: grid; gap: 0.18rem; padding: 0.7rem 0.85rem 0.7rem 1rem; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; position: relative; }
.trow::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--pc, transparent); }
.trow:hover { background: var(--surface-2); }
.trow.sel { background: var(--brand-soft); }
.trow .l1 { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.trow .who { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trow time { font-size: 0.75rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.trow .subj { font-size: 0.85rem; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trow .l3 { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.trow .why { font-size: 0.75rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

.tdetail { display: grid; gap: 1rem; max-width: 1180px; padding: 1.5rem 1.75rem 3rem; }
.tdetail.empty, section#task-detail.empty { padding-top: 20vh; }
.tdh { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.tdh h1 { font-size: 1.25rem; margin-bottom: 0.3rem; }
.tmeta { display: flex; flex-wrap: wrap; gap: 0.25rem 0.6rem; align-items: center; font-size: 0.82rem; color: var(--muted); }
.tcols { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; }
.tcol-main, .tcol-side { display: grid; gap: 1rem; min-width: 0; }
.draft-subj { font-weight: 600; font-size: 0.88rem; color: var(--ink-2); }
.body-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.9rem; line-height: 1.6; background: var(--surface-2); border-radius: 8px; padding: 0.8rem 0.9rem; max-height: 60vh; overflow-y: auto; }
.vsel { width: auto; max-width: 280px; margin-left: auto; font-size: 0.8rem; padding: 0.25rem 0.45rem; }
.oldver { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; background: var(--st-snz-bg); color: var(--st-snz); border-radius: 8px; padding: 0.5rem 0.7rem; font-size: 0.84rem; }
.abar { display: grid; gap: 0.6rem; border-top: 1px solid var(--line); padding-top: 0.75rem; }
.remark { display: flex; gap: 0.5rem; align-items: flex-start; }
.remark textarea { flex: 1; min-width: 0; }
.busy { display: none; font-weight: 400; }
.htmx-request .busy, .busy.htmx-request { display: inline; }
.abtns { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.manual summary { list-style: none; display: inline-flex; }
.manual summary::-webkit-details-marker { display: none; }
.manual form { display: grid; gap: 0.5rem; margin-top: 0.6rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 0.75rem; margin: 0; font-size: 0.86rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.conf { display: inline-flex; align-items: center; gap: 0.4rem; }
.conf-bars { display: inline-flex; gap: 2px; } .conf-bars i { width: 7px; height: 9px; border-radius: 2px; background: var(--line); }
.conf-hi .conf-bars i.on { background: #16a34a; } .conf-mid .conf-bars i.on { background: #d97706; } .conf-lo .conf-bars i.on { background: #dc2626; }
.hist { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.45rem; font-size: 0.84rem; }
.hist li { display: grid; grid-template-columns: 96px 1fr; gap: 0.5rem; }
.hist time { color: var(--muted); font-variant-numeric: tabular-nums; }
.hist em { color: var(--muted); font-style: normal; }
.htmx-swapping { opacity: 0.6; transition: opacity 0.1s; }

/* ---- сообщения ---- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 0.5rem; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--bg); border-radius: 10px; padding: 0.7rem 0.9rem; font-size: 0.88rem; box-shadow: 0 8px 24px rgb(0 0 0 / 0.18); white-space: pre-line; }
.toast-error { background: var(--st-err); color: #fff; }
.toast-success { background: #166534; color: #fff; }

@media (max-width: 1100px) { .tcols { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 900px) { .addrow { grid-template-columns: 1fr; } }
@media (max-width: 768px) {
    .shell { flex-direction: column; height: auto; }
    .nav { width: 100%; flex: none; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.5rem; padding: 0.6rem 0.75rem; }
    .brand span, .nav-foot { display: none; }
    .nav-links { display: flex; overflow-x: auto; gap: 2px; width: 100%; }
    .nav-sep { display: none; }
    .content, .content-inbox { overflow: visible; }
    .inbox { flex-direction: column; height: auto; }
    .inbox-side { width: 100%; flex: none; max-height: 60vh; border-right: none; border-bottom: 1px solid var(--line); }
    .page, .tdetail { padding: 1.25rem 1rem 3rem; }
    .al { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---- формы и разделы второй волны (база знаний, тестирование, настройки, логи) ---- */
.page-wide { max-width: 1280px; }
.stack { display: grid; gap: 0.75rem; align-content: start; min-width: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0.85rem 1rem; align-items: start; }
.form-grid label, .lbl { display: grid; gap: 0.25rem; font-size: 0.86rem; font-weight: 600; color: var(--ink-2); }
.form-grid small, .lbl small { font-weight: 400; color: var(--muted); }
.form-grid .wide { grid-column: 1 / -1; }
.form-wide { max-width: none; }
label.check { display: flex; gap: 0.5rem; align-items: center; font-weight: 500; font-size: 0.88rem; }
fieldset.opts { border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem 0.8rem; display: grid; gap: 0.4rem; }
fieldset.opts legend { font-size: 0.82rem; color: var(--muted); padding: 0 0.3rem; }
details.adv { grid-column: 1 / -1; border-top: 1px dashed var(--line); padding-top: 0.6rem; }
details.adv summary { cursor: pointer; color: var(--ink-2); font-size: 0.88rem; margin-bottom: 0.5rem; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 0.82rem; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; font-family: ui-monospace, Consolas, monospace; font-size: 0.78rem; background: var(--surface-2); border-radius: 8px; padding: 0.7rem; max-height: 50vh; overflow: auto; margin: 0; }
.row-form { min-width: 280px; }

.filters { display: grid; grid-template-columns: 1fr 240px; gap: 0.5rem; }
.kb-list { display: grid; gap: 0.5rem; }
.kb-counts { font-size: 0.82rem; }
.fact { display: flex; gap: 1rem; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid #16a34a; border-radius: 8px; padding: 0.75rem 0.9rem; }
.fact-pending { border-left-color: #d97706; } .fact-rejected { border-left-color: var(--muted); opacity: 0.75; }
.fact-edit { border-left-color: var(--brand); display: block; }
.fact-body { flex: 1; min-width: 0; display: grid; gap: 0.3rem; }
.fact-body h3 { font-size: 0.92rem; }
.fact-body p { margin: 0; font-size: 0.87rem; color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.fact-meta { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; font-size: 0.78rem; }
.fact-meta .used { color: var(--st-sent); font-weight: 600; }
.fact-meta .src { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
.kb-new { display: grid; gap: 0.6rem; }

.test-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
.batch { list-style: none; margin: 0; padding: 0; max-height: 460px; overflow-y: auto; }
.batch a { display: grid; gap: 0.05rem; padding: 0.4rem 0.2rem; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; font-size: 0.8rem; }
.batch a span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.batch a:hover b { color: var(--brand); }
#test-busy.htmx-request { display: inline; }

.logs { background: #0b1120; color: #cbd5e1; border-radius: 10px; padding: 0.6rem 0.8rem; font-family: ui-monospace, Consolas, monospace; font-size: 0.78rem; max-height: calc(100vh - 210px); overflow-y: auto; }
.logs .empty { color: #94a3b8; } .logs .empty b { color: #e2e8f0; }
.log { display: grid; grid-template-columns: 150px 64px 90px 1fr; gap: 0.6rem; padding: 0.12rem 0; border-bottom: 1px solid rgba(255,255,255,0.04); }
.log-msg { white-space: pre-wrap; overflow-wrap: anywhere; }
.log-ts, .log-src { color: #64748b; }
.log-error .log-lvl, .log-critical .log-lvl { color: #fca5a5; } .log-warning .log-lvl { color: #fcd34d; } .log-info .log-lvl { color: #86efac; }

@media (max-width: 1000px) { .test-grid { grid-template-columns: minmax(0, 1fr); } .filters { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .log { grid-template-columns: 1fr; gap: 0; } .fact { flex-direction: column; } }

/* ---- версии инструкций ---- */
.edit-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.vlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.3rem; }
.vlist a { display: grid; gap: 0.1rem; padding: 0.5rem 0.6rem; border-radius: 8px; border: 1px solid var(--line); color: inherit; text-decoration: none; font-size: 0.84rem; }
.vlist a:hover { border-color: #94a3b8; }
.vlist li.on a { border-color: var(--brand); background: var(--brand-soft); }
.vlist span { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vlist small { color: var(--muted); font-size: 0.74rem; }
.diff { font-family: ui-monospace, Consolas, monospace; font-size: 0.8rem; border: 1px solid var(--line); border-radius: 8px; overflow: auto; max-height: 60vh; }
.dl { display: grid; grid-template-columns: 1.4rem 1fr; padding: 0 0.4rem; }
.dl .dt { white-space: pre-wrap; overflow-wrap: anywhere; }
.dl-add { background: var(--st-sent-bg); } .dl-add .dm { color: var(--st-sent); }
.dl-del { background: var(--st-err-bg); } .dl-del .dm { color: var(--st-err); } .dl-del .dt { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--st-err) 45%, transparent); }
.dl-gap { color: var(--muted); background: var(--surface-2); }
.cmp-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.cmp-col { display: grid; gap: 0.5rem; align-content: start; min-width: 0; }
.cmp-meta { display: flex; flex-wrap: wrap; gap: 0.4rem 0.7rem; align-items: center; font-size: 0.8rem; }
@media (max-width: 1000px) { .edit-grid, .cmp-cols { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Провайдеры ИИ, лимиты, расходы ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.pv { margin-top: 0.75rem; display: grid; gap: 0.6rem; }
.pv .card-h .pv-toggle { margin-left: auto; }
.pv-key { font-size: 0.88rem; }
.pv-key code, .pv-models code { font-size: 0.8rem; }
.pv-keyform { grid-template-columns: 1fr 0 auto; }
.pv-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; font-size: 0.84rem; }
.pv-err { background: var(--st-err-bg); color: var(--st-err); }
.pv-models tr.on td:first-child { box-shadow: inset 3px 0 0 var(--brand); }
.pv-price { display: grid; grid-template-columns: repeat(3, minmax(64px, 88px)) auto; gap: 0.35rem; align-items: center; }
.input.num { text-align: right; font-variant-numeric: tabular-nums; padding-left: 0.4rem; padding-right: 0.4rem; }
.pv-add { display: grid; grid-template-columns: 1fr auto auto; gap: 0.5rem; margin-top: 0.6rem; }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 0.78rem; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tr.err td { background: var(--st-err-bg); }
.st-err-text { color: var(--st-err); }
.barcol { width: 22%; min-width: 60px; }
.bar { display: block; height: 8px; min-width: 2px; border-radius: 4px; background: var(--brand); }
.periods { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-left: auto; }
.meters { display: grid; gap: 0.5rem; margin: 0.25rem 0 0.75rem; font-size: 0.88rem; }
.meter-row { display: grid; grid-template-columns: minmax(0, 260px) 1fr; gap: 0.75rem; align-items: center; }
.meter { display: block; height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--st-sent); }
.meter-warn > span { background: #d97706; }
.meter-over > span { background: var(--st-err); }
@media (max-width: 700px) {
    .pv-price { grid-template-columns: repeat(3, 1fr); }
    .pv-price .btn { grid-column: 1 / -1; }
    .pv-add, .meter-row { grid-template-columns: 1fr; }
}
.cost-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: 1rem; }
.tbl td:first-child { min-width: 9rem; }
.input-bad { border-color: var(--st-err); }

/* Состояние агента (Обзор) */
.health-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.health-list li { display: grid; grid-template-columns: minmax(150px, 220px) auto 1fr; gap: 0.75rem; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.8rem; font-size: 0.88rem; }
.health-name { font-weight: 600; }
.health-msg { min-width: 0; overflow-wrap: anywhere; }
.health-api { font-size: 0.8rem; margin: 0; }
@media (max-width: 640px) { .health-list li { grid-template-columns: 1fr auto; } .health-msg { grid-column: 1 / -1; } }

/* Подсказки к фильтру входящих Gmail */
.query-help { margin-top: 0.6rem; }
.query-examples { display: grid; grid-template-columns: minmax(0, max-content) 1fr; gap: 0.45rem 0.9rem; margin: 0.6rem 0; align-items: baseline; }
.query-examples dt, .query-examples dd { margin: 0; min-width: 0; }
.query-examples dd { color: var(--ink-2); font-size: 0.88rem; }
.qchip { font: 0.8rem/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; text-align: left; white-space: normal; overflow-wrap: anywhere;
         max-width: 26rem; padding: 0.2rem 0.5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-2); color: inherit; cursor: pointer; }
.qchip:hover, .qchip:focus-visible { border-color: var(--brand); }
.query-filled { outline: 2px solid var(--brand); outline-offset: 1px; transition: outline-color 0.6s; }
@media (max-width: 640px) {
    .query-examples { grid-template-columns: 1fr; }
    .query-examples dd { margin-bottom: 0.4rem; }
}
