/*
 * alignvu UI v2.1: the entity profile v1 (#search-profile-modal in application/views/search/profile.php).
 * A Dialog: the head (entity type, name and status, the record's ID and feed, Try New Profile, Filter, close; then
 * the Details / History / Relationships tabs and the section links) stays put while the body scrolls. Each section
 * is a heading with its count and summary, then a FeedTable (js/modules/search/profile/relationships.js
 * getSectionHTML; shell.js adds av-table to the tables and blanks missing values).
 * The id beats the old .search-profile rules in css/search.css and the <style> in application/views/search/profile_v2.php.
 */

/* ---------- The Dialog ---------- */

#search-profile-modal.app-profile {
    padding: 24px 16px;
    box-sizing: border-box;
}

#search-profile-modal > .modal-content.app-profile__box {
    width: min(1440px, calc(100vw - 32px));
    height: calc(100vh - 48px);
    max-height: calc(100vh - 48px);
    padding: 0;
    gap: 0;
    overflow: hidden;
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--body-ink);
    font-family: var(--font-display);
    box-shadow: 0 12px 40px rgba(26, 26, 46, 0.18);
}

/* ---------- Head: entity type, title and status, ID and feed; the buttons on the right ---------- */

#search-profile-modal .profile-header.app-profile__head {
    position: static;
    flex: none;
    padding: 16px 20px 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 3;
}

#search-profile-modal .app-profile__top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

#search-profile-modal .title-banner {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: auto;
    min-width: 0;
    margin: 0;
    padding: 0;
    background: none;
}

#search-profile-modal .title-banner img#profile-entity-type {
    float: none;
    flex: none;
    width: 40px;
    height: 40px;
    padding: 8px;
    box-sizing: border-box;
    border-radius: var(--radius-pill);
    background: var(--fill);
    object-fit: contain;
}

#search-profile-modal .title-banner .title {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    padding: 0;
}

#search-profile-modal .profile-header .history-breadcrumbs:not(:has(li)) {
    display: none;
}

#search-profile-modal .app-profile__crumb {
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    color: var(--body-ink);
    cursor: pointer;
}

#search-profile-modal .app-profile__crumb:hover {
    color: var(--heading-ink);
    text-decoration: underline;
}

#search-profile-modal .app-profile__titlerow {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 12px;
}

#search-profile-modal .app-profile__titlerow h2 {
    margin: 0;
    font: 600 20px/28px var(--font-display);
    color: var(--heading-ink);
    overflow-wrap: anywhere;
}

#search-profile-modal .app-profile__status:empty {
    display: none;
}

#search-profile-modal .title-banner .title .details,
#search-profile-modal .title-banner .id {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 6px 8px;
    width: auto;
    text-align: left;
    font: 400 13px/18px var(--font-display);
    color: var(--body-ink);
}

#search-profile-modal .title-banner .details:empty,
#search-profile-modal .title-banner .id:empty,
#search-profile-modal .title-banner .profile-filtered-text:empty {
    display: none;
}

#search-profile-modal .app-profile__facts {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-right: 4px;
}

#search-profile-modal .app-profile__recordid {
    font-weight: 600;
}

#search-profile-modal .profile-filtered-text .av-chip {
    font-family: var(--font-display);
}

#search-profile-modal .profile-filtered-text .av-chip .av-icon {
    width: 14px;
    height: 14px;
}

#search-profile-modal .app-profile__actions {
    display: flex;
    flex: none;
    align-items: center;
    gap: 8px;
}

/* Try New Profile: shown by showProfileModal when the profileVersionSwitchEnabled setting is on */
#search-profile-modal.app-profile .app-profile__actions .profile-version-switch-container {
    position: static !important;
    top: auto !important;
    right: auto !important;
    z-index: auto !important;
    align-items: center;
}

#search-profile-modal .app-profile__close {
    margin-left: 4px;
}

/* ---------- Filter menu: a menu surface under the Filter button ---------- */

#search-profile-modal .vendor-filter-menu.app-profile__filter {
    position: relative;
    margin: 0;
}

#search-profile-modal .vendor-filter-menu .filterMenuOpenButton .av-icon {
    width: 16px;
    height: 16px;
}

#search-profile-modal .vendor-filter-menu .vendor-filter-menu-container {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 20;
    width: 340px;
}

