/* Manrope — шрифт корпоративной дизайн-системы. Лежит у нас (vendor/fonts,
   лицензия OFL рядом), а не на Google Fonts — как htmx: без внешних CDN. */
@font-face {
    font-family: Manrope;
    font-style: normal;
    font-display: swap;
    font-weight: 200 800;
    src: url("vendor/fonts/manrope-cyrillic-wght-normal.e58febde317b.woff2") format("woff2-variations");
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
    font-family: Manrope;
    font-style: normal;
    font-display: swap;
    font-weight: 200 800;
    src: url("vendor/fonts/manrope-latin-wght-normal.938c6e8019b6.woff2") format("woff2-variations");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Токены корпоративной дизайн-системы (devplan.iz.ru/design-system, --ds-*),
   значения скопированы из её Storybook — только те, что нам нужны.
   Ниже них — наши семантические переменные, которые на них указывают:
   остальной CSS знает только их, поэтому смена ДС = правка этого блока.
   Утверждено на макете docs/ui-mockup.html. */
:root {
    --ds-typography-font-family-base: Manrope, sans-serif;
    --ds-typography-font-weight-regular: 500;
    --ds-radius-md: 8px;
    --ds-radius-lg: 12px;
    --ds-color-black-3: #f8f8f9;
    --ds-color-primary: #6a1cb7;
    --ds-color-primary-6: #f6f1fb;
    --ds-color-primary-40: #c3a4e2;
    --ds-color-primary-60: #a677d4;
    --ds-color-green: #129800;
    --ds-color-green-10: #e7f5e5;
    --ds-color-green-40: #a0d699;
    --ds-color-red: #d21114;
    --ds-color-red-10: #fbe7e8;
    --ds-color-red-40: #eda0a1;

    /* Светлая тема дизайн-системы */
    --ds-color-background-surface: #fff;
    --ds-color-background-hover: #f2f2f3;
    --ds-color-border: #e4e2f8;
    --ds-color-text-primary: #282f44;
    --ds-color-text-secondary: #4b4f5c;
    --ds-color-brand-primary: #6a1cb7;
    --ds-color-brand-primary-hover: #8631da;

    --bg: var(--ds-color-black-3);
    --surface: var(--ds-color-background-surface);
    --surface-hover: var(--ds-color-background-hover);
    --inset: var(--ds-color-black-3);
    --border: var(--ds-color-border);
    --text: var(--ds-color-text-primary);
    --text-muted: var(--ds-color-text-secondary);
    --accent: var(--ds-color-brand-primary);
    --accent-hover: var(--ds-color-brand-primary-hover);
    --brand-text: var(--ds-color-primary);
    --success-bg: var(--ds-color-green-10);
    --success-text: var(--ds-color-green);
    --success-border: var(--ds-color-green-40);
    --error-bg: var(--ds-color-red-10);
    --error-text: var(--ds-color-red);
    --error-border: var(--ds-color-red-40);
    --pending-bg: var(--ds-color-primary-6);
    --pending-text: var(--ds-color-primary);
    --pending-border: var(--ds-color-primary-40);
    --radius: var(--ds-radius-lg);
    --radius-sm: var(--ds-radius-md);
    color-scheme: light;
}
/* Тёмная тема дизайн-системы. Сознательные отступления от неё — фоны
   статусов (у ДС они светлые пастельные и на тёмной карточке выглядят
   дырой), чуть темнее карточки и светлее название: см. макет. Блок
   повторён дважды — для системной тёмной темы и для выбранной вручную. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --ds-color-background-hover: rgba(255, 255, 255, 0.05);
        --ds-color-border: rgba(255, 255, 255, 0.2);
        --ds-color-text-primary: #fff;
        --ds-color-text-secondary: rgba(255, 255, 255, 0.8);
        --ds-color-brand-primary: #8849c5;

        --bg: #282f44;
        --surface: #343a4f;
        --surface-hover: #3d4459;
        --inset: #232839;
        --brand-text: var(--ds-color-primary-40);
        --success-bg: rgba(113, 193, 102, 0.16);
        --success-text: var(--ds-color-green-40);
        --success-border: rgba(113, 193, 102, 0.45);
        --error-bg: rgba(228, 112, 114, 0.16);
        --error-text: var(--ds-color-red-40);
        --error-border: rgba(228, 112, 114, 0.45);
        --pending-bg: rgba(136, 73, 197, 0.22);
        --pending-text: var(--ds-color-primary-40);
        --pending-border: var(--ds-color-primary-60);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --ds-color-background-hover: rgba(255, 255, 255, 0.05);
    --ds-color-border: rgba(255, 255, 255, 0.2);
    --ds-color-text-primary: #fff;
    --ds-color-text-secondary: rgba(255, 255, 255, 0.8);
    --ds-color-brand-primary: #8849c5;

    --bg: #282f44;
    --surface: #343a4f;
    --surface-hover: #3d4459;
    --inset: #232839;
    --brand-text: var(--ds-color-primary-40);
    --success-bg: rgba(113, 193, 102, 0.16);
    --success-text: var(--ds-color-green-40);
    --success-border: rgba(113, 193, 102, 0.45);
    --error-bg: rgba(228, 112, 114, 0.16);
    --error-text: var(--ds-color-red-40);
    --error-border: rgba(228, 112, 114, 0.45);
    --pending-bg: rgba(136, 73, 197, 0.22);
    --pending-text: var(--ds-color-primary-40);
    --pending-border: var(--ds-color-primary-60);
    color-scheme: dark;
}

* { box-sizing: border-box; }

html { background: var(--bg); }
body {
    font-family: var(--ds-typography-font-family-base);
    font-weight: var(--ds-typography-font-weight-regular);
    margin: 0;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    /* Иначе верхний отступ .app «проваливается» сквозь body и вместе
       с min-height даёт лишнюю прокрутку на коротких страницах. */
    display: flow-root;
}
b, strong { font-weight: 700; }

