/* ── Contacts List ─────────────────────────────────────────── */

.contacts-main {
    display: flex;
    flex-direction: column;
    background-color: var(--color-bg);
}

/* No explicit height/overflow here — same natural page-scroll as board.css's
   .board-section and summary.css's .content. padding-bottom clears the fixed
   FAB button (.add-contact-btn) so it doesn't cover the last contact. */
.contacts-list {
    position: relative;
    /* Clips the bleeding divider (.contact-group h3::after) exactly at this
       edge instead of letting it push this element (or the page) into
       unwanted horizontal scroll. */
    overflow-x: hidden;
    padding: clamp(var(--space-sm), 4vw, var(--space-xl));
}

.contact-group {
    padding-bottom: var(--space-2xs);
}

.contact-group h3 {
    font-weight: var(--font-weight-regular);
    padding-left: 2rem;
}

/* Bleeds to .contacts-list's outer edge by exactly reversing its fixed
   horizontal padding. */
.contact-group-divider {
    border: none;
    border-bottom: 1px solid var(--color-border);
    width: 100%;
}

.contact-card {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 15px 32px;
    padding-left: 1rem;
    border-radius: var(--border-radius-md);
    cursor: pointer;
}

.contact-card:hover {
    background-color: #eeeeee;
}

.contact-avatar {
    width: 42px;
    height: 42px;
    font-size: 16px;
    border: 2px solid var(--color-white);
}

/* Gives the name/email column a fixed share of the row (rather than
   shrink-to-fit sizing) so both truncate at the same width on every card,
   instead of depending on how long the other line happens to be. */
.contact-card-info {
    flex: 1;
    min-width: 0;
}

.contact-card h4 {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: var(--font-weight-regular);
}

.contact-card p {
    margin: 0;
    display: block;
    font-size: 16px;
    color: var(--color-link);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.add-contact-btn,
.menu_contact_btn {
    position: fixed;
    right: 25px;
    bottom: 100px;
    width: 45px;
    height: 45px;
    border: unset;
    border-radius: 50%;
    background-color: var(--color-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: var(--shadow-fab);
}

.add-contact-btn img,
.menu_contact_btn img {
    width: 28px;
    height: 28px;
}

.d-none {
    display: none;
}

/* ── Contact Details ───────────────────────────────────────── */

.contact-details {
    padding: clamp(var(--space-sm), 4vw, var(--space-xl)) clamp(var(--space-sm), 4vw, var(--space-xl)) 0;
    background-color: var(--color-bg);
}

.contact-details-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: var(--space-2xs);
}

.contact-details-title-row h1 {
    margin: 0;
}

.contact-details-header h1 {
    font-weight: var(--font-weight-bold);
    margin: 0;
}

/* Shared "heading + divider + subtext" stacked/row pattern for
   .desktop-contact-placeholder (no contact selected) and .contact-details-header
   (contact selected) — same widget, two states, same narrow detail-panel column.
   Stacked look reuses global/base.css's shared .subline/.title-hr defaults,
   same pattern as summary.css's .title. */
.contact-panel-heading {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.contact-panel-heading .subline {
    font-size: clamp(18px, 2vw, 27px);
}

.back-to-contacts-btn {
    border: unset;
    background: transparent;
    cursor: pointer;
    font-size: 32px;
    line-height: 1;
    color: var(--color-accent);
    padding: 0;
}

.contact-details-profile {
    display: flex;
    align-items: center;
    gap: var(--space-2xs);
    margin-top: 40px;
    min-width: 0;
}

.contact-details-name {
    overflow-wrap: break-word;
}

.contact-details-avatar {
    width: 70px;
    height: 70px;
    font-size: 27px;
    border: 3px solid var(--color-white);
}

.contact-information-title {
    font-size: 20px;
    margin-top: 40px;
    margin-bottom: var(--space-md);
}

.contact-information h4 {
    margin: 0 0 var(--space-2xs) 0;
}

.contact-information a {
    display: block;
    font-size: 16px;
    color: var(--color-link);
    text-decoration: none;
    margin-bottom: var(--space-md);
}

.contact-information p {
    font-size: 16px;
    margin: 0;
}

/* ── Mobile Contact Menu ───────────────────────────────────── */

.contact_menu {
    position: fixed;
    right: -140px;
    bottom: 75px;
    width: 110px;
    padding: 10px;
    border-radius: 20px 20px 0 20px;
    background-color: var(--color-white);
    box-shadow: var(--shadow-fab);
    display: flex;
    flex-direction: column;
    gap: var(--space-2xs);
    transition: right 125ms ease-in-out;
    z-index: 19;
}

.contact_menu button {
    background: transparent;
    border: unset;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--space-2xs);
}

.contact_menu_open {
    right: 15px;
}

.menu_contact_btn_active {
    background-color: var(--color-accent);
}

.contact_menu_backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 18;
}

