* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

header h1 {
    font-size: 28px;
    font-weight: 600;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.app-header-user {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.app-header-username {
    opacity: 0.9;
    white-space: nowrap;
}

.app-header .btn {
    white-space: nowrap;
}

/* Вкладки */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.tab-btn {
    padding: 12px 24px;
    border: none;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.tab-btn:hover {
    background: #f8f9fa;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.tab-btn.active {
    background: #667eea;
    color: white;
}

/* Содержимое вкладок */
.tab-content {
    display: none;
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.tab-content.active {
    display: block;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-header h2 {
    font-size: 24px;
    color: #333;
}

/* Кнопки */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.btn-secondary {
    background: #e0e0e0;
    color: #333;
}

.btn-secondary:hover {
    background: #d0d0d0;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.btn-info {
    background: #17a2b8;
    color: white;
}

.btn-info:hover {
    background: #138496;
}

.btn-success {
    background: #28a745;
    color: white;
}

.btn-success:hover {
    background: #218838;
}

/* Таблицы */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

thead {
    background: #f8f9fa;
}

th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: #495057;
    border-bottom: 2px solid #dee2e6;
}

td {
    padding: 12px;
    border-bottom: 1px solid #dee2e6;
}

tr:hover {
    background: #f8f9fa;
}

/* Модальные окна */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

.modal-overlay.active {
    display: block;
}

.modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    z-index: 1000;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal.modal-large {
    max-width: 900px;
}

.modal.active {
    display: block;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #dee2e6;
}

.modal-header h3 {
    font-size: 20px;
    color: #333;
}

.close-btn {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #999;
    line-height: 1;
}

.close-btn:hover {
    color: #333;
}

.modal-body {
    padding: 20px;
}

/* Окно загрузки логотипа использует свою упрощённую разметку (без modal-header/modal-body) */
.modal-content {
    padding: 20px;
    position: relative;
}

.modal-content h3 {
    font-size: 20px;
    color: #333;
    margin-bottom: 16px;
    padding-right: 30px;
}

.close {
    position: absolute;
    top: 16px;
    right: 20px;
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    color: #999;
}

.close:hover {
    color: #333;
}

/* Формы */
.form-group {
    margin-bottom: 15px;
    flex: 1;
}

.form-row {
    display: flex;
    gap: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #495057;
    font-size: 14px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-group textarea {
    resize: vertical;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #dee2e6;
}

/* Иконка информации */
.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: #17a2b8;
    color: white;
    border-radius: 50%;
    font-size: 11px;
    font-weight: bold;
    font-style: normal;
    cursor: pointer;
    margin-left: 6px;
    user-select: none;
    vertical-align: middle;
    flex-shrink: 0;
    line-height: 1;
}

.info-icon:hover {
    background: #138496;
}

/* Всплывающая подсказка с деталями */
.info-tooltip-popup {
    display: none;
    position: fixed;
    z-index: 9999;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
    padding: 14px;
    max-width: 520px;
    min-width: 260px;
    max-height: 420px;
    overflow-y: auto;
    font-size: 13px;
    pointer-events: none;
}

.info-tooltip-popup.visible {
    display: block;
}

.tooltip-section {
    margin-bottom: 12px;
}

.tooltip-section:last-child {
    margin-bottom: 0;
}

.tooltip-title {
    font-weight: 700;
    color: #495057;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
    padding-bottom: 3px;
    border-bottom: 1px solid #dee2e6;
}

.tooltip-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 4px;
}

.tooltip-table th,
.tooltip-table td {
    padding: 4px 8px;
    border: 1px solid #dee2e6;
    text-align: left;
    white-space: nowrap;
}

.tooltip-table th {
    background: #f8f9fa;
    font-weight: 600;
}

.tooltip-table td:first-child {
    white-space: normal;
    max-width: 200px;
}

.modal-body h4 {
    margin: 20px 0 10px;
    color: #667eea;
    font-size: 16px;
}

/* Позиции документа */
.document-item {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 10px;
    position: relative;
}

.document-item-remove {
    position: absolute;
    top: 10px;
    right: 10px;
}

.total-section {
    text-align: right;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
    margin: 15px 0;
    font-size: 18px;
}

/* Действия в таблице */
.table-actions {
    display: flex;
    gap: 5px;
}

/* Отчёт */
.report-chart-wrap {
    margin: 6px 0 20px;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 10px;
}

.report-note {
    color: #6c757d;
    font-size: 13px;
    margin-top: -12px;
}

.report-subheading {
    margin: 28px 0 6px;
    color: #495057;
    font-size: 16px;
}

.report-subheading:first-of-type {
    margin-top: 6px;
}

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.report-table {
    min-width: 100%;
}

.report-table th,
.report-table td {
    white-space: nowrap;
}

.report-table th:first-child,
.report-table td:first-child {
    white-space: normal;
    min-width: 180px;
}

.report-table tfoot td {
    border-top: 2px solid #dee2e6;
    border-bottom: none;
    background: #f8f9fa;
}

/* ============ Адаптивность (планшет/телефон) ============ */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    header {
        padding: 16px;
        border-radius: 8px;
        margin-bottom: 12px;
    }

    header h1 {
        font-size: 19px;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .app-header-user {
        width: 100%;
        justify-content: space-between;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    /* Вкладки: не колонка на всю высоту, а горизонтальная свайпаемая лента */
    .tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 8px;
        margin-bottom: 12px;
        padding-bottom: 2px;
        scrollbar-width: none;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        flex: 0 0 auto;
        white-space: nowrap;
        padding: 10px 16px;
        font-size: 13px;
    }

    .tab-content {
        padding: 14px;
        border-radius: 8px;
    }

    .section-header {
        flex-wrap: wrap;
        gap: 10px;
    }

    .section-header h2 {
        font-size: 19px;
    }

    .section-header .btn {
        width: 100%;
    }

    /* Модалки — на весь экран, без плавающей рамки: удобнее заполнять формы */
    .modal {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        transform: none;
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        border-radius: 0;
    }

    .modal.modal-large {
        max-width: none;
    }

    .modal-header {
        position: sticky;
        top: 0;
        background: white;
        z-index: 1;
    }

    .form-actions {
        position: sticky;
        bottom: 0;
        background: white;
        margin-top: 12px;
        padding: 12px 0;
    }

    /* --- Таблицы -> карточки --- */
    table {
        border: none;
    }

    thead {
        display: none;
    }

    tbody {
        display: block;
    }

    table, tr, td {
        display: block;
        width: 100%;
    }

    tr {
        background: white;
        border: 1px solid #e9ecef;
        border-radius: 10px;
        margin-bottom: 10px;
        padding: 10px 12px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    }

    tr:hover {
        background: white;
    }

    td {
        border: none;
        padding: 7px 0;
        text-align: left;
    }

    td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: 10.5px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: #8a94a6;
        margin-bottom: 3px;
    }

    /* Строка действий — кнопки в ряд на всю ширину карточки, крупные для тапа */
    td.table-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin-top: 8px;
        padding-top: 10px;
        border-top: 1px dashed #e9ecef;
    }

    td.table-actions .btn {
        flex: 1 1 calc(50% - 8px);
        padding: 10px 8px;
        font-size: 13px;
    }

    /* Подсказка "i" с деталями — не шире экрана */
    .info-tooltip-popup {
        max-width: calc(100vw - 28px);
        min-width: 0;
        max-height: 70vh;
    }

    .tooltip-table {
        display: block;
        overflow-x: auto;
    }

    /* Таблицы отчёта — это сводная матрица (клиент × год), карточная раскладка
       её только испортит. Возвращаем обычное табличное поведение и скроллим вбок. */
    .report-table,
    .report-table thead,
    .report-table tbody,
    .report-table tfoot,
    .report-table tr,
    .report-table th,
    .report-table td {
        display: revert;
        width: revert;
    }

    .report-table tr {
        background: none;
        border: none;
        border-radius: 0;
        margin-bottom: 0;
        padding: 0;
        box-shadow: none;
    }

    .report-table th,
    .report-table td {
        padding: 8px 12px;
        border-bottom: 1px solid #dee2e6;
    }

    .report-table td[data-label]::before {
        content: none;
    }
}

/* Совсем узкие экраны — по одной кнопке действия в ряд */
@media (max-width: 400px) {
    td.table-actions .btn {
        flex: 1 1 100%;
    }
}

/* Скроллбар */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}
