/* ═══════════════════════════════════════════════════════════════════
   REGEXHELPER - HISTORY.CSS
   Секция истории: коллапсируемая панель + модальное окно
   ═══════════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────────────
   HISTORY SECTION — фиксированная коллапсируемая панель
   ───────────────────────────────────────────────────────────────── */

#history-section {
    padding: 0 40px 16px 40px;
    background: var(--color-bg-page);
}

#history-section::before {
    content: '';
    display: block;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--color-border-default), transparent);
    margin: 0 auto 0;
    width: 60%;
}

.history-container {
    padding: 0 24px;
}

/* ─────────────────────────────────────────────────────────────────
   HISTORY HEADER — тоньше, с кнопками управления
   ───────────────────────────────────────────────────────────────── */

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
}

.history-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-toggle-history {
    background: transparent;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border-default);
    height: 32px;
    padding: 0 12px;
    border-radius: var(--radius-small);
    font-size: 12px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-toggle-history:hover {
    border-color: var(--color-border-hover);
    color: var(--color-text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.btn-toggle-history svg {
    transition: transform var(--transition-normal);
}

.btn-toggle-history.collapsed svg {
    transform: rotate(180deg);
}

/* ─────────────────────────────────────────────────────────────────
   HISTORY GRID — коллапсируемая панель (макс. 2 ряда)
   ───────────────────────────────────────────────────────────────── */

.history-grid-wrapper {
    overflow: hidden;
    transition: max-height 0.35s ease, opacity 0.25s ease;
    max-height: 500px;
    opacity: 1;
}

.history-grid-wrapper.collapsed {
    max-height: 0;
    opacity: 0;
    padding: 0;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    padding-bottom: 14px;
    align-items: stretch;
}

@media (min-width: 1920px) {
    .history-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1024px) and (max-width: 1279px) {
    .history-grid { grid-template-columns: repeat(2, 1fr); }
}

.history-card[data-type="simple"] { border-left: 3px solid var(--color-text-tertiary); }
.history-card[data-type="linked"] { border-left: 3px solid var(--color-primary); }
.history-card[data-type="manual"] { border-left: 3px solid var(--color-text-secondary); }

/* Empty state */
.history-empty,
.history-grid .empty-message {
    grid-column: 1 / -1;
    text-align: center;
    padding: var(--spacing-l) var(--spacing-m);
    background: var(--color-bg-panel);
    border: 2px dashed var(--color-border-default);
    border-radius: var(--radius-medium);
}

.history-empty p,
.history-grid .empty-message {
    font-size: 14px;
    color: var(--color-text-secondary);
    margin: 0;
}

/* ─────────────────────────────────────────────────────────────────
   HISTORY CARD — компактная карточка
   ───────────────────────────────────────────────────────────────── */

.history-card {
    background: var(--color-bg-panel);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-medium);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
    box-shadow: var(--shadow-small);
}

.history-card:hover {
    border-color: var(--color-border-hover);
    box-shadow: var(--shadow-medium);
}

/* Card inner structure — фиксированная иерархия */
.history-card .history-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-border-default);
    gap: 8px;
}

.history-card .history-card-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.history-card .history-date {
    font-size: 11px;
    color: var(--color-text-tertiary);
    font-weight: 500;
    letter-spacing: 0.02em;
}

.history-card .btn-history-expand {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-small);
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}

.history-card .btn-history-expand:hover {
    color: var(--color-primary);
    border-color: var(--color-primary);
    background: rgba(91, 141, 239, 0.08);
}

/* Бейдж типа — в стиле кнопки «Показать всё»: outline, не яркий */
.history-card .history-type {
    font-size: 10px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
    background: transparent;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border-default);
}

.history-card[data-type="linked"] .history-type {
    color: var(--color-primary);
    border-color: var(--color-primary);
    background: transparent;
}

