/* ==========================================================
   CRM PIPELINE
   Page-specific CSS
   Uses base.css / utilities.css / style.css tokens
   ========================================================== */

.crm-pipeline {
    --pipeline-column-width: 392px;
    /* Dynamic board height: follows the visible viewport instead of a fixed px height */
    --pipeline-height: calc(100dvh - 172px);

    border-radius: var(--radius-lg);
    width: 100%;
    height: var(--pipeline-height);
    min-height: 0;

    background: var(--surface);
    color: var(--text);

    overflow: hidden;
}


/* ==========================================================
   BOARD VIEWPORT
   ========================================================== */

.crm-pipeline__viewport {
    display: flex;
    flex-direction: column;

    width: 100%;
    height: 100%;
    min-height: 0;
    border-radius: var(--radius-lg);

    overflow-x: auto;
    overflow-y: hidden;

    padding: 8px 14px 12px;

    box-sizing: border-box;

    scrollbar-width: auto;
    scrollbar-color:var(--surface-3) transparent;
}

.crm-pipeline__viewport::-webkit-scrollbar {
    height: 13px;
}

.crm-pipeline__viewport::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 8px;
}

.crm-pipeline__viewport::-webkit-scrollbar-thumb {
    background: #bdbdbd;
    border-radius: 8px;
    border: 2px solid #f1f1f1;
}


/* ==========================================================
   BOARD
   ========================================================== */

.crm-pipeline__board {
    display: flex;
    align-items: stretch;

    gap: 12px;

    flex: 1 1 auto;
    min-width: max-content;
    /* Leave room for the horizontal scrollbar so column footers stay visible */
    height: calc(100% - 16px);
    max-height: calc(100% - 16px);
    min-height: 0;
}


/* ==========================================================
   COLUMN
   ========================================================== */

.crm-pipeline__column {
    position: relative;

    display: flex;
    flex-direction: column;

    flex: 0 0 var(--pipeline-column-width);

    width: var(--pipeline-column-width);
    min-width: var(--pipeline-column-width);

    height: 100%;
    min-height: 0;

    background: var(--surface-2);

    border-radius: 21px 21px 0 0;

    overflow: hidden;
}


/* ==========================================================
   COLUMN HEADER
   ========================================================== */

.crm-pipeline__column-header {
    flex-shrink: 0;
    min-height: 64px;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 2px;

    padding: 14px 12px 10px;

    box-sizing: border-box;

    text-align: center;

    color: #363636;
}

.crm-pipeline__column-header.is-draggable {
    cursor: grab;
    user-select: none;
    border-radius: 8px;
}
.crm-pipeline__column-header.is-draggable:active {
    cursor: grabbing;
}
.crm-pipeline__column.is-col-dragging {
    opacity: 0.5;
}
.crm-pipeline__column.is-col-drag-over {
    box-shadow: inset 0 0 0 2px var(--brand);
    border-radius: 10px;
}

.crm-pipeline__column-title {
    display: block;

    min-width: 0;
    max-width: 100%;

    font-size: 17px;
    line-height: 22px;
    font-weight: 700;

    letter-spacing: -.02em;

    white-space: normal;
    overflow-wrap: anywhere;
}

.crm-pipeline__count {
    margin-left: 0;
    font-size: 14px;
    line-height: 18px;
    font-weight: 600;
}

