/* CRM Design System v2
   Central typography, spacing and component rhythm.
   Loaded after legacy styles so all screens share the same visual language. */

:root {
    --font-sans: Inter, "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, Arial, sans-serif;

    --fs-xs: 12px;
    --fs-sm: 13px;
    --fs-md: 14px;
    --fs-base: 15px;
    --fs-lg: 16px;
    --fs-h3: 18px;
    --fs-h2: 22px;
    --fs-h1: 28px;

    --fw-regular: 400;
    --fw-medium: 500;
    --fw-semibold: 600;
    --fw-bold: 700;

    --lh-tight: 1.2;
    --lh-ui: 1.35;
    --lh-body: 1.5;

    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --surface-soft: #fafbfe;
    --surface-muted: #f6f8fc;
    --text-strong: #12172a;
    --text-secondary: #65708a;
}

html {
    font-family: var(--font-sans);
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: var(--lh-body);
    font-weight: var(--fw-regular);
    color: var(--text-strong);
}

button,
input,
select,
textarea {
    font-family: inherit;
    font-size: var(--fs-md);
}

input,
select,
textarea {
    font-weight: var(--fw-regular);
}

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-strong);
    line-height: var(--lh-tight);
    letter-spacing: -0.015em;
}

h1 { font-size: var(--fs-h1); font-weight: var(--fw-bold); }
h2 { font-size: var(--fs-h2); font-weight: var(--fw-semibold); }
h3 { font-size: var(--fs-h3); font-weight: var(--fw-semibold); }
h4, h5, h6 { font-weight: var(--fw-semibold); }

p,
dd,
td,
li {
    font-weight: var(--fw-regular);
}

small,
.muted-text,
.page-head p,
.contact-cell small,
.contacts-row small,
.team-person small,
.team-task-person small,
.team-task-contact small,
.user-block span {
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    font-weight: var(--fw-regular);
}

.contact-list-person .link-button,
.team-task-person a,
.team-task-contact a,
.task-main-cell > .link-button {
    color: var(--text-strong);
    font-weight: var(--fw-semibold);
}

.contact-list-city,
.contact-list-phone,
.team-person small,
.team-task-person small,
.team-task-contact small {
    color: var(--text-secondary);
    font-weight: var(--fw-regular);
}

.contact-list-phone {
    font-size: var(--fs-xs);
    color: #7c879d;
}

label,
.filter-label,
dt {
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
}

strong,
b {
    font-weight: var(--fw-semibold);
}

.link-button,
.contact-link {
    font-weight: var(--fw-semibold);
}

.primary-btn,
.secondary-btn,
.outline-btn,
.action-menu summary,
.action-menu-panel button,
.switch-btn,
.date-pill,
.date-mode,
.role-badge,
.badge {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
}

.nav-item {
    font-size: var(--fs-base);
    font-weight: var(--fw-medium);
}

.nav-item.active {
    font-weight: var(--fw-semibold);
}

.brand {
    font-size: 23px;
    font-weight: var(--fw-bold);
}

.user-details strong {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
}

.page-head {
    margin-bottom: 20px;
}

.page-head p {
    margin-top: 6px;
}

.table-card,
.profile-card,
.team-period-card,
.team-members-card {
    border-radius: var(--radius-md);
}

.table-head,
.contacts-head,
.team-head,
.team-planned-head {
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    letter-spacing: .01em;
}

.table-row,
.contacts-row {
    font-size: var(--fs-md);
}

.time-cell {
    font-weight: var(--fw-medium);
}

.task-main-cell > .link-button,
.contact-list-person .link-button {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
}

.comment-preview,
.contacts-row,
.profile-details,
.details-grid,
.history-details {
    line-height: var(--lh-ui);
}

.profile-details dd {
    font-weight: var(--fw-medium);
}

.profile-heading h2,
.section-head h2,
.completed-summary,
.team-period-top strong,
.team-person strong,
.team-task-action strong,
.team-task-funnel strong {
    font-weight: var(--fw-semibold);
}

.stat-card strong {
    font-weight: var(--fw-bold);
}

.stat-card b {
    font-weight: var(--fw-semibold);
}

.funnel-mini strong,
.task-funnel strong,
.contact-funnel-line strong {
    font-weight: var(--fw-semibold);
}

.funnel-mini small,
.task-funnel em,
.contact-funnel-line em {
    font-weight: var(--fw-semibold);
}

