/* ── Territorial Unified Management Page ─────────────────────────────────── */
/*
   Layout: fixed-height panels, no resize.
   ┌─────────────────────────────────────────────────────────────┐
   │ ┌────── Country (50%) ──────┬── CountryAdminLevel (50%) ─┐ │
   │ │                            │                             │ │
   │ │      (fixed height)        │       (fixed height)        │ │
   │ │                            │                             │ │
   │ └────────────────────────────┴─────────────────────────────┘ │
   │ ┌────── AdministrativeDivision (100%, larger) ────────────┐ │
   │ │                                                           │ │
   │ │                    (larger fixed height)                   │ │
   │ │                                                           │ │
   │ └───────────────────────────────────────────────────────────┘ │
   └─────────────────────────────────────────────────────────────┘
*/

.territorial-page {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 0.5rem;
    padding: 0.5rem;
    box-sizing: border-box;
}

/* ── Top row: side-by-side panels ─────────────────────────────────────── */
.territorial-top-row {
    display: flex;
    gap: 0.5rem;
    flex: 0 0 38%;
    min-height: 0;
}

/* ── Bottom row: full-width Administrative Division panel ──────────────── */
.territorial-bottom-row {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
}

/* ── Individual panel card ─────────────────────────────────────────────── */
.territorial-panel {
    display: flex;
    flex-direction: column;
    border: 1px solid #ced4da;
    border-radius: 0.5rem;
    background-color: #f8f9fa;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    min-height: 0;
}

/* ── Panel header ──────────────────────────────────────────────────────── */
.territorial-panel-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background-color: #6c757d;
    color: #fff;
    flex-shrink: 0;
    border-bottom: 1px solid #5a6268;
}

.territorial-panel-title {
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    flex: 1 1 auto;
}

/* ── Link badge (shows active parent filter) ───────────────────────────── */
.territorial-link-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.7rem;
    background-color: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 1rem;
    padding: 0.1rem 0.6rem;
    white-space: nowrap;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
}

.territorial-link-badge.d-none {
    display: none !important;
}

/* ── Panel body (CRUD host) ────────────────────────────────────────────── */
.territorial-panel-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.territorial-crud-host {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ── Top-left panel: Country ───────────────────────────────────────────── */
.territorial-panel-country {
    flex: 1 1 50%;
}

/* ── Top-right panel: CountryAdministrativeLevel ────────────────────────── */
.territorial-panel-levels {
    flex: 1 1 50%;
}

/* ── Bottom panel: AdministrativeDivision ───────────────────────────────── */
.territorial-panel-divisions {
    flex: 1 1 100%;
}

/* ── Compact the CrudManager UI inside panels ───────────────────────────── */
.territorial-panel .table-page-card {
    padding: 0.25rem !important;
}

.territorial-panel .crud-toolbar-row {
    margin-bottom: 0.2rem;
    gap: 0.15rem;
    flex-wrap: nowrap;
    overflow: hidden;
}

.territorial-panel .crud-toolbar-title {
    font-size: 0.85rem;
    margin-right: 0.25rem;
}

.territorial-panel .crud-tb-btn {
    width: 1.65rem;
    height: 1.65rem;
    font-size: 0.7rem;
}

.territorial-panel .crud-page-info {
    font-size: 0.7rem;
    gap: 0.15rem;
}

.territorial-panel .crud-grid-table {
    font-size: 0.8rem;
}

.territorial-panel .crud-grid-table thead th {
    font-size: 0.72rem;
    padding: 0.25rem 0.35rem;
}

.territorial-panel .crud-grid-table tbody td {
    padding: 0.2rem 0.35rem;
    height: 30px;
    font-size: 0.78rem;
}

.territorial-panel .crud-row {
    height: 30px;
}

.territorial-panel .crud-filter-cell select,
.territorial-panel .crud-filter-cell input {
    font-size: 0.65rem;
    height: 1.4rem;
    padding: 0.1rem 0.25rem;
}

.territorial-panel .crud-filter-cell .crud-filter-op {
    flex: 0 0 1.8rem;
    width: 1.8rem;
    max-width: 1.8rem;
    font-size: 0.6rem;
}

.territorial-panel .crud-multiselect-btn {
    font-size: 0.65rem;
    height: 1.4rem;
    padding: 0.1rem 0.25rem;
}

.territorial-panel .crud-filter-row th {
    padding: 0.1rem 0.2rem;
}

.territorial-panel .table-page-body {
    overflow: hidden;
}

/* ── Bottom panel gets slightly larger row height ─────────────────────── */
.territorial-panel-divisions .crud-grid-table tbody td {
    height: 34px;
}

.territorial-panel-divisions .crud-row {
    height: 34px;
}

.territorial-panel-divisions .crud-grid-table thead th {
    font-size: 0.75rem;
    padding: 0.3rem 0.4rem;
}

/* ── Responsive: stack panels vertically on small screens ───────────────── */
@media (max-width: 991.98px) {
    .territorial-top-row {
        flex-direction: column;
        flex: 0 0 auto;
        min-height: 40vh;
    }

    .territorial-panel-country,
    .territorial-panel-levels {
        flex: 1 1 auto;
        min-height: 20vh;
    }

    .territorial-bottom-row {
        flex: 1 1 auto;
        min-height: 40vh;
    }
}

@media (max-width: 767.98px) {
    .territorial-page {
        gap: 0.3rem;
        padding: 0.3rem;
    }

    .territorial-top-row {
        gap: 0.3rem;
        min-height: 35vh;
    }

    .territorial-panel-header {
        padding: 0.3rem 0.5rem;
    }

    .territorial-panel-title {
        font-size: 0.78rem;
    }

    .territorial-link-badge {
        font-size: 0.62rem;
        max-width: 140px;
        padding: 0.08rem 0.45rem;
    }

    .territorial-panel .crud-tb-btn {
        width: 1.5rem;
        height: 1.5rem;
        font-size: 0.65rem;
    }
}