/* ==========================================================================
   الملف الشخصي (/profile/{id}). كل الأصناف تبدأ بـ pf- حتى لا تتعارض مع style.css
   نفس لغة التصميم المستخدمة في الرئيسية وغرفة اسألي (بنفسجي + وردي، زوايا مدوّرة).
   ========================================================================== */

body:has(.pf) {
    background: #f8f6fd;
}

.pf {
    --pf-primary: #8145d8;
    --pf-primary-dark: #6a33bd;
    --pf-accent: #e894e6;
    --pf-grad: linear-gradient(135deg, #e894e6 0%, #8145d8 100%);
    --pf-ink: #1f1b2e;
    --pf-muted: #6f6a82;
    --pf-line: #e8e3f3;
    --pf-soft: #f3effb;
    --pf-surface: #fff;
    --pf-danger: #e5367a;
    --pf-radius: 18px;
    --pf-radius-sm: 12px;
    --pf-shadow: 0 1px 2px rgba(31, 27, 46, .05), 0 10px 28px -14px rgba(76, 40, 140, .25);

    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 0 48px;
    color: var(--pf-ink);
    font-size: 17px;
    line-height: 1.6;
}

.pf *,
.pf *::before,
.pf *::after {
    box-sizing: border-box;
}

.pf [hidden] {
    display: none !important;
}

.pf :focus-visible {
    outline: 2px solid var(--pf-primary);
    outline-offset: 2px;
}

/* ---------- Buttons ---------- */
.pf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    padding: 0 22px;
    border: 1px solid transparent;
    border-radius: var(--pf-radius-sm);
    font: inherit;
    font-size: 17px;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    transition: box-shadow .2s, transform .15s, border-color .2s, color .2s, filter .2s;
}

.pf-btn:active {
    transform: scale(.97);
}

.pf-btn[disabled] {
    opacity: .6;
    cursor: not-allowed;
}

.pf-btn--primary {
    background: var(--pf-grad);
    color: #fff;
    box-shadow: 0 8px 18px -8px rgba(129, 69, 216, .7);
}

.pf-btn--primary:hover {
    color: #fff;
    filter: brightness(1.05);
}

.pf-btn--ghost {
    background: var(--pf-surface);
    border-color: var(--pf-line);
    color: var(--pf-ink);
}

.pf-btn--ghost:hover {
    border-color: var(--pf-primary);
    color: var(--pf-primary);
}

.pf-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--pf-line);
    border-top-color: var(--pf-primary);
    border-radius: 50%;
    animation: pf-spin .7s linear infinite;
}

@keyframes pf-spin {
    to { transform: rotate(360deg); }
}

/* ---------- Header ---------- */
.pf-head {
    overflow: hidden;
    border: 1px solid var(--pf-line);
    border-radius: var(--pf-radius);
    background: var(--pf-surface);
    box-shadow: var(--pf-shadow);
}

.pf-head__cover {
    height: 92px;
    background: var(--pf-grad);
}

.pf-head__main {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 14px 18px;
    padding: 0 22px 18px;
    margin-top: -44px;
}

.pf-avatar {
    flex: none;
    width: 104px;
    height: 104px;
    overflow: hidden;
    border: 4px solid #fff;
    border-radius: 50%;
    background: var(--pf-soft);
    box-shadow: 0 6px 18px -6px rgba(76, 40, 140, .4);
}

.pf-avatar img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pf-head__info {
    flex: 1 1 220px;
    min-width: 0;
    padding-bottom: 4px;
}

.pf-name {
    margin: 0;
    font-size: 1.55rem;
    font-weight: 700;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.pf-since {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 4px 0 0;
    color: var(--pf-muted);
    font-size: 15px;
}

.pf-head__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding-bottom: 4px;
}

.pf-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin: 0;
    border-top: 1px solid var(--pf-line);
    background: #fcfbff;
}

.pf-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 14px 6px;
    text-align: center;
}

.pf-stat + .pf-stat {
    border-inline-start: 1px solid var(--pf-line);
}