/* Compact funnel language shared by contacts/tasks/history-adjacent lists */
.funnel-mini-track {
    --mini-funnel-color: var(--violet);
    display: inline-flex;
    align-items: center;
    min-width: 88px;
    gap: 0;
}

.funnel-mini-track.is-business {
    --mini-funnel-color: #0c9aa6;
}

.funnel-mini-node {
    position: relative;
    width: 18px;
    height: 14px;
    flex: 0 0 18px;
    display: inline-flex;
    align-items: center;
}

.funnel-mini-node::before {
    content: "";
    width: 7px;
    height: 7px;
    margin: auto;
    border: 1.5px solid #c7cfdd;
    border-radius: 50%;
    background: #fff;
    position: relative;
    z-index: 2;
}

.funnel-mini-node:not(:last-child)::after {
    content: "";
    position: absolute;
    z-index: 1;
    top: 50%;
    left: 11px;
    width: 14px;
    height: 2px;
    transform: translateY(-50%);
    background: #d9deea;
}

.funnel-mini-node.is-reached::before {
    border-color: var(--mini-funnel-color);
    background: var(--mini-funnel-color);
}

.funnel-mini-node.is-current::before {
    width: 9px;
    height: 9px;
    border: 2px solid var(--mini-funnel-color);
    background: #fff;
    box-shadow: inset 0 0 0 2px #fff, 0 0 0 1px color-mix(in srgb, var(--mini-funnel-color) 30%, transparent);
}

.funnel-mini-node.is-reached:not(:last-child)::after,
.funnel-mini-node.is-current:not(:last-child)::after {
    background: color-mix(in srgb, var(--mini-funnel-color) 62%, #d9deea);
}

.funnel-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 22px;
    color: var(--text-secondary);
}

.funnel-inline > strong {
    min-width: 58px;
    color: var(--text-strong);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
}

.funnel-inline-status {
    padding: 2px 7px;
    border-radius: 999px;
    background: #fff2df;
    color: #bd6500;
    font-size: 11px;
    font-weight: var(--fw-semibold);
}

/* Normalize legacy very-heavy typography without flattening hierarchy */
.history-timeline-v2 *,
.history-legend-strip *,
.team-page-head *,
.team-period-card *,
.team-members-card *,
.team-planned-card * {
    font-family: var(--font-sans);
}

.history-entity-name,
.history-action-heading > strong,
.history-funnel-kicker,
.history-funnel-kind,
.history-funnel-transition-line b,
.history-next-main strong,
.history-category-pill,
.history-period-pill,
.history-filter-pill,
.history-legend-item b,
.history-funnel-chip,
.team-task-scope,
.team-period-pill,
.member-task-status {
    font-weight: var(--fw-semibold) !important;
}

.history-event-card,
.history-details,
.history-next-step,
.history-no-next-step,
.history-open-contact {
    font-size: var(--fs-sm);
}

/* Auth pages inherit the same hierarchy */
.auth-panel h1,
.auth-panel h2 {
    font-weight: var(--fw-bold);
}

.auth-panel label {
    font-weight: var(--fw-semibold);
}

.auth-brand strong {
    font-size: var(--fs-lg);
    font-weight: var(--fw-semibold);
}

.auth-brand span,
.muted-link {
    font-size: var(--fs-sm);
    font-weight: var(--fw-regular);
}

.member-overview-card h1,
.member-panel-title h2,
.member-workspace-tabs strong,
.member-overview-person strong,
.member-overview-metrics strong,
.team-member-row strong,
.contact-summary-grid strong {
    font-weight: var(--fw-semibold);
}

.member-overview-meta,
.member-readonly-chip,
.member-breadcrumbs,
.team-count,
.team-details-link {
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
}

.member-overview-metrics span,
.member-overview-person p,
.contact-summary-grid small {
    font-size: var(--fs-sm);
    font-weight: var(--fw-regular);
    color: var(--text-secondary);
}

/* Desktop density */
@media (min-width: 721px) {
    .content {
        padding-top: 28px;
    }

    .contacts-row,
    .table-row {
        min-height: 66px;
    }

    .contacts-head,
    .table-head {
        min-height: 48px;
    }
}

