/* /assets/css/ai-advisor.css — دستیار هوشمند انتخاب رسانه تاپیکال (v1.3.0) */

#tpAiAdvisor {
    --tpai-navy: #173e75;
    --tpai-deep: #0d2a53;
    --tpai-blue: #2f64ad;
    --tpai-sky: #7aa2d8;
    --tpai-red: #df263c;
    --tpai-green: #168566;
    --tpai-paper: #f5f7fb;
    --tpai-ink: #152235;
    --tpai-muted: #66758a;
    --tpai-line: #dde4ee;
    --tpai-soft: #edf3fc;
    font-size: 14px;
    line-height: 1.8;
    color: var(--tpai-ink);
}

#tpAiAdvisor *,
#tpAiAdvisor *::before,
#tpAiAdvisor *::after { box-sizing: border-box; }

#tpAiAdvisor [hidden] { display: none !important; }

/* ---------- launcher ---------- */

.tpai-launcher {
    position: fixed;
    z-index: 1040;
    right: 22px;
    bottom: 22px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 0 18px 0 14px;
    border: 0;
    border-radius: 999px;
    background: var(--tpai-navy);
    color: #fff;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 14px 34px rgba(13, 42, 83, .28);
    cursor: pointer;
    transition: background-color .15s ease, transform .15s ease;
}
.tpai-launcher:hover { background: var(--tpai-deep); }
.tpai-launcher:active { transform: translateY(1px); }

/* آیکون: سه نوار با طول‌های متفاوت = تقسیم بودجه بین رسانه‌ها */
.tpai-launcher-icon {
    width: 20px;
    height: 16px;
    flex: 0 0 auto;
    background:
        linear-gradient(#fff, #fff) 0 0 / 100% 3px no-repeat,
        linear-gradient(#fff, #fff) 0 6px / 62% 3px no-repeat,
        linear-gradient(var(--tpai-red), var(--tpai-red)) 0 12px / 36% 3px no-repeat;
    border-radius: 2px;
}
[dir="rtl"] .tpai-launcher-icon { transform: scaleX(-1); }

/* ---------- teaser ---------- */

.tpai-teaser {
    position: fixed;
    z-index: 1040;
    right: 22px;
    bottom: 82px;
    display: flex;
    align-items: flex-start;
    gap: 6px;
    max-width: 290px;
    padding: 12px 12px 12px 8px;
    border: 1px solid var(--tpai-line);
    border-radius: 14px 14px 4px 14px;
    background: #fff;
    box-shadow: 0 16px 40px rgba(17, 40, 71, .18);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .25s ease, transform .25s ease;
}
.tpai-teaser.is-visible { opacity: 1; transform: none; }
.tpai-teaser-text {
    padding: 0;
    border: 0;
    background: none;
    color: var(--tpai-ink);
    font: inherit;
    font-size: 13px;
    line-height: 1.9;
    text-align: right;
    cursor: pointer;
}
.tpai-teaser-close {
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--tpai-paper);
    color: var(--tpai-muted);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
}

/* ---------- panel ---------- */

.tpai-panel {
    position: fixed;
    z-index: 1060;
    right: 22px;
    bottom: 22px;
    display: flex;
    flex-direction: column;
    width: 410px;
    height: min(680px, calc(100vh - 44px));
    border: 1px solid var(--tpai-line);
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 28px 70px rgba(13, 42, 83, .26);
    overflow: hidden;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity .2s ease, transform .2s ease;
}
.tpai-panel.is-open { opacity: 1; transform: none; }

.tpai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    background: var(--tpai-deep);
    color: #fff;
}
.tpai-title { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.6; color: #fff; }
.tpai-subtitle { margin: 0; font-size: 12px; color: #b9cbe6; line-height: 1.6; }
.tpai-close {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .25);
    border-radius: 10px;
    background: transparent;
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}
.tpai-close:hover { background: rgba(255, 255, 255, .1); }

.tpai-log {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--tpai-paper);
}

