/* ── PM AI Chat Widget ──────────────────────────────────────────────────────── */

#pm-ai-root {
    position: fixed;
    z-index: 99999;
    font-family: Tahoma, 'Vazirmatn', sans-serif;
    direction: rtl;
}
#pm-ai-root.pm-ai-pos-bottom-right { bottom: 24px; right: 24px; }
#pm-ai-root.pm-ai-pos-bottom-left  { bottom: 24px; left: 24px; }
#pm-ai-root.pm-ai-pos-top-right    { top: 24px; right: 24px; }
#pm-ai-root.pm-ai-pos-top-left     { top: 24px; left: 24px; }

/* ── FAB button ───────────────────────────────────────────────────────────── */
#pm-ai-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(37,99,235,.45);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    transition: transform .2s, box-shadow .2s;
    padding: 0;
}
.pm-ai-fab-icon { font-size: 20px; line-height: 1; display: block; }
.pm-ai-fab-label {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.5px;
    line-height: 1;
    display: block;
    font-family: 'Vazirmatn', system-ui, sans-serif;
}
#pm-ai-toggle:hover { transform: scale(1.08); box-shadow: 0 6px 24px rgba(37,99,235,.55); }

/* ── Panel ────────────────────────────────────────────────────────────────── */
#pm-ai-panel {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 120px);
    background: #0f172a;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 40px rgba(0,0,0,.5);
    transform: translateY(20px) scale(.97);
    opacity: 0;
    pointer-events: none;
    transition: transform .22s ease, opacity .22s ease;
    overflow: hidden;
}
#pm-ai-panel.pm-ai-open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}
/* left-side: panel opens to the left */
#pm-ai-root.pm-ai-pos-bottom-left #pm-ai-panel,
#pm-ai-root.pm-ai-pos-top-left    #pm-ai-panel { right: auto; left: 0; }
/* top-side: panel opens downward */
#pm-ai-root.pm-ai-pos-top-right #pm-ai-panel,
#pm-ai-root.pm-ai-pos-top-left  #pm-ai-panel { bottom: auto; top: 72px; }

/* ── Header ───────────────────────────────────────────────────────────────── */
#pm-ai-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(90deg, #1e3a5f, #1e40af);
    border-radius: 16px 16px 0 0;
    flex-shrink: 0;
}
#pm-ai-header .pm-ai-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
#pm-ai-header .pm-ai-title-wrap {
    flex: 1;
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    line-height: 1.2;
    min-width: 0;
}
#pm-ai-header .pm-ai-subtitle {
    font-size: 11px;
    color: rgba(255,255,255,.65);
    margin-top: 2px;
    font-weight: normal;
}
#pm-ai-tokens-display {
    font-size: 11px;
    color: rgba(255,255,255,.75);
    background: rgba(255,255,255,.1);
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
    flex-shrink: 0;
    display: none;
}
#pm-ai-header-btns { display: flex; gap: 4px; align-items: center; }
#pm-ai-header button,
#pm-ai-expand {
    background: none;
    border: none;
    color: rgba(255,255,255,.7);
    cursor: pointer;
    font-size: 15px;
    padding: 3px 5px;
    border-radius: 4px;
    transition: color .15s, background .15s;
    line-height: 1;
    text-decoration: none;
    display: flex;
    align-items: center;
}
#pm-ai-header button:hover,
#pm-ai-expand:hover { color: #fff; background: rgba(255,255,255,.12); }
#pm-ai-expand svg { width: 17px; height: 17px; fill: currentColor; }