#search-profile-modal .vendor-filter-menu .app-feedmenu__head {
    flex-wrap: nowrap;
    justify-content: flex-end;
}

#search-profile-modal .vendor-filter-menu .app-feedmenu__head .filterMenuCloseButton {
    margin-right: auto;
}

#search-profile-modal .vendor-filter-menu .sources-main-container {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 200px);
    gap: 2px;
}

#search-profile-modal .vendor-filter-menu .sources-main-container:empty::after {
    content: "No feeds or reference codes to filter by";
    padding: 8px;
    font: 400 13px/18px var(--font-display);
    color: var(--muted);
}

/* an open category turns its chevron down */
#search-profile-modal .vendor-filter-menu .source-type-container:has(> .sources-container[data-status="active"]) > .source-type > span:last-child {
    transform: rotate(90deg);
}

#search-profile-modal .vendor-filter-menu .sources-container.source {
    flex-direction: column;
    gap: 0;
    padding: 2px 0 6px 8px;
}

#search-profile-modal .vendor-filter-menu label.source-container {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    font: 400 13px/18px var(--font-display);
    color: var(--heading-ink);
    cursor: pointer;
}

#search-profile-modal .vendor-filter-menu label.source-container:hover {
    background: var(--fill);
}

#search-profile-modal .vendor-filter-menu label.source-container input {
    flex: none;
    width: 16px;
    height: 16px;
    margin: 1px 0 0;
    accent-color: var(--heading-ink);
}

#search-profile-modal .vendor-filter-menu .datafeed-source-vendor-name {
    color: var(--muted);
}

/* ---------- Tabs, then the section links (Details) or the date interval (History) ---------- */

#search-profile-modal .search-profile-tabs-container {
    margin: 12px 0 0;
    background: none;
    box-shadow: none;
}

#search-profile-modal .search-profile-tabs.av-tabs {
    width: auto;
    margin: 0;
    gap: 24px;
    border: 0;
}

#search-profile-modal .search-profile-tab.av-tab {
    height: auto;
    padding: 10px 0;
    border: 0;
    background: none;
}

#search-profile-modal .search-profile-tab.av-tab:hover {
    color: var(--heading-ink);
    background: none;
}

#search-profile-modal .search-profile-quicklinks-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 24px;
    height: auto;
    padding: 10px 0;
    border-top: 1px solid var(--row-rule);
}

#search-profile-modal .search-profile-quicklinks-container:not(:has(> :not([style*="display: none"]))) {
    display: none;
}

#search-profile-modal #profile-quicklinks {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 18px;
}

#search-profile-modal .search-profile-quicklinks-container #profile-quicklinks a {
    margin: 0;
    font: 400 13px/18px var(--font-display);
    color: var(--body-ink);
    text-decoration: none;
}

#search-profile-modal .search-profile-quicklinks-container #profile-quicklinks a:hover {
    color: var(--heading-ink);
    text-decoration: underline;
}

#search-profile-modal .app-profile__interval {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

#search-profile-modal .app-profile__interval label.av-field__label {
    margin: 0;
    font: 600 13px/18px var(--font-display);
    color: var(--heading-ink);
}

#search-profile-modal #search-profile-date-interval select.av-select {
    width: 140px;
    padding: 0 32px 0 12px;
}

/* ---------- Body: the sections ---------- */

#search-profile-modal > .modal-content > .modal-body.app-profile__body {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    padding: 20px 20px 24px;
    overflow: auto;
}

#search-profile-modal .search-profile-body {
    display: flex;
    flex-direction: column;
    gap: 28px;
}

#search-profile-modal .details-tab a.profile-link-anchor-offset {
    position: relative;
    top: -20px;
    display: block;
    visibility: hidden;
}

#search-profile-modal .details-tab .search-header-container.app-profile__sectionhead {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    margin: 0 0 10px;
    color: var(--body-ink) !important;
}

#search-profile-modal .app-profile__sectiontitle {
    margin: 0;
    font: 600 15px/22px var(--font-display);
    color: var(--heading-ink);
}

#search-profile-modal .app-profile__count {
    margin-left: 4px;
    font-weight: 400;
    color: var(--muted);
}

#search-profile-modal .search-header-container .profile-section-summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 16px;
    font: 400 13px/18px var(--font-display);
    color: var(--body-ink);
}

#search-profile-modal .search-header-container .profile-section-summary span,
#search-profile-modal .search-header-container .profile-section-summary .av-chip {
    font-size: 13px;
}

