/*
 * Team history — final visual layer.
 * This file intentionally overrides the generic history styles so the live UI
 * follows the approved mockup: entity first, status second, details compact,
 * funnel and next step as subordinate blocks.
 */

.history-card-v2 { background: #fff; }

/* ---------- filters ---------- */
.history-filters-v2 { border-bottom: 1px solid var(--line); }
.history-advanced-filter { border-top: 1px solid #ece9f5; }
.history-advanced-filter > summary {
    min-height: 38px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 7px;
    color: #6a728a;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}
.history-advanced-filter > summary::-webkit-details-marker { display: none; }
.history-advanced-filter > summary::before {
    content: "⌄";
    color: var(--violet);
    font-size: 15px;
    line-height: 1;
    transition: transform .15s ease;
}
.history-advanced-filter[open] > summary::before { transform: rotate(180deg); }
.history-advanced-filter:not([open]) .custom-period { display: none; }

/* ---------- day/timeline ---------- */
.history-day-group { margin-top: 14px; }
.history-day-heading {
    gap: 10px;
    margin: 0 0 3px;
    color: #303752;
    font-size: 12px;
    font-weight: 700;
}
.history-timeline-v2 { padding-top: 0; }
.history-timeline-v2 .history-event {
    grid-template-columns: 78px 14px minmax(0, 1fr);
    gap: 10px;
    padding-top: 10px;
}
.history-timeline-v2 .history-event:not(:last-child)::after {
    top: 27px;
    bottom: -11px;
    left: 84px;
}
.history-timeline-v2 .history-event-time {
    padding-top: 1px;
    font-size: 12px;
    text-align: right;
}

/* Timeline marker reflects state. Entity identity stays in the square icon. */
.history-timeline-v2 .history-event.history-type-action.history-state-completed .history-dot {
    border-color: #d8f4e4;
    background: #18ad5d;
}
.history-timeline-v2 .history-event.history-type-action.history-state-rescheduled .history-dot {
    border-color: #ffead0;
    background: #ff8a00;
}
.history-timeline-v2 .history-event.history-type-action.history-state-cancelled .history-dot {
    border-color: #ffe4e9;
    background: #d9415c;
}
.history-timeline-v2 .history-event.history-type-action.history-state-paused .history-dot {
    border-color: #e7eaf0;
    background: #69718a;
}
.history-timeline-v2 .history-event.history-type-contact .history-dot {
    border-color: #ddecff;
    background: #2682ee;
}
.history-timeline-v2 .history-event.history-type-funnel.history-funnel-business .history-dot {
    border-color: #d5f2f4;
    background: #0aa1ad;
}
.history-timeline-v2 .history-event.history-type-funnel.history-funnel-product .history-dot {
    border-color: #e9e2ff;
    background: #7651db;
}

/* ---------- event card ---------- */
.history-timeline-v2 .history-event-card {
    padding: 11px 13px 12px;
    border: 1px solid #e2e4ee;
    border-radius: 10px;
    background: #fff;
}
.history-contact-row-v2 {
    margin: 0 0 5px 40px;
    line-height: 1.15;
}
.history-contact-inline {
    display: inline-block;
    max-width: 360px;
    overflow: hidden;
    color: #33206f;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.history-contact-inline:hover { color: var(--violet); }

.history-primary-row {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    align-items: start;
    gap: 10px;
}
.history-entity-icon {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 8px;
}
.history-type-action .history-entity-icon {
    background: #f0ebff;
    color: #6845df;
}
.history-type-contact .history-entity-icon {
    background: #eaf3ff;
    color: #267eea;
}
.history-type-funnel.history-funnel-business .history-entity-icon {
    background: #e6f8fa;
    color: #0a929d;
}
.history-type-funnel.history-funnel-product .history-entity-icon,
.history-type-funnel:not(.history-funnel-business) .history-entity-icon {
    background: #f0ebff;
    color: #7651db;
}
.history-entity-icon svg {
    width: 17px;
    height: 17px;
    display: block;
}
.history-primary-copy { min-width: 0; }
.history-kicker-row {
    min-height: 20px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}
.history-entity-name {
    color: #6845df;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .035em;
    text-transform: uppercase;
}
.history-type-contact .history-entity-name { color: #267eea; }
.history-type-funnel.history-funnel-business .history-entity-name { color: #0a929d; }
.history-type-funnel.history-funnel-product .history-entity-name { color: #7651db; }
.history-funnel-chip {
    min-height: 19px;
    padding: 2px 7px;
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    font-size: 9px;
    font-weight: 600;
    line-height: 1;
}
.funnel-chip-product { background: #eee9ff; color: #6d49d3; }
.funnel-chip-business { background: #def6f7; color: #087f89; }
.funnel-chip-generic { background: #eef1f6; color: #68718a; }

.history-event-heading {
    display: block;
    margin-top: 2px;
    color: #10162b;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.25;
}

/* ---------- status badge: same anatomy for every action state ---------- */
.history-status-badge {
    min-height: 22px;
    padding: 2px 8px 2px 4px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border-radius: 999px;
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}
.history-status-orb {
    width: 15px;
    height: 15px;
    display: inline-grid;
    place-items: center;
    flex: 0 0 15px;
    border-radius: 50%;
    color: #fff;
}
.history-status-orb svg {
    width: 10px;
    height: 10px;
    display: block;
}
.history-status-badge.status-completed { background: #e5f8ed; color: #078a45; }
.history-status-badge.status-completed .history-status-orb { background: #19ad5c; }
.history-status-badge.status-rescheduled { background: #fff0dc; color: #b96200; }
.history-status-badge.status-rescheduled .history-status-orb { background: #ff8900; }
.history-status-badge.status-cancelled { background: #ffe9ed; color: #c93c55; }
.history-status-badge.status-cancelled .history-status-orb { background: #d9415c; }
.history-status-badge.status-paused { background: #eef1f6; color: #5d667d; }
.history-status-badge.status-paused .history-status-orb { background: #69718a; }
.history-status-badge.status-planned { background: #eee9ff; color: #6d49d3; }
.history-status-badge.status-planned .history-status-orb { background: #7651db; }
.history-status-badge.status-created { background: #eee9ff; color: #6d49d3; }
.history-status-badge.status-created .history-status-orb { background: #7651db; }
.history-status-badge.status-changed { background: #eee9ff; color: #6d49d3; }
.history-status-badge.status-changed .history-status-orb { background: #7651db; }
.history-status-badge.status-resumed { background: #e5f8f9; color: #087f89; }
.history-status-badge.status-resumed .history-status-orb { background: #0a9ba6; }
.history-status-badge.status-attempt { background: #eef1f6; color: #5d667d; }
.history-status-badge.status-attempt .history-status-orb { background: #69718a; }

/* ---------- compact metadata row ---------- */
.history-timeline-v2 .history-action-details {
    margin: 6px 0 0 40px;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 5px 0;
}
.history-timeline-v2 .history-action-details > div {
    position: relative;
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding-right: 17px;
    margin-right: 16px;
}
.history-timeline-v2 .history-action-details > div:not(:last-child)::after {
    position: absolute;
    right: 0;
    top: 2px;
    width: 1px;
    height: 13px;
    background: #dddfea;
    content: "";
}
.history-timeline-v2 .history-action-details dt {
    color: #75809c;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}
.history-timeline-v2 .history-action-details dd {
    margin: 0;
    color: #27304b;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.35;
}
.history-open-contact {
    margin: 7px 0 0 40px;
    color: #7256c7;
    font-size: 12px;
    font-weight: 600;
}
.history-no-next-step {
    margin: 7px 0 0 40px;
    color: var(--muted);
    font-size: 11px;
}

/* ---------- embedded funnel ---------- */
.history-funnel-panel {
    --funnel-color: #7651db;
    --funnel-soft: #f2edff;
    margin: 8px 0 0 40px;
    border: 1px solid #dcd4fa;
    border-radius: 8px;
    background: #faf9ff;
}
.history-funnel-panel.funnel-tone-business {
    --funnel-color: #0c9aa6;
    --funnel-soft: #e7f8fa;
    border-color: #cbeaec;
    background: #f7fcfc;
}
.history-funnel-panel.is-embedded {
    width: min(100%, 860px);
    padding: 8px 10px 7px;
}
.history-funnel-layout {
    display: grid;
    grid-template-columns: minmax(220px, 300px) minmax(260px, 420px);
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}
.history-funnel-summary { min-width: 0; }
.history-funnel-label {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}
.history-funnel-icon {
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
    flex: 0 0 22px;
    border-radius: 7px;
    background: var(--funnel-soft);
    color: var(--funnel-color);
}
.history-funnel-icon svg { width: 13px; height: 13px; }
.history-funnel-kicker {
    color: var(--funnel-color);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .035em;
    text-transform: uppercase;
}
.history-funnel-kind {
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--funnel-soft);
    color: var(--funnel-color);
    font-size: 9px;
    font-weight: 700;
}
.history-funnel-transition-line {
    margin: 5px 0 0 28px;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 5px;
    color: #66708a;
    font-size: 11px;
}
.history-funnel-transition-line b { color: #27304b; }
.history-funnel-transition-line i {
    color: var(--funnel-color);
    font-style: normal;
    font-weight: 700;
}
.history-funnel-visual { min-width: 0; }

/* ---------- data-driven funnel track ---------- */
.compact-funnel-track {
    width: min(100%, 400px);
    max-width: 400px;
    height: 38px;
    margin: 5px auto 0;
    padding: 0 4px;
    display: flex;
    align-items: flex-start;
}
.compact-funnel-step {
    position: relative;
    min-width: 0;
    flex: 1 1 0;
    display: flex;
    justify-content: center;
}
.compact-funnel-step::before {
    position: absolute;
    top: 6px;
    right: 50%;
    left: -50%;
    height: 1.5px;
    background: #d9ddea;
    content: "";
}
.compact-funnel-step:first-child::before { display: none; }
.compact-funnel-step.is-reached::before { background: color-mix(in srgb, var(--funnel-color) 58%, white); }
.compact-funnel-dot {
    position: relative;
    z-index: 2;
    width: 7px;
    height: 7px;
    margin-top: 3px;
    border: 2px solid #c7ccdc;
    border-radius: 50%;
    background: #fff;
    box-sizing: border-box;
}
.compact-funnel-step.is-reached .compact-funnel-dot { border-color: color-mix(in srgb, var(--funnel-color) 62%, white); }
.compact-funnel-step.is-old .compact-funnel-dot {
    width: 11px;
    height: 11px;
    margin-top: 1px;
    border-color: var(--funnel-color);
    background: var(--funnel-color);
}
.compact-funnel-step.is-current .compact-funnel-dot {
    width: 13px;
    height: 13px;
    margin-top: 0;
    border: 3px solid var(--funnel-color);
    background: #fff;
    box-shadow: 0 0 0 3px var(--funnel-soft);
}
.compact-funnel-arrow {
    position: absolute;
    z-index: 4;
    top: -5px;
    left: -11px;
    padding: 0 2px;
    background: #faf9ff;
    color: var(--funnel-color);
    font-size: 18px;
    font-style: normal;
    font-weight: 700;
    line-height: 1;
}
.funnel-tone-business .compact-funnel-arrow { background: #f7fcfc; }
.compact-funnel-stage-label {
    position: absolute;
    top: 19px;
    max-width: 105px;
    overflow: hidden;
    color: #414a66;
    font-size: 9px;
    font-style: normal;
    font-weight: 600;
    line-height: 1.1;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.compact-funnel-step.is-current .compact-funnel-stage-label { color: var(--funnel-color); }
.compact-funnel-mobile-summary { display: none; }

/* ---------- standalone funnel event ---------- */
.history-funnel-panel.is-standalone {
    width: min(100%, 760px);
    margin-top: 6px;
    padding: 7px 10px 5px;
}
.history-funnel-standalone-layout {
    display: grid;
    grid-template-columns: minmax(260px, 420px) minmax(180px, 1fr);
    align-items: center;
    gap: 16px;
}
.history-funnel-panel.is-standalone .compact-funnel-track {
    margin-left: 0;
    margin-right: 0;
}
.history-funnel-standalone-copy {
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: flex-end;
    gap: 5px;
    color: #66708a;
    font-size: 10px;
}
.history-funnel-standalone-copy b { color: #27304b; }
.history-funnel-standalone-copy i {
    color: var(--funnel-color);
    font-style: normal;
    font-weight: 700;
}

/* ---------- next step ---------- */
.history-next-step {
    width: min(100%, 860px);
    margin: 7px 0 0 40px;
    padding: 7px 9px;
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    border: 1px solid #dfdaf2;
    border-radius: 8px;
    background: #fbfaff;
}
.history-next-icon {
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border-radius: 7px;
    background: #f0ebff;
    color: #6845df;
}
.history-next-icon svg { width: 15px; height: 15px; }
.history-next-copy { min-width: 0; }
.history-next-label {
    display: block;
    color: #7256c7;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .035em;
    text-transform: uppercase;
}
.history-next-main {
    margin-top: 2px;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 5px 16px;
}
.history-next-main > strong {
    color: #17203a;
    font-size: 12px;
}
.history-next-prefix { font-weight: 600; }
.history-next-main time {
    color: #56607c;
    font-size: 10px;
}
.history-next-details { margin: 5px 0 0 !important; }

.history-details-after-funnel {
    width: min(100%, 760px);
    margin: 6px 0 0 40px !important;
}
.history-details-after-funnel > div {
    grid-template-columns: 120px minmax(0, 1fr) !important;
}

@media (max-width: 980px) {
    .history-funnel-layout {
        grid-template-columns: minmax(190px, 270px) minmax(230px, 360px);
        gap: 12px;
    }
    .compact-funnel-track { max-width: 350px; }
    .history-funnel-standalone-layout {
        grid-template-columns: minmax(230px, 350px) minmax(150px, 1fr);
    }
}

@media (max-width: 720px) {
    .history-advanced-filter > summary {
        min-height: 34px;
        padding: 0 10px;
        font-size: 11px;
    }

    .history-timeline-v2 { padding: 0 10px 14px; }
    .history-day-group { margin-top: 12px; }
    .history-day-heading { font-size: 12px; }
    .history-timeline-v2 .history-event {
        grid-template-columns: 12px minmax(0, 1fr);
        gap: 4px 8px;
        padding-top: 9px;
    }
    .history-timeline-v2 .history-event:not(:last-child)::after {
        top: 24px;
        bottom: -10px;
        left: 5px;
    }
    .history-timeline-v2 .history-event-time {
        grid-column: 2;
        grid-row: 1;
        padding: 0;
        font-size: 10px;
        text-align: left;
    }
    .history-timeline-v2 .history-dot {
        grid-column: 1;
        grid-row: 1 / span 2;
        width: 8px;
        height: 8px;
        margin-top: 1px;
        border-width: 2px;
    }
    .history-timeline-v2 .history-event-card {
        grid-column: 2;
        grid-row: 2;
        padding: 9px 10px 10px;
    }

    .history-contact-row-v2 { margin: 0 0 4px 35px; }
    .history-contact-inline {
        max-width: 70vw;
        font-size: 11px;
    }
    .history-primary-row {
        grid-template-columns: 27px minmax(0, 1fr);
        gap: 8px;
    }
    .history-entity-icon {
        width: 27px;
        height: 27px;
    }
    .history-entity-icon svg { width: 15px; height: 15px; }
    .history-kicker-row {
        min-height: 18px;
        gap: 4px;
    }
    .history-entity-name { font-size: 8px; }
    .history-funnel-chip {
        min-height: 17px;
        padding: 2px 5px;
        font-size: 8px;
    }
    .history-status-badge {
        min-height: 19px;
        padding: 2px 6px 2px 3px;
        gap: 4px;
        font-size: 8px;
    }
    .history-status-orb {
        width: 13px;
        height: 13px;
        flex-basis: 13px;
    }
    .history-status-orb svg { width: 8px; height: 8px; }
    .history-event-heading { font-size: 13px; }

    .history-timeline-v2 .history-action-details,
    .history-open-contact,
    .history-funnel-panel,
    .history-next-step,
    .history-no-next-step,
    .history-details-after-funnel {
        margin-left: 0 !important;
    }
    .history-timeline-v2 .history-action-details {
        margin-top: 6px;
        display: grid;
        gap: 3px;
    }
    .history-timeline-v2 .history-action-details > div {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        gap: 5px;
        padding: 0;
        margin: 0;
    }
    .history-timeline-v2 .history-action-details > div::after { display: none !important; }
    .history-timeline-v2 .history-action-details dt { font-size: 9px; }
    .history-timeline-v2 .history-action-details dd { font-size: 11px; }

    .history-funnel-panel.is-embedded,
    .history-funnel-panel.is-standalone {
        width: 100%;
        margin-top: 6px;
        padding: 7px;
    }
    .history-funnel-layout,
    .history-funnel-standalone-layout {
        display: block;
    }
    .history-funnel-transition-line { margin-left: 28px; font-size: 10px; }
    .history-funnel-visual { margin-top: 5px; }
    .history-funnel-standalone-copy { display: none; }
    .compact-funnel-track {
        width: min(100%, 285px);
        max-width: 285px;
        height: 18px;
        margin: 6px 0 0;
    }
    .compact-funnel-stage-label { display: none; }
    .compact-funnel-arrow {
        top: -5px;
        left: -9px;
        font-size: 15px;
    }
    .compact-funnel-mobile-summary {
        min-width: 0;
        margin-top: 4px;
        display: flex;
        align-items: center;
        gap: 6px;
        color: #67708b;
        font-size: 10px;
        white-space: nowrap;
    }
    .compact-funnel-mobile-summary span,
    .compact-funnel-mobile-summary strong {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .compact-funnel-mobile-summary i {
        flex: 0 0 auto;
        color: var(--funnel-color);
        font-style: normal;
        font-weight: 700;
    }
    .compact-funnel-mobile-summary strong { color: var(--funnel-color); }

    .history-next-step {
        width: 100%;
        grid-template-columns: 25px minmax(0, 1fr);
        gap: 7px;
        margin-top: 6px;
        padding: 6px 7px;
    }
    .history-next-icon {
        width: 24px;
        height: 24px;
    }
    .history-next-icon svg { width: 14px; height: 14px; }
    .history-next-main {
        gap: 3px;
        flex-direction: column;
        align-items: flex-start;
    }
    .history-next-main > strong { font-size: 11px; }
    .history-next-main time { font-size: 9px; }

    .history-details-after-funnel > div {
        grid-template-columns: 1fr !important;
        gap: 1px !important;
    }
}
