/* Contracts Table - таблицы актов/контрактов */

/* ============================================================================
   БУРГЕР-МЕНЮ
   ============================================================================ */

.burger-menu-container {
    position: relative;
    float: right;
    margin-left: 10px;
}

.burger-icon {
    cursor: pointer;
    padding: 5px 8px;
    font-size: 18px;
    line-height: 1;
    -webkit-user-select: none;
    user-select: none;
    border-radius: 3px;
    transition: background-color 0.2s;
}

.burger-icon:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.burger-dropdown {
    position: absolute;
    right: 0;
    top: 100%;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: none;
    z-index: 1000;
    min-width: 220px;
    margin-top: 5px;
}

.burger-dropdown.show {
    display: block;
}

.burger-menu-item {
    padding: 10px 20px;
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s;
}

.burger-menu-item:last-child {
    border-bottom: none;
}

.burger-menu-item:hover {
    background-color: #f5f5f5;
}

/* ============================================================================
   ТАБЛИЦЫ
   ============================================================================ */

.contract-table {
    width: 100%;
    table-layout: fixed;
    border: 2px solid #000;
    border-collapse: collapse;
    margin-bottom: 10px;
    font-size: 11px;
    page-break-inside: avoid;
    /* Оптимизация для плавной перерисовки */
    will-change: auto;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Фиксированная ширина таблиц для средних экранов */
@media (min-width: 769px) and (max-width: 1024px) {
    .table-wrapper {
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
    }
    
    .contract-table {
        table-layout: fixed;
        width: 100%;
    }
}

/* Ограничение ширины на десктопе */
@media (min-width: 1025px) {
    .table-wrapper {
        max-width: 1100px;
        margin-left: auto;
        margin-right: auto;
    }
    
    .contract-table {
        max-width: 1100px;
        margin-left: auto;
        margin-right: auto;
        table-layout: fixed;
        width: 100%;
    }
}

.contract-table th,
.contract-table td {
    border: 1px solid #000;
    padding: 6px 10px;
    vertical-align: middle;
    line-height: 1.4;
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Шапка с бургер-меню — не обрезать overflow */
.contract-table .header-row td,
.contract-table .preview-header-row td {
    overflow: visible;
}

.contract-table th {
    text-align: left;
}

.contract-table td {
    text-align: center;
}

/* Ячейки с заголовками (Заказчик, Исполнитель, Сумма договора и т.д.) - слева */
.contract-table td strong {
    text-align: left;
    display: block;
}

/* Итоговая строка: рекламный сбор без переноса */
.contract-table .ad-fee-cell strong,
.contract-table .ad-fee-cell span {
    display: inline;
    white-space: nowrap;
}

/* Строка с заказчиком/исполнителем - обе колонки слева */
.contract-table .contract-info-row td {
    text-align: left !important;
}

/* Ячейки содержащие только <strong> элемент - слева */
.contract-table td:has(> strong:first-child) {
    text-align: left !important;
}

.contract-table td[id] {
    vertical-align: middle;
}

.contract-table td > span[id],
.contract-table td[contenteditable="true"] {
    display: inline-block;
    vertical-align: middle;
    line-height: 1.25;
}

/* Компактнее по ширине на десктопе */
@media (min-width: 1025px) {
    .contract-table th,
    .contract-table td {
        padding: 6px 8px;
    }
    
    /* Делаем столбцы пропорциональными на десктопе - используем процентные ширины */
    .contract-table th[style*="width: 100px"],
    .contract-table td[style*="width: 100px"] {
        width: 10% !important;
        min-width: 100px;
    }
    
    .contract-table th[style*="width: 120px"],
    .contract-table td[style*="width: 120px"] {
        width: 12% !important;
        min-width: 120px;
    }
    
    .contract-table th[style*="width: 90px"],
    .contract-table td[style*="width: 90px"] {
        width: 9% !important;
        min-width: 90px;
    }
    
    /* Явно переопределяем для строк Заказчик/Исполнитель на широких экранах */
    .contract-table tr.contract-info-row td {
        padding: 6px 8px !important;
        font-size: 11px !important;
        line-height: 1.4 !important;
        vertical-align: middle !important;
    }
    
    /* Явно переопределяем для строк "Креативы без публикаций" на широких экранах */
    .contract-table tr.no-publications-header td {
        padding: 6px 8px !important;
        font-size: 11px !important;
        line-height: 1.4 !important;
        vertical-align: middle !important;
    }
    
    /* Явно переопределяем для строк "Размещения на неизвестных площадках" на широких экранах */
    .contract-table tr.unknown-platform-header td {
        padding: 6px 8px !important;
        font-size: 11px !important;
        line-height: 1.4 !important;
        vertical-align: middle !important;
    }
    
    /* УНИВЕРСАЛЬНОЕ ПРАВИЛО для всех заголовочных строк с colspan на широких экранах */
    .contract-table tr td[colspan] {
        padding: 6px 8px !important;
        font-size: 11px !important;
        line-height: 1.4 !important;
        vertical-align: middle !important;
        height: auto !important;
        min-height: auto !important;
    }
    
    .contract-table tr td[colspan] strong {
        font-size: 11px !important;
        line-height: 1.4 !important;
    }
}

.contract-table th {
    background: #f0f0f0;
    font-weight: bold;
    vertical-align: middle;
}

.header-row {
    background: #e8e8e8;
    font-weight: bold;
}

.header-row td,
.preview-header-row td {
    padding: 6px 10px;
    font-size: 11px;
}

/* Стили для предварительных отчетов */
.preview-contract {
    border: 3px solid #1976d2 !important;
}

.preview-header-row {
    background: #bbdefb !important;
    font-weight: bold;
}

/* Компактнее на десктопе */
@media (min-width: 1025px) {
    .header-row td,
    .preview-header-row td {
        padding: 6px 8px;
    }
}

/* Компактные стили для строк Заказчик и Исполнитель */
.contract-table tr.contract-info-row td {
    padding: 6px 10px !important;
    font-size: 11px !important;
    line-height: 1.4 !important;
    vertical-align: middle !important;
}

.contract-table tr.contract-info-row td strong {
    font-size: 11px !important;
    font-weight: bold;
}

@media (min-width: 1025px) {
    .contract-table tr.contract-info-row {
        height: auto !important;
    }
    
    .contract-table tr.contract-info-row td {
        padding: 6px 8px !important;
        font-size: 11px !important;
        line-height: 1.4 !important;
        vertical-align: middle !important;
        height: auto !important;
        min-height: auto !important;
    }
    
    .contract-table tr.contract-info-row td strong {
        font-size: 11px !important;
        line-height: 1.4 !important;
    }
}

.section-header {
    background: #d0d0d0;
    font-weight: bold;
    text-align: center;
}

/* Универсальное правило для всех заголовочных строк с colspan */
.contract-table tr td[colspan] {
    padding: 6px 10px !important;
    font-size: 11px !important;
    line-height: 1.4 !important;
    vertical-align: middle !important;
}

.contract-table tr td[colspan] strong {
    font-size: 11px !important;
    line-height: 1.4 !important;
}

@media (min-width: 1025px) {
    .contract-table tr td[colspan] {
        padding: 6px 8px !important;
        font-size: 11px !important;
        line-height: 1.4 !important;
        vertical-align: middle !important;
        height: auto !important;
        min-height: auto !important;
    }
    
    .contract-table tr td[colspan] strong {
        font-size: 11px !important;
        line-height: 1.4 !important;
    }
}

.no-publications-header {
    background: #fff9e6;
    font-weight: bold;
    text-align: center;
}

/* Компактные стили для таблицы "Креативы без публикаций" */
.contract-table tr.no-publications-header td {
    padding: 6px 10px !important;
    font-size: 11px !important;
    line-height: 1.4 !important;
    vertical-align: middle !important;
}

.contract-table tr.no-publications-header td strong {
    font-size: 11px !important;
    font-weight: bold;
}

@media (min-width: 1025px) {
    .contract-table tr.no-publications-header {
        height: auto !important;
    }
    
    .contract-table tr.no-publications-header td {
        padding: 6px 8px !important;
        font-size: 11px !important;
        line-height: 1.4 !important;
        vertical-align: middle !important;
        height: auto !important;
        min-height: auto !important;
    }
    
    .contract-table tr.no-publications-header td strong {
        font-size: 11px !important;
        line-height: 1.4 !important;
    }
}

.no-publications-row {
    background: #fffbf0;
}

.defect-creative-header {
    background: #e0e0e0;
    font-weight: bold;
    text-align: center;
    color: #757575;
}

.defect-creative-row {
    background: #f5f5f5;
    color: #757575;
}

.creative-after-period-row {
    background: #e3f2fd;
}

/* Строки будущих периодов (не участвующие в разалокации) */
.future-period-row td {
    background: #fff3e0 !important;
}

.unknown-platform-header {
    background: #ffe6e6;
    font-weight: bold;
    text-align: center;
}

/* Компактные стили для заголовка "Размещения на неизвестных площадках" */
.contract-table tr.unknown-platform-header td {
    padding: 6px 10px !important;
    font-size: 11px !important;
    line-height: 1.4 !important;
    vertical-align: middle !important;
}

.contract-table tr.unknown-platform-header td strong {
    font-size: 11px !important;
    font-weight: bold;
}

@media (min-width: 1025px) {
    .contract-table tr.unknown-platform-header {
        height: auto !important;
    }
    
    .contract-table tr.unknown-platform-header td {
        padding: 6px 8px !important;
        font-size: 11px !important;
        line-height: 1.4 !important;
        vertical-align: middle !important;
        height: auto !important;
        min-height: auto !important;
    }
    
    .contract-table tr.unknown-platform-header td strong {
        font-size: 11px !important;
        line-height: 1.4 !important;
    }
}

.unknown-platform-row {
    background: #fff5f5;
}

.nowrap {
    white-space: nowrap;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
    white-space: nowrap;
}

.error-alert {
    background: #ffebee;
    border-left: 4px solid #f44336;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 4px;
}

.error-alert h3 {
    color: #c62828;
    margin-bottom: 5px;
}

.contract-link {
    color: #1976d2;
    text-decoration: none;
    cursor: pointer;
    font-weight: 600;
}

.contract-link:hover {
    text-decoration: underline;
}

.contract-section.scroll-target {
    outline: 2px solid #1976d2;
    box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.15);
    border-radius: 6px;
}

/* Обертка для горизонтальной прокрутки таблиц */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 20px;
    border-radius: 8px;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.05);
    position: relative;
    width: 100%;
}

