/* ============================================================
   conexoes.css — Telas de Curadoria de Territórios
   Cobre: /conexoes (lista) e /conexoes/territorio/<slug> (builder)
   Organização: Core layout → Lista → Builder → Responsivo
   ============================================================ */


/* ── Variáveis locais ─────────────────────────────────────── */
:root {
    --cnx-col-width:     320px;
    --cnx-col-min:       260px;
    --cnx-zone-bg:       rgba(126, 224, 193, 0.04);
    --cnx-zone-over:     rgba(126, 224, 193, 0.10);
    --cnx-item-bg:       rgba(255, 255, 255, 0.03);
    --cnx-item-hover:    rgba(255, 255, 255, 0.06);
    --cnx-divider:       rgba(255, 255, 255, 0.07);
    --cnx-radius:        var(--radius-md, 8px);
    --cnx-col-radius:    12px;
}


/* ────────────────────────────────────────────────────────────
   TELA 1 — /conexoes (Lista de territórios)
   ──────────────────────────────────────────────────────────── */

.cnx-main {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
    padding-block: var(--space-6);
}

/* Hero */
.cnx-hero {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-5);
    align-items: flex-start;
    justify-content: space-between;
    padding: var(--space-6) var(--space-5);
    min-height: 270px;
    border-radius: var(--radius-xl);
}

.cnx-hero::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    background: linear-gradient(180deg, transparent 12%, rgba(11, 17, 24, 0.94) 92%);
}

.cnx-hero-constellation {
    position: absolute;
    top: -18px;
    right: -38px;
    width: min(62vw, 250px);
    opacity: 0.3;
    pointer-events: none;
}

.cnx-hero-copy { position: relative; z-index: 1; }

.cnx-hero-icon {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    padding: 8px;
    margin-bottom: var(--space-4);
    border: 1px solid rgba(126, 224, 193, 0.28);
    border-radius: var(--radius-lg);
    background: rgba(126, 224, 193, 0.08);
}

.cnx-hero-copy .eyebrow {
    margin-bottom: var(--space-2);
}

.cnx-hero-copy h1 {
    max-width: 17ch;
    font-size: clamp(2rem, 9vw, 3rem);
    font-weight: 300;
    line-height: 1.08;
    margin-bottom: var(--space-2);
}