.contact_menu_backdrop_open {
    display: block;
}

/* ── Desktop-only Placeholders ─────────────────────────────── */

.desktop-add-contact-wrapper,
.desktop-contact-placeholder {
    display: none;
}

.desktop-contact-actions {
    display: none;
}

/* ── Contact Overlay (Add/Edit/Delete) ────────────────────── */

.modal--contact {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    width: 100vw;
    height: 100dvh;
    max-width: 100vw;
    max-height: 100dvh;
    margin: 0;
    padding: 16px 16px calc(var(--mobile-nav-height) + 5px);
    background: transparent;
    overflow: visible;
}

.modal--contact::backdrop {
    background: rgba(0, 0, 0, 0.25);
    opacity: 0;
    transition: opacity 180ms ease-out;
}

.modal--contact.is-open::backdrop {
    opacity: 1;
}

.modal--contact:has(.contact-edit-overlay),
.modal--contact:has(.contact-add-overlay) {
    align-items: stretch;
    padding-top: var(--header-height);
    padding-bottom: var(--mobile-nav-height);
}

.contact-overlay {
    position: relative;
    display: grid;
    grid-template-columns: 1fr;
    width: min(390px, 100%);
    min-height: unset;
    max-height: calc(100dvh - var(--mobile-nav-height) - 112px);
    overflow: hidden;
    overflow-y: auto;
    border-radius: var(--border-radius-lg);
    background-color: var(--color-white);
    box-shadow: 0 0 14px 3px rgba(0, 0, 0, 0.12);
    transform: translateY(120px);
    transition: transform 180ms ease-out;
}

.modal--contact.is-open .contact-overlay,
.modal--contact.is-open .contact-add-overlay,
.modal--contact.is-open .contact-edit-overlay,
.modal--contact.is-open .contact-delete-overlay {
    transform: translateY(0);
}

.contact-overlay > .close-btn {
    position: absolute;
    top: 24px;
    right: 24px;
    color: var(--color-white);
}

.contact-overlay > .close-btn:hover {
    background: var(--color-primary-dark);
}

.contact-overlay-brand {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: var(--space-lg) var(--space-md);
    background-color: var(--color-primary);
    color: var(--color-white);
}

.contact-overlay-brand img {
    width: 56px;
    height: 68px;
    object-fit: contain;
    margin-bottom: var(--space-md);
    display: none;
}

.contact-overlay-brand h2 {
    margin: 0;
}

.contact-overlay-brand p {
    margin: 12px 0 0;
    font-size: clamp(18px, 2vw, 18px);
}

.contact-overlay-brand div {
    width: 90px;
    height: 3px;
    margin-top: var(--space-sm);
    background-color: var(--color-accent);
}


.contact-delete-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: var(--space-md);
    padding: var(--space-lg) var(--space-md);
}

.contact-edit-form {
    position: relative;
    align-items: center;
    gap: var(--space-lg);
    display: flex;
    flex-direction: column;
    padding: 82px 24px 32px;
}

.contact-edit-avatar {
    border: 3px solid var(--color-white);
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.15);
    position: absolute;
    top: -55px;
    left: 50%;
    width: 104px;
    height: 104px;
    font-size: 34px;
    transform: translateX(-50%);
}

.contact-edit-fields {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 14px;
}

/* Two close buttons, one shown per breakpoint (see the 1024px block below):
   the mobile one docks to the overlay's corner like the delete overlay, the
   desktop one lives in the fields column instead — its form (also carrying
   contact-edit-form for the shared avatar positioning) is itself a
   position:relative sibling that paints over the corner button otherwise. */
.contact-edit-close-btn-desktop,
.contact-add-close-btn-desktop {
    display: none;
}

.contact-edit-overlay {
    width: min(440px, 100%);
    max-height: none;
}

.contact-add-overlay {
    max-height: none;
}

/* Extra bottom padding so the "Edit contact" heading (single line, no
   subtitle unlike the add-overlay) doesn't collide with the avatar badge
   floating in from the form below, on narrow screens. */
.contact-edit-overlay .contact-overlay-brand {
    padding-bottom: calc(var(--space-lg) + var(--space-sm));
}

.contact-add-overlay .contact-overlay-brand {
    min-height: 305px;
    padding: 86px 22px 104px;
}

.contact-add-overlay .contact-overlay-brand p {
    font-size: 20px;
}