@media (max-width: 768px) {
    .table-wrapper::after {
        opacity: 1;
    }
}

/* Блок детализации ошибок */
.error-header {
    background: #ffebee !important;
    font-weight: bold;
    text-align: center;
}

.error-row {
    background: #fff3e0 !important;
}

.error-row td {
    vertical-align: top;
}

.error-row pre {
    margin: 0;
    font-size: 10px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.copy-btn {
    cursor: pointer;
    color: #1976d2;
    text-decoration: underline;
    font-size: 11px;
    margin-left: 5px;
}

.copy-btn:hover {
    color: #1565c0;
}

/* ============================================================================
   ВСПЛЫВАЮЩАЯ ПОДСКАЗКА ДЛЯ ПУБЛИКАЦИЙ
   ============================================================================ */

.pubs-count-tooltip {
    position: relative;
    display: inline-block;
    cursor: pointer;
    transition: color 0.2s ease;
}

.pubs-count-tooltip:active {
    transform: scale(0.95);
}

.pubs-tooltip-content {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 8px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 10px 12px;
    min-width: 280px;
    max-width: 400px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    text-align: left;
    white-space: normal;
}

/* Стрелочка вниз */
.pubs-tooltip-content::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: white;
}

.pubs-tooltip-content::before {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 7px solid transparent;
    border-top-color: #ddd;
    margin-top: 1px;
}

