/* ── Utility ── */
.mobile-install { margin: 24px 0; padding: 14px; border: 1px solid #ded4c4; border-radius: 12px; }
.mobile-install summary { cursor: pointer; padding: 8px 0; }
#mobile-offline { padding: 14px; background: #fff0ce; border: 1px solid #b7791f; border-radius: 12px; margin: 12px 0; }
.agent-ui :focus-visible, .mobile-login :focus-visible { outline: 3px solid #b7791f; outline-offset: 3px; }
.agent-ui [hidden], .mobile-login [hidden] { display: none !important; }
.mobile-select-dialog { box-sizing: border-box; width: calc(100% - 24px); max-width: 520px; max-height: 85vh; max-height: 85dvh; padding: 16px; border: 1px solid #ded4c4; border-radius: 16px; background: #fffdf9; color: #24211c; overflow-y: auto; }
.mobile-select-dialog::backdrop { background: #0007; }
.mobile-select-dialog h2 { margin: 0 0 12px; }
.mobile-select-dialog > button, .mobile-select-dialog input { width: 100%; margin-bottom: 12px; }
.mobile-select-options { display: grid; gap: 8px; }
.mobile-select-options button { width: 100%; text-align: left; white-space: normal; overflow-wrap: anywhere; min-height: 48px; padding: 12px; background: #f5efe5; color: #24211c; border: 1px solid #ded4c4; }
.mobile-select-options button[aria-pressed="true"] { background: #dfeeea; border-color: #2f7a6f; }
@media (min-width: 761px) { .mobile-install { max-width: 650px; } }

/* ════════════════════════════════════════════════
   MOBILE AGENT UI  —  полное переосмысление
   только для агентского контура (agent-ui)
   на экранах ≤ 760 px
   ════════════════════════════════════════════════ */
@media (max-width: 760px) {

    /* ── Root & body ── */
    html { -webkit-text-size-adjust: 100%; }
    .agent-ui {
        font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
        font-size: 16px;
        line-height: 1.45;
        background: #F0F0F5;
    }

    /* make room for fixed bottom nav */
    .agent-ui body { padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }
    .agent-ui .shell {
        max-width: 100%;
        padding:
            max(12px, env(safe-area-inset-top))
            max(12px, env(safe-area-inset-right))
            max(80px, calc(60px + env(safe-area-inset-bottom)))
            max(12px, env(safe-area-inset-left));
    }

    /* ── Top bar → compact ── */
    .agent-ui .topbar {
        padding: 14px 16px;
        gap: 10px;
        align-items: stretch;
        border-radius: 14px;
        margin-bottom: 12px;
        background: #fff;
        border-color: rgba(0,0,0,.08);
    }
    .agent-ui .brand h1 { font-size: 20px; font-weight: 800; letter-spacing: -.03em; margin: 0; }
    .agent-ui .brand p { font-size: 13px; margin: 2px 0 0; }

    /* hide top nav — replaced by injected bottom nav */
    .agent-ui .topbar .nav { display: none; }

    /* ── Headings ── */
    .agent-ui h2 { font-size: 22px; font-weight: 800; letter-spacing: -.03em; overflow-wrap: anywhere; margin-top: 0; }
    .agent-ui h3 { font-size: 17px; font-weight: 700; margin-top: 0; }

    /* ── Cards ── */
    .agent-ui .card {
        padding: 16px;
        border-radius: 14px;
        min-width: 0;
        overflow-wrap: anywhere;
        background: #fff;
        border-color: rgba(0,0,0,.08);
    }
    .agent-ui .card .card { padding: 12px; }
    .agent-ui .grid { gap: 10px; min-width: 0; }
    .agent-ui .grid[style*="auto-fit"] { grid-template-columns: repeat(2,minmax(0,1fr)) !important; gap: 10px; }

    /* metric cards — big numbers */
    .agent-ui .metric-card { text-align: center; padding: 16px 8px; }
    .agent-ui .metric-card .muted { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
    .agent-ui .metric { font-size: 36px; font-weight: 800; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; }

    /* ── Layout grid → single column ── */
    .agent-ui .split,
    .agent-ui .task-grid-tight,
    .agent-ui .task-bottom-grid,
    .agent-ui .workflow-filters { grid-template-columns: minmax(0,1fr); gap: 10px; }

    /* ── KV list ── */
    .agent-ui .kv { grid-template-columns: minmax(0,1fr); gap: 2px; }
    .agent-ui .kv dt { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: #6b6258; margin-top: 10px; }
    .agent-ui .kv dt:first-child { margin-top: 0; }
    .agent-ui .kv dd { margin: 2px 0 0; overflow-wrap: anywhere; font-size: 15px; font-weight: 600; }

    /* ── Forms ── */
    .agent-ui input, .agent-ui select, .agent-ui textarea,
    .agent-ui button, .mobile-login input, .mobile-login button { font-size: 16px; max-width: 100%; }
    .agent-ui input:not([type="checkbox"]):not([type="hidden"]),
    .agent-ui select, .agent-ui textarea { width: 100%; min-width: 0; min-height: 44px; box-sizing: border-box; border-radius: 10px; }
    .agent-ui input[type="file"] { display: block; padding: 10px 0; overflow: hidden; }
    .agent-ui input[type="checkbox"] { width: 28px; height: 28px; margin: 8px; flex-shrink: 0; accent-color: #2f7a6f; }
    .agent-ui button, .agent-ui .button { min-height: 48px; white-space: normal; overflow-wrap: anywhere; border-radius: 12px; }
    .agent-ui .inline-actions { gap: 10px; }
    .agent-ui .inline-actions > button, .agent-ui .inline-actions > .button { flex: 1 1 145px; }
    .agent-ui form > button, .agent-ui form > p > button { width: 100%; margin-top: 8px; }
    .agent-ui summary { min-height: 44px; padding: 10px 0; }
    .agent-ui p, .agent-ui li, .agent-ui dd, .agent-ui td, .agent-ui a { overflow-wrap: anywhere; }

    /* ── Task detail: "Что нужно сделать" — prominent ── */
    .agent-ui .kv dt:first-child ~ dd:first-of-type,
    .agent-ui .kv dd:first-of-type {
        /* handled generically above */
    }
    /* Highlight the assignment_reason (first dd in task card kv) */
    .agent-ui article.card > dl.kv > dd:first-of-type {
        font-size: 18px;
        font-weight: 700;
        line-height: 1.4;
        letter-spacing: -.02em;
        color: #24211c;
    }

    /* ── Overdue date ── */
    .agent-ui .overdue-date { color: #a83c32; font-weight: 800; }

    /* ── Result submit button — large sticky CTA ── */
    .agent-ui #result-entry button[type="submit"] {
        width: 100%;
        min-height: 56px;
        font-size: 17px;
        font-weight: 800;
        letter-spacing: -.02em;
        border-radius: 14px;
        margin-top: 4px;
    }
    /* Sticky submit wrapper — stays at bottom when scrolling */
    .agent-ui #result-entry {
        position: relative;
    }
    .agent-ui #result-entry .m-sticky-submit {
        position: sticky;
        bottom: calc(60px + env(safe-area-inset-bottom, 0px) + 8px);
        z-index: 10;
        padding: 10px 0 2px;
        background: linear-gradient(to bottom, transparent, #F0F0F5 40%);
        margin-top: 8px;
    }
    .agent-ui #result-entry .m-sticky-submit button[type="submit"] {
        margin-top: 0;
        box-shadow: 0 4px 16px rgba(47,122,111,.3);
    }

    /* ── Workflow exit link ── */
    .agent-ui [data-workflow-exit] { display: block; border: 1px solid #2f7a6f; border-radius: 10px; min-height: 44px; padding: 12px; text-align: center; }

    /* ── Badges ── */
    .agent-ui .badge { font-size: 12px; font-weight: 700; }

    /* ── Messages ── */
    .agent-ui .messages li { font-size: 15px; font-weight: 500; }

    /* ── Filter group ── */
    .agent-ui .filter-group { min-width: 0; width: 100%; }

    /* ── Selection status ── */
    .agent-ui .selection-save-status { min-height: 1.2em; }

    /* ── Mobile card table ── */
    .agent-ui .mobile-card-table { display: block; width: 100%; }
    .agent-ui .mobile-card-table > thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    .agent-ui .mobile-card-table > tbody { display: grid; gap: 10px; }
    .agent-ui .mobile-card-table > tbody > tr {
        display: block;
        min-width: 0;
        border: 1px solid rgba(0,0,0,.08);
        background: #fff;
        border-radius: 14px;
        padding: 14px;
        box-shadow: none;
        cursor: pointer;
        position: relative;
    }
    .agent-ui .mobile-card-table > tbody > tr:active { background: #f5efe5; }

    /* hide checkbox column and "Открыть задачу" column on mobile task list */
    .agent-ui .mobile-card-table td[data-label="Включить в подборку"],
    .agent-ui .mobile-card-table td[data-label="Действие"],
    .agent-ui .mobile-card-table td[data-label="ID"],
    .agent-ui .mobile-card-table td[data-label="Результаты"] { display: none; }

    /* remaining cells: label + value */
    .agent-ui .mobile-card-table > tbody > tr > td {
        display: grid;
        grid-template-columns: minmax(70px,28%) minmax(0,1fr);
        gap: 8px;
        padding: 7px 0;
        align-items: start;
        min-width: 0;
        border-bottom: 1px solid rgba(0,0,0,.06);
    }
    .agent-ui .mobile-card-table > tbody > tr > td:last-child { border-bottom: 0; padding-bottom: 0; }
    .agent-ui .mobile-card-table td::before { content: attr(data-label); color: #6b6258; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding-top: 2px; }
    .agent-ui .mobile-card-table td.mobile-cell-full { display: block; }
    .agent-ui .mobile-card-table td.mobile-cell-full::before { display: none; }

    /* "Дело" cell — largest, most prominent */
    .agent-ui .mobile-card-table td[data-label="Дело"] .mobile-cell-value strong {
        font-size: 17px;
        font-weight: 800;
        letter-spacing: -.02em;
        display: block;
        margin-bottom: 2px;
    }
    .agent-ui .mobile-card-table td[data-label="Дело"] .mobile-cell-value .muted {
        font-size: 12px;
        color: #6b6258;
    }

    /* "Срок" cell — red if overdue */
    .agent-ui .mobile-card-table td[data-label="Срок"] .mobile-cell-value { font-size: 14px; font-weight: 700; }

    /* "ФССП" cell */
    .agent-ui .mobile-card-table td[data-label="ФССП"] .mobile-cell-value,
    .agent-ui .mobile-card-table td[data-label="Тип задачи"] .mobile-cell-value { font-size: 13px; color: #6b6258; }

    /* "Статус" cell */
    .agent-ui .mobile-card-table td[data-label="Статус"] .mobile-cell-value { font-size: 13px; font-weight: 600; }

    .agent-ui .mobile-cell-value { min-width: 0; }
    .agent-ui .mobile-cell-value a { display: inline-block; min-height: 44px; padding: 6px 0; }

    /* ── Nav (non-top) ── */
    .agent-ui nav:not(.nav) { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 16px 0; }
    .agent-ui nav:not(.nav) a { min-height: 44px; padding: 10px 14px; border: 1px solid #ded4c4; border-radius: 10px; }

    /* ── Bottom navigation bar (injected by JS) ── */
    .m-botnav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        display: flex;
        background: #fff;
        border-top: 1px solid rgba(0,0,0,.1);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        box-shadow: 0 -2px 12px rgba(0,0,0,.07);
    }
    .m-botnav a {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 10px 4px;
        height: 60px;
        font-size: 10px;
        font-weight: 700;
        letter-spacing: .04em;
        text-transform: uppercase;
        color: #6b6258;
        text-decoration: none;
        -webkit-tap-highlight-color: transparent;
        position: relative;
    }
    .m-botnav a:hover { text-decoration: none; }
    .m-botnav a.active { color: #2f7a6f; }
    .m-botnav a svg { width: 22px; height: 22px; flex-shrink: 0; }
    .m-botnav .m-bn-dot {
        position: absolute;
        top: 8px;
        right: calc(50% - 18px);
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #a83c32;
        border: 2px solid #fff;
        display: none;
    }
    .m-botnav .m-bn-dot.on { display: block; }

    /* ── Login page ── */
    .mobile-login { padding: max(16px,env(safe-area-inset-top)) 16px max(16px,env(safe-area-inset-bottom)); font-family: system-ui,-apple-system,sans-serif; }
    .mobile-login .login-card { padding: 22px; min-width: 0; background: #fff; border-color: rgba(0,0,0,.08); border-radius: 18px; }
    .mobile-login .login-card h1 { font-size: 26px; font-weight: 800; letter-spacing: -.03em; }
    .mobile-login input, .mobile-login button { min-height: 48px; }
    .mobile-login button { font-weight: 700; font-size: 16px; }
}