.contact-add-form {
    position: relative;
    align-items: center;
    gap: 56px;
    display: flex;
    padding: 82px 14px 14px;
}

.contact-add-avatar {
    border: 3px solid var(--color-white);
    background-color: var(--color-border);
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.15);
    position: absolute;
    top: -55px;
    left: 50%;
    width: 104px;
    height: 104px;
    transform: translateX(-50%);
}

.contact-add-avatar img {
    width: 52px;
    height: 52px;
    filter: brightness(0) invert(1);
}

.contact-add-fields {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 14px;
}

.contact-add-fields .input-field,
.contact-edit-fields .input-field {
    max-width: none;
}

.contact-add-actions {
    justify-content: center;
}

.contact-add-actions .btn-secondary {
    display: none;
}

.contact-add-actions .btn-primary {
    min-height: 44px;
    padding: var(--space-2xs) 12px;
    font-size: 18px;
}

.contact-overlay-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-top: var(--space-2xs);
    flex-wrap: wrap;
}

.contact-overlay-actions .btn {
    min-height: 48px;
}

.contact-delete-content p {
    margin: 0;
    font-size: 24px;
}

@media (min-width: 1024px) {

    .modal--contact {
        align-items: center;
        padding: var(--space-md);
    }

    /* Reset the mobile full-height edit/add-overlay treatment (see the base
       .modal--contact:has(...) rule above) back to the normal centered dialog
       once the two-column desktop layout has its own sidebar instead of a
       bottom navbar. */
    .modal--contact:has(.contact-edit-overlay),
    .modal--contact:has(.contact-add-overlay) {
        align-items: center;
        padding: var(--space-md);
    }

    .contact-overlay {
        grid-template-columns: minmax(220px, 320px) minmax(280px, 1fr);
        width: min(900px, 100%);
        min-height: 360px;
        max-height: none;
        overflow-y: hidden;
        transform: translateX(120px);
    }

    .modal--contact.is-open .contact-overlay {
        transform: translateX(0);
    }

    .contact-overlay-brand {
        padding: 40px;
    }

    .contact-overlay-brand img {
        display: block;
    }

    .contact-overlay > .close-btn {
        color: inherit;
    }

    /* Only the mobile card sits over the dark brand panel (delete overlay
       stays a direct .contact-overlay child there, unlike edit/add which
       moved their desktop button into the fields column) — past this
       breakpoint it's on the light background, so it needs the same default
       hover as every other close button instead of the dark one. */
    .contact-overlay > .close-btn:hover {
        background: var(--color-bg);
    }

    .contact-delete-content {
        padding: 72px 48px 48px;
    }

    .contact-edit-form {
        display: grid;
        grid-template-columns: 100px minmax(280px, 1fr);
        padding: var(--space-lg);
    }

    .contact-edit-close-btn-mobile,
    .contact-add-close-btn-mobile {
        display: none;
    }

    .contact-edit-close-btn-desktop,
    .contact-add-close-btn-desktop {
        display: flex;
        align-self: flex-end;
    }

    .contact-edit-avatar {
        position: static;
        top: auto;
        left: auto;
        width: 100px;
        height: 100px;
        font-size: 32px;
        transform: none;
    }

    .contact-edit-fields {
        width: auto;
        gap: var(--space-md);
    }

    .contact-add-overlay {
        grid-template-columns: minmax(280px, 370px) minmax(420px, 1fr);
        width: min(960px, 100%);
        min-height: 468px;
    }

    .contact-edit-overlay {
        width: min(1000px, 100%);
    }

    .contact-add-overlay .contact-overlay-brand {
        min-height: auto;
        padding: 64px 40px;
    }

    .contact-add-overlay .contact-overlay-brand p {
        font-size: clamp(18px, 2vw, 18px);
    }

    .contact-add-form {
        display: grid;
        grid-template-columns: 120px minmax(280px, 1fr);
        padding: 72px 40px;
    }

    .contact-add-avatar {
        position: static;
        top: auto;
        left: auto;
        width: 100px;
        height: 100px;
        transform: none;
    }

    .contact-add-fields {
        width: auto;
        gap: var(--space-md);
    }

    .contact-add-actions {
        justify-content: flex-start;
    }

    .contact-add-actions .btn-secondary {
        display: inline-block;
    }

    .contact-add-actions .btn-primary {
        min-height: 48px;
        padding: 8px var(--space-md);
        font-size: 16px;
    }

    .contact-overlay-actions {
        flex-wrap: nowrap;
    }


    .contact-card.active {
        background-color: var(--color-primary);
    }

    .contact-card.active h4 {
        color: var(--color-white);
    }

    /* Column between 1024–1365px (narrow detail panel), row again from 1366px
       up — see the shared breakpoint block further down. */
    .desktop-contact-actions {
        display: flex;
        gap: var(--space-sm);
        margin-top: var(--space-2xs);
    }

    .contact-details-name-actions {
        display: flex;
        flex-direction: column;
        justify-content: center;
        min-width: 0;
    }

    .contact-details-name-actions h2 {
        margin: 0;
    }

    .desktop-contact-actions button {
        border: unset;
        background: transparent;
        display: flex;
        align-items: center;
        gap: var(--space-2xs);
        cursor: pointer;
        font-size: 16px;
    }

    .desktop-contact-actions :hover {
        color: var(--color-accent);
    }

    .desktop-contact-actions img {
        width: 20px;
        height: 20px;
    }

    /* max-width intentionally left-aligned (no margin: auto like .max-content)
       so the two-column layout stays flush against the sidebar on ultra-wide screens. */
    .contacts-main {
        display: grid;
        grid-template-columns: clamp(400px, 32vw, 430px) 1fr;
        height: calc(100vh - var(--header-height));
        max-width: 1440px;
        background-color: var(--color-bg);
        overflow: hidden;
    }

    /* flex column + .contacts-scroll-container's flex:1 replaces a hand-calculated
       height, so the scroll area always fills exactly what's left, regardless of
       how tall the add-contact button or padding above it end up being. */
    .contacts-list {
        display: flex;
        flex-direction: column;
        background-color: var(--color-white);
        height: calc(100vh - var(--header-height));
        padding: var(--space-md) var(--space-md) 0 clamp(var(--space-sm), 4vw, var(--space-xl));
        overflow: hidden;
        box-shadow: 4px 0px 6px 0px #00000014;
    }

    /* Keep the list visible even if JS added .d-none for the mobile drill-down
       view before the viewport grew past this breakpoint. */
    .contacts-list.d-none {
        display: flex;
    }

    .desktop-add-contact-wrapper {
        display: block;
        margin-bottom: var(--space-md);
    }

    .desktop-add-contact-btn {
        width: 100%;
        height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: var(--space-sm);
        font-size: 21px;
    }

    .desktop-add-contact-btn img {
        width: 24px;
        height: 24px;
    }

    .contacts-scroll-container {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .add-contact-btn,
    .back-to-contacts-btn,
    .menu_contact_btn {
        display: none;
    }

    .contact-details {
        display: block;
        background-color: var(--color-bg);
        min-width: 0;
    }

    .contact-details.d-none {
        display: block;
    }

    .contact-details-title-row {
        display: flex;
        align-items: center;
        /* The mobile-only back button this padding reserves space for is
           display:none here, so drop it to keep the title-hr divider aligned
           with the deselected placeholder's bare h1. */
        padding-right: 0;
    }

    .contact-details-profile {
        margin-top: 0;
        gap: var(--space-lg);
    }

    .contact-details-card {
        max-width: 640px;
        margin-top: 48px;
        background: transparent;
        box-shadow: none;
        opacity: 0;
        transform: translateX(80px);
        transition: opacity 225ms ease-out, transform 225ms ease-out;
    }

    .contact-details-card.is-open {
        opacity: 1;
        transform: translateX(0);
    }

    .contact-details-avatar {
        width: 120px;
        height: 120px;
        font-size: 47px;
    }

    .contact-details-profile h2 {
        font-weight: var(--font-weight-medium);
    }

    .contact-information-title {
        margin-top: 48px;
    }

    /* Layout/subline/title-hr recipe now lives in the shared .contact-panel-heading
       rules (mobile-base + the 1366px block below) — this just re-enables visibility,
       since .desktop-contact-placeholder is display:none by default at mobile. */
    .desktop-contact-placeholder {
        display: flex;
    }

    .contact_menu {
        display: none;
    }
}

/* 1366px is intentional here (not 768/1024) — matches board.css's own
   breakpoint for the same reasoning: keep the compact layout through most
   laptop widths, since this sits in the narrower 1fr detail-panel column,
   not the full main content width. Shared by .desktop-contact-placeholder
   (no contact selected) and .contact-details-header (contact selected). */
@media (min-width: 1366px) {
    .contact-panel-heading {
        flex-direction: row;
        align-items: center;
        gap: var(--space-md);
    }

    .contact-panel-heading .subline {
        background: none;
        padding-bottom: 0;
    }

    .contact-panel-heading .title-hr {
        height: 59px;
        background-color: var(--color-accent);
        width: 3px;
        margin: 0;
        border: none;
        display: inherit;
    }

    .desktop-contact-actions {
        flex-direction: row;
    }
}