.tpai-msg {
    max-width: 92%;
    font-size: 13.5px;
    line-height: 1.95;
    white-space: pre-line;
}
.tpai-msg-bot {
    align-self: flex-start;
    padding: 10px 14px;
    border: 1px solid var(--tpai-line);
    border-inline-start: 3px solid var(--tpai-navy);
    border-radius: 4px 12px 12px 4px;
    background: #fff;
}
.tpai-msg-bot.is-error { border-inline-start-color: var(--tpai-red); background: #fff6f7; }
.tpai-msg-bot.is-success { border-inline-start-color: var(--tpai-green); }
.tpai-msg-bot.is-thinking { display: flex; align-items: center; gap: 10px; color: var(--tpai-muted); }
.tpai-msg-me {
    align-self: flex-end;
    padding: 7px 13px;
    border-radius: 12px;
    background: var(--tpai-soft);
    color: var(--tpai-deep);
    font-size: 13px;
}

.tpai-dots { display: inline-flex; gap: 4px; }
.tpai-dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--tpai-navy);
    animation: tpai-dot 1.1s infinite ease-in-out;
}
.tpai-dots i:nth-child(2) { animation-delay: .15s; }
.tpai-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes tpai-dot {
    0%, 80%, 100% { opacity: .25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- composer & form controls ---------- */

.tpai-composer {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 62%;
    padding: 12px 16px 14px;
    border-top: 1px solid var(--tpai-line);
    background: #fff;
    overflow-y: auto;
}
.tpai-composer:empty { display: none; }
.tpai-composer.is-waiting { opacity: .6; pointer-events: none; }

.tpai-form { display: flex; flex-direction: column; gap: 10px; }
.tpai-row { display: flex; gap: 8px; align-items: stretch; }
.tpai-row > .tpai-input { flex: 1 1 auto; min-width: 0; }
.tpai-row-links { justify-content: space-between; }

.tpai-field { display: flex; flex-direction: column; gap: 4px; margin: 0; }
.tpai-field-tight { margin-top: 8px; }
.tpai-field-label { font-size: 12px; font-weight: 700; color: var(--tpai-ink); }
.tpai-field-hint { font-size: 11.5px; color: var(--tpai-muted); }

.tpai-input {
    width: 100%;
    min-height: 42px;
    padding: 8px 12px;
    border: 1px solid #cdd7e4;
    border-radius: 10px;
    background: #fff;
    color: var(--tpai-ink);
    font: inherit;
    font-size: 14px;
    line-height: 1.7;
    resize: vertical;
}
textarea.tpai-input { min-height: 76px; }
.tpai-input:focus { outline: none; border-color: var(--tpai-navy); box-shadow: 0 0 0 3px rgba(23, 62, 117, .14); }
.tpai-input-ltr { direction: ltr; text-align: left; }
.tpai-input-code { letter-spacing: .4em; font-size: 17px; text-align: center; }
.tpai-input-title { font-weight: 700; font-size: 13.5px; }

.tpai-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid var(--tpai-line);
    border-radius: 10px;
    background: #fff;
    color: var(--tpai-navy);
    font: inherit;
    font-size: 13.5px;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}
.tpai-btn:hover { border-color: var(--tpai-navy); }
.tpai-btn-primary { border-color: var(--tpai-red); background: var(--tpai-red); color: #fff !important; }
.tpai-btn-primary:hover { border-color: #b9152a; background: #b9152a; }
.tpai-btn-ghost { border-color: transparent; background: transparent; }
.tpai-btn-ghost:hover { border-color: var(--tpai-line); }
.tpai-btn-block { width: 100%; }
.tpai-btn[disabled] { opacity: .55; cursor: not-allowed; }

.tpai-link {
    padding: 0;
    border: 0;
    background: none;
    color: var(--tpai-navy);
    font: inherit;
    font-size: 12.5px;
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}
.tpai-link[disabled] { color: var(--tpai-muted); text-decoration: none; cursor: default; }

.tpai-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.tpai-chip {
    padding: 4px 11px;
    border: 1px solid var(--tpai-line);
    border-radius: 999px;
    background: #fff;
    color: var(--tpai-ink);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}
.tpai-chip.is-active { border-color: var(--tpai-navy); background: var(--tpai-soft); color: var(--tpai-navy); font-weight: 700; }

#tpAiAdvisor :focus-visible { outline: 2px solid var(--tpai-red); outline-offset: 2px; }

/* ---------- mode switch: رپورتاژ / بک‌لینک ---------- */

.tpai-segment {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--tpai-line);
    border-radius: 12px;
    background: var(--tpai-paper);
}
.tpai-segment-btn {
    min-height: 38px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--tpai-muted);
    font: inherit;
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
}
.tpai-segment-btn.is-active {
    background: #fff;
    color: var(--tpai-deep);
    box-shadow: 0 1px 0 var(--tpai-line), 0 4px 12px rgba(13, 42, 83, .08);
}

/* ---------- review toggle ---------- */

.tpai-review {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid var(--tpai-line);
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
}
.tpai-review strong { display: block; font-size: 13px; line-height: 1.7; }
.tpai-review .tpai-field-hint { display: block; line-height: 1.8; }

/* ---------- link pairs ---------- */

.tpai-link-pair { display: flex; flex-direction: column; gap: 4px; }
.tpai-link-pair + .tpai-link-pair { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--tpai-line); }
.tpai-link-no { font-size: 12px; font-weight: 700; color: var(--tpai-deep); }
.tpai-link-inputs { display: grid; grid-template-columns: 1fr; gap: 6px; }

