/*
 * История загрузок: список файлов и партий, кнопки действий, таблицы
 * разбора и постраничная навигация.
 */

.job {
    border: 1px solid var(--web-border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
    background: var(--web-bg-sunken);
    overflow: hidden;
    min-width: 0;
}

.job strong { overflow-wrap: anywhere; word-break: break-word; color: var(--web-text); }

.job.done { border-color: var(--web-accent); }

.job.error { border-color: var(--web-danger-border); }

.history-item {
    border: 1px solid var(--web-border);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 8px;
    background: var(--web-bg-sunken);
    min-width: 0;
    position: relative;
}

/* Списки истории и задач целиком приглушены (.muted у контейнера), поэтому
   крупной строке - именам игроков - цвет задаём явно. */
.history-item strong {
    overflow-wrap: anywhere;
    word-break: break-word;
    color: var(--web-text);
}

/* победитель - отдельной строкой под игроками, тем же шрифтом */
.history-item .history-winner { display: block; }

.history-item a { color: var(--web-link); }

.open-modes { margin-top: 8px; }

.open-modes .btn { font-size: 0.85rem; padding: 8px 10px; }

.open-modes .btn:hover {
    background: var(--web-ghost-hover);
    color: var(--web-text);
}

.open-modes .btn.primary,
.history-match-analysis-btn.primary {
    background: var(--web-accent);
    color: #fff;
}

.open-modes .btn.primary:hover,
.history-match-analysis-btn.primary:hover {
    background: var(--web-accent-2);
    color: #fff;
}

.sub {
    margin: 8px 0 0;
    padding: 0;
    list-style: none;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.job-file {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--web-border);
    border-radius: 8px;
    background: #101010;
}

html[data-theme="light"] .job,
html[data-theme="light"] .job-file,
html[data-theme="light"] .history-item {
    border: 1px solid #6b7280;
}

html[data-theme="light"] .job-file {
    background: #c8ccd4;
}

html[data-theme="light"] .history-item--nested:hover {
    border-color: #6b7280;
}

.job-file-name {
    overflow-wrap: anywhere;
    word-break: break-word;
    min-width: 0;
}

.job-file-actions {
    margin-top: 0;
}

.progress {
    height: 8px;
    background: var(--web-progress-bg);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 10px;
}

.progress-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--web-accent), var(--web-accent-2));
    border-radius: 999px;
    transition: width 0.35s linear;
}

.job.error .progress-fill { background: var(--web-danger-border); }

.job.done .progress-fill { background: var(--web-accent); }

.progress-label { margin-top: 6px; }

