/*
 * Header profile menu: trigger (avatar + name + second line), profile card, grouped rows, flip open / close.
 * Partials: resources/views/partials/profile-menu/*.blade.php, data: App\Support\ProfileMenu.
 * Identical in admin-panel, hms-diyalo and rms-diyalo. Load AFTER responsive-overrides.css.
 * The row look (icon tiles, colours per link, hover) still comes from responsive-overrides.css
 * (.header-user-group .origin-top-right ul > li > a); this file adds the card, chips, switches, groups, avatar and
 * the animation. Light and dark (html.dark). Root font is 14px, so 1rem = 14px here.
 */

/* ---------- avatar ---------- */
.pm-avatar {
    --pm-hue: 160;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    overflow: hidden;
    border-radius: 9999px;
    background: hsl(var(--pm-hue) 70% 90%);
    color: hsl(var(--pm-hue) 60% 28%);
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1;
    box-shadow: 0 0 0 2px #fff, 0 1px 3px rgb(15 23 42 / 0.18);
    user-select: none;
}
.pm-avatar--sm { width: 1.85rem; height: 1.85rem; font-size: 0.68rem; }
.pm-avatar--lg { width: 3.1rem; height: 3.1rem; font-size: 1.05rem; }
.pm-avatar > img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #fff;
}
html.dark .pm-avatar {
    background: hsl(var(--pm-hue) 40% 24%);
    color: hsl(var(--pm-hue) 70% 82%);
    box-shadow: 0 0 0 2px #0f172a, 0 1px 3px rgb(0 0 0 / 0.5);
}

