/* =========================================================
   VISITORS — PRIMARY STYLES
   ========================================================= */

/* layout */
.layout-visitors {
    display: flex;
}

.layout-visitors .visitors-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* main card */
.visitors-card {
    padding: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* list wrapper */
.visitors-table {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* list row */
.visitors-row {
    display: grid;
    grid-template-columns:
        32px 56px minmax(110px, 0.7fr) 90px minmax(260px, 1.8fr) 95px 82px 36px;
    align-items: center;
    padding: 8px 0;
    font-size: 13px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.visitors-row div:nth-child(5) {
    padding-left: clamp(6px, 1vw, 18px);
}

.visitors-row div:nth-child(6) {
    overflow: visible;
    text-overflow: clip;
    white-space: nowrap;
    position: relative;
    z-index: 2;
}

.visitors-row div:nth-child(7) {
    position: relative;
    z-index: 3;
    background: #fff;
}


/* HEADER i BODY muszą mieć tę samą geometrię */
.visitors-header,
.visitors-body .visitors-row {
    border-left: 3px solid transparent;
    box-sizing: border-box;
}

/* kolumna Online — header i body jako grid item */
.visitors-header div:nth-child(4),
.visitors-body .visitors-row div:nth-child(4) {
    justify-self: center;
}

/* kolumna Aktualna strona + Źródło */
.visitors-row div:nth-child(5),
.visitors-row div:nth-child(6) {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.visitors-row .visitors-badge {
    min-width: 50px;
    justify-content: center;
}


/* tylko dane (body) */
.visitors-body .visitors-row div:last-child {
    text-align: center;
}

/* list header */
.visitors-header {
    font-weight: 500;
    font-size: 12px;
    color: var(--text-secondary);
    border-bottom: 1px solid #e5e7eb;
}

.visitors-header div:nth-child(4) {
    text-align: center;
}

.visitors-header div:nth-child(7),
.visitors-header div:nth-child(8) {
    text-align: center;
}


/* list body */
.visitors-body {
    overflow-y: auto;
    flex: 1;
}

.visitors-body .visitors-row {
    border-bottom: 1px solid #f1f1f3;
    cursor: pointer;
    transition: background 0.15s ease;
    border-left: 3px solid transparent;
}

.visitors-body .visitors-row:hover {
    background: #f3f4f6;
}

.visitors-body .visitors-row.active {
    border-left-color: #1565C0;
}



/* ==== CONTEXT ==== */
.context-visitors-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.context-visitors-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    overflow: visible;
}


/* =========================================================
   GLOBAL — BADGE / SVG
   ========================================================= */

/* badge base */
.visitors-badge,
.context-intent-badge,
.vi-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;

    height: 22px;
    min-width: 50px;
    padding: 0 10px;

    border-radius: 8px;

    font-size: 12px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
}

/* badge svg base */
.visitors-badge svg,
.context-intent-badge svg,
.vi-badge svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    flex-shrink: 0;
}

/* neutral badge colors */
.visitors-badge,
.context-intent-badge,
.vi-badge {
    background: #f3f4f6;
    color: #111827;
}

/* semantic badge colors */
.visitors-badge-online,
.context-intent-checkout,
.vi-badge-checkout {
    background: #dbeafe;
    color: #1565C0;
}

.visitors-badge-warning,
.context-intent-cart,
.vi-badge-cart {
    background: #fef3c7;
    color: #92400e;
}

.visitors-badge-muted {
    background: #f3f4f6;
    color: #6b7280;
}

.visitors-badge-success,
.context-intent-client,
.vi-badge-client {
    background: #dcfce7;
    color: #15803d;
}

/* base svg */
.visitors-row svg,
.visitors-live svg,
.visitors-identity-icon svg,
.context-intent-badge svg {
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}



/* ==== VISITORS BADGE SYSTEM ==== */

/* semantic variants */
.visitors-badge-online {
    background: #dbeafe;
    color: #1565C0;
}

.visitors-badge-warning {
    background: #fef3c7;
    color: #b45309;
}

.visitors-badge-muted {
    background: #f3f4f6;
    color: #6b7280;
}

.visitors-badge-success {
    background: #dcfce7;
    color: #15803d;
}

/* context intent: kolor tła semantyczny, treść czarna */
.visitors-badge-context {
    color: #111827;
}

.visitors-badge-cart {
    background: #fef3c7;
    color: #92400e;
}

.visitors-badge-checkout {
    background: #dbeafe;
    color: #1d4ed8;
}

.visitors-badge-client {
    background: #dcfce7;
    color: #166534;
}

/* ===== compatibility aliases — current HTML/JS ===== */



.context-intent-cart {
    background: #fef3c7;
    color: #92400e;
}

.context-intent-checkout {
    background: #dbeafe;
    color: #1d4ed8;
}

.context-intent-client {
    background: #dcfce7;
    color: #166534;
}

/* old list intent badge */


.vi-badge-cart {
    background: #fef3c7;
    color: #d97706;
}

.vi-badge-checkout {
    background: #dbeafe;
    color: #1565C0;
}

.vi-badge-client {
    background: #dcfce7;
    color: #15803d;
}


/* chat state */
.visitors-chat-state {
    width: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.visitors-chat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.visitors-chat-svg-filled {
    width: 22px;
    height: 22px;
}

.visitors-chat-icon-pending .visitors-chat-svg-filled {
    fill: #22c55e;
}

.visitors-chat-icon-human .visitors-chat-svg-filled {
    fill: #22c55e;
}

.visitors-chat-svg-ai {
    width: 23px;
    height: 23px;
}

.layout-visitors .visitors-chat-state svg {
    transform: scaleX(-1);
}

.visitors-chat-ai-base {
    fill: var(--chat-bg-ai);
}

.visitors-chat-ai-detail {
    fill: none;
    stroke: var(--chat-bg-ai-dark);
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.visitors-chat-ai-eye {
    fill: #ffffff;
    stroke-width: 1.4;
}




/* ==== identity contact ==== */
.visitors-id {
    font-size: 13px;
}

/* header */
.visitors-identity-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.visitors-identity-header .visitors-identity-avatar {
    flex-shrink: 0;
}

.visitors-identity-header .visitors-identity-text {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
}

/* main */
.visitors-identity-main {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* badges */
.visitors-identity-badges {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.visitors-identity-badges .visitors-badge {
    width: auto;
    justify-content: center;
}

.visitors-identity-badges .visitors-badge-status {
    min-width: 90px;
}

.visitors-identity-badges .visitors-badge-visits {
    min-width: 70px;
}

/* contact */
.visitors-identity-contact {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 0;
}

.visitors-identity-field {
    display: flex;
    align-items: center;
    gap: 8px;
}

.visitors-identity-field:focus-within {
    background: #f3f4f6;
}

.visitors-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.visitors-icon svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2.0;
    fill: none;
}

.visitors-identity-input {
    flex: 1;
    height: 26px;
    padding: 0 8px;

    border: 1px solid transparent;
    border-radius: 5px;

    font-size: 11px;
    background: transparent;
    color: #111827;

    box-sizing: border-box;
}

.visitors-identity-input::placeholder {
    color: #9ca3af;
    font-size: 11px;
}

.visitors-identity-input:focus {
    outline: none;
    border-color: #e5e7eb;
    background: #fff;
}

.visitors-identity-input:not(:placeholder-shown) {
    background: #f9fafb;
    border-color: #e5e7eb;
}

.visitors-identity-field:hover {
    background: #f9fafb;
    border-radius: 6px;
}







/* ==== actions ==== */
.visitors-actions {
    display: flex;
    gap: 8px;
}

.visitors-btn {
    border: none;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 12px;
    cursor: pointer;

    min-width: 140px;
    justify-content: center;
    display: inline-flex;
}

.visitors-btn-primary {
    background: var(--accent);
    color: #fff;
}

.visitors-btn-secondary {
    background: #f3f4f6;
    color: #111827;
}

.visitors-btn-tag {
    min-width: 90px;
}




/* ==== activity ==== */
.visitors-live {
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 13px;
}

/* top */
.visitors-live-location {
    font-weight: 600;
    margin-bottom: 4px;
}

/* BLOKI */
.visitors-live-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 6px;
}

/* LABEL */
.visitors-live .label {
    font-size: 11px;
    color: var(--text-secondary);
}

/* VALUE */
.visitors-live .value {
    font-size: 11px;
}

/* LINK */
.visitors-live .link a {
    color: #2563eb;
    text-decoration: none;
    word-break: break-word;
}

.visitors-live .link a:hover {
    text-decoration: underline;
}

/* STRONG */
.visitors-live .strong {
    font-weight: 600;
}

/* LISTA */
.visitors-live-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ROW */
.visitors-live-row {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    opacity: 0.85;
}

/* TITLE */
.visitors-live-row .title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 70%;
}

.visitors-live-row .title.active {
    font-weight: 600;
    color: #111;
}

/* TIME */
.visitors-live-row .time {
    opacity: 0.6;
    flex-shrink: 0;
}

.visitors-visits {
    text-align: center;
}


/* ==== CRM ==== */
.visitors-crm {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.visitors-crm-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.visitors-crm-label {
    font-size: 11px;
    color: var(--text-secondary);
}

.visitors-crm-value,
.visitors-crm-tags {
    font-size: 13px;
    color: #111827;
}

.visitors-crm-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;

    min-height: 22px;
    /* wysokość badge */
    align-items: center;
}

.visitors-crm-empty {
    color: #9ca3af;
    font-size: 12px;
}

.visitors-crm-textarea {
    width: 100%;
    min-height: 70px;

    padding: 10px 12px;

    border: 1px solid #e5e7eb;
    border-radius: 8px;

    font-size: 11px;
    line-height: 1.4;

    background: #f9fafb;
    color: #111827;

    resize: vertical;
    box-sizing: border-box;
}

.visitors-crm-textarea:focus {
    outline: none;
    border-color: #d1d5db;
    background: #ffffff;
}

/* ==== crm tag input ==== */
.visitors-crm-tag-input {
    width: 100%;
    height: 28px;
    padding: 0 10px;

    border: 1px solid #e5e7eb;
    border-radius: 5px;

    font-size: 11px;
    background: #f9fafb;
    color: #111827;

    box-sizing: border-box;
}

.visitors-crm-tag-input::placeholder {
    color: #9ca3af;
    font-size: 11px;
}

.visitors-crm-tag-input:focus {
    outline: none;
    border-color: #d1d5db;
    background: #ffffff;
}

.visitors-tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.visitors-tag-remove {
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    opacity: 0.6;
}

.visitors-tag-remove:hover {
    opacity: 1;
}



/* ==== technical ==== */
.visitors-technical-ip {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
}

.visitors-tech {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.visitors-tech-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.visitors-tech-value {
    font-size: 12px;
    color: #111827;
    line-height: 1.2;
}




/* ==== Intetntion ==== */
.visitors-intent {
    display: flex;
    justify-content: center;
    align-items: center;
}

.visitors-intent .visitors-badge svg {
    width: 13px;
    height: 13px;
    stroke-width: 2.2;
}


/* =========================================================
   SHARED CONTEXT BOXES
   ========================================================= */
.context {
    overflow-y: auto;
    height: 100%;
}

.context-box {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
}

.context-box-header {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
}

.context-box-heading {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.context-box-heading h4 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
}

.context-box-description {
    margin: 2px 0 0 0;
    font-size: 10px;
    color: var(--text-secondary);
}

.context-box-body {
    padding: 12px;
    font-size: 13px;
    overflow: visible;
}

.context-box-toggle {
    border: none;
    background: transparent;
    font-size: 14px;
    cursor: pointer;
    color: var(--text-secondary);
}

.context-box-toggle:hover {
    color: var(--text-primary);
}

.context-box.collapsed .context-box-body {
    display: none;
}

.context-box-ghost {
    opacity: 0.4;
}

.context-drag-handle {
    cursor: grab;
    font-size: 12px;
    color: #9ca3af;
    margin-right: 8px;
    flex-shrink: 0;
}

.context-drag-handle:hover {
    color: #374151;
}


/* =========================================================
   VISITORS — EXTRA SMALL MOBILE <400
   ========================================================= */

@media (max-width: 399px) {

    .layout-visitors .visitors-row div:nth-child(8) {
        display: none !important;
    }

}


/* =========================================================
   VISITORS — MOBILE <768
   ========================================================= */

@media (max-width: 767px) {

    .layout-visitors .visitors-header {
        display: none;
    }


    .layout-visitors .visitors-row {
        grid-template-columns:
            48px minmax(90px, 1fr) auto;

        grid-template-rows: auto auto;
        column-gap: 8px;
        row-gap: 4px;

        padding: 10px 8px;
        align-items: center;

        position: relative;
    }


    .layout-visitors .visitors-row div:nth-child(2) {
        grid-column: 1;
        grid-row: 1 / span 2;
        position: relative;
    }

    .layout-visitors .visitors-chat-state {
        display: flex;

        position: absolute;

        top: 8px;
        left: 1px;

        width: 14px;
        height: 14px;

        border-radius: 50%;
        background: #ffffff;

        align-items: center;
        justify-content: center;

        z-index: 5;
    }


    .layout-visitors .visitors-row div:nth-child(3) {
        grid-column: 2;
        grid-row: 1;
        font-weight: 600;
    }

    .layout-visitors .visitors-row div:nth-child(4) {
        grid-column: 3;
        grid-row: 1;
        justify-self: end;
        align-self: center;
    }

    .layout-visitors .visitors-row div:nth-child(5) {
        grid-column: 2;
        grid-row: 2;

        padding-left: 0;
        color: #64748B;
        font-size: 12px;

        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .layout-visitors .visitors-row div:nth-child(6) {
        display: none;
    }

    .layout-visitors .visitors-row div:nth-child(7) {
        display: none;
    }


    .layout-visitors .visitors-row div:nth-child(8) {
        grid-column: 3;
        grid-row: 1;
        justify-self: end;
        align-self: start;

        transform: translateX(-75px);

        display: inline-flex;
        align-items: center;
        justify-content: center;

        height: 22px;
        min-width: 34px;
        padding: 0 8px;

        border-radius: 8px;
        background: #f3f4f6;
        color: #64748B;

        font-size: 11px;
        font-weight: 600;
    }
}


/* =========================================================
   VISITORS — TABLET 768–1023
   ========================================================= */

@media (min-width: 768px) and (max-width: 1023px) {

    .layout-visitors .visitors-header {
        display: none;
    }

    .layout-visitors .visitors-row {
        grid-template-columns:
            24px 56px minmax(110px, 1fr) auto;
        grid-template-rows: auto auto;
        column-gap: 8px;
        row-gap: 4px;

        padding: 10px 8px;
        align-items: center;
    }

    .layout-visitors .visitors-row div:nth-child(1) {
        grid-column: 1;
        grid-row: 1 / span 2;
    }

    .layout-visitors .visitors-row div:nth-child(2) {
        grid-column: 2;
        grid-row: 1 / span 2;
    }

    .layout-visitors .visitors-row div:nth-child(3) {
        grid-column: 3;
        grid-row: 1;
        font-weight: 600;
    }

    .layout-visitors .visitors-row div:nth-child(4) {
        grid-column: 4;
        grid-row: 2;
        justify-self: end;
        align-self: start;
    }

    .layout-visitors .visitors-row div:nth-child(5) {
        grid-column: 3;
        grid-row: 2;

        color: #64748B;
        font-size: 12px;

        padding-left: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .layout-visitors .visitors-row div:nth-child(6) {
        display: none;
    }

    .layout-visitors .visitors-row div:nth-child(7) {
        grid-column: 4;
        grid-row: 1;
        justify-self: end;
        align-self: end;
    }

    .layout-visitors .visitors-row div:nth-child(7) .visitors-badge {
        min-width: 92px;
    }

    .layout-visitors .visitors-row div:nth-child(8) {
        grid-column: 4;
        grid-row: 2;
        justify-self: end;
        align-self: start;

        transform: translateX(-75px);

        display: inline-flex;
        align-items: center;
        justify-content: center;

        height: 22px;
        min-width: 34px;
        padding: 0 8px;

        border-radius: 8px;
        background: #f3f4f6;
        color: #64748B;

        font-size: 11px;
        font-weight: 600;
    }

}


/* =========================================================
   VISITORS — LAPTOP NARROW (1024–1120)
   ========================================================= */

@media (min-width: 1024px) and (max-width: 1120px) {

    .layout-visitors .visitors-row {
        grid-template-columns:
            32px 56px minmax(95px, 0.55fr)
            /* Gość */
            80px
            /* Online */
            minmax(180px, 1.2fr)
            /* Aktualna strona */
            90px
            /* Źródło */
            82px
            /* Intencja */
            32px;
        /* Wizyty */
    }

}