.pf-stat dd {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--pf-primary-dark);
}

.pf-stat dt {
    font-size: 14px;
    font-weight: 400;
    color: var(--pf-muted);
}

.pf-star {
    color: #f5a623;
    font-size: 1.05rem;
}

/* ---------- Tabs ---------- */
.pf-tabs {
    display: flex;
    gap: 8px;
    margin: 18px 0 16px;
    padding: 6px;
    overflow-x: auto;
    border: 1px solid var(--pf-line);
    border-radius: var(--pf-radius-sm);
    background: var(--pf-surface);
    box-shadow: var(--pf-shadow);
    scrollbar-width: none;
}

.pf-tabs::-webkit-scrollbar {
    display: none;
}

.pf-tab {
    display: inline-flex;
    flex: 1 1 0;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 18px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--pf-muted);
    font: inherit;
    font-size: 17px;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .2s, color .2s;
}

.pf-tab:hover {
    color: var(--pf-primary);
}

.pf-tab.is-active {
    background: var(--pf-grad);
    color: #fff;
}

.pf-tab__count {
    min-width: 24px;
    padding: 0 8px;
    border-radius: 999px;
    background: var(--pf-soft);
    color: var(--pf-primary-dark);
    font-size: 14px;
    line-height: 24px;
}

.pf-tab.is-active .pf-tab__count {
    background: rgba(255, 255, 255, .25);
    color: #fff;
}

/* ---------- Ads grid ---------- */
.pf-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.pf-card {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--pf-line);
    border-radius: var(--pf-radius);
    background: var(--pf-surface);
    box-shadow: var(--pf-shadow);
    transition: transform .25s, box-shadow .25s, border-color .25s;
}

@media (hover: hover) {
    .pf-card:hover {
        transform: translateY(-4px);
        border-color: #d9ccf3;
        box-shadow: 0 2px 4px rgba(31, 27, 46, .06), 0 18px 36px -14px rgba(76, 40, 140, .38);
    }

    .pf-card:hover .pf-card__media img {
        transform: scale(1.05);
    }
}

.pf-card__media {
    position: relative;
    display: block;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    background: var(--pf-soft);
}

.pf-card__media img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .5s cubic-bezier(.2, .8, .2, 1);
}

.pf-card__ph {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #f6eefc 0%, #ebe3fa 100%);
    color: #c9b6ee;
    font-size: 2.4rem;
}

.pf-card__time {
    position: absolute;
    inset-block-start: 10px;
    inset-inline-start: 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: calc(100% - 64px);
    padding: 2px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .94);
    color: var(--pf-muted);
    font-size: 13px;
    line-height: 1.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pf-fav {
    position: absolute;
    inset-block-start: 10px;
    inset-inline-end: 10px;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--pf-accent);
    color: #fff;
    font-size: 18px;
    line-height: 1;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .15);
    cursor: pointer;
    transition: transform .2s, background-color .2s, color .2s;
}

.pf-fav i {
    display: block;
    width: 1em;
    height: 1em;
    line-height: 1;
}

.pf-fav i::before {
    display: block;
    vertical-align: baseline;
    line-height: 1;
}

.pf-fav:hover {
    transform: scale(1.1);
}

.pf-fav.is-on {
    background: #fff;
    color: var(--pf-danger);
}

.pf-card__body {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 6px;
    padding: 12px 14px 14px;
}

.pf-card__price {
    font-size: 1.1rem;
    line-height: 1.3;
}

.pf-card__price .price-with-currency {
    gap: 5px;
}

.pf-card__price .price-amount {
    font-weight: 700;
    font-size: 1.35rem;
    color: var(--pf-primary);
}

.pf-card__price .price-currency {
    width: 22px;
    height: 22px;
    filter: invert(30%) sepia(60%) saturate(2200%) hue-rotate(250deg) brightness(.95);
}

.pf-card__price--none {
    font-size: 15px;
    color: var(--pf-muted);
}

.pf-card__title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.55;
    min-height: 3.1em;
}

.pf-card__title a {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    color: var(--pf-ink);
    text-decoration: none;
}