/* ---------- trigger button ---------- */
.header-user-group:not(#_) > button.pm-trigger {
    gap: 0.5rem;
    min-height: 2.55rem !important;
    padding: 0.25rem 0.55rem 0.25rem 0.3rem !important;
    max-width: 16rem;
}
.pm-trigger-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
    max-width: 11rem;
    text-align: left;
    line-height: 1.15;
}
.pm-trigger-name,
.pm-trigger-sub {
    display: block;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.pm-trigger-name { font-size: 0.82rem; font-weight: 600; color: #1e293b; }
.pm-trigger-sub { margin-top: 1px; font-size: 0.68rem; font-weight: 500; color: #64748b; }
.pm-trigger-chevron { width: 0.7rem; height: 0.7rem; flex: 0 0 auto; fill: #94a3b8; transition: transform 0.25s ease; }
.pm-trigger[aria-expanded="true"] .pm-trigger-chevron { transform: rotate(180deg); }
html.dark .pm-trigger-name { color: #f1f5f9; }
html.dark .pm-trigger-sub { color: #94a3b8; }
html.dark .header-user-group:not(#_) > button.pm-trigger {
    background: #1e293b !important;
    border-color: #334155 !important;
}

/* ---------- panel ---------- */
.header-user-group:not(#_):not(#_) .origin-top-right.pm-panel {
    width: 23.5rem !important;
    min-width: 23.5rem !important;
    max-width: 23.5rem !important;
    max-height: calc(100dvh - 5.5rem);
    overflow-y: auto !important;
    overscroll-behavior: contain;
    padding: 0.4rem !important;
    border-radius: 0.9rem;
    transform-origin: top right;
}
@media (max-width: 640px) {
    .header-user-group:not(#_):not(#_) .origin-top-right.pm-panel {
        width: min(calc(100vw - 1rem), 23.5rem) !important;
        min-width: min(calc(100vw - 1rem), 23.5rem) !important;
        max-width: min(calc(100vw - 1rem), 23.5rem) !important;
    }
    .pm-trigger-text { max-width: min(34vw, 8.5rem); }
}

/* ---------- profile card ---------- */
.pm-head {
    margin-bottom: 0.35rem;
    padding: 0.7rem;
    border: 1px solid #e2e8f0;
    /* same leaf corners as the panel (custom.css) */
    border-radius: 1rem 0.3rem 1rem 0.3rem;
    background: linear-gradient(160deg, #ecfdf5 0%, #f8fafc 55%, #ffffff 100%);
}
.pm-card { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }
.pm-card-avatar { display: inline-flex; flex: 0 0 auto; border-radius: 9999px; }
a.pm-card-avatar:hover .pm-avatar,
a.pm-card-avatar:focus-visible .pm-avatar { box-shadow: 0 0 0 2px #fff, 0 0 0 4px #10b981; }
.pm-card-main { min-width: 0; flex: 1 1 auto; }
.pm-card-name {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    max-width: 100%;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.25;
    color: #0f172a;
    text-decoration: none;
}
/* long names (an organization's name used as the user name) wrap to two lines before they are cut */
.pm-card-name > span {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow-wrap: anywhere;
}
.pm-card-name > :is(i, svg) { flex: 0 0 auto; width: 0.62rem; height: 0.62rem; font-size: 0.62rem; color: #94a3b8; opacity: 0; transition: opacity 0.15s ease; }
a.pm-card-name:hover,
a.pm-card-name:focus-visible { color: #047857; }
a.pm-card-name:hover > :is(i, svg),
a.pm-card-name:focus-visible > :is(i, svg) { opacity: 1; color: #047857; }
.pm-card-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; margin-top: 0.3rem; }
.pm-role {
    padding: 0.08rem 0.5rem;
    border-radius: 9999px;
    background: #d1fae5;
    color: #047857;
    font-size: 0.66rem;
    font-weight: 600;
    line-height: 1.35;
}
.pm-version {
    padding: 0.08rem 0.4rem;
    border-radius: 9999px;
    background: #f1f5f9;
    color: #64748b;
    font-size: 0.62rem;
    font-weight: 600;
    line-height: 1.35;
}

/* details: compact chips that wrap (customer no. · mobile · address ...), each cut with … and full text on hover */
.pm-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0.6rem 0 0; padding: 0; }
.pm-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
    max-width: 100%;
    padding: 0.22rem 0.55rem;
    border: 1px solid #e2e8f0;
    border-radius: 9999px;
    background: rgb(255 255 255 / 0.85);
    color: #334155;
    font-size: 0.72rem;
    font-weight: 500;
    line-height: 1.3;
}
.pm-chip > :is(i, svg) { flex: 0 0 auto; width: 0.66rem; height: 0.66rem; font-size: 0.66rem; color: #10b981; }
.pm-chip-text { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* switches: two matching segmented controls. The active option itself carries the solid emerald fill (no separate
   sliding layer that a theme / skin rule could hide), with a small gap between the two options. Light + dark. */
.pm-switches { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.35rem; margin-top: 0.6rem; }
.pm-switches--single { grid-template-columns: minmax(0, 1fr); }
.header-user-group:not(#_):not(#_) .pm-seg {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.2rem;
    height: 2.3rem;
    padding: 0.18rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.7rem;
    background: #f1f5f9;
}
.header-user-group:not(#_):not(#_) .pm-seg > button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    min-width: 0;
    height: 100%;
    padding: 0 0.25rem;
    border: 1px solid transparent;
    border-radius: 0.5rem;
    background: transparent !important;
    box-shadow: none;
    color: #475569 !important;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
/* the label clips (ellipsis), so it needs a line box tall enough for descenders ("g" in Light / Mega) */
.header-user-group:not(#_):not(#_) .pm-seg > button > span { overflow: hidden; text-overflow: ellipsis; line-height: 1.35; padding-block: 0.05rem; }
.header-user-group:not(#_):not(#_) .pm-seg > button :is(i, svg) { flex: 0 0 auto; width: 0.7rem; height: 0.7rem; font-size: 0.7rem; color: #10b981 !important; }
.header-user-group:not(#_):not(#_) .pm-seg > button:not(.is-on):hover { background: #fff !important; color: #047857 !important; }
.header-user-group:not(#_):not(#_) .pm-seg > button.is-on {
    background: #047857 !important;
    border-color: #047857;
    color: #fff !important;
    font-weight: 700;
    box-shadow: 0 2px 6px -2px rgb(4 120 87 / 0.6);
}
.header-user-group:not(#_):not(#_) .pm-seg > button.is-on :is(i, svg) { color: #fff !important; }
.header-user-group:not(#_):not(#_) .pm-seg > button:focus-visible { outline: 2px solid rgb(16 185 129 / 0.6); outline-offset: 1px; }
html.dark .header-user-group:not(#_):not(#_) .pm-seg { background: #0f172a; border-color: #334155; }
html.dark .header-user-group:not(#_):not(#_) .pm-seg > button { color: #cbd5e1 !important; }
html.dark .header-user-group:not(#_):not(#_) .pm-seg > button :is(i, svg) { color: #34d399 !important; }
html.dark .header-user-group:not(#_):not(#_) .pm-seg > button:not(.is-on):hover { background: #1e293b !important; color: #6ee7b7 !important; }
/* dark: brighter fill + light ring so the active option stands out on the dark card */
html.dark .header-user-group:not(#_):not(#_) .pm-seg > button.is-on {
    background: #059669 !important;
    border-color: #34d399;
    color: #fff !important;
    box-shadow: 0 0 0 1px rgb(52 211 153 / 0.35), 0 4px 10px -4px rgb(0 0 0 / 0.6);
}
html.dark .header-user-group:not(#_):not(#_) .pm-seg > button.is-on :is(i, svg) { color: #fff !important; }
@media (max-width: 1023px) {
    /* the menu-mode switch only matters on the desktop header */
    .header-user-group:not(#_):not(#_) .pm-seg--mode { display: none; }
    .pm-switches { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- groups ---------- */
.pm-group + .pm-group { margin-top: 0.3rem; padding-top: 0.3rem; border-top: 1px solid #eef2f7; }
.pm-group-title {
    padding: 0.3rem 0.6rem 0.15rem;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #94a3b8;
}
.pm-group--session .pm-group-title { display: none; }
/* the logout row already sits in its own group: no extra rule above it */
.header-user-group:not(#_):not(#_) .pm-panel ul > li.profile-row-logout { margin-top: 0; padding-top: 0; border-top: 0 !important; }

/* ---------- open / close: the whole menu flips as one card, right to left ----------
   Open: turning on its vertical centre line, the card swings in from edge-on (right side first) to flat.
   Close: the exact reverse (same duration, mirrored curve), flat back to edge-on.
   Alpine x-transition classes in each layout: enter = pm-flip-enter + from -> to, leave = pm-flip-leave + to -> from.
   Nothing inside the panel animates on its own, and the resting state has no transform, so the text stays crisp
   (a 3D transform left on an element renders its text soft). */
.pm-flip-enter { transition: transform 0.42s cubic-bezier(0.2, 0.8, 0.3, 1), opacity 0.3s ease-out; }
.pm-flip-leave { transition: transform 0.42s cubic-bezier(0.7, 0, 0.8, 0.2), opacity 0.3s ease-in 0.12s; }
.pm-flip-from { opacity: 0; transform: perspective(1400px) rotateY(90deg); }
.pm-flip-to { opacity: 1; transform: perspective(1400px) rotateY(0deg); }
.header-user-group:not(#_):not(#_) .origin-top-right.pm-panel:is(.pm-flip-enter, .pm-flip-leave) {
    transform-origin: 50% 50%;
    backface-visibility: hidden;
    will-change: transform, opacity;
}
@media (prefers-reduced-motion: reduce) {
    .pm-flip-enter, .pm-flip-leave { transition: opacity 0.12s linear; }
    .pm-flip-from, .pm-flip-to { transform: none; }
}

/* ---------- dark ---------- */
html.dark .pm-head {
    border-color: #1e293b;
    background: linear-gradient(160deg, rgb(16 185 129 / 0.12) 0%, rgb(255 255 255 / 0.03) 60%);
}
html.dark .pm-card-name { color: #f1f5f9; }
html.dark a.pm-card-name:hover,
html.dark a.pm-card-name:focus-visible,
html.dark a.pm-card-name:hover > :is(i, svg) { color: #6ee7b7; }
html.dark a.pm-card-avatar:hover .pm-avatar { box-shadow: 0 0 0 2px #0f172a, 0 0 0 4px #10b981; }
html.dark .pm-role { background: rgb(16 185 129 / 0.16); color: #6ee7b7; }
html.dark .pm-version { background: rgb(255 255 255 / 0.06); color: #94a3b8; }
html.dark .pm-chip { background: rgb(255 255 255 / 0.04); border-color: #1e293b; color: #cbd5e1; }
html.dark .pm-chip > :is(i, svg) { color: #34d399; }
html.dark .pm-group + .pm-group { border-top-color: #1e293b; }
html.dark .pm-group-title { color: #64748b; }