/* ── Quota bar ────────────────────────────────────────────────────────────── */
#pm-ai-quota { flex-shrink: 0; background: #f0f4f8; border-bottom: 1px solid #dde3ea; font-size: 12px; color: #4a5568; }
#pm-ai-quota:empty { display: none; }
.pm-ai-quota-inner { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 14px; flex-wrap: wrap; }
.pm-ai-quota-bar-wrap { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.pm-ai-quota-row { display: flex; justify-content: space-between; font-size: 10px; color: #64748b; }
.pm-ai-quota-track { background: #d1d9e0; border-radius: 3px; height: 4px; overflow: hidden; }
.pm-ai-quota-fill { height: 4px; border-radius: 3px; transition: width .3s; }

/* ── Disclaimer ───────────────────────────────────────────────────────────── */
#pm-ai-disclaimer {
    padding: 7px 14px;
    background: #1c1a10;
    border-bottom: 1px solid #3d3510;
    color: #a89030;
    font-size: 11.5px;
    text-align: center;
    flex-shrink: 0;
    line-height: 1.4;
}

/* ── Messages ─────────────────────────────────────────────────────────────── */
#pm-ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}
#pm-ai-messages::-webkit-scrollbar { width: 4px; }
#pm-ai-messages::-webkit-scrollbar-track { background: transparent; }
#pm-ai-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

.pm-ai-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
    animation: pm-ai-msg-in .18s ease;
}
@keyframes pm-ai-msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.pm-ai-user {
    background: #2563eb;
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.pm-ai-assistant {
    background: #1e293b;
    color: #e2e8f0;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

/* Markdown */
.pm-ai-msg strong { color: #f1f5f9; }
.pm-ai-msg em { color: #93c5fd; }
.pm-ai-msg .pm-ai-h { margin: 6px 0 4px; color: #e2e8f0; font-size: 13px; }
.pm-ai-msg h2.pm-ai-h { font-size: 14px; }
.pm-ai-msg .pm-ai-icode {
    background: rgba(0,0,0,.35);
    color: #7dd3fc;
    padding: 1px 5px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
}
.pm-ai-msg .pm-ai-pre {
    position: relative;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 10px 12px;
    margin: 6px 0;
    overflow-x: auto;
    font-size: 12px;
}
.pm-ai-msg .pm-ai-pre code { font-family: 'Cascadia Code','Fira Code',monospace; color: #c9d1d9; white-space: pre; }
.pm-ai-msg .pm-ai-lang { position: absolute; top: 6px; left: 10px; font-size: 10px; color: #6e7681; font-family: monospace; }
.pm-ai-msg .pm-ai-ul, .pm-ai-msg .pm-ai-ol { margin: 4px 0; padding-right: 18px; }
.pm-ai-msg .pm-ai-ul li, .pm-ai-msg .pm-ai-ol li { margin: 2px 0; }

/* MathJax */
.pm-ai-msg mjx-container { direction: ltr !important; white-space: normal !important; overflow-x: auto; max-width: 100%; margin: 4px 0; }

/* Cursor */
.pm-ai-cursor {
    display: inline-block;
    width: 2px;
    height: 14px;
    background: #60a5fa;
    margin-right: 2px;
    animation: pm-ai-blink .7s infinite;
    vertical-align: text-bottom;
}
@keyframes pm-ai-blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* History */
.pm-ai-hist-list { display: flex; flex-direction: column; gap: 4px; }
.pm-ai-hist-item {
    padding: 9px 12px;
    background: #1e293b;
    border-radius: 8px;
    cursor: pointer;
    color: #cbd5e1;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background .15s;
}
.pm-ai-hist-item:hover { background: #273548; }
.pm-ai-hist-item small { color: #64748b; font-size: 11px; direction: ltr; }

/* Meta bar */
#pm-ai-meta { padding: 4px 14px; font-size: 11px; color: #475569; text-align: left; direction: ltr; flex-shrink: 0; font-family: monospace; }

/* ── Input area ───────────────────────────────────────────────────────────── */
#pm-ai-input-row {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    background: #1e293b;
    border-radius: 0 0 16px 16px;
    flex-shrink: 0;
    border-top: 1px solid rgba(255,255,255,.07);
}
#pm-ai-input {
    flex: 1;
    background: #0f172a;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 10px;
    color: #e2e8f0;
    padding: 9px 12px;
    font-size: 13.5px;
    resize: none;
    outline: none;
    line-height: 1.4;
    max-height: 120px;
    font-family: inherit;
    transition: border-color .15s;
}
#pm-ai-input:focus { border-color: #2563eb; }
#pm-ai-input::placeholder { color: #475569; }

#pm-ai-send {
    background: #2563eb;
    border: none;
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .1s;
    align-self: flex-end;
}
#pm-ai-send:hover:not(:disabled) { background: #1d4ed8; }
#pm-ai-send:active:not(:disabled) { transform: scale(.93); }
#pm-ai-send:disabled { background: #334155; cursor: not-allowed; }
#pm-ai-send svg { width: 18px; height: 18px; fill: currentColor; }

#pm-ai-stop {
    background: #dc2626;
    border: none;
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .1s;
    align-self: flex-end;
}
#pm-ai-stop:hover { background: #b91c1c; }
#pm-ai-stop:active { transform: scale(.93); }
#pm-ai-stop svg { width: 16px; height: 16px; fill: currentColor; }

/* ── Code action buttons ──────────────────────────────────────────────────── */
.pm-ai-code-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.pm-ai-code-btn {
    background: #1e293b;
    border: 1px solid rgba(255,255,255,.15);
    color: #94a3b8;
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 11px;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.pm-ai-code-btn:hover { background: #273548; color: #e2e8f0; }
.pm-ai-code-run { color: #4ade80; border-color: rgba(74,222,128,.3); }
.pm-ai-code-run:hover { background: #14532d; color: #86efac; }

/* ── Python run modal ─────────────────────────────────────────────────────── */
#pm-ai-run-modal, #pm-ai-tg-popup {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.7);
    z-index: 999999;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.pm-ai-run-inner, .pm-ai-tg-popup-inner {
    background: #0f172a;
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 12px;
    width: 100%;
    max-width: 680px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 85dvh;
}
.pm-ai-run-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(90deg, #1e3a5f, #1e40af);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}
.pm-ai-run-header button {
    background: none; border: none; color: rgba(255,255,255,.7);
    cursor: pointer; font-size: 16px; padding: 2px 6px; border-radius: 4px;
}
.pm-ai-run-header button:hover { color: #fff; background: rgba(255,255,255,.12); }
#pm-ai-run-code {
    flex: 1;
    background: #0d1117;
    border: none;
    color: #c9d1d9;
    padding: 14px 16px;
    font-family: 'Cascadia Code','Fira Code',monospace;
    font-size: 12.5px;
    resize: none;
    outline: none;
    min-height: 160px;
    max-height: 320px;
}
.pm-ai-run-actions {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    background: #0d1117;
    border-top: 1px solid rgba(255,255,255,.07);
    flex-shrink: 0;
}
#pm-ai-run-output {
    background: #020817;
    color: #86efac;
    padding: 12px 16px;
    font-family: 'Cascadia Code','Fira Code',monospace;
    font-size: 12px;
    min-height: 60px;
    max-height: 200px;
    overflow-y: auto;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    flex-shrink: 0;
    border-top: 1px solid rgba(255,255,255,.07);
}
#pm-ai-tg-popup-body code {
    background: #1e293b;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    color: #7dd3fc;
}

/* ══════════════════════════════════════════════════════════════════════════════
   FULL-PAGE CHAT MODE
   ══════════════════════════════════════════════════════════════════════════════ */
#pm-ai-page {
    font-family: Tahoma, 'Vazirmatn', sans-serif;
    direction: rtl;
}
.pm-ai-page-wrap {
    display: flex;
    min-height: calc(100svh - 220px);
    height: calc(100svh - 220px);
    max-height: 900px;
    background: #0f172a;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,.07);
    box-shadow: 0 4px 32px rgba(0,0,0,.4);
}

/* ── Full-page mode (body.pm-aichat-fullpage) ────────────────────────────── */

/* 1. Hide page title, footer */
.pm-aichat-fullpage .page-header,
.pm-aichat-fullpage h1.entry-title,
.pm-aichat-fullpage h1.wp-block-post-title,
.pm-aichat-fullpage .entry-header { display: none !important; }

.pm-aichat-fullpage #site-footer,
.pm-aichat-fullpage .site-footer { display: none !important; }

/* 3. Zero out the Hello Elementor page-content wrapper */
.pm-aichat-fullpage .page-content,
.pm-aichat-fullpage .entry-content,
.pm-aichat-fullpage .wp-block-post-content {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
}

/* 4. The chat container fills naturally (no 100vw trick needed) */
.pm-aichat-fullpage #pm-ai-page {
    width: 100%;
}

.pm-aichat-fullpage .pm-ai-page-wrap {
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    box-shadow: none;
    height: calc(100dvh - var(--wp-admin--admin-bar--height, 0px) - 65px);
    min-height: calc(100dvh - var(--wp-admin--admin-bar--height, 0px) - 65px);
    max-height: none;
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.pm-ai-sidebar {
    width: 260px;
    min-width: 220px;
    max-width: 260px;
    display: flex;
    flex-direction: column;
    background: #070e1b;
    border-left: 1px solid rgba(255,255,255,.07);
    flex-shrink: 0;
    min-height: 0;
    transition: width .22s ease, min-width .22s ease;
    overflow: hidden;
}
.pm-ai-sidebar.pm-ai-sidebar-collapsed {
    width: 44px;
    min-width: 44px;
}
.pm-ai-sidebar.pm-ai-sidebar-collapsed .pm-ai-sidebar-body,
.pm-ai-sidebar.pm-ai-sidebar-collapsed #pm-ai-page-new,
.pm-ai-sidebar.pm-ai-sidebar-collapsed .pm-ai-sidebar-footer { display: none; }
.pm-ai-sidebar-header {
    padding: 10px 8px;
    border-bottom: 1px solid rgba(255,255,255,.07);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
#pm-ai-sidebar-toggle {
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
    font-size: 16px;
    padding: 4px 6px;
    border-radius: 6px;
    line-height: 1;
    flex-shrink: 0;
    transition: color .15s, background .15s, transform .22s;
}
#pm-ai-sidebar-toggle:hover { color: #e2e8f0; background: rgba(255,255,255,.08); }
.pm-ai-sidebar.pm-ai-sidebar-collapsed #pm-ai-sidebar-toggle {
    transform: rotate(180deg);
}
.pm-ai-sidebar-header-inner {
    flex: 1;
    overflow: hidden;
}
.pm-ai-sidebar-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}
#pm-ai-page-new {
    width: 100%;
    background: #1e3a5f;
    border: 1px solid #2563eb;
    color: #93c5fd;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: background .15s;
    text-align: right;
    font-family: inherit;
}
#pm-ai-page-new:hover { background: #1e40af; color: #bfdbfe; }

#pm-ai-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
#pm-ai-sidebar-list::-webkit-scrollbar { width: 3px; }
#pm-ai-sidebar-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 3px; }

.pm-ai-sidebar-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 7px;
    cursor: pointer;
    color: #94a3b8;
    font-size: 12.5px;
    transition: background .12s, color .12s;
    margin-bottom: 2px;
}
.pm-ai-sidebar-item:hover { background: #131e30; color: #e2e8f0; }
.pm-ai-sidebar-item.pm-ai-sidebar-active { background: #1e293b; color: #e2e8f0; }
.pm-ai-sidebar-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pm-ai-sidebar-actions {
    display: none;
    gap: 2px;
    flex-shrink: 0;
}
.pm-ai-sidebar-item:hover .pm-ai-sidebar-actions,
.pm-ai-sidebar-item.pm-ai-sidebar-active .pm-ai-sidebar-actions { display: flex; }
.pm-ai-sidebar-actions button {
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 4px;
    line-height: 1;
    transition: color .12s, background .12s;
}
.pm-ai-sidebar-actions button:hover { color: #e2e8f0; background: rgba(255,255,255,.1); }
.pm-ai-sidebar-rename-inp {
    flex: 1;
    background: #0f172a;
    border: 1px solid #2563eb;
    color: #e2e8f0;
    border-radius: 5px;
    padding: 3px 7px;
    font-size: 12px;
    outline: none;
    font-family: inherit;
    min-width: 0;
}
.pm-ai-sidebar-empty, .pm-ai-sidebar-loading {
    padding: 16px 12px;
    color: #475569;
    font-size: 12px;
    text-align: center;
}
.pm-ai-sidebar-footer {
    padding: 10px 12px;
    border-top: 1px solid rgba(255,255,255,.07);
    flex-shrink: 0;
}
.pm-ai-tg-link-btn {
    width: 100%;
    background: none;
    border: 1px solid rgba(255,255,255,.1);
    color: #64748b;
    border-radius: 7px;
    padding: 7px 10px;
    font-size: 12px;
    cursor: pointer;
    text-align: right;
    font-family: inherit;
    transition: background .12s, color .12s;
}
.pm-ai-tg-link-btn:hover { background: #131e30; color: #94a3b8; }

/* ── Page main area ─────────────────────────────────────────────────────────── */
.pm-ai-page-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #0f172a;
}
.pm-ai-page-main #pm-ai-quota { border-radius: 0; flex-shrink: 0; }
.pm-ai-page-main #pm-ai-messages { border-radius: 0; min-height: 0; }
.pm-ai-page-main #pm-ai-input-row { border-radius: 0; flex-shrink: 0; }
.pm-ai-page-main #pm-ai-disclaimer { border-radius: 0; flex-shrink: 0; }
.pm-ai-page-main #pm-ai-meta { flex-shrink: 0; }

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    #pm-ai-panel {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        height: 65dvh;
        max-height: calc(100dvh - 56px);
    }
    #pm-ai-root.pm-ai-pos-bottom-right,
    #pm-ai-root.pm-ai-pos-bottom-left { bottom: max(18px, env(safe-area-inset-bottom)); }
    #pm-ai-root.pm-ai-pos-bottom-right { right: 18px; }
    #pm-ai-root.pm-ai-pos-bottom-left  { left: 18px; right: auto; }
    #pm-ai-root.pm-ai-pos-top-right    { top: 18px; }
    #pm-ai-root.pm-ai-pos-top-left     { top: 18px; left: 18px; }
    #pm-ai-input-row {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    .pm-ai-page-wrap {
        flex-direction: column;
        height: auto;
        min-height: 85svh;
        border-radius: 8px;
    }
    .pm-ai-sidebar {
        width: 100%;
        max-width: 100%;
        max-height: 180px;
        border-left: none;
        border-bottom: 1px solid rgba(255,255,255,.07);
    }
    #pm-ai-sidebar-list { max-height: 100px; }
}

/* ── Feedback buttons ─────────────────────────────────────────────────────── */
.pm-ai-feedback {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    justify-content: flex-end;
}
.pm-ai-fb-btn {
    background: none;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 20px;
    color: #94a3b8;
    font-size: 14px;
    padding: 3px 10px;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .1s;
    line-height: 1.4;
}
.pm-ai-fb-btn:hover { background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.25); }
.pm-ai-fb-btn:active { transform: scale(.9); }
.pm-ai-fb-btn:disabled { opacity: .4; cursor: default; }
.pm-ai-fb-like:hover  { color: #4ade80; border-color: rgba(74,222,128,.4); }
.pm-ai-fb-dislike:hover { color: #f87171; border-color: rgba(248,113,113,.4); }
.pm-ai-fb-done {
    font-size: 12px;
    color: #64748b;
    align-self: center;
}