/* Mobile typography and tap targets */
@media (max-width: 720px) {
    body {
        font-size: var(--fs-md);
    }

    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }

    .content {
        padding: 16px 12px calc(24px + env(safe-area-inset-bottom));
    }

    .page-head,
    .contacts-page-head,
    .today-page-head,
    .team-page-head {
        margin-bottom: 10px;
    }

    .nav-item,
    .primary-btn,
    .secondary-btn,
    .outline-btn,
    .action-menu-panel button {
        font-size: var(--fs-md);
    }

    .task-plan-table .link-button,
    .contact-list-person .link-button {
        font-size: var(--fs-sm);
    }

    .contact-funnel-line {
        font-size: var(--fs-xs);
    }

    .funnel-inline {
        gap: 6px;
    }

    .funnel-inline > strong {
        min-width: 52px;
        font-size: var(--fs-xs);
    }

    .funnel-mini-node {
        width: 15px;
        flex-basis: 15px;
    }

    .funnel-mini-node:not(:last-child)::after {
        left: 9px;
        width: 12px;
    }
}


/* v2 visual scale: closer to approved CRM mockup */
@media (min-width: 721px) {
    h1 { font-size: 30px; }

    .contacts-card {
        padding: 22px 20px;
    }

    .contacts-filters input[type="search"],
    .contacts-filters select {
        min-height: 46px;
        font-size: 14px;
    }

    .contacts-filter-submit {
        min-height: 44px;
    }

    .contacts-row {
        grid-template-columns: 48px 270px minmax(280px, 1fr) minmax(240px, .9fr);
        min-height: 74px;
        gap: 10px 14px;
        padding-left: 20px;
        padding-right: 20px;
    }

    .contacts-head {
        min-height: 48px;
    }

    .contacts-head > :first-child {
        grid-column: 1 / 3;
    }

    .contacts-row:not(.contacts-head) .contact-list-avatar {
        width: 40px;
        height: 40px;
        display: grid;
        place-items: center;
        border-radius: 50%;
        background: var(--violet-soft);
        color: var(--violet);
        font-size: 13px;
        font-weight: var(--fw-semibold);
        overflow: hidden;
    }

    .contact-list-person {
        align-content: center;
        gap: 2px 8px;
    }

    .contact-list-person .link-button {
        font-size: 15px;
        line-height: 1.25;
    }

    .contact-list-city {
        margin-top: 4px !important;
        font-size: 13px !important;
    }

    .contact-list-phone {
        margin-top: 2px !important;
        font-size: 12px !important;
    }

    .funnel-mini-track {
        min-width: 108px;
    }

    .funnel-mini-node {
        width: 20px;
        flex-basis: 20px;
    }

    .funnel-mini-node:not(:last-child)::after {
        left: 12px;
        width: 16px;
    }
}

.contact-list-avatar img,
.avatar img,
.profile-avatar img,
.member-overview-avatar img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    border-radius: inherit;
}

.avatar,
.profile-avatar,
.member-overview-avatar {
    overflow: hidden;
}

.profile-edit-form {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr);
    gap: 18px;
    padding: 24px 28px 28px;
}

.profile-edit-form > .form-alert,
.profile-edit-form > .profile-static-fields,
.profile-edit-form > .primary-btn {
    grid-column: 1 / -1;
}

.profile-static-fields {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.profile-static-fields > div {
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
}

.profile-static-fields span,
.profile-static-fields strong {
    display: block;
}

.profile-static-fields span {
    color: var(--text-secondary);
    font-size: var(--fs-xs);
}

.profile-static-fields strong {
    margin-top: 4px;
    font-size: var(--fs-sm);
}

@media (max-width: 720px) {
    .profile-edit-form {
        grid-template-columns: 1fr;
        padding: 18px;
    }

    .profile-edit-form > * {
        grid-column: 1 !important;
    }

    .profile-static-fields {
        grid-template-columns: 1fr;
    }

    .contact-list-avatar img {
        width: 100%;
        height: 100%;
    }
}


/* Contact photos and universal lightbox */
.contact-avatar-button,
.contact-card-photo,
.contact-edit-photo,
.contact-summary-avatar {
    padding: 0;
    border: 0;
    cursor: zoom-in;
    background: transparent;
}

.contact-avatar-button:focus-visible,
.contact-card-photo:focus-visible,
.contact-edit-photo:focus-visible,
.contact-summary-avatar:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--violet) 35%, transparent);
    outline-offset: 3px;
}

.contact-card-hero {
    display: grid;
    grid-template-columns: 104px minmax(0, 1fr) auto;
    align-items: center;
    gap: 18px;
    margin: 0 0 22px;
    padding-right: 44px;
}