/* Триггеры: макс. 2 строки, ellipsis, подсказка через title в разметке */
.history-card .history-triggers {
    font-size: 12px;
    color: var(--color-text-secondary);
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
    min-height: 2.7em;
}

/* Результат: минимум 3 строки, всегда видимый вывод regex */
.history-card .history-result {
    flex: 1 1 0;
    min-height: 3.6em;
    background: rgba(0, 0, 0, 0.25);
    padding: 10px 12px;
    border-radius: var(--radius-small);
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 11px;
    line-height: 1.4;
    color: var(--color-success);
    word-break: break-all;
    border: 1px solid rgba(52, 211, 153, 0.12);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.history-card .history-result code {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: inherit;
    min-height: 1.4em;
}

.history-result-collapsed {
    /* совместимость: свернутый вид уже через line-clamp выше */
}

.history-result-collapsed code {
    -webkit-line-clamp: 3;
}

/* ─────────────────────────────────────────────────────────────────
   HISTORY CARD ACTIONS — компактная группа кнопок
   ───────────────────────────────────────────────────────────────── */

.history-card .history-actions {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    flex-shrink: 0;
    margin-top: auto;
}

.history-card .history-actions .btn-history-action {
    flex: 1;
    min-width: 0;
    height: 28px;
    padding: 0 8px;
    font-size: 11px;
    font-weight: 500;
    border-radius: var(--radius-small);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    transition: border-color var(--transition-fast), color var(--transition-fast), background var(--transition-fast);
    border: 1px solid var(--color-border-default);
    background: var(--color-bg-card);
    color: var(--color-text-secondary);
}

.history-card .history-actions .btn-history-action svg {
    flex-shrink: 0;
}

.history-card .history-actions .btn-history-action:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: rgba(var(--color-primary-rgb), 0.08);
}

/* Кнопка Копировать */
.history-card .history-actions .btn-history-copy:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: rgba(91, 141, 239, 0.08);
}

/* Кнопка Экспорт с dropdown */
.history-card .history-actions .btn-history-export-wrap {
    flex: 1;
    position: relative;
}

.history-card .history-actions .btn-history-export-wrap .btn-history-action {
    width: 100%;
}

.history-card .history-actions .btn-history-export-wrap:hover .btn-history-action {
    border-color: var(--color-success);
    color: var(--color-success);
    background: rgba(52, 211, 153, 0.08);
}

/* Выпадающий список экспорта: по умолчанию вверх (нижние карточки) */
.history-export-dropdown {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    margin-bottom: 4px;
    margin-top: 0;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-small);
    box-shadow: var(--shadow-medium);
    z-index: 9990;
    overflow: hidden;
}

/* Верхние карточки: раскрывается вниз */
.btn-history-export-wrap.dropdown-down .history-export-dropdown {
    bottom: auto;
    top: 100%;
    margin-top: 4px;
    margin-bottom: 0;
}

.history-export-dropdown.open {
    display: block;
}

.history-export-dropdown .export-option {
    display: block;
    width: 100%;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--color-text-primary);
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.history-export-dropdown .export-option:hover {
    background: rgba(var(--color-primary-rgb), 0.1);
}

.history-export-dropdown .export-option:not(:last-child) {
    border-bottom: 1px solid var(--color-border-default);
}

/* Кнопка Удалить */
.history-card .history-actions .btn-history-delete:hover {
    border-color: var(--color-error);
    color: var(--color-error);
    background: rgba(239, 68, 68, 0.08);
}

/* ─────────────────────────────────────────────────────────────────
   ANIMATION
   ───────────────────────────────────────────────────────────────── */

.history-card {
    animation: cardAppear 0.3s ease;
}

@keyframes cardAppear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─────────────────────────────────────────────────────────────────
   FULL HISTORY MODAL — широкая модалка (+15%), 2 столбца, 8 карточек в окне
   Порядок: сверху последние (FIFO), вниз — старые, остальное по скроллу
   ───────────────────────────────────────────────────────────────── */