/* الرابط يغطي البطاقة كلها */
.pf-card__title a::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
}

.pf-card__title a:hover {
    color: var(--pf-primary);
}

.pf-card__loc {
    display: flex;
    align-items: center;
    gap: 5px;
    margin: auto 0 0;
    padding-top: 8px;
    border-top: 1px dashed var(--pf-line);
    color: var(--pf-muted);
    font-size: 15px;
}

.pf-card__loc span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pf-card__badge {
    align-self: flex-start;
    padding: 0 10px;
    border-radius: 999px;
    background: #fff3e0;
    color: #b26a00;
    font-size: 13px;
}

.pf-more {
    display: flex;
    justify-content: center;
    margin-top: 22px;
}

/* ---------- Empty state ---------- */
.pf-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 48px 20px;
    border: 1px dashed #d9ccf3;
    border-radius: var(--pf-radius);
    background: var(--pf-surface);
    color: var(--pf-muted);
    text-align: center;
}

.pf-empty strong {
    color: var(--pf-ink);
    font-size: 1.2rem;
}

.pf-empty .pf-btn {
    margin-top: 10px;
}

.pf-empty__icon {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--pf-soft);
    color: var(--pf-primary);
    font-size: 1.8rem;
}

/* ---------- Chat ---------- */
.pf-chat {
    display: flex;
    flex-direction: column;
    max-width: 820px;
    margin: 0 auto;
    overflow: hidden;
    border: 1px solid var(--pf-line);
    border-radius: var(--pf-radius);
    background: var(--pf-surface);
    box-shadow: 0 10px 30px rgba(48, 22, 92, .08);
}

.pf-chat__head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--pf-line);
    background: linear-gradient(135deg, #f6efff 0%, #fdf5ff 100%);
}

.pf-chat__avatar {
    flex: none;
    width: 44px;
    height: 44px;
    overflow: hidden;
    border-radius: 50%;
    background: var(--pf-soft);
}