.contact-card-photo {
    width: 104px;
    height: 104px;
    border-radius: 16px;
    overflow: hidden;
    background: var(--violet-soft);
    color: var(--violet);
    display: grid;
    place-items: center;
    font-size: 28px;
    font-weight: var(--fw-semibold);
}

.contact-card-photo img,
.contact-edit-photo img,
.contact-summary-avatar img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.contact-card-hero-copy h3 {
    margin: 0 0 6px;
}

.contact-card-hero-copy p,
.contact-edit-heading p {
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--fs-sm);
}

.contact-card-edit-btn {
    justify-self: end;
}

.contact-edit-heading {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 0 0 20px;
    padding-right: 44px;
}

.contact-edit-photo {
    width: 88px;
    height: 88px;
    flex: 0 0 88px;
    border-radius: 14px;
    overflow: hidden;
    background: var(--violet-soft);
    color: var(--violet);
    display: grid;
    place-items: center;
    font-size: 24px;
    font-weight: var(--fw-semibold);
}

.contact-edit-heading h3 {
    margin-bottom: 6px;
}

.contact-page-hero {
    justify-content: flex-start;
}

.contact-page-photo {
    width: 112px;
    height: 112px;
    flex: 0 0 112px;
    margin-right: 2px;
}

.contact-summary-card {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
}

.contact-summary-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    display: grid;
    place-items: center;
    background: var(--violet-soft);
    color: var(--violet);
    font-size: 13px;
    font-weight: var(--fw-semibold);
}

.contact-summary-main {
    min-width: 0;
}

.photo-lightbox[hidden] {
    display: none !important;
}

.photo-lightbox {
    position: fixed;
    z-index: 30000;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 30px;
}

.photo-lightbox-backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: rgba(10, 13, 25, .82);
    cursor: zoom-out;
}

.photo-lightbox-frame {
    position: relative;
    z-index: 1;
    max-width: min(92vw, 1100px);
    max-height: 88vh;
    margin: 0;
}

.photo-lightbox-frame img {
    max-width: 100%;
    max-height: 88vh;
    display: block;
    border-radius: 12px;
    object-fit: contain;
    box-shadow: 0 30px 100px rgba(0, 0, 0, .35);
}

.photo-lightbox-close {
    position: fixed;
    z-index: 2;
    top: 20px;
    right: 24px;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .96);
    color: #11172b;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

.photo-lightbox-open {
    overflow: hidden;
}

@media (max-width: 720px) {
    .contact-card-hero {
        grid-template-columns: 76px minmax(0, 1fr);
        gap: 14px;
        padding-right: 36px;
    }

    .contact-card-photo {
        width: 76px;
        height: 76px;
        border-radius: 12px;
        font-size: 22px;
    }

    .contact-card-edit-btn {
        grid-column: 1 / -1;
        width: 100%;
        justify-self: stretch;
    }

    .contact-edit-photo {
        width: 72px;
        height: 72px;
        flex-basis: 72px;
    }

    .contact-page-hero {
        display: grid;
        grid-template-columns: 76px minmax(0, 1fr);
        align-items: center;
    }

    .contact-page-photo {
        width: 76px;
        height: 76px;
    }

    .photo-lightbox {
        padding: 16px;
    }

    .photo-lightbox-close {
        top: 12px;
        right: 12px;
    }
}


/* Contact card v3: photo left, concise facts right, long content below */
.contact-card-layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 28px;
    align-items: start;
    margin-bottom: 24px;
}

.contact-card-photo-column {
    min-width: 0;
}

.contact-card-photo-large {
    width: 220px;
    height: 220px;
    border-radius: 18px;
    font-size: 46px;
}

.contact-card-main {
    min-width: 0;
}

.contact-card-title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 20px;
    padding-right: 34px;
}

.contact-card-title-row h3 {
    margin: 0 0 6px;
    font-size: 24px;
}

.contact-card-title-row p {
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--fs-sm);
}

.contact-card-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 24px;
    margin: 0;
}

.contact-card-facts > div {
    min-width: 0;
    padding: 12px 0;
    border-bottom: 1px solid #edf0f6;
}

.contact-card-facts dt {
    margin-bottom: 5px;
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
}

.contact-card-facts dd {
    margin: 0;
    color: var(--text-strong);
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    overflow-wrap: anywhere;
}