/* Показываем подсказку при наведении */
.pubs-count-tooltip:hover .pubs-tooltip-content {
    display: block;
}

/* Для случая, когда подсказка не помещается сверху - показываем снизу */
@media (max-height: 600px) {
    .pubs-tooltip-content {
        bottom: auto;
        top: 100%;
        margin-top: 8px;
        margin-bottom: 0;
    }
    
    .pubs-tooltip-content::after {
        top: auto;
        bottom: 100%;
        border-top-color: transparent;
        border-bottom-color: white;
    }
    
    .pubs-tooltip-content::before {
        top: auto;
        bottom: 100%;
        border-top-color: transparent;
        border-bottom-color: #ddd;
        margin-top: 0;
        margin-bottom: 1px;
    }
}

/* Скроллбар для длинных списков */
.pubs-tooltip-content::-webkit-scrollbar {
    width: 6px;
}

.pubs-tooltip-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.pubs-tooltip-content::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.pubs-tooltip-content::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Eternal-stats: hover через CSS вместо inline onmouseover на каждой строке */
.eternal-stats-table tbody tr:hover {
    background: #fcfcff;
}

/* Eternal-stats: editable поля становятся contenteditable по клику (делегировано) */
.eternal-stats-table .editable-stat-field[contenteditable="true"] {
    outline: none;
    background: #fffbea;
}

/* Self-promo: hover через CSS вместо inline onmouseover на каждой строке */
.self-promo-stats-table tbody tr:hover {
    background: #fffcf5;
}

.self-promo-stats-table .editable-selfpromo-field[contenteditable="true"] {
    outline: none;
    background: #fffbea;
}