#search-profile-modal .search-header-container .profile-section-summary .av-chip {
    gap: 6px;
}

#search-profile-modal .search-header-container .profile-section-summary .av-chip[aria-pressed="true"] .av-muted {
    color: inherit;
}

#search-profile-modal .search-header-container .profile-section-summary:has(.av-chip) {
    gap: 6px 8px;
}

#search-profile-modal .profile-relationships-search-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

#search-profile-modal .details-tab .search-header-container .profile-relationships-search-container input.av-input {
    width: 220px;
    border: 1px solid var(--muted);
    background: var(--surface);
    color: var(--heading-ink);
    font: 400 14px/20px var(--font-display);
}

#search-profile-modal .details-tab .search-profile-extra-header-tag {
    margin: -4px 0 10px;
    font: 400 12px/18px var(--font-display);
    color: var(--muted);
}

/* a table with no rows says so (shell.js adds the row) */
#search-profile-modal .search-profile-body .av-table tr.app-profile__empty td {
    padding: 16px 12px;
    color: var(--muted);
}

/* ---------- The section tables (FeedTable) ---------- */

#search-profile-modal .app-profile__content.av-table__frame {
    overflow-x: auto;
}

#search-profile-modal .search-profile-body .av-table {
    width: 100%;
}

#search-profile-modal .search-profile-body .av-table th {
    display: table-cell;
    max-width: none;
    margin: 0;
    padding: 10px 12px;
    vertical-align: bottom;
    border-bottom: 1px solid var(--border);
    font: 600 12.5px/16px var(--font-display);
    color: var(--heading-ink);
    white-space: nowrap;
}

#search-profile-modal .search-profile-body .av-table td {
    height: auto;
    max-width: 360px;
    margin: 0;
    padding: 8px 12px;
    vertical-align: top;
    border-bottom: 1px solid var(--row-rule);
    font: 400 13px/20px var(--font-display);
    color: var(--table-ink);
    word-break: normal;
    overflow-wrap: break-word;
}

#search-profile-modal .search-profile-body .av-table tr:last-child td {
    border-bottom: 0;
}

#search-profile-modal .search-profile-body .av-table :is(th, td).wider {
    min-width: 260px;
    max-width: 420px;
}

#search-profile-modal .search-profile-body .av-table td p {
    margin: 0;
    font: inherit;
}

#search-profile-modal .search-profile-body .av-table td .flex-col {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

#search-profile-modal .search-profile-body .av-table td a {
    display: inline;
    font: inherit;
    color: var(--heading-ink);
    text-decoration: none;
    word-break: normal;
}

#search-profile-modal .search-profile-body .av-table td a:is([data-action], [href^="http"], [href^="www"]) {
    text-decoration: underline;
    text-decoration-style: dotted;
    text-decoration-color: var(--muted);
    text-underline-offset: 2px;
    cursor: pointer;
}

#search-profile-modal .search-profile-body .av-table td a[href^="#profile-qlink"]:hover,
#search-profile-modal .search-profile-body .av-table td a[data-action]:hover {
    text-decoration: underline;
    text-decoration-color: var(--heading-ink);
}

#search-profile-modal .search-profile-body .av-table td .enrichedRGCValue {
    font-weight: 600;
    text-decoration: underline;
    text-decoration-thickness: 1px;
}

#search-profile-modal .search-profile-body .av-table .boldText {
    font-weight: 600;
}

/* name and address components: the header and cells that open them */
#search-profile-modal .search-profile-body .av-table :is(th, td).expand {
    cursor: pointer;
}

#search-profile-modal .search-profile-body .av-table :is(th, td).expand span img,
#search-profile-modal .search-profile-body .av-table [data-action="profile-history-toggle-group"] img {
    width: 14px;
    max-width: 14px;
    height: 14px;
    margin-left: 2px;
    vertical-align: -2px;
    filter: grayscale(1);
    opacity: 0.7;
}

#search-profile-modal .search-profile-body .av-table td img {
    max-width: 20px;
}

/* the record ID (and on Relationships the link to that record) as a plain Badge; its feed as text under it */
#search-profile-modal .search-profile-body .av-table td a.search-result-tag.orange:not([data-action="profile-show-rgc-timestamps"]) {
    display: inline-flex;
    align-items: center;
    margin: 0 0 4px;
    padding: 2px 10px;
    border: 1px solid var(--muted);
    border-radius: var(--radius-pill);
    background: var(--surface);
    font: 500 12px/16px var(--font-display);
    color: var(--heading-ink);
    text-decoration: none;
    white-space: nowrap;
}