.contact-card-wide-section {
    padding-top: 18px;
    border-top: 1px solid #e8ebf2;
}

.contact-card-wide-section + .contact-card-wide-section {
    margin-top: 22px;
}

.contact-card-wide-section h4 {
    margin: 0 0 12px;
    font-size: 15px;
    font-weight: var(--fw-semibold);
}

.contact-card-comment {
    min-height: 48px;
    padding: 14px 16px;
    border: 1px solid #e4e8f1;
    border-radius: 10px;
    background: var(--surface-soft);
    color: #3f475c;
    font-size: var(--fs-md);
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.contact-card-funnels-section .contact-funnels {
    margin-top: 0;
}

.contact-card-layout-page {
    padding: 0 20px 4px;
}

.contact-page-card > .contact-card-wide-section {
    margin: 0 20px 20px;
}

.contact-edit-photo {
    width: 140px;
    height: 140px;
    flex-basis: 140px;
    border-radius: 16px;
    font-size: 34px;
}

@media (max-width: 900px) {
    .contact-card-layout {
        grid-template-columns: 180px minmax(0, 1fr);
        gap: 22px;
    }

    .contact-card-photo-large {
        width: 180px;
        height: 180px;
    }

    .contact-card-facts {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .contact-card-layout,
    .contact-card-layout-page {
        grid-template-columns: 1fr;
        gap: 18px;
        padding-left: 0;
        padding-right: 0;
    }

    .contact-card-photo-large {
        width: 132px;
        height: 132px;
        border-radius: 16px;
        font-size: 32px;
    }

    .contact-card-title-row {
        padding-right: 30px;
        margin-bottom: 12px;
    }

    .contact-card-title-row h3 {
        font-size: 21px;
    }

    .contact-card-title-row .primary-btn {
        min-height: 38px;
        padding: 0 12px;
        font-size: 12px;
    }

    .contact-card-facts {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0 14px;
    }

    .contact-card-facts > div {
        padding: 10px 0;
    }

    .contact-card-wide-section {
        padding-top: 16px;
    }

    .contact-edit-photo {
        width: 92px;
        height: 92px;
        flex-basis: 92px;
        font-size: 24px;
    }

    .contact-page-card > .contact-card-wide-section {
        margin-left: 16px;
        margin-right: 16px;
    }
}

@media (max-width: 480px) {
    .contact-card-facts {
        grid-template-columns: 1fr;
    }

    .contact-card-title-row {
        align-items: stretch;
        flex-direction: column;
        padding-right: 34px;
    }

    .contact-card-title-row .primary-btn {
        align-self: flex-start;
    }
}


/* Unified contact card modes */
[data-contact-view-panel][hidden],
[data-contact-edit-panel][hidden] {
    display: none !important;
}

.contact-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 4px;
}

.contact-edit-actions .primary-btn,
.contact-edit-actions .secondary-btn {
    min-width: 150px;
}

@media (max-width: 720px) {
    .contact-edit-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .contact-edit-actions .primary-btn,
    .contact-edit-actions .secondary-btn {
        width: 100%;
        min-width: 0;
    }
}


/* Contact list click targets */
.contact-card-open-target {
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font: inherit;
    color: inherit;
}

.contact-list-person.contact-card-open-target {
    display: grid;
    align-content: center;
    justify-items: start;
    width: 100%;
    padding: 0;
}

.contact-list-name {
    color: var(--text-strong);
    font-size: 15px;
    font-weight: var(--fw-semibold);
    line-height: 1.25;
}

.contact-card-open-target:hover .contact-list-name {
    color: var(--violet);
}

.contact-list-avatar.contact-card-open-target:hover {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--violet) 14%, transparent);
}

.contact-card-open-target:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--violet) 30%, transparent);
    outline-offset: 2px;
}

/* Native dialog lightbox: participates in browser top layer */
.photo-lightbox {
    width: 100vw;
    max-width: none;
    height: 100vh;
    max-height: none;
    margin: 0;
    padding: 30px;
    border: 0;
    background: transparent;
    overflow: hidden;
}

.photo-lightbox::backdrop {
    background: rgba(10, 13, 25, .82);
}

.photo-lightbox-backdrop {
    background: transparent;
}

.photo-lightbox[open] {
    display: grid;
}