.pager {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.pager button {
    padding: 8px 12px;
    min-width: 40px;
    background: var(--web-ghost-bg);
    color: var(--web-ghost-fg);
}

.pager button.active { background: var(--web-accent); color: #fff; }

.pager .pager-info { color: var(--web-text-muted); font-size: 0.85rem; margin-left: 4px; }

.history-item--expandable {
    cursor: pointer;
    position: relative;
}

.history-item--expandable:hover { border-color: #4caf50; }

.history-item--expandable.is-open { border-color: var(--web-accent); }

.history-item-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }

.history-item-head > div:first-child { min-width: 0; flex: 1; }

.history-item-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

.history-item-title-row strong { min-width: 0; }

.history-toggle-btn {
    font-size: 0.8rem;
    padding: 6px;
    white-space: nowrap;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    min-width: 36px;
}

.history-toggle-btn svg {
    display: block;
    width: 18px;
    height: 18px;
}

@media (min-width: 721px) {
    .history-item--expandable {
        padding-bottom: 44px;
    }
    .history-item--expandable > .history-item-head .history-toggle-btn {
        position: absolute;
        right: 10px;
        bottom: 8px;
        z-index: 2;
    }
}

.history-table-wrap { margin-top: 12px; overflow-x: auto; }

.analyze-vs { margin: 0 0 10px; font-weight: 600; color: var(--web-text); }

.analyze-block { margin-bottom: 14px; }

.analyze-block h3 { margin: 0 0 6px; font-size: 0.9rem; color: var(--web-analyze-h); }

.analyze-table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 0.85rem; }

.analyze-table col { width: 33.33%; }

.analyze-table th, .analyze-table td {
    border: 1px solid var(--web-table-border);
    padding: 6px 8px;
    text-align: left;
    overflow-wrap: anywhere;
    word-break: break-word;
    color: var(--web-text);
}

.analyze-table th { background: var(--web-table-th); }

.analyze-table td { background: var(--web-table-td); }

html[data-theme="light"] .analyze-result,
html[data-theme="light"] .analyze-vs,
html[data-theme="light"] .analyze-block h3,
html[data-theme="light"] .analyze-table th,
html[data-theme="light"] .analyze-table td,
html[data-theme="light"] .history-table-wrap,
html[data-theme="light"] .batch-summary {
    color: #000000;
}

html[data-theme="light"] .history-table-wrap .muted {
    color: #000000;
}

/* В светлой теме содержимое разбора читается с чисто белого фона:
   серым остаётся только шапка таблицы, чтобы колонки различались. */
html[data-theme="light"] .batch-summary,
html[data-theme="light"] .analyze-table td {
    background: #ffffff;
}

.history-item-actions { display: flex; align-items: flex-start; gap: 8px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }

.history-pdf-btn { font-size: 0.8rem; padding: 6px 10px; white-space: nowrap; }

.history-item--batch > .history-item-head strong::before { content: "📁 "; }

.batch-summary {
    margin: 0 0 12px;
    padding: 10px 12px;
    border: 1px solid var(--web-border);
    border-radius: 10px;
    background: var(--web-bg-card);
}

.batch-summary-head { font-weight: 600; margin-bottom: 8px; white-space: pre-line; }

.batch-pr { margin: 6px 0; }

.batch-files { margin-top: 4px; display: flex; flex-direction: column; gap: 8px; }

.batch-files .history-item { margin-bottom: 0; }

.history-item--nested { cursor: default; }

.history-item--nested:hover { border-color: var(--web-border); }

@media (max-width: 720px) {
    .job-file-actions .btn,
    .job-file-actions button,
    .open-modes .btn {
        flex: 1 1 calc(50% - 4px);
        min-height: 44px;
        padding: 10px 12px;
        font-size: 0.85rem;
    }
    .history-item-head {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .history-item-actions {
        justify-content: stretch;
        width: 100%;
    }
    .history-item-actions .btn,
    .history-item-actions button {
        flex: 1 1 calc(50% - 4px);
        min-height: 44px;
        padding: 10px 12px;
        font-size: 0.85rem;
    }
    .history-toggle-btn {
        position: static;
        min-width: 44px;
        min-height: 44px;
        width: 44px;
        height: 44px;
        padding: 8px;
    }
    .history-pdf-btn { white-space: nowrap; }
    .history-table-wrap { -webkit-overflow-scrolling: touch; }
    .analyze-table { font-size: 0.78rem; }
    .analyze-table th, .analyze-table td { padding: 5px 6px; }
    .pager { gap: 4px; }
    .pager button {
        min-height: 40px;
        padding: 8px 10px;
    }
}

@media (max-width: 400px) {
    .history-item-actions .btn,
    .history-item-actions button,
    .job-file-actions .btn,
    .job-file-actions button,
    .open-modes .btn {
        flex: 1 1 100%;
    }
}

/* Крупная строка - имена игроков (обычный цвет текста: белый в тёмной теме,
   чёрный в светлой), под ней приглушённо - название протокола и статус. */
.history-meta {
    font-size: 0.9rem;
    color: var(--web-text-muted);
    overflow-wrap: anywhere;
}

/* Дата анализа - справа от кнопки меток, зелёным (в обеих темах свой оттенок). */
.history-date {
    color: var(--web-link);
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
}