/* Модалка на 15% шире: 1440 * 1.15 ≈ 1656px */
#modal-full-history .modal {
    max-width: min(1656px, calc(100vw - 32px));
    width: 100%;
    max-height: calc(100vh - 32px);
    height: calc(100vh - 32px);
}

/* Шапка модалки: заголовок слева, кнопки экспорта/очистки и закрыть справа на одной линии */
#modal-full-history .modal-header.modal-header-with-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 16px 12px 20px;
}

#modal-full-history .modal-title-history {
    flex: 0 1 auto;
    min-width: 0;
    margin: 0;
    font-size: 18px;
}

#modal-full-history .modal-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    justify-content: flex-end;
    min-width: 0;
}

#modal-full-history .modal-header-actions .btn-small {
    height: 32px;
    padding: 0 10px;
    font-size: 12px;
    white-space: nowrap;
}

#modal-full-history .modal-header-actions .btn-small svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

#modal-full-history .modal-body {
    padding: 14px 20px 16px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Пустое состояние: фон на всю область контента, «История пуста» по центру */
#modal-full-history .history-grid:has(.empty-message) {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 280px;
    max-height: none;
    background: var(--color-bg-page);
    border-radius: var(--radius-medium);
}

#modal-full-history .history-grid .empty-message {
    border: none;
    background: transparent;
    padding: 0;
    font-size: 15px;
    color: var(--color-text-secondary);
    margin: 0;
}

/* Сетка: 2 колонки, высота под 8 карточек (4 ряда), остальное — скролл */
#modal-full-history .history-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: minmax(200px, auto);
    gap: 18px 22px;
    padding-bottom: 12px;
    flex: 1;
    min-height: 0;
    max-height: calc(4 * 200px + 3 * 18px); /* ~854px: 4 ряда по ~200px + 3 отступа */
    overflow-y: auto;
    overflow-x: hidden;
    align-content: start;
}

/* Карточки в модалке: компактные отступы, содержимое не вылезает за границы по ширине */
#modal-full-history .history-card {
    padding: 12px 14px;
    gap: 8px;
    min-height: 0;
    min-width: 0;
}

#modal-full-history .history-card .history-card-header {
    padding-bottom: 6px;
    flex-shrink: 0;
    min-width: 0;
    gap: 6px;
}

#modal-full-history .history-card .history-card-header-left {
    min-width: 0;
    flex: 1 1 auto;
}

#modal-full-history .history-card .history-date {
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#modal-full-history .history-card .history-type {
    font-size: 10px;
    padding: 2px 6px;
    flex-shrink: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#modal-full-history .history-card .history-triggers {
    font-size: 12px;
    line-height: 1.38;
    min-height: 2.6em;
    -webkit-line-clamp: 2;
}

#modal-full-history .history-card .history-result {
    min-height: 4em;
    padding: 10px 12px;
    flex: 1 1 0;
}

#modal-full-history .history-card .history-result code {
    font-size: 12px;
    line-height: 1.42;
    -webkit-line-clamp: 4;
}

#modal-full-history .history-result-collapsed code {
    -webkit-line-clamp: 4;
}

#modal-full-history .history-card .history-actions {
    gap: 5px;
    margin-top: auto;
    flex-shrink: 0;
    min-width: 0;
    flex-wrap: wrap;
}

#modal-full-history .history-card .history-actions .btn-history-action {
    height: 26px;
    padding: 0 6px;
    font-size: 10px;
    min-width: 0;
    flex: 1 1 0;
    max-width: 100%;
}

#modal-full-history .history-card .history-actions .btn-history-action svg {
    width: 10px;
    height: 10px;
}

#modal-full-history .history-export-dropdown {
    z-index: 10002;
}

#modal-full-history .modal-footer {
    padding: 10px 20px 14px;
    flex-shrink: 0;
}

#modal-full-history .modal-footer .btn-modal-close {
    min-width: 112px;
}