.pf-chat__avatar img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pf-chat__who {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.pf-chat__who strong {
    overflow: hidden;
    font-size: 1.05rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pf-chat__who span {
    color: var(--pf-muted);
    font-size: 13px;
}

.pf-chat__messages {
    position: relative;
    height: min(60vh, 520px);
    min-height: 320px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px 16px 8px;
    background: #faf8fd;
    scrollbar-width: thin;
    scrollbar-color: #d9cdf2 transparent;
}

.pf-chat__list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pf-chat__list > ul {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

/* الرسائل المرسلة من الخادم: صفّ لكل رسالة. رسائلي على اليمين وردّها على اليسار */
.pf-chat [data-conversation-id] {
    display: flex;
    margin: 0 !important;
}

.pf-chat [data-conversation-id]:has(> .mine) {
    justify-content: flex-start;
}

.pf-chat [data-conversation-id]:has(> .other) {
    justify-content: flex-end;
}

.pf-chat .chat-bubble {
    max-width: min(80%, 520px);
    margin: 0;
    padding: 9px 14px;
    border-radius: 16px;
    direction: rtl;
    box-shadow: 0 1px 2px rgba(31, 27, 46, .06);
}

.pf-chat .chat-bubble.mine {
    border-end-start-radius: 16px;
    border-end-end-radius: 4px;
    background: var(--pf-grad) !important;
    color: #fff;
}

.pf-chat .chat-bubble.other {
    border: 1px solid var(--pf-line);
    border-end-start-radius: 4px;
    background: #fff !important;
    color: var(--pf-ink);
}

.pf-chat .chat-bubble__body {
    font-size: 16px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.pf-chat .chat-bubble__meta {
    margin-top: 2px;
    font-size: 12px !important;
    text-align: start !important;
    opacity: .85;
}

.pf-chat .chat-bubble.is-failed {
    opacity: .6;
}

.pf-chat__empty,
.pf-chat__loading {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    position: absolute;
    inset: 0;
    color: var(--pf-muted);
    text-align: center;
}

.pf-chat__empty i {
    color: #c9b6ee;
    font-size: 2.4rem;
}

.pf-chat__empty strong {
    color: var(--pf-ink);
    font-size: 1.1rem;
}

.pf-chat__messages.is-empty .pf-chat__empty {
    display: flex;
}

.pf-chat__messages.is-loading .pf-chat__empty {
    display: none;
}

.pf-chat__loading:not([hidden]) {
    display: flex;
    background: rgba(250, 248, 253, .85);
}

.pf-chat__form {
    padding: 12px 14px;
    border-top: 1px solid var(--pf-line);
    background: #fff;
}

.pf-chat__row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.pf-chat__input {
    flex: 1;
    min-height: 46px;
    max-height: 140px;
    padding: 10px 16px;
    resize: none;
    border: 1px solid var(--pf-line);
    border-radius: 23px;
    background: #faf8fd;
    color: var(--pf-ink);
    font: inherit;
    font-size: 16px;
    line-height: 1.6;
    outline: none;
    scrollbar-width: none;
    transition: border-color .2s, box-shadow .2s, background-color .2s;
}

.pf-chat__input::-webkit-scrollbar {
    display: none;
}

.pf-chat__input:focus {
    border-color: var(--pf-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(129, 69, 216, .15);
}

.pf-chat__send {
    display: grid;
    flex: none;
    place-items: center;
    width: 46px;
    height: 46px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--pf-grad);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    transition: transform .15s, opacity .2s;
}

.pf-chat__send i {
    display: block;
    line-height: 1;
    transform: scaleX(-1); /* السهم يتجه لليسار في الواجهة العربية */
}

.pf-chat__send:active {
    transform: scale(.93);
}

.pf-chat__send:disabled {
    opacity: .45;
    cursor: not-allowed;
}

.pf-chat__meta {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    min-height: 20px;
    margin-top: 6px;
    padding-inline: 6px;
    color: var(--pf-muted);
    font-size: 13px;
}

.pf-chat__error {
    color: var(--pf-danger);
}

/* ---------- Responsive ---------- */
@media (min-width: 640px) {
    .pf-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 16px;
    }

    .pf-tab {
        flex: 0 0 auto;
    }
}

@media (min-width: 992px) {
    .pf-grid {
        gap: 22px;
    }

    .pf-head__cover {
        height: 120px;
    }

    .pf-head__main {
        margin-top: -56px;
        padding-inline: 30px;
    }

    .pf-avatar {
        width: 128px;
        height: 128px;
    }
}

@media (max-width: 575.98px) {
    .pf {
        padding-top: 12px;
        font-size: 16px;
    }

    .pf-head__main {
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding-inline: 16px;
    }

    .pf-head__info {
        flex-basis: auto;
        width: 100%;
    }

    .pf-since {
        justify-content: center;
    }

    .pf-head__actions {
        width: 100%;
    }

    .pf-head__actions .pf-btn {
        flex: 1 1 0;
    }

    .pf-stat dd {
        font-size: 1.15rem;
    }

    .pf-stat dt {
        font-size: 12px;
    }

    .pf-tab {
        padding: 0 10px;
    }

    .pf-card__body {
        padding: 10px 11px 12px;
    }

    .pf-card__title {
        font-size: 16px;
    }

    .pf-card__price .price-amount {
        font-size: 1.15rem;
    }

    .pf-chat__hint {
        display: none;
    }

    .pf-chat .chat-bubble {
        max-width: 88%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .pf *,
    .pf *::before,
    .pf *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}

/* ---------- Toast ---------- */
.pf-toast {
    position: fixed;
    inset-inline: 16px;
    inset-block-end: 24px;
    z-index: 2000;
    width: fit-content;
    max-width: calc(100% - 32px);
    margin-inline: auto;
    padding: 10px 20px;
    border-radius: 999px;
    background: #1f1b2e;
    color: #fff;
    font-size: 16px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity .25s, transform .25s;
}

.pf-toast.is-visible {
    opacity: 1;
    transform: none;
}

.pf-toast.is-error {
    background: #c62855;
}