#search-profile-modal .search-profile-body .av-table td a.search-result-tag.orange[data-action]:hover {
    background: var(--fill);
}

#search-profile-modal .search-profile-body .av-table td a.search-result-tag.datafeed-pill {
    display: block;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    font: 400 12.5px/18px var(--font-display);
    color: var(--body-ink);
    text-align: left;
    text-decoration: none;
}

#search-profile-modal .search-profile-body .av-table td a.search-result-tag.datafeed-pill .flex-col {
    display: block;
}

#search-profile-modal .search-profile-body .datafeed-source-vendor-name {
    color: var(--muted);
}

/* "See Added Timestamps": a small link under the reference codes */
#search-profile-modal .search-profile-body .av-table td a.search-result-tag[data-action="profile-show-rgc-timestamps"] {
    display: inline;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    font: 400 12px/16px var(--font-display);
    color: var(--muted);
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

#search-profile-modal .search-profile-body .av-table td a.search-result-tag[data-action="profile-show-rgc-timestamps"]:hover {
    color: var(--heading-ink);
}

/* History: "Same Day Change" as a Badge; long values open with [more...] */
#search-profile-modal .search-profile-body .av-table td a.search-result-tag.samedaychange {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 4px 0 0;
    padding: 2px 10px;
    border: 1px solid var(--muted);
    border-radius: var(--radius-pill);
    background: var(--surface);
    font: 500 12px/16px var(--font-display);
    color: var(--heading-ink);
    white-space: nowrap;
}

#search-profile-modal .search-profile-body .av-table td a.search-result-tag.samedaychange::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: var(--radius-pill);
    background: var(--status-modified);
}

#search-profile-modal .search-profile-body .av-table td p[data-group] + p[data-group] {
    margin-top: 2px;
}

#search-profile-modal .search-profile-body [data-action="profile-history-show-more"],
#search-profile-modal .search-profile-body .profile-notes-expand {
    color: var(--muted);
    text-decoration: underline;
    cursor: pointer;
}

/* ---------- Related Records (countries): place-type tabs, then the feeds' entity counts ---------- */

#search-profile-modal .related-record-place-types {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

#search-profile-modal .related-record-place-types .tab {
    margin: 0;
    padding: 10px 0;
    font: 500 14px/20px var(--font-display);
    color: var(--body-ink);
    text-decoration: none;
    cursor: pointer;
    box-shadow: inset 0 -2px 0 transparent;
}

#search-profile-modal .related-record-place-types .tab.active {
    font-weight: 600;
    color: var(--heading-ink);
    box-shadow: inset 0 -2px 0 var(--heading-ink);
}

#search-profile-modal .search-profile-related-record-header {
    position: static;
    padding: 8px 0;
    border-bottom: 1px solid var(--row-rule);
    font: 600 12.5px/16px var(--font-display);
    color: var(--heading-ink);
}

#search-profile-modal .search-profile-related-record-row {
    padding: 10px 0;
    font: 400 13px/20px var(--font-display);
}

#search-profile-modal .search-profile-related-record-row h2 {
    font: 600 15px/22px var(--font-display);
    color: var(--heading-ink);
}

#search-profile-modal .search-profile-related-record-row .sanction-badge {
    width: auto;
    height: auto;
    padding: 2px 10px;
    border: 1px solid var(--muted);
    border-radius: var(--radius-pill);
}

#search-profile-modal .search-profile-related-record-row .sanction-badge:hover {
    background: var(--fill);
}

#search-profile-modal .search-profile-related-record-row .sanction-badge p {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font: 500 12px/16px var(--font-display);
    color: var(--heading-ink);
}

/* ---------- Relationships pages ---------- */

#search-profile-modal .profile-relationships-pagination.pagination {
    justify-content: flex-end;
    gap: 4px;
    width: auto;
    margin-top: -12px;
    font: 400 13px/18px var(--font-display);
}

#search-profile-modal .profile-relationships-pagination span {
    min-width: 28px;
    height: 28px;
    margin: 0;
    padding: 0 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--heading-ink);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}