a { color: var(--pending-text); }
a:hover { color: var(--text); }
button:focus-visible, input:focus-visible, a:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

h1 { font-size: 1.5rem; margin: 0 0 1.25rem; }

/* ===== Каркас: слева меню, справа контент на всю оставшуюся ширину =====
   1720px — потолок: на 27" это 5 колонок плиток, на 4K не расползётся в 8. */
.app {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 1.75rem;
    max-width: 1720px;
    margin: 1.5rem auto 1rem;
    padding: 0 1rem;
}
/* Меню всегда высотой с окно, независимо от того, сколько плиток на
   странице: подгонка под высоту контента заставляла его прыгать при
   каждом фильтре. Липкое — на длинной странице остаётся на месте.
   2.5rem = отступ .app сверху (1.5rem) + снизу (1rem): короткая страница
   ровно в окно, без лишней прокрутки. */
.side-col { min-width: 0; }
.content { min-width: 0; padding-bottom: 3rem; }
/* Формы и страница видео читаются в узкой колонке — растягивать текст
   на 1100px вредно, поэтому широкими остаются только списки. */
.content.narrow { max-width: 880px; }
/* Список: вся страница ровно в окно. Меню, верхняя строка и пагинация стоят
   на месте, прокручиваются только плитки. На телефоне меню превращается в
   полосу сверху, там остаётся обычная прокрутка страницы. */
@media (min-width: 901px) {
    .content.fill { height: calc(100vh - 2.5rem); padding-bottom: 0; display: flex; flex-direction: column; }
    .content.fill .job-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
}