@media (max-width: 720px) {
    .contact-list-person.contact-card-open-target {
        justify-items: stretch;
    }

    .contact-list-name {
        font-size: var(--fs-sm);
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .contact-funnels-mobile .funnel-inline {
        flex-wrap: wrap;
    }

    .photo-lightbox {
        padding: 16px;
    }
}


/* Closed native photo dialog must never cover the page */
.photo-lightbox:not([open]) {
    display: none !important;
    pointer-events: none !important;
}

.photo-lightbox[open] {
    pointer-events: auto;
}


/* Contact edit v3 — same visual structure as contact view */
.contact-edit-form-v2 {
    display: grid;
    gap: 22px;
}

.contact-edit-alert {
    margin: 0;
}

.contact-edit-layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 28px;
    align-items: start;
}

.contact-edit-photo-column {
    display: grid;
    gap: 12px;
    align-content: start;
}

.contact-photo-upload {
    display: grid;
    gap: 8px;
    padding: 12px;
    border: 1px solid #e3e7f0;
    border-radius: 10px;
    background: var(--surface-soft);
}

.contact-photo-upload > span {
    color: var(--text-strong);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
}

.contact-photo-upload input[type="file"] {
    min-height: 38px;
    padding: 6px 8px;
    font-size: var(--fs-xs);
    background: #fff;
}

.contact-edit-main {
    min-width: 0;
}

.contact-edit-title-row {
    margin-bottom: 18px;
    padding-right: 34px;
}

.contact-edit-title-row h3 {
    margin: 0 0 5px;
    font-size: 24px;
}

.contact-edit-title-row p {
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--fs-sm);
}

.contact-edit-fields-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 18px;
}

.contact-edit-fields-grid label,
.contact-edit-extra-grid label {
    gap: 7px;
    font-weight: var(--fw-semibold);
}

.contact-edit-fields-grid label > span,
.contact-edit-extra-grid label > span {
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
}

.contact-edit-section {
    padding: 18px;
    border: 1px solid #e3e7f0;
    border-radius: 12px;
    background: #fff;
}

.contact-edit-section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.contact-edit-section-head h4 {
    margin: 0 0 4px;
    font-size: 16px;
    font-weight: var(--fw-semibold);
}

.contact-edit-section-head p {
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--fs-sm);
}

.contact-edit-interest {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 18px;
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid #e6e9f1;
    border-radius: 10px;
    background: var(--surface-soft);
}

.contact-edit-interest .checkbox-label {
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    color: var(--text-strong);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
}

.contact-edit-interest input[type="checkbox"] {
    width: 18px;
    height: 18px;
    min-height: 0;
    padding: 0;
}

.contact-edit-funnels-section .contact-funnel-editor {
    margin-top: 0;
}

.contact-edit-extra-grid {
    display: grid;
    grid-template-columns: minmax(180px, .35fr) minmax(0, 1fr);
    gap: 16px 18px;
    align-items: start;
}

.contact-edit-comment textarea {
    min-height: 120px;
}