/* ---------- result: budget meter (focal element) ---------- */

.tpai-result {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 0 4px;
}
.tpai-result.is-done { opacity: .6; }

.tpai-meter {
    position: sticky;
    top: -16px;
    z-index: 2;
    margin: 0 -16px;
    padding: 12px 16px 12px;
    border-bottom: 1px solid var(--tpai-line);
    background: var(--tpai-paper);
}
.tpai-meter-label {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 6px;
    margin-bottom: 7px;
    font-size: 12.5px;
    color: var(--tpai-muted);
}
.tpai-meter-label strong { font-size: 16px; color: var(--tpai-deep); }
.tpai-meter-rest { margin-inline-start: auto; font-size: 12px; color: var(--tpai-green); font-weight: 700; }
.tpai-meter.is-over .tpai-meter-rest,
.tpai-meter.is-over .tpai-meter-label strong { color: var(--tpai-red); }

.tpai-meter-bar {
    display: flex;
    height: 16px;
    border-radius: 5px;
    overflow: hidden;
    background: repeating-linear-gradient(-45deg, #e4eaf2 0 5px, #f3f6fa 5px 10px);
}
.tpai-meter.is-over .tpai-meter-bar { box-shadow: 0 0 0 2px var(--tpai-red); }
.tpai-meter-seg {
    height: 100%;
    flex: 0 0 auto;
    border-inline-end: 2px solid #fff;
    background: var(--tpai-navy);
    transition: width .2s ease;
}
.tpai-meter-seg:nth-child(3n+2) { background: var(--tpai-blue); }
.tpai-meter-seg:nth-child(3n+3) { background: var(--tpai-sky); }

/* ---------- result list ---------- */

.tpai-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }

.tpai-item {
    padding: 12px;
    border: 1px solid var(--tpai-line);
    border-radius: 12px;
    background: #fff;
    transition: opacity .15s ease, border-color .15s ease;
}
.tpai-item:has(.tpai-check:checked) { border-color: #a9bedb; }
.tpai-item.is-off { opacity: .55; }
.tpai-item.is-off .tpai-input-title { text-decoration: line-through; text-decoration-color: var(--tpai-muted); }

.tpai-item-head { display: flex; align-items: flex-start; gap: 10px; }
.tpai-check { width: 18px; height: 18px; margin: 3px 0 0; flex: 0 0 auto; accent-color: var(--tpai-navy); cursor: pointer; }

.tpai-site { flex: 1 1 auto; min-width: 0; cursor: pointer; }
.tpai-site-name { font-size: 14px; font-weight: 700; line-height: 1.6; }
.tpai-site-domain { font-size: 12px; color: var(--tpai-muted); text-align: right; unicode-bidi: plaintext; }
.tpai-site-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 2px; font-size: 11.5px; color: var(--tpai-muted); }
.tpai-score { color: var(--tpai-navy); font-weight: 700; }

.tpai-price { display: flex; flex-direction: column; align-items: flex-end; flex: 0 0 auto; line-height: 1.4; text-align: left; }
.tpai-price s { font-size: 11px; color: var(--tpai-muted); }
.tpai-price strong { font-size: 14px; color: var(--tpai-deep); }
.tpai-price small { font-size: 10.5px; color: var(--tpai-muted); }

.tpai-angle { margin: 6px 0 0; font-size: 12.5px; line-height: 1.9; color: var(--tpai-muted); }

.tpai-details { margin-top: 6px; }
.tpai-details summary {
    width: max-content;
    font-size: 12px;
    font-weight: 700;
    color: var(--tpai-navy);
    cursor: pointer;
}
.tpai-details[open] summary { margin-bottom: 6px; }
.tpai-details .tpai-field + .tpai-field { margin-top: 8px; }

.tpai-extras { margin-top: 6px; }
.tpai-extras-title { margin: 0 0 6px; font-size: 12.5px; font-weight: 700; color: var(--tpai-muted); }

/* ---------- mobile ---------- */

