/* Компактний дизайн модального вікна - Material Design */
#contractsAnalyticsModal .modal-dialog {
    max-width: 95vw;
    margin: 0.5rem auto;
}

#contractsAnalyticsModal .modal-content {
    border-radius: 12px;
    border: none;
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
    overflow: hidden;
}

#contractsAnalyticsModal .modal-header {
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, #1976d2, #1565c0);
    color: white;
    border-bottom: none;
}

#contractsAnalyticsModal .modal-header h5 {
    font-size: 1.1rem;
    font-weight: 500;
    margin: 0;
    letter-spacing: 0.25px;
}

#contractsAnalyticsModal .modal-header .btn-close {
    filter: brightness(0) invert(1);
    opacity: 0.8;
    width: 1rem;
    height: 1rem;
}

#contractsAnalyticsModal .modal-header .btn-close:hover {
    opacity: 1;
}

#contractsAnalyticsModal .modal-body {
    padding: 1rem;
    max-height: calc(100vh - 150px);
    overflow-y: auto;
    background: #fafafa;
}

#contractsAnalyticsModal .modal-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid #e0e0e0;
    background: #ffffff;
}

/* Material Design фільтри */
.analytics-filters {
    background: white;
    border-radius: 8px;
    padding: 0.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.analytics-filters .form-control,
.analytics-filters .form-select {
    font-size: 0.75rem;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.analytics-filters .form-control:focus,
.analytics-filters .form-select:focus {
    border-color: #1976d2;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
}

.analytics-filters .btn {
    font-size: 0.75rem;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.analytics-filters .btn-primary {
    background: linear-gradient(135deg, #1976d2, #1565c0);
    border: none;
    box-shadow: 0 1px 3px rgba(25, 118, 210, 0.3);
}

.analytics-filters .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(25, 118, 210, 0.4);
}

/* Material Design статистичні картки - надкомпактні */
.stats-row .col-lg-3 {
    margin-bottom: 0.5rem;
}

.stats-card {
    padding: 0.5rem;
    border-radius: 8px;
    background: white;
    border: none;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    position: relative;
    overflow: hidden;
    min-height: 60px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stats-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.stats-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(135deg, #1976d2, #1565c0);
}

.stats-card .stats-number {
    font-size: 1.1rem;
    font-weight: 600;
    color: #424242;
    margin-bottom: 0.2rem;
    line-height: 1.1;
}

.stats-card .stats-label {
    font-size: 0.7rem;
    color: #757575;
    margin: 0;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    line-height: 1.2;
}

/* Розділи з Material Design */
.critical-years-section,
.heatmap-section,
.stats-section {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.section-title {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 1rem;
    color: #424242;
    display: flex;
    align-items: center;
    letter-spacing: 0.25px;
}

.section-title::before {
    content: '';
    width: 4px;
    height: 20px;
    background: linear-gradient(135deg, #1976d2, #1565c0);
    margin-right: 0.75rem;
    border-radius: 2px;
}

/* Адаптивність */
@media (max-width: 768px) {
    #contractsAnalyticsModal .modal-dialog {
        margin: 0.25rem;
        max-width: calc(100vw - 0.5rem);
    }
    
    #contractsAnalyticsModal .modal-body {
        padding: 0.75rem;
    }
    
    .contracts-heatmap-table .sticky-column {
        min-width: 100px;
        font-size: 0.7rem;
        padding: 0.3rem 0.5rem;
    }
    
    .heatmap-cell {
        min-height: 30px;
        font-size: 0.65rem;
        margin: 0.5px;
    }
    
    .heatmap-cell .cell-area {
        font-size: 0.6rem;
    }
    
    .heatmap-cell .cell-contracts {
        font-size: 0.5rem;
    }
    
    .critical-year-card {
        padding: 0.3rem;
        min-height: 60px;
    }
    
    .year-number {
        font-size: 0.9rem;
    }
    
    .year-area {
        font-size: 0.65rem;
    }
    
    .year-contracts {
        font-size: 0.6rem;
    }
    
    .year-stats {
        font-size: 0.55rem;
    }
    
    .stats-card {
        padding: 0.6rem;
    }
    
    .stats-card .stats-number {
        font-size: 1.2rem;
    }
    
    .stats-card .stats-label {
        font-size: 0.75rem;
    }
    
    .section-title {
        font-size: 1rem;
    }
    
    .critical-years-section,
    .heatmap-section,
    .stats-section {
        padding: 1rem;
        margin-bottom: 1rem;
    }
}

@media (max-width: 576px) {
    #contractsAnalyticsModal .modal-dialog {
        margin: 0.125rem;
        max-width: calc(100vw - 0.25rem);
    }
    
    #contractsAnalyticsModal .modal-body {
        padding: 0.5rem;
    }
    
    .contracts-heatmap-table .sticky-column {
        min-width: 80px;
        font-size: 0.65rem;
        padding: 0.25rem 0.4rem;
    }
    
    .contracts-heatmap-table thead th {
        padding: 0.5rem 0.25rem;
        font-size: 0.65rem;
    }
    
    .heatmap-cell {
        min-height: 25px;
        font-size: 0.6rem;
        border-radius: 4px;
    }
    
    .heatmap-cell .cell-area {
        font-size: 0.55rem;
    }
    
    .heatmap-cell .cell-contracts {
        font-size: 0.45rem;
    }
    
    .critical-year-card {
        padding: 0.25rem;
        min-height: 50px;
    }
    
    .year-number {
        font-size: 0.8rem;
    }
    
    .year-area {
        font-size: 0.6rem;
    }
    
    .year-contracts {
        font-size: 0.55rem;
    }
    
    .year-stats {
        font-size: 0.5rem;
    }
    
    .stats-card {
        padding: 0.5rem;
    }
    
    .stats-card .stats-number {
        font-size: 1rem;
    }
    
    .stats-card .stats-label {
        font-size: 0.7rem;
    }
    
    .critical-years-section,
    .heatmap-section,
    .stats-section {
        padding: 0.75rem;
        margin-bottom: 0.75rem;
    }
    
    .section-title {
        font-size: 0.9rem;
        margin-bottom: 0.75rem;
    }
}

@media (max-width: 400px) {
    .contracts-heatmap-table .sticky-column {
        min-width: 70px;
        font-size: 0.6rem;
    }
    
    .heatmap-cell {
        min-height: 22px;
        font-size: 0.55rem;
    }
    
    .heatmap-cell .cell-area {
        font-size: 0.5rem;
    }
    
    .heatmap-cell .cell-contracts {
        display: none; /* Приховуємо на дуже малих екранах */
    }
    
    .critical-year-card {
        min-height: 45px;
    }
    
    .year-number {
        font-size: 0.75rem;
    }
    
    .year-area {
        font-size: 0.55rem;
    }
    
    .year-contracts {
        font-size: 0.5rem;
    }
    
    .year-stats {
        display: none; /* Приховуємо на дуже малих екранах */
    }
}

/* Стилі для аналітики договорів */

/* Картки критичних років - ультракомпактні */
.critical-year-card {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 0.15rem;
    text-align: center;
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    min-height: 35px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.critical-year-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.critical-year-card.critical:hover {
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.4);
}

.critical-year-card.warning:hover {
    box-shadow: 0 4px 12px rgba(253, 126, 20, 0.4);
}

.critical-year-card.caution:hover {
    box-shadow: 0 4px 12px rgba(255, 193, 7, 0.4);
}

.critical-year-card.success:hover {
    box-shadow: 0 4px 12px rgba(25, 135, 84, 0.4);
}

.critical-year-card.expired:hover {
    box-shadow: 0 4px 12px rgba(111, 66, 193, 0.4);
}

.critical-year-card.critical {
    background: linear-gradient(135deg, #dc3545, #e55353);
    border-color: #dc3545;
    color: white;
    box-shadow: 0 2px 4px rgba(220, 53, 69, 0.3);
}

.critical-year-card.warning {
    background: linear-gradient(135deg, #fd7e14, #ff8500);
    border-color: #fd7e14;
    color: white;
    box-shadow: 0 2px 4px rgba(253, 126, 20, 0.3);
}

.critical-year-card.caution {
    background: linear-gradient(135deg, #ffc107, #ffca2c);
    border-color: #ffc107;
    color: #212529;
    box-shadow: 0 2px 4px rgba(255, 193, 7, 0.3);
}

.critical-year-card.success {
    background: linear-gradient(135deg, #198754, #20c997);
    border-color: #198754;
    color: white;
    box-shadow: 0 2px 4px rgba(25, 135, 84, 0.3);
}

.critical-year-card.expired {
    background: linear-gradient(135deg, #6f42c1, #7952b3);
    border-color: #6f42c1;
    color: white;
    box-shadow: 0 2px 4px rgba(111, 66, 193, 0.3);
}

.year-number {
    font-size: 0.7rem;
    font-weight: 600;
    margin-bottom: 0.05rem;
    line-height: 1;
}

.year-area {
    font-size: 0.55rem;
    font-weight: 500;
    margin-bottom: 0.05rem;
    line-height: 1;
}

.year-contracts {
    font-size: 0.5rem;
    margin-bottom: 0.05rem;
    line-height: 1;
}

.year-stats {
    font-size: 0.45rem;
    opacity: 0.8;
    line-height: 1;
}

/* Таблиця хітмап - компактна */
.contracts-heatmap-table {
    font-size: 0.7rem;
}

.contracts-heatmap-table th {
    background: linear-gradient(135deg, #198754, #20c997) !important;
    color: white !important;
    font-weight: 600;
    text-align: center;
    vertical-align: middle;
    border: 1px solid #198754;
    padding: 0.3rem 0.2rem;
    font-size: 0.65rem;
}

.contracts-heatmap-table td {
    text-align: center;
    vertical-align: middle;
    border: 1px solid #dee2e6;
    padding: 0.3rem 0.2rem;
    transition: all 0.2s ease;
    font-size: 0.65rem;
    height: 25px;
}

.contracts-heatmap-table .sticky-column {
    position: sticky;
    left: 0;
    background-color: #f8f9fa;
    font-weight: 600;
    text-align: left !important;
    min-width: 80px;
    max-width: 120px;
    z-index: 1;
    font-size: 0.7rem;
    padding: 0.3rem 0.4rem;
    word-wrap: break-word;
    white-space: normal;
    line-height: 1.2;
}

.contracts-heatmap-table tbody .sticky-column {
    background-color: white;
}

/* Material Design хітмап таблиця */
.contracts-heatmap-container {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1), 0 8px 16px rgba(0,0,0,0.1);
    overflow: hidden;
    margin: 1rem 0;
    overflow-x: auto;
    max-width: 100%;
}

.contracts-heatmap-table {
    font-size: 0.75rem;
    margin: 0;
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    min-width: 600px;
    background: #ffffff;
}

.contracts-heatmap-table thead th {
    background: linear-gradient(135deg, #1976d2, #1565c0);
    color: white;
    font-weight: 500;
    font-size: 0.75rem;
    padding: 0.75rem 0.5rem;
    text-align: center;
    border: none;
    position: sticky;
    top: 0;
    z-index: 10;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.contracts-heatmap-table thead th:first-child {
    border-top-left-radius: 16px;
    text-align: left;
    padding-left: 1rem;
}

.contracts-heatmap-table thead th:last-child {
    border-top-right-radius: 16px;
}

.contracts-heatmap-table .sticky-column {
    position: sticky;
    left: 0;
    background: linear-gradient(135deg, #f5f5f5, #eeeeee);
    font-weight: 500;
    text-align: left !important;
    min-width: 120px;
    z-index: 5;
    font-size: 0.75rem;
    padding: 0.4rem 0.8rem;
    border-right: 2px solid #e0e0e0;
    color: #424242;
}

.contracts-heatmap-table tbody .sticky-column {
    background: linear-gradient(135deg, #fafafa, #f5f5f5);
}

.contracts-heatmap-table tbody tr:hover .sticky-column {
    background: linear-gradient(135deg, #e3f2fd, #bbdefb);
    color: #1976d2;
}

.contracts-heatmap-table td {
    padding: 0.25rem;
    border: none;
    position: relative;
}

.contracts-heatmap-table tbody tr {
    transition: all 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.contracts-heatmap-table tbody tr:hover {
    background-color: rgba(25, 118, 210, 0.04);
}

/* Material Design хітмап клітинки */
.heatmap-cell {
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    min-height: 35px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 0.7rem;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    margin: 1px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.heatmap-cell:hover {
    transform: scale(1.03);
    z-index: 3;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.heatmap-cell.critical {
    color: #212529;
    font-weight: 600;
    text-shadow: none;
    box-shadow: 0 2px 4px rgba(220, 53, 69, 0.3);
}

.heatmap-cell.critical:hover {
    box-shadow: 0 4px 8px rgba(220, 53, 69, 0.6);
    transform: scale(1.05);
}

.heatmap-cell.warning {
    color: #212529;
    font-weight: 600;
    text-shadow: none;
    box-shadow: 0 2px 4px rgba(253, 126, 20, 0.3);
}

.heatmap-cell.warning:hover {
    box-shadow: 0 4px 8px rgba(253, 126, 20, 0.6);
    transform: scale(1.05);
}

.heatmap-cell.caution {
    color: #212529;
    font-weight: 600;
    text-shadow: none;
    box-shadow: 0 2px 4px rgba(255, 193, 7, 0.3);
}

.heatmap-cell.caution:hover {
    box-shadow: 0 4px 8px rgba(255, 193, 7, 0.6);
    transform: scale(1.05);
}

.heatmap-cell.success {
    color: #212529;
    font-weight: 600;
    text-shadow: none;
    box-shadow: 0 2px 4px rgba(25, 135, 84, 0.3);
}

.heatmap-cell.success:hover {
    box-shadow: 0 4px 8px rgba(25, 135, 84, 0.6);
    transform: scale(1.05);
}

.heatmap-cell.empty {
    background: linear-gradient(135deg, #f5f5f5, #eeeeee);
    color: #9e9e9e;
    opacity: 0.7;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.heatmap-cell.total {
    background: linear-gradient(135deg, #6c757d, #495057);
    color: white;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(108, 117, 125, 0.3);
}

.heatmap-cell.total:hover {
    box-shadow: 0 4px 8px rgba(108, 117, 125, 0.4);
}

/* Ефект пульсації для критичних клітинок */
@keyframes pulse {
    0% { box-shadow: 0 2px 4px rgba(220, 53, 69, 0.3); }
    50% { box-shadow: 0 4px 8px rgba(220, 53, 69, 0.7); }
    100% { box-shadow: 0 2px 4px rgba(220, 53, 69, 0.3); }
}

.heatmap-cell.critical.pulse {
    animation: pulse 2s infinite;
}

/* Дані в клітинках */
.heatmap-cell .cell-area {
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1;
}

.heatmap-cell .cell-contracts {
    font-size: 0.55rem;
    opacity: 0.9;
    line-height: 1;
    margin-top: 1px;
}

.heatmap-cell.critical {
    background: linear-gradient(135deg, #dc3545, #e55353);
    color: white;
}

.heatmap-cell.warning {
    background: linear-gradient(135deg, #fd7e14, #ff8500);
    color: white;
}

.heatmap-cell.caution {
    background: linear-gradient(135deg, #ffc107, #ffca2c);
    color: #333;
}

.heatmap-cell.success {
    background: linear-gradient(135deg, #198754, #20c997);
    color: white;
}

.heatmap-cell.empty {
    background: #f8f9fa;
    color: #6c757d;
    opacity: 0.6;
}

.heatmap-cell.total {
    background: linear-gradient(135deg, #6f42c1, #7952b3);
    color: white;
    font-weight: bold;
}

.cell-area {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.cell-contracts {
    font-size: 0.75rem;
    opacity: 0.9;
}

/* Загальна статистика */
.stat-card {
    text-align: center;
    padding: 1rem;
    border-radius: 8px;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border: 1px solid #dee2e6;
}

.stat-number {
    font-size: 1.5rem;
    font-weight: bold;
    color: #495057;
}

.stat-label {
    font-size: 0.875rem;
    color: #6c757d;
    margin-top: 0.25rem;
}

/* Адаптивність - надкомпактна */
@media (max-width: 768px) {
    .contracts-heatmap-table {
        font-size: 0.65rem;
    }
    
    .contracts-heatmap-table .sticky-column {
        min-width: 70px;
        max-width: 100px;
        font-size: 0.65rem;
        word-wrap: break-word;
        white-space: normal;
    }
    
    .contracts-heatmap-table th,
    .contracts-heatmap-table td {
        padding: 0.2rem 0.1rem;
        height: 22px;
    }
    
    .stats-card {
        min-height: 50px;
        padding: 0.4rem;
    }
    
    .stats-card .stats-number {
        font-size: 1rem;
    }
    
    .stats-card .stats-label {
        font-size: 0.65rem;
    }
    
    .critical-year-card {
        min-height: 30px;
        padding: 0.1rem;
    }
    
    .year-number {
        font-size: 0.6rem;
    }
    
    .year-area,
    .year-contracts,
    .year-stats {
        font-size: 0.45rem;
    }
}

@media (max-width: 576px) {
    .contracts-heatmap-table .sticky-column {
        min-width: 60px;
        max-width: 80px;
        font-size: 0.6rem;
        word-wrap: break-word;
        white-space: normal;
    }
    
    .contracts-heatmap-table th,
    .contracts-heatmap-table td {
        padding: 0.15rem 0.05rem;
        height: 20px;
        font-size: 0.6rem;
    }
    
    .stats-card {
        min-height: 40px;
        padding: 0.3rem;
    }
    
    .stats-card .stats-number {
        font-size: 0.9rem;
    }
    
    .stats-card .stats-label {
        font-size: 0.6rem;
    }
    
    .critical-year-card {
        min-height: 35px;
        padding: 0.15rem;
    }
    
    .year-number {
        font-size: 0.7rem;
    }
    
    .year-area,
    .year-contracts,
    .year-stats {
        font-size: 0.5rem;
    }
}

/* Надкомпактний режим для найменших екранів */
@media (max-width: 400px) {
    .modal-lg {
        max-width: 95% !important;
    }
    
    .modal-content {
        padding: 0.5rem !important;
    }
    
    .analytics-filters {
        padding: 0.3rem;
        margin-bottom: 0.5rem;
    }
    
    .analytics-filters .form-control,
    .analytics-filters .form-select {
        font-size: 0.7rem;
        padding: 0.3rem 0.4rem;
    }
    
    .analytics-filters .btn {
        font-size: 0.7rem;
        padding: 0.3rem 0.6rem;
    }
    
    .stats-card {
        min-height: 35px;
        padding: 0.25rem;
    }
    
    .stats-card .stats-number {
        font-size: 0.8rem;
    }
    
    .stats-card .stats-label {
        font-size: 0.55rem;
    }
    
    .critical-year-card {
        min-height: 25px;
        padding: 0.05rem;
    }
    
    .year-number {
        font-size: 0.55rem;
    }
    
    .year-area,
    .year-contracts,
    .year-stats {
        font-size: 0.4rem;
    }
    
    .contracts-heatmap-table {
        font-size: 0.55rem;
    }
    
    .contracts-heatmap-table .sticky-column {
        min-width: 50px;
        max-width: 70px;
        font-size: 0.55rem;
        word-wrap: break-word;
        white-space: normal;
    }
    
    .contracts-heatmap-table th,
    .contracts-heatmap-table td {
        padding: 0.1rem 0.05rem;
        height: 18px;
        font-size: 0.55rem;
    }
}

/* Легенда хітмепу */
.heatmap-legend {
    font-size: 0.7rem;
}

.heatmap-legend .legend-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.heatmap-legend .legend-color {
    border: 1px solid rgba(0,0,0,0.1);
    flex-shrink: 0;
}

/* Адаптивність легенди */
@media (max-width: 768px) {
    .heatmap-legend {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem !important;
    }
    
    .heatmap-legend > div {
        gap: 1rem !important;
    }
}

@media (max-width: 576px) {
    .heatmap-legend {
        display: none; /* Приховати на дуже маленьких екранах */
    }
}

/* Анімації */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.critical-year-card {
    animation: fadeInUp 0.5s ease forwards;
}

.heatmap-cell {
    animation: fadeInUp 0.3s ease forwards;
}

/* PDF стилі для експорту */
@media print {
    .heatmap-cell {
        animation: none !important;
        transition: none !important;
    }
    
    .critical-year-card {
        animation: none !important;
        transition: none !important;
    }
    
    .stats-card {
        animation: none !important;
        transition: none !important;
    }
}

/* Tooltip для додatkової інформації */
.heatmap-cell[data-bs-toggle="tooltip"] {
    cursor: help;
}

/* Виділення при пошуку */
.tenant-highlight {
    background-color: #fff3cd !important;
    border: 2px solid #ffc107 !important;
}