#search-profile-modal .profile-relationships-pagination span:hover {
    background: var(--fill);
}

#search-profile-modal .profile-relationships-pagination span.current {
    background: var(--heading-ink);
    color: var(--surface);
    font-weight: 600;
}

/* ---------- The profile's pop-ups: possible connections and the dates a reference code was added ---------- */

:is(#profile-same-attribute-modal, #profile-rgc-vendor-timestamp-modal) .card-container {
    min-height: 0;
    margin: 0;
    background: none;
    box-shadow: none;
}

:is(#profile-same-attribute-modal, #profile-rgc-vendor-timestamp-modal) .modal-content.app-profile-sub {
    width: min(760px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    padding: 0;
    gap: 0;
    overflow: hidden;
    border-radius: var(--radius-md);
    font-family: var(--font-display);
}

#profile-rgc-vendor-timestamp-modal .modal-content.app-profile-sub {
    width: min(520px, calc(100vw - 32px));
}

:is(#profile-same-attribute-modal, #profile-rgc-vendor-timestamp-modal) .modal-header {
    padding: 16px 20px 12px;
}

:is(#profile-same-attribute-modal, #profile-rgc-vendor-timestamp-modal) .modal-title {
    margin: 0;
    font: 600 17px/24px var(--font-display);
    color: var(--heading-ink);
    overflow-wrap: anywhere;
}

:is(#profile-same-attribute-modal, #profile-rgc-vendor-timestamp-modal) .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    padding: 4px 20px 20px;
    overflow: auto;
}

:is(#profile-same-attribute-modal, #profile-rgc-vendor-timestamp-modal) .modal-scroll-content.av-table__frame {
    max-height: none;
    overflow: auto;
}

:is(#profile-same-attribute-modal, #profile-rgc-vendor-timestamp-modal) .modal-scroll-content table.av-table {
    width: 100%;
}

:is(#profile-same-attribute-modal, #profile-rgc-vendor-timestamp-modal) .modal-scroll-content .av-table :is(th, td) {
    width: auto;
    min-width: 0;
    max-width: none;
    height: auto;
    padding: 8px 12px;
    vertical-align: top;
    border-bottom: 1px solid var(--row-rule);
}

:is(#profile-same-attribute-modal, #profile-rgc-vendor-timestamp-modal) .modal-scroll-content .av-table th {
    border-bottom-color: var(--border);
}

#profile-same-attribute-modal .modal-scroll-content .av-table td a {
    font-size: 13px;
    color: var(--heading-ink);
}

#profile-same-attribute-modal .modal-scroll-content .av-table td .search-result-tag {
    display: inline-flex;
    margin: 0 4px 4px 0;
    padding: 2px 10px;
    border: 1px solid var(--muted);
    border-radius: var(--radius-pill);
    background: var(--surface);
    font: 500 12px/16px var(--font-display);
    color: var(--heading-ink);
}

#profile-same-attribute-modal .modal-scroll-content .av-table td .search-result-tag.datafeed-pill {
    border: 0;
    padding: 0;
    font-weight: 400;
}

:is(#profile-same-attribute-modal, #profile-rgc-vendor-timestamp-modal) .nav-buttons-container {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    margin: 0;
    padding: 12px 20px;
    border-top: 1px solid var(--row-rule);
}

/* ---------- Narrow windows: the buttons wrap under the title ---------- */

@media (max-width: 1200px) {
    #search-profile-modal .app-profile__top {
        flex-wrap: wrap;
    }

    #search-profile-modal .app-profile__actions {
        margin-left: auto;
    }

    #search-profile-modal .search-profile-body .av-table td {
        max-width: 280px;
    }
}

/* the pop-ups' head and foot on the Dialog's white; "no connections" when the search found none */
:is(#profile-same-attribute-modal, #profile-rgc-vendor-timestamp-modal) .modal-content.app-profile-sub {
    background: var(--surface);
}

:is(#profile-same-attribute-modal, #profile-rgc-vendor-timestamp-modal) :is(.modal-header, .nav-buttons-container) {
    border-bottom: 0;
    background: none;
}

#profile-same-attribute-modal .modal-scroll-content:not(:has(tr)) {
    border: 0;
}

#profile-same-attribute-modal .modal-scroll-content:not(:has(tr))::after {
    content: "No possible connections found.";
    font: 400 14px/21px var(--font-display);
    color: var(--muted);
}