.cnx-hero-copy p {
    color: var(--color-muted, #8B95A1);
    max-width: 48ch;
    line-height: 1.6;
}

.cnx-hero-stats {
    display: flex;
    gap: var(--space-5);
    flex-wrap: wrap;
}

.cnx-stat {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}

.cnx-stat strong {
    font-family: var(--font-mono);
    font-size: var(--text-xl, 1.5rem);
    font-weight: 500;
    color: var(--obs-green-0, #7EE0C1);
    line-height: 1;
}

.cnx-stat span {
    font-size: var(--text-xs, 0.75rem);
    color: var(--color-muted, #8B95A1);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Seção genérica */
.cnx-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.cnx-create-section {
    padding: var(--space-5);
    border-radius: var(--cnx-radius);
}

/* Lista de territórios */
.cnx-territory-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.cnx-territory-row {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-4);
    border-radius: var(--cnx-radius);
    transition: background 0.15s;
}

.cnx-territory-row--inactive {
    opacity: 0.5;
}

.cnx-territory-mark {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--cnx-zone-bg);
    border: 1px solid var(--cnx-divider);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--obs-green-0, #7EE0C1);
}

.cnx-territory-icon,
.cnxb-territory-icon {
    width: 24px;
    height: 24px;
    color: var(--obs-menta);
}

.cnx-territory-info {
    flex: 1;
    min-width: 0;
}

.cnx-territory-info h3 {
    font-size: var(--text-base, 1rem);
    font-weight: 600;
    margin: 0 0 var(--space-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cnx-territory-info p {
    font-size: var(--text-sm, 0.875rem);
    color: var(--color-muted, #8B95A1);
    margin: 0 0 var(--space-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cnx-territory-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.cnx-meta-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: var(--text-xs, 0.75rem);
    color: var(--color-muted, #8B95A1);
}

.cnx-meta-badge svg {
    width: 12px;
    height: 12px;
    opacity: 0.6;
}

.cnx-meta-badge--dim {
    opacity: 0.5;
}

.cnx-territory-action {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-3);
    border-radius: 6px;
    font-size: var(--text-sm, 0.875rem);
    font-weight: 500;
    color: var(--obs-green-0, #7EE0C1);
    border: 1px solid rgba(126, 224, 193, 0.25);
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.cnx-territory-action:hover {
    background: rgba(126, 224, 193, 0.08);
    border-color: rgba(126, 224, 193, 0.5);
}

.cnx-territory-action svg {
    width: 14px;
    height: 14px;
}

/* Empty state */
.cnx-empty-state {
    padding: var(--space-8) var(--space-4);
    text-align: center;
    color: var(--color-muted, #8B95A1);
    font-size: var(--text-sm, 0.875rem);
}

/* Formulário de criação */
.cnx-create-form {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: flex-end;
}

.cnx-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.cnx-field label {
    font-size: var(--text-xs, 0.75rem);
    color: var(--color-muted, #8B95A1);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.cnx-field input {
    background: var(--cnx-item-bg);
    border: 1px solid var(--cnx-divider);
    border-radius: 6px;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm, 0.875rem);
    color: inherit;
    width: 100%;
}

.cnx-field input:focus {
    outline: none;
    border-color: rgba(126, 224, 193, 0.4);
}

.cnx-field small {
    font-size: var(--text-xs, 0.75rem);
    color: var(--color-muted, #8B95A1);
}

.cnx-field--grow { flex: 1 1 180px; }
.cnx-field--sm   { flex: 0 1 100px; }
.cnx-field--xs   { flex: 0 1 80px; }

.cnx-submit-btn {
    flex-shrink: 0;
    align-self: flex-end;
    padding: var(--space-2) var(--space-4);
    border-radius: 6px;
    font-size: var(--text-sm, 0.875rem);
    font-weight: 500;
    background: rgba(126, 224, 193, 0.12);
    color: var(--obs-green-0, #7EE0C1);
    border: 1px solid rgba(126, 224, 193, 0.3);
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

.cnx-submit-btn:hover {
    background: rgba(126, 224, 193, 0.2);
}


/* ────────────────────────────────────────────────────────────
   TELA 2 — /conexoes/territorio/<slug> (Builder)
   ──────────────────────────────────────────────────────────── */

.cnxb-main {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 56px); /* descontar topbar */
    overflow: hidden;
}

/* Cabeçalho do território */
.cnxb-header {
    position: relative;
    overflow: hidden;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--cnx-divider);
    flex-shrink: 0;
}

.cnxb-back {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--text-sm, 0.875rem);
    color: var(--color-muted, #8B95A1);
    text-decoration: none;
    flex-shrink: 0;
    transition: color 0.15s;
}

.cnxb-back:hover { color: var(--obs-green-0, #7EE0C1); }
.cnxb-back svg   { width: 14px; height: 14px; }

.cnxb-header-body {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex: 1;
    min-width: 0;
}

.cnxb-header-mark {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--cnx-zone-bg);
    border: 1px solid var(--cnx-divider);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--obs-green-0, #7EE0C1);
}

@media (min-width: 769px) {
    .cnx-hero { min-height: 310px; padding: var(--space-8); }
    .cnx-hero-constellation {
        top: 50%;
        right: 4%;
        width: min(30vw, 380px);
        opacity: 0.38;
        transform: translateY(-50%);
    }
    .cnx-hero-copy h1 { font-size: clamp(2.75rem, 5vw, 4rem); }
    .cnx-hero-icon { width: 48px; height: 48px; padding: 9px; }
}

.cnxb-header-body .eyebrow {
    display: block;
    margin-bottom: 0;
}

.cnxb-header-body h1 {
    font-size: var(--text-lg, 1.25rem);
    font-weight: 600;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cnxb-header-body .c-muted {
    font-size: var(--text-sm, 0.875rem);
    margin: 0;
}

.cnxb-header-counts {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm, 0.875rem);
    color: var(--color-muted, #8B95A1);
    flex-shrink: 0;
    margin-left: auto;
}

.cnxb-count strong {
    color: var(--obs-green-0, #7EE0C1);
}

.cnxb-count-sep {
    opacity: 0.4;
}

/* Tab bar — só visível em mobile */
.cnxb-tab-bar {
    display: none;
    flex-shrink: 0;
    border-bottom: 1px solid var(--cnx-divider);
}

.cnxb-tab {
    flex: 1;
    padding: var(--space-3) var(--space-2);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-size: var(--text-sm, 0.875rem);
    font-weight: 500;
    color: var(--color-muted, #8B95A1);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.cnxb-tab.is-active {
    color: var(--obs-green-0, #7EE0C1);
    border-bottom-color: var(--obs-green-0, #7EE0C1);
}

/* Builder: 3 colunas */
.cnxb-builder {
    display: grid;
    grid-template-columns: var(--cnx-col-width) 1fr var(--cnx-col-width);
    flex: 1;
    overflow: hidden;
    gap: 0;
}

/* Coluna genérica */
.cnxb-col {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--cnx-divider);
}

.cnxb-col:last-child {
    border-right: none;
    border-left: 1px solid var(--cnx-divider);
}

.cnxb-col--territory {
    border-right: 1px solid var(--cnx-divider);
    border-left: none;
}

/* Cabeçalho da coluna */
.cnxb-col-head {
    flex-shrink: 0;
    padding: var(--space-4) var(--space-4) var(--space-2);
    border-bottom: 1px solid var(--cnx-divider);
}

.cnxb-col-head h2 {
    font-size: var(--text-base, 1rem);
    font-weight: 600;
    margin: 0 0 2px;
}

.cnxb-col-caption {
    font-size: var(--text-xs, 0.75rem);
    color: var(--color-muted, #8B95A1);
}

/* Filtro */
.cnxb-filter-bar {
    flex-shrink: 0;
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--cnx-divider);
}

.cnxb-filter {
    width: 100%;
    background: var(--cnx-item-bg);
    border: 1px solid var(--cnx-divider);
    border-radius: 6px;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm, 0.875rem);
    color: inherit;
}

.cnxb-filter:focus {
    outline: none;
    border-color: rgba(126, 224, 193, 0.35);
}

/* Lista de itens do pool */
.cnxb-item-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
    margin: 0;
    padding: var(--space-2) 0;
}

.cnxb-item-list.is-over {
    background: rgba(126, 224, 193, 0.04);
}

.cnxb-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    cursor: grab;
    transition: background 0.1s;
    user-select: none;
}

.cnxb-item:hover {
    background: var(--cnx-item-hover);
}

.cnxb-item.is-dragging {
    opacity: 0.45;
    cursor: grabbing;
}

.cnxb-item-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.cnxb-item-name {
    font-size: var(--text-sm, 0.875rem);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cnxb-item-sub {
    font-size: var(--text-xs, 0.75rem);
    color: var(--color-muted, #8B95A1);
}

.cnxb-item-add {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: none;
    border: 1px solid transparent;
    color: var(--color-muted, #8B95A1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.cnxb-item:hover .cnxb-item-add {
    opacity: 1;
}

.cnxb-item-add:hover {
    background: rgba(126, 224, 193, 0.12);
    color: var(--obs-green-0, #7EE0C1);
    border-color: rgba(126, 224, 193, 0.3);
}

.cnxb-item-add svg { width: 14px; height: 14px; }

.cnxb-empty {
    padding: var(--space-4) var(--space-3);
    font-size: var(--text-sm, 0.875rem);
    color: var(--color-muted, #8B95A1);
    list-style: none;
}

/* Drop zone do território */
.cnxb-territory-zone {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: var(--space-3);
    background: var(--cnx-zone-bg);
    transition: background 0.15s;
}

.cnxb-territory-zone.is-over {
    background: var(--cnx-zone-over);
}

/* Duas sub-colunas: eventos (esq) · entidades (dir) */
.cnxb-zone-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.cnxb-zone-col {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* Divisor vertical entre as sub-colunas */
.cnxb-zone-col:first-child {
    border-right: 1px solid var(--cnx-divider);
    padding-right: var(--space-3);
}

.cnxb-zone-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.cnxb-zone-label {
    font-size: var(--text-xs, 0.75rem);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-muted, #8B95A1);
    padding: 0 var(--space-1);
}

.cnxb-zone-list {
    list-style: none;
    margin: 0;
    padding: var(--space-1);
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    overflow-y: auto;
    min-height: 48px;
    border-radius: 8px;
    border: 1px dashed var(--cnx-divider);
    transition: border-color 0.15s, background 0.15s;
}

.cnxb-zone-list.is-over {
    border-color: rgba(126, 224, 193, 0.4);
    background: rgba(126, 224, 193, 0.06);
}

.cnxb-zone-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: 6px;
    background: var(--cnx-item-bg);
    cursor: grab;
    user-select: none;
    transition: background 0.1s;
    list-style: none;
}

.cnxb-zone-item:hover {
    background: var(--cnx-item-hover);
}

.cnxb-zone-item.is-dragging {
    opacity: 0.45;
    cursor: grabbing;
}

.cnxb-zone-item-name {
    flex: 1;
    font-size: var(--text-sm, 0.875rem);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cnxb-zone-item-sub {
    font-size: var(--text-xs, 0.75rem);
    color: var(--color-muted, #8B95A1);
    flex-shrink: 0;
}

.cnxb-zone-remove {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: none;
    border: none;
    color: var(--color-muted, #8B95A1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.cnxb-zone-item:hover .cnxb-zone-remove {
    opacity: 1;
}

.cnxb-zone-remove:hover {
    background: rgba(220, 80, 80, 0.12);
    color: #e07070;
}

.cnxb-zone-remove svg { width: 12px; height: 12px; }

.cnxb-zone-placeholder {
    padding: var(--space-3);
    text-align: center;
    font-size: var(--text-xs, 0.75rem);
    color: var(--color-muted, #8B95A1);
    opacity: 0.5;
    list-style: none;
}


/* ────────────────────────────────────────────────────────────
   RESPONSIVO
   ──────────────────────────────────────────────────────────── */

@media (max-width: 1100px) {
    .cnxb-builder {
        grid-template-columns: var(--cnx-col-min) 1fr var(--cnx-col-min);
    }
}

@media (max-width: 768px) {

    /* Tela 1: lista */
    .cnx-main {
        padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px) + var(--space-4));
    }

    .cnx-hero {
        flex-direction: column;
    }

    .cnx-hero-stats {
        gap: var(--space-4);
    }

    .cnx-territory-row {
        flex-wrap: wrap;
        gap: var(--space-3);
    }

    .cnx-territory-action {
        width: 100%;
        justify-content: center;
    }

    .cnx-create-form {
        flex-direction: column;
    }

    .cnx-field--sm,
    .cnx-field--xs,
    .cnx-field--grow {
        flex: 1 1 100%;
    }

    /* Tela 2: builder */
    .cnxb-main {
        height: auto;
        overflow: visible;
    }

    .cnxb-header {
        flex-wrap: wrap;
    }

    .cnxb-header-counts {
        margin-left: 0;
        width: 100%;
    }

    /* Aba visível em mobile */
    .cnxb-tab-bar {
        display: flex;
    }

    /* Builder vira empilhado; tabs controlam visibilidade */
    .cnxb-builder {
        display: flex;
        flex-direction: column;
        overflow: visible;
        height: auto;
    }

    .cnxb-col {
        display: none;
        border: none;
        overflow: visible;
    }

    .cnxb-col.is-tab-active {
        display: flex;
        min-height: 50vh;
    }

    .cnxb-col--territory.is-tab-active {
        min-height: 60vh;
    }

    .cnxb-item-list,
    .cnxb-territory-zone {
        max-height: none;
        overflow: visible;
    }

    /* Sub-colunas do território empilham em mobile */
    .cnxb-zone-cols {
        grid-template-columns: 1fr;
        overflow: visible;
    }

    .cnxb-zone-col:first-child {
        border-right: none;
        padding-right: 0;
        border-bottom: 1px solid var(--cnx-divider);
        padding-bottom: var(--space-3);
    }

    .cnxb-zone-list {
        overflow: visible;
        min-height: 48px;
    }

    /* Botão + sempre visível em mobile */
    .cnxb-item-add {
        opacity: 1;
    }

    /* Remover sempre visível em mobile */
    .cnxb-zone-remove {
        opacity: 1;
    }

    /* Padding para bottom nav */
    .cnxb-col:last-child {
        padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px) + var(--space-4));
    }
}


/* ────────────────────────────────────────────────────────────
   Busca ampliada de entidades
   ──────────────────────────────────────────────────────────── */

/* Hint do campo que gerou o match (ex.: "movimento: Romantismo") */
.cnxb-item-hint {
    display: inline-block;
    margin-left: var(--space-2);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.68rem;
    font-style: italic;
    color: var(--obs-gold-0, #D6B26D);
    background: rgba(214, 178, 109, 0.08);
    border: 1px solid rgba(214, 178, 109, 0.18);
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

/* Itens injetados pela busca servidor — separador visual sutil */
.cnxb-item--busca {
    border-left: 2px solid rgba(214, 178, 109, 0.25);
}

/* Mensagem de status (buscando… / nenhum resultado / erro) */
.cnxb-search-status {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs, 0.75rem);
    color: var(--color-muted, #8B95A1);
    list-style: none;
    font-style: italic;
}