@media (max-width: 767.98px) {
    .tpai-launcher {
        right: 12px;
        bottom: 78px; /* بالای نوار ناوبری پایین موبایل */
        min-height: 44px;
        padding: 0 14px 0 12px;
        font-size: 12px;
    }
    .tpai-teaser { right: 12px; left: 12px; bottom: 132px; max-width: none; }
    .tpai-panel {
        inset: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;
        border: 0;
        border-radius: 0;
    }
    .tpai-composer { max-height: 55%; padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
    /* باز شدن خودکار در موبایل: نیم‌صفحه پایین؛ با لمس، تمام‌صفحه می‌شود */
    .tpai-panel.is-peek {
        top: auto;
        height: 58vh;
        height: 58dvh;
        border-top: 1px solid var(--tpai-line);
        border-radius: 18px 18px 0 0;
        box-shadow: 0 -18px 50px rgba(13, 42, 83, .25);
    }
    .tpai-panel.is-peek .tpai-composer { max-height: 60%; }
    html.tpai-open, html.tpai-open body { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
    .tpai-panel, .tpai-teaser, .tpai-launcher, .tpai-item, .tpai-meter-seg { transition: none; }
    .tpai-dots i { animation: none; opacity: .6; }
}


/* ==========================================================
   حالت درون‌صفحه‌ای + شخصیت «لینک‌الدوله» (v1.3.0)
   فقط وقتی root دارای data-inline="1" باشد استفاده می‌شود.
   ========================================================== */

#tpAiAdvisor.is-inline { display: block; }

.tpai-panel.is-inline {
    position: relative;
    inset: auto;
    z-index: 1;
    width: 100%;
    height: auto;
    min-height: 0;
    border-radius: 22px;
    opacity: 1;
    transform: none;
    overflow: clip; /* برای sticky (بر خلاف hidden، کادر اسکرول نمی‌سازد) */
    box-shadow: 0 26px 70px rgba(13, 42, 83, .22);
}
.tpai-panel.is-inline .tpai-header { justify-content: flex-start; }
/* نتایج در خود صفحه اسکرول می‌شوند، نه داخل یک کادر تودرتو */
.tpai-panel.is-inline .tpai-log { flex: 0 0 auto; min-height: 300px; max-height: none; overflow: visible; }
.tpai-panel.is-inline .tpai-msg { scroll-margin-top: 110px; }
.tpai-panel.is-inline .tpai-composer.is-sticky {
    position: sticky;
    bottom: 0;
    z-index: 3;
    box-shadow: 0 -12px 28px rgba(13, 42, 83, .12);
}
.tpai-panel.is-inline .tpai-composer { max-height: none; overflow: visible; }
.tpai-panel.is-inline .tpai-close { display: none; }

.tpai-avatar {
    flex: 0 0 auto;
    width: 46px;
    height: 46px;
    border: 2px solid #d4b062;
    border-radius: 50%;
    background: #fbf4e4;
    object-fit: cover;
}

/* ظاهر لینک‌الدوله */
.tpai-persona .tpai-header {
    background: linear-gradient(120deg, #0d2a53 0%, #173e75 58%, #5b2540 135%);
    border-bottom: 3px solid #d4b062;
}
.tpai-persona .tpai-subtitle { color: #f0d9a2; }
.tpai-persona .tpai-log { background: #fbf8f1; }

.tpai-persona .tpai-msg-bot {
    position: relative;
    margin-inline-start: 46px;
    border-inline-start-color: #d4b062;
}
.tpai-persona .tpai-msg-bot.is-error { border-inline-start-color: var(--tpai-red); }
.tpai-persona .tpai-msg-bot.is-success { border-inline-start-color: var(--tpai-green); }
.tpai-persona .tpai-msg-bot:not(.is-thinking)::before {
    content: "";
    position: absolute;
    top: 0;
    inset-inline-start: -48px;
    width: 36px;
    height: 36px;
    border: 2px solid #d4b062;
    border-radius: 50%;
    background: #fbf4e4 var(--tpai-avatar) center / cover no-repeat;
}
/* آواتار فقط برای اولین پیام از چند پیام پشت‌سرهم */
.tpai-persona .tpai-msg-bot + .tpai-msg-bot::before { display: none; }

@media (max-width: 767.98px) {
    .tpai-panel.is-inline {
        inset: auto;
        width: 100%;
        height: auto;
        min-height: 0;
        border: 1px solid var(--tpai-line);
        border-radius: 18px;
    }
    .tpai-panel.is-inline .tpai-composer.is-sticky { bottom: calc(66px + env(safe-area-inset-bottom, 0px)); } /* بالای نوار ناوبری پایین موبایل */
    .tpai-panel.is-inline .tpai-composer { padding-bottom: 14px; }
    .tpai-persona .tpai-msg-bot { margin-inline-start: 40px; }
    .tpai-persona .tpai-msg-bot:not(.is-thinking)::before { inset-inline-start: -42px; width: 32px; height: 32px; }
}