.crm-pipeline__column-total {
    font-size: 12px;
    line-height: 16px;
    font-weight: 500;
    color: var(--text, #363636);
}


/* ==========================================================
   COLUMN FOOTER (stage totals)
   ========================================================== */

.crm-pipeline__column-footer {
    flex-shrink: 0;
    z-index: 1;

    padding: 12px 14px 14px;

    border-top: 1px solid var(--border, rgba(0, 0, 0, 0.08));
    background: color-mix(in srgb, var(--surface-3, #e8e8e8) 70%, var(--surface-2));

    text-align: left;
}

.crm-pipeline__column-footer .crm-pipeline__column-total {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* ==========================================================
   COLUMN SCROLL
   ========================================================== */

.crm-pipeline__cards {
    flex: 1 1 auto;
    min-height: 0;

    padding: 0 14px 12px 12px;

    box-sizing: border-box;

    overflow-x: hidden;
    overflow-y: auto;

    scrollbar-width: auto;
    scrollbar-color:var(--surface-3) transparent;
}

.crm-pipeline__cards::-webkit-scrollbar {
    width: 12px;
}

.crm-pipeline__cards::-webkit-scrollbar-track {
    background: transparent;
}

.crm-pipeline__cards::-webkit-scrollbar-thumb {
    background: #bdbdbd;

    border-radius: 8px;

    border: 2px solid var(--surface-3);
}


/* ==========================================================
   CONTACT CARD
   ========================================================== */

.crm-pipeline__card {
    position: relative;

    width: 100%;
    min-height: 0;

    margin-bottom: 12px;

    padding: 14px 16px 12px;

    background: var(--surface);

    border: 1px solid var(--border-strong);

    border-radius: 16px;

    box-shadow: var(--shadow-sm);

    box-sizing: border-box;

    overflow: visible;
}

.crm-pipeline__card--tall {
    min-height: 0;
}


/* ==========================================================
   CONTACT NAME
   ========================================================== */

.crm-pipeline__name {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    min-height: 25px;
    margin-bottom: 8px;
    color: var(--text);
    font-size: 16px;
    line-height: 21px;
    font-weight: 700;
    letter-spacing: -.25px;
    white-space: nowrap;
}

.crm-pipeline__name > span:first-child,
.crm-pipeline__name > .crm-pipeline__deal-link {
    min-width: 0;

    overflow: hidden;
    text-overflow: ellipsis;
}

.crm-pipeline__name--email {
    font-size: 17px;
    letter-spacing: -.35px;
}


/* ==========================================================
   FIXED CLOCK ICON
   ========================================================== */

.crm-pipeline__clock {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    flex: 0 0 18px;

    width: 18px;
    height: 18px;

    color: #303030;
}

.crm-pipeline__clock svg {
    display: block;

    width: 18px !important;
    height: 18px !important;

    fill: none !important;
    stroke: currentColor !important;

    stroke-width: 1.7;

    stroke-linecap: round;
    stroke-linejoin: round;

    vector-effect: non-scaling-stroke;
}


/* ==========================================================
   CONTACT INFORMATION
   ========================================================== */

.crm-pipeline__info {
    color: var(--text-muted);
    font-size: 13px;
    line-height: 18px;
    font-weight: 400;
}
.crm-pipeline__info > div {
    white-space: nowrap;

    overflow: hidden;
    text-overflow: ellipsis;
}

.crm-pipeline__amount {
    color: var(--text);
    font-weight: 600;
}


/* ==========================================================
   DIVIDER
   ========================================================== */

.crm-pipeline__divider {
    width: 100%;
    height: 1px;

    margin: 8px 0;

    background: var(--border-strong);
}

.crm-pipeline__badges {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.crm-pipeline__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-height: 26px;
    padding: 0 10px;

    border: 1px solid var(--border-strong);
    border-radius: 999px;

    background: var(--surface-2);

    color: var(--text);
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;

    white-space: nowrap;
}

.crm-pipeline__badge:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.crm-pipeline__badge--high {
    border-color: color-mix(in srgb, #ef4444 45%, var(--border-strong));
    background: color-mix(in srgb, #ef4444 12%, var(--surface));
}

.crm-pipeline__badge--medium {
    border-color: color-mix(in srgb, #f59e0b 45%, var(--border-strong));
    background: color-mix(in srgb, #f59e0b 12%, var(--surface));
}

.crm-pipeline__badge--low {
    border-color: color-mix(in srgb, #22c55e 45%, var(--border-strong));
    background: color-mix(in srgb, #22c55e 12%, var(--surface));
}


/* ==========================================================
   COMPANY
   ========================================================== */

.crm-pipeline__company {
    display: flex;
    align-items: center;

    gap: 9px;

    min-height: 31px;

    color: #53666a;

    font-size: 14px;
    line-height: 20px;
    font-weight: 500;

    text-decoration: none;

    white-space: nowrap;
}

a.crm-pipeline__company:hover {
    color: var(--brand);
}

.crm-pipeline__company > span:last-child {
    min-width: 0;

    overflow: hidden;
    text-overflow: ellipsis;
}

.crm-pipeline__company-logo {
    display: flex;
    align-items: center;
    justify-content: center;

    flex: 0 0 31px;

    width: 31px;
    height: 31px;

    border-radius: 50%;

    background: var(--brand);

    color: #ffffff;

    font-size: 11px;
    font-weight: 700;

    overflow: hidden;
}

.crm-pipeline__company-logo img {
    width: 100%;
    height: 100%;

    object-fit: cover;
}


/* ==========================================================
   ACTIVITY BADGE
   ========================================================== */

.crm-pipeline__activity {
    display: inline-flex;
    align-items: center;
    height: 28px;
    margin-top: 0;
    padding: 0 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
}

.crm-pipeline__activity--gray {
    background: var(--surface-2);
    border-color: #999;
}


/* ==========================================================
   FIXED ACTIVITY ICON
   ========================================================== */

.crm-pipeline__activity-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    flex: 0 0 17px;

    width: 17px;
    height: 17px;

    margin-right: 7px;

    color: #333;
}

.crm-pipeline__activity-icon svg {
    display: block;

    width: 17px !important;
    height: 17px !important;

    fill: none !important;
    stroke: currentColor !important;

    stroke-width: 1.7;

    stroke-linecap: round;
    stroke-linejoin: round;

    vector-effect: non-scaling-stroke;
}

.crm-pipeline__activity-divider {
    width: 1px;
    height: 20px;

    margin: 0 9px;

    background: #777;
}

.crm-pipeline__warning {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 17px;
    height: 17px;

    border: 1px solid var(--border);
    border-radius: 50%;

    color:var(--text-border);

    font-size: 11px;
    line-height: 1;
    font-weight: 700;
}


/* ==========================================================
   BOTTOM ACTIONS
   ========================================================== */

.crm-pipeline__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;

    gap: 20px;

    height: 31px;

    margin-top: 5px;
}

.crm-pipeline__action {
    position: relative;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    flex: 0 0 20px;

    width: 20px;
    height: 20px;

    padding: 0;

    color: #777;

    background: transparent;
    border: 0;
    border-radius: 4px;

    cursor: pointer;

    transition:
        color .15s ease,
        background-color .15s ease,
        transform .15s ease;
}

.crm-pipeline__action:hover {
    color: #303030;
    background: var(--surface-hover);

    transform: translateY(-1px);
}

.crm-pipeline__action:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.crm-pipeline__action svg {
    display: block;

    width: 18px !important;
    height: 18px !important;

    fill: none !important;
    stroke: currentColor !important;

    stroke-width: 1.55;

    stroke-linecap: round;
    stroke-linejoin: round;

    vector-effect: non-scaling-stroke;
}


/* ==========================================================
   GLOBAL PIPELINE SVG SAFETY
   Prevents base/browser fill from creating black squares/dots
   ========================================================== */

.crm-pipeline svg {
    max-width: none;

    fill: none !important;
    stroke: currentColor !important;
}


/* ==========================================================
   HOVER POPOVER
   ========================================================== */

.crm-pipeline__popover {
    position: fixed;

    z-index: 120;

    width: max-content;
    max-width: 240px;

    padding: 6px 10px;

    background: var(--text);
    color: var(--bg);

    border-radius: 6px;

    font-size: 12px;
    line-height: 17px;
    font-weight: 600;

    white-space: nowrap;

    box-shadow: var(--shadow);

    pointer-events: none;

    opacity: 0;

    transform: translateY(3px);

    transition:
        opacity var(--fast) var(--ease),
        transform var(--fast) var(--ease);
}

.crm-pipeline__popover.is-visible {
    opacity: 1;
    transform: translateY(0);
}


/* ==========================================================
   DARK THEME
   ========================================================== */

[data-theme="dark"] .crm-pipeline__column-header {
    color: var(--text);
}

[data-theme="dark"] .crm-pipeline__column-footer {
    border-top-color: var(--border);
    background: color-mix(in srgb, var(--surface) 55%, var(--surface-2));
}

[data-theme="dark"] .crm-pipeline__column-total {
    color: var(--text);
}

[data-theme="dark"] .crm-pipeline__clock,
[data-theme="dark"] .crm-pipeline__activity-icon {
    color: var(--text-muted);
}

[data-theme="dark"] .crm-pipeline__company {
    color: var(--text-muted);
}

[data-theme="dark"] a.crm-pipeline__company:hover {
    color: var(--brand);
}

[data-theme="dark"] .crm-pipeline__badge {
    background: var(--surface-2);
    border-color: var(--border-strong);
    color: var(--text);
}

[data-theme="dark"] .crm-pipeline__activity {
    background: var(--surface-2);
    border-color: var(--border-strong);
}

[data-theme="dark"] .crm-pipeline__activity-divider {
    background: var(--border-strong);
}

[data-theme="dark"] .crm-pipeline__action {
    color: var(--text-subtle);
}

[data-theme="dark"] .crm-pipeline__action:hover {
    color: var(--text);
    background: var(--surface-hover);
}


/* ==========================================================
   MOBILE
   ========================================================== */

@media (max-width: 767.98px) {

    .crm-pipeline {
        /* Slightly smaller surrounding UI on phones */
        --pipeline-height: calc(100dvh - 120px);
        min-height: 0;
    }

    .crm-pipeline__viewport {
        min-height: 0;

        padding-left: 8px;
        padding-right: 8px;
    }

    .crm-pipeline__column {
        --pipeline-column-width: 330px;

        width: 330px;
        min-width: 330px;
    }

    .crm-pipeline__card {
        padding-left: 14px;
        padding-right: 14px;
    }

    .crm-pipeline__name {
        font-size: 18px;
    }

    .crm-pipeline__info {
        font-size: 14px;
    }

    .crm-pipeline__company {
        font-size: 15px;
    }

    .crm-pipeline__activity {
        font-size: 14px;
    }
}