.sidenav {
    position: sticky;
    top: 1rem;
    height: calc(100vh - 2.5rem);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 0.75rem;
}
.brand {
    font-weight: 700;
    font-size: 1.15rem;
    padding: 0 0.6rem;
    color: var(--brand-text);
    letter-spacing: -0.02em;
    text-decoration: none;
}
.brand:hover { color: var(--brand-text); }
.nav-links { display: flex; flex-direction: column; gap: 0.2rem; }
.nav-section {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 600;
    padding: 0.6em 0.75em;
    border-radius: var(--radius-sm);
    transition: background 0.15s ease, color 0.15s ease;
}
.nav-section svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-section:hover { background: var(--surface-hover); color: var(--text); }
.nav-section.active { background: var(--accent); color: #fff; }
.nav-section .count {
    margin-left: auto;
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    padding: 0.05em 0.55em;
    border-radius: 999px;
    background: var(--pending-bg);
    color: var(--pending-text);
}
.nav-section.active .count { background: rgba(255, 255, 255, 0.2); color: #fff; }
.nav-user {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 0.9rem 0.6rem 0;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-muted);
}
.nav-user .user-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.nav-user .username { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.theme-toggle {
    flex-shrink: 0;
    width: 2em;
    height: 2em;
    padding: 0;
    border-radius: 50%;
    font-size: 0.9rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.nav-user .btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.nav-user form { margin: 0; }

/* Планшет и телефон: меню превращается в верхнюю полосу. */
@media (max-width: 900px) {
    .app { grid-template-columns: minmax(0, 1fr); gap: 1.25rem; }
    .sidenav {
        position: static;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.75rem 1rem;
        padding: 0.7rem 0.9rem;
    }
    .brand { padding: 0; }
    .nav-links { flex-direction: row; flex-wrap: wrap; }
    .nav-section { padding: 0.45em 0.7em; }
    .nav-section .count { display: none; }
    .nav-user { margin: 0 0 0 auto; flex-direction: row; align-items: center; border: 0; padding: 0; }
}
@media (max-width: 560px) {
    .nav-user .username { display: none; }
}

/* Страница входа — без меню, карточка по центру. */
.guest { max-width: 900px; margin: 2rem auto; padding: 0 1rem; }
.guest .brand { display: inline-block; padding: 0; margin-bottom: 1rem; }

.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li {
    padding: 0.7rem 1rem;
    margin-bottom: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
}

button, .btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.65em 1.5em;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: background-color 0.15s ease;
}
button:hover, .btn:hover { background-color: var(--accent-hover); color: #fff; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-hover); color: var(--text); }
.btn-sm { padding: 0.4em 1em; font-size: 0.85rem; font-weight: 500; }

form.upload-form, form.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 400px;
}
form label { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.9rem; color: var(--text-muted); }
form input[type="text"],
form input[type="password"] {
    background: var(--inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6em 0.8em;
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.45em;
    padding: 0.25em 0.75em;
    border-radius: 999px;
    font-size: 0.85em;
    font-weight: 600;
    white-space: nowrap;
}
.status-badge.status-done { background: var(--success-bg); color: var(--success-text); }
.status-badge.status-failed { background: var(--error-bg); color: var(--error-text); }
.status-badge.status-pending,
.status-badge.status-downloading,
.status-badge.status-extracting_audio,
.status-badge.status-transcribing,
.status-badge.status-calling_llm,
.status-badge.status-validating,
.status-badge.status-retrying_pro,
.status-badge.status-uploading_result { background: var(--pending-bg); color: var(--pending-text); }
.status-dot {
    width: 0.55em;
    height: 0.55em;
    border-radius: 50%;
    background: currentColor;
    animation: status-pulse 1.2s ease-in-out infinite;
}
@keyframes status-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.25; }
}
@media (prefers-reduced-motion: reduce) { .status-dot { animation: none; } }

/* ===== Тулбар над списком: загрузка, поиск, фильтры, вид ===== */
.toolbar { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar-search { flex: 1 1 220px; margin: 0; }
.toolbar-search input[type="search"] {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.55em 0.9em;
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
}
.toolbar-search input::placeholder { color: var(--text-muted); }
.toolbar .spacer { flex: 1 0 0; }
.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.chip {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 0.3em 0.85em;
    font-size: 0.84rem;
    text-decoration: none;
}
.chip:hover { color: var(--text); background: var(--surface-hover); }
.chip.active { background: var(--pending-bg); color: var(--pending-text); border-color: var(--accent); }
.chip .n { color: var(--text-muted); font-variant-numeric: tabular-nums; margin-left: 0.3em; }

.view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.view-toggle button {
    background: transparent;
    color: var(--text-muted);
    border: 0;
    border-radius: 0;
    padding: 0.45em 0.6em;
    display: inline-flex;
    align-items: center;
}
.view-toggle button + button { border-left: 1px solid var(--border); }
.view-toggle button:hover { background: var(--surface-hover); color: var(--text); }
.view-toggle button.active { background: var(--pending-bg); color: var(--pending-text); }
.view-toggle svg { width: 16px; height: 16px; }

/* Мини-чипы артефактов на плитке */
.art-chips { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.art-chip {
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    padding: 0.15em 0.6em;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
}
.art-chip.ok { color: var(--success-text); border-color: var(--success-border); }
.art-chip.run { color: var(--pending-text); border-color: var(--pending-border); }
.art-chip.err { color: var(--error-text); border-color: var(--error-border); }

/* Пагинация */
.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1.25rem;
    gap: 1rem;
    flex-wrap: wrap;
}
.pager .range { font-size: 0.85rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.pager .pages { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.pnum {
    min-width: 2.1em;
    text-align: center;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    padding: 0.35em 0.5em;
    font-size: 0.88rem;
    text-decoration: none;
    font-variant-numeric: tabular-nums;
}
a.pnum:hover { color: var(--text); background: var(--surface-hover); }
.pnum.active { background: var(--surface); color: var(--text); border-color: var(--accent); }

/* ===== Плитки видео =====
   Колонок столько, сколько влезает плиток от 240px — 1 на телефоне,
   4 на 14" ноутбуке, 5 на 27" мониторе. TILE_MIN_WIDTH и зазор
   продублированы в jobs/views.py и скрипте job_list.html: на странице
   ровно 3 полных ряда, поэтому менять — во всех трёх местах. */
.job-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; align-content: start; }
.tile {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.tile:hover { border-color: var(--pending-border); box-shadow: 0 4px 16px rgba(106, 28, 183, 0.12); }
/* Вся плитка кликабельна: ссылка на имени растянута на плитку псевдоэлементом,
   а кнопка «Результат» лежит поверх (z-index) и остаётся отдельной целью. */
.tile-link { color: inherit; text-decoration: none; }
.tile-link::after { content: ""; position: absolute; inset: 0; }
.tile-link:hover { color: inherit; }
.tile-thumb {
    position: relative;
    aspect-ratio: 2 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--inset);
    color: rgba(255, 255, 255, 0.85);
    overflow: hidden;
}
.tile-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile-thumb svg { width: 34px; height: 34px; filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.35)); }
.tile-dur {
    position: absolute;
    right: 0.5rem;
    bottom: 0.5rem;
    background: rgba(0, 0, 0, 0.62);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.1em 0.45em;
    border-radius: 4px;
    font-variant-numeric: tabular-nums;
}
.tile-body { flex: 1; display: flex; flex-direction: column; gap: 0.75rem; padding: 0.85rem 1rem 1rem; }
.tile-info { display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; }
.tile-name {
    font-weight: 700;
    line-height: 1.3;
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.tile-date { font-size: 0.8rem; color: var(--text-muted); }
.tile-foot {
    margin-top: auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.tile-foot .btn { position: relative; z-index: 1; }

/* Режим «списком» — те же плитки, разложенные в строки:
   для тех, кто ищет по дате/имени глазами сверху вниз. */
.job-grid.as-list { grid-template-columns: minmax(0, 1fr); gap: 0.6rem; }
.as-list .tile { flex-direction: row; align-items: stretch; }
.as-list .tile-thumb { width: 132px; flex-shrink: 0; aspect-ratio: auto; }
.as-list .tile-thumb svg { width: 24px; height: 24px; }
.as-list .tile-body {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1.1rem;
}
.as-list .tile-name { -webkit-line-clamp: 1; }
.as-list .tile-foot { margin-top: 0; flex-shrink: 0; gap: 1rem; }
@media (max-width: 560px) {
    .as-list .tile-thumb { display: none; }
    .as-list .tile-body { flex-direction: column; align-items: stretch; }
}

.job-list-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-muted);
    padding: 3rem 1rem;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

/* Upload dropzone */
.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    text-align: center;
    padding: 2.5rem 1.5rem;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover { border-color: var(--accent); background: var(--surface-hover); }
.dropzone input[type="file"] { display: none; }
.dropzone .dropzone-title { font-weight: 600; color: var(--text); }
.dropzone .dropzone-hint { font-size: 0.85rem; color: var(--text-muted); }
.dropzone .dropzone-filename { font-size: 0.9rem; color: var(--pending-text); }

.upload-warning {
    display: none;
    margin-top: 1rem;
    padding: 0.9rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--pending-bg);
    color: var(--pending-text);
    line-height: 1.5;
}

progress {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    appearance: none;
    border: none;
    background: var(--border);
}
progress::-webkit-progress-bar { background: var(--border); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }

.hint { color: var(--text-muted); font-size: 0.9em; }

.detail-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.detail-head h1 { margin-bottom: 0.25rem; word-break: break-word; }
.detail-meta { display: flex; gap: 0.5rem 1.1rem; flex-wrap: wrap; margin-top: 0.5rem; font-size: 0.87rem; color: var(--text-muted); }
.artifact { margin-top: 1rem; }
.artifact-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.artifact-title { display: flex; align-items: center; gap: 0.7rem; }
.artifact-name { font-weight: 600; font-size: 1.02rem; }
.artifact-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.artifact-body { margin-top: 1rem; }
.artifact-body details summary { cursor: pointer; color: var(--text-muted); font-size: 0.9rem; margin-bottom: 0.75rem; }

.result-text {
    background: var(--inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin: 0;
    font-family: ui-monospace, "SF Mono", Consolas, monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 420px;
    overflow-y: auto;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.error-text { color: var(--error-text); }

.login-wrap { display: flex; justify-content: center; margin-top: 3rem; }
.login-wrap .card { width: 100%; max-width: 360px; }