.contact-edit-actions {
    position: sticky;
    bottom: 0;
    z-index: 3;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin: 0 -2px -2px;
    padding: 14px 0 2px;
    background: linear-gradient(to bottom, rgba(255,255,255,0), #fff 24%);
}

.contact-edit-actions .primary-btn,
.contact-edit-actions .secondary-btn {
    min-width: 150px;
}

@media (max-width: 900px) {
    .contact-edit-layout {
        grid-template-columns: 180px minmax(0, 1fr);
        gap: 22px;
    }

    .contact-edit-layout .contact-card-photo-large {
        width: 180px;
        height: 180px;
    }

    .contact-edit-fields-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .contact-edit-layout {
        grid-template-columns: 132px minmax(0, 1fr);
        gap: 16px;
    }

    .contact-edit-layout .contact-card-photo-large {
        width: 132px;
        height: 132px;
    }

    .contact-edit-title-row {
        padding-right: 30px;
    }

    .contact-edit-title-row h3 {
        font-size: 21px;
    }

    .contact-photo-upload {
        padding: 10px;
    }

    .contact-edit-section {
        padding: 14px;
    }

    .contact-edit-extra-grid {
        grid-template-columns: 1fr;
    }

    .contact-edit-actions {
        grid-template-columns: 1fr 1fr;
        display: grid;
    }
}

@media (max-width: 520px) {
    .contact-edit-layout {
        grid-template-columns: 1fr;
    }

    .contact-edit-photo-column {
        grid-template-columns: 112px minmax(0, 1fr);
        align-items: start;
    }

    .contact-edit-layout .contact-card-photo-large {
        width: 112px;
        height: 112px;
    }

    .contact-edit-fields-grid {
        grid-template-columns: 1fr;
    }
}


/* Contact funnel fit: keep labels readable without desktop horizontal scroll */
@media (min-width: 721px) {
    .modal.contact-card-modal {
        width: min(940px, calc(100vw - 32px));
    }

    .contact-edit-funnels-section {
        padding-left: 14px;
        padding-right: 14px;
    }

    .contact-edit-funnels-section .contact-funnel-editor {
        gap: 14px;
    }

    .contact-edit-funnels-section .edit-funnel-card {
        padding: 16px 14px 18px;
        gap: 14px;
        overflow-x: visible;
    }

    .contact-edit-funnels-section .stage-rail {
        width: 100%;
        min-width: 0;
        grid-template-columns: repeat(var(--steps), minmax(0, 1fr));
    }

    .contact-edit-funnels-section .stage-choice {
        min-width: 0;
        padding-left: 3px;
        padding-right: 3px;
    }

    .contact-edit-funnels-section .stage-choice small {
        max-width: 118px;
    }
}

@media (max-width: 720px) {
    .contact-edit-funnels-section .edit-funnel-card {
        overflow-x: auto;
    }

    .contact-edit-funnels-section .stage-rail {
        min-width: max(640px, 100%);
        grid-template-columns: repeat(var(--steps), minmax(88px, 1fr));
    }
}


/* Contact card action toolbar */
.contact-card-toolbar {
    position: sticky;
    top: 0;
    z-index: 8;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    margin: -2px 0 14px;
    padding: 0 0 6px;
    background: linear-gradient(to bottom, #fff 72%, rgba(255,255,255,.94));
}

.contact-card-toolbar form {
    margin: 0;
}

.contact-toolbar-btn {
    min-height: 40px;
    height: 40px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font: inherit;
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    cursor: pointer;
    white-space: nowrap;
}

.contact-toolbar-edit {
    background: var(--violet);
    color: #fff;
}

.contact-toolbar-edit:hover {
    filter: brightness(.97);
}

.contact-toolbar-delete {
    border-color: #ffd1d7;
    background: #fff3f5;
    color: #c9283f;
}

.contact-toolbar-delete:hover {
    background: #ffe8ec;
    border-color: #ffbcc6;
}

.contact-toolbar-close {
    width: 40px;
    padding: 0;
    border-color: #e7eaf1;
    background: #f5f6fa;
    color: #1d2433;
    font-size: 24px;
    line-height: 1;
}

.contact-toolbar-close:hover {
    background: #eceff5;
}

.contact-card-toolbar [hidden] {
    display: none !important;
}

@media (max-width: 720px) {
    .contact-card-toolbar {
        gap: 6px;
        margin-bottom: 10px;
    }

    .contact-toolbar-btn {
        min-height: 38px;
        height: 38px;
        padding: 0 10px;
        font-size: 12px;
    }

    .contact-toolbar-close {
        width: 38px;
        padding: 0;
        font-size: 22px;
    }

    .contact-toolbar-edit span:first-child,
    .contact-toolbar-delete span:first-child {
        display: none;
    }
}

@media (max-width: 380px) {
    .contacts-filters { grid-template-columns: minmax(0, 1fr) auto; }
    .contacts-funnel-filter { grid-column: 1 / -1; }
    .contacts-paused-filter { grid-column: 1; }
    .contacts-filter-submit { grid-column: 2; }
}

/* Server-side pagination for CRM listings */
.listing-pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-top: 1px solid rgba(100, 116, 139, .16);
}
.listing-pagination-count { color: #64748b; font-size: 13px; }
.listing-pagination-links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
}
.listing-pagination-links a,
.listing-pagination-current,
.listing-pagination-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    min-height: 34px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.2;
    text-decoration: none;
}
.listing-pagination-links a {
    color: inherit;
    border: 1px solid rgba(100, 116, 139, .2);
}
.listing-pagination-links a:hover { background: rgba(100, 116, 139, .08); }
.listing-pagination-current {
    background: #5b35f5;
    color: #fff;
    font-weight: 600;
}
.listing-pagination-ellipsis { color: #64748b; }
@media (max-width: 720px) {
    .listing-pagination { justify-content: center; padding: 12px; }
    .listing-pagination-count { width: 100%; text-align: center; }
}
