/* ============================================================
   PIIMACHEMIST — "Kimyogar" AI yordamchi
   Claude uslubidagi interfeys: iliq, sokin, minimal
   ============================================================ */

.pai {
    --c-bg: #faf9f5;          /* iliq oq fon */
    --c-bg2: #f0eee6;         /* biroz to'qroq panel */
    --c-ink: #1f1e1a;         /* asosiy matn */
    --c-dim: #6e6b60;         /* ikkilamchi matn */
    --c-line: #e3e0d5;        /* chiziqlar */
    --c-accent: #c96442;      /* terrakota urg'u */
    --c-accent2: #a84f32;
    --c-user: #ece9df;        /* foydalanuvchi xabari foni */
    --c-code-bg: #f0eee6;
    --pai-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
    --pai-serif: 'Georgia', 'Times New Roman', serif;
    font-family: var(--pai-font);
}

/* ---------- Suzuvchi tugma ---------- */
.pai-fab {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 9998;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 13px 20px 13px 16px;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    color: #faf9f5;
    font-family: var(--pai-font);
    font-weight: 600;
    font-size: 14.5px;
    letter-spacing: .2px;
    background: #1f1e1a;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
    transition: transform .25s cubic-bezier(.2,.8,.3,1.2), box-shadow .25s, opacity .2s;
}

.pai-fab:hover { transform: translateY(-2px); box-shadow: 0 10px 32px rgba(0, 0, 0, .45); }
.pai-fab:active { transform: translateY(0) scale(.98); }
.pai-fab.hidden { opacity: 0; pointer-events: none; transform: scale(.9); }
.pai-fab .ic { font-size: 19px; line-height: 1; }
.pai-fab .pulse { display: none; }

@media (max-width: 560px) {
    .pai-fab { right: 14px; bottom: 14px; padding: 13px 15px; }
    .pai-fab .lbl { display: none; }
}

/* ---------- Panel ---------- */
.pai-panel {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 9999;
    width: min(430px, calc(100vw - 28px));
    height: min(660px, calc(100vh - 40px));
    display: none;
    flex-direction: column;
    border-radius: 18px;
    overflow: hidden;
    background: var(--c-bg);
    border: 1px solid var(--c-line);
    box-shadow: 0 24px 70px rgba(30, 25, 15, .3), 0 4px 18px rgba(30, 25, 15, .14);
    color: var(--c-ink);
}

.pai-panel.open { display: flex; animation: paiIn .3s cubic-bezier(.2,.9,.3,1.1); }

@keyframes paiIn {
    from { opacity: 0; transform: translateY(18px) scale(.97); }
    to { opacity: 1; transform: none; }
}

@media (max-width: 560px) {
    .pai-panel { right: 0; bottom: 0; width: 100vw; height: 100dvh; border-radius: 0; border: none; }
}

/* Sarlavha */
.pai-head {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 13px 16px;
    background: var(--c-bg);
    border-bottom: 1px solid var(--c-line);
    flex: none;
}

.pai-avatar {
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    background: var(--c-accent);
    color: #fff;
}

.pai-head .t { flex: 1; min-width: 0; }

.pai-head .t b {
    display: block;
    font-family: var(--pai-serif);
    font-size: 16.5px;
    font-weight: 600;
    letter-spacing: .2px;
    color: var(--c-ink);
}

.pai-head .t span {
    font-size: 12px;
    color: var(--c-dim);
    display: flex;
    align-items: center;
    gap: 5px;
}

.pai-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: #7ba05b;
}

.pai-ibtn {
    width: 32px; height: 32px; flex: none;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--c-dim);
    font-size: 15px;
    cursor: pointer;
    transition: background .2s, color .2s;
    display: flex; align-items: center; justify-content: center;
}

.pai-ibtn:hover { background: var(--c-bg2); color: var(--c-ink); }

/* Xabarlar maydoni */
.pai-body {
    flex: 1;
    overflow-y: auto;
    padding: 22px 20px 8px;
    scroll-behavior: smooth;
}

.pai-body::-webkit-scrollbar { width: 8px; }
.pai-body::-webkit-scrollbar-track { background: transparent; }
.pai-body::-webkit-scrollbar-thumb { background: #d6d2c4; border-radius: 8px; }

.pai-msg {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    animation: paiMsg .25s ease;
}

@keyframes paiMsg {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

/* Yordamchi xabari — Claude kabi bubblesiz, toza matn */
.pai-msg.ai .who {
    width: 26px; height: 26px; flex: none;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px;
    background: var(--c-accent);
    color: #fff;
    margin-top: 2px;
}

.pai-msg.ai .pai-bubble {
    max-width: 100%;
    padding: 1px 0 0;
    background: none;
    border: none;
    font-size: 15px;
    line-height: 1.75;
    color: var(--c-ink);
    overflow-wrap: anywhere;
}

/* Foydalanuvchi xabari — o'ngda, yumshoq bej bubble */
.pai-msg.me {
    flex-direction: row-reverse;
}

.pai-msg.me .who { display: none; }

.pai-msg.me .pai-bubble {
    max-width: 85%;
    padding: 10px 16px;
    border-radius: 16px;
    background: var(--c-user);
    border: none;
    font-size: 15px;
    line-height: 1.65;
    color: var(--c-ink);
    overflow-wrap: anywhere;
}

.pai-bubble p { margin: 0 0 10px; }
.pai-bubble p:last-child { margin-bottom: 0; }
.pai-bubble ul, .pai-bubble ol { margin: 6px 0 10px 22px; padding: 0; }
.pai-bubble li { margin-bottom: 5px; }
.pai-bubble li::marker { color: var(--c-accent); }
.pai-bubble strong { color: var(--c-ink); font-weight: 650; }
.pai-bubble em { font-style: italic; color: var(--c-ink); }

.pai-bubble code {
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: .88em;
    padding: 2px 6px;
    border-radius: 5px;
    background: var(--c-code-bg);
    border: 1px solid var(--c-line);
    color: var(--c-accent2);
}

.pai-bubble pre {
    margin: 10px 0;
    padding: 13px 15px;
    border-radius: 10px;
    background: #1f1e1a;
    border: none;
    overflow-x: auto;
}

.pai-bubble pre code {
    background: none;
    border: none;
    padding: 0;
    color: #e8e6dd;
    font-size: 13px;
}

.pai-bubble a {
    color: var(--c-accent2);
    text-decoration: underline;
    text-decoration-color: rgba(201, 100, 66, .4);
    text-underline-offset: 2px;
}

.pai-bubble a:hover { text-decoration-color: var(--c-accent2); }

.pai-bubble a.pai-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin: 3px 5px 3px 0;
    padding: 6px 13px;
    border-radius: 999px;
    border: 1px solid var(--c-line);
    background: #fff;
    font-size: 13px;
    font-weight: 550;
    color: var(--c-ink);
    text-decoration: none;
    transition: border-color .2s, background .2s;
}

.pai-bubble a.pai-link:hover { border-color: var(--c-accent); background: #fdf6f3; }

/* Yozmoqda */
.pai-typing { display: flex; gap: 4px; padding: 6px 0; }
.pai-typing i {
    width: 6px; height: 6px; border-radius: 50%;
    background: #b8b4a5;
    animation: paiType 1.2s ease-in-out infinite;
}
.pai-typing i:nth-child(2) { animation-delay: .15s; }
.pai-typing i:nth-child(3) { animation-delay: .3s; }

@keyframes paiType {
    0%, 60%, 100% { transform: translateY(0); opacity: .4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* Xato */
.pai-err {
    margin: 0 0 14px;
    padding: 11px 15px;
    border-radius: 10px;
    font-size: 13.5px;
    background: #fbeee9;
    border: 1px solid #eccfc2;
    color: #9c4a2d;
}

/* Tavsiya savollar */
.pai-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 12px;
    flex: none;
}

.pai-chip {
    padding: 8px 15px;
    border-radius: 999px;
    border: 1px solid var(--c-line);
    background: #fff;
    color: var(--c-dim);
    font-family: var(--pai-font);
    font-size: 12.8px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color .2s, color .2s, background .2s;
    text-align: left;
}

.pai-chip:hover {
    color: var(--c-ink);
    border-color: #c9c5b6;
    background: var(--c-bg2);
}

/* Kirish maydoni */
.pai-foot {
    flex: none;
    padding: 12px 16px 12px;
    background: var(--c-bg);
}

.pai-inputrow {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 10px 10px 18px;
    border-radius: 22px;
    border: 1px solid #d9d5c7;
    background: #fff;
    box-shadow: 0 2px 10px rgba(30, 25, 15, .05);
    transition: border-color .2s, box-shadow .2s;
}

.pai-inputrow:focus-within {
    border-color: #b8b2a0;
    box-shadow: 0 3px 14px rgba(30, 25, 15, .09);
}

.pai-input {
    flex: 1;
    min-height: 24px;
    max-height: 130px;
    border: none;
    outline: none;
    resize: none;
    background: none;
    color: var(--c-ink);
    font-family: var(--pai-font);
    font-size: 14.8px;
    line-height: 1.55;
    padding: 3px 0;
}

.pai-input::placeholder { color: #a8a494; }

.pai-send {
    width: 34px; height: 34px; flex: none;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    background: var(--c-accent);
    transition: background .2s, transform .15s;
    display: flex; align-items: center; justify-content: center;
}

.pai-send:hover { background: var(--c-accent2); }
.pai-send:active { transform: scale(.94); }
.pai-send:disabled { background: #d9d5c7; cursor: not-allowed; }

.pai-note {
    margin-top: 8px;
    text-align: center;
    font-size: 11px;
    color: #a8a494;
}

/* ---------- To'liq sahifa rejimi ---------- */
.pai-full .pai-panel {
    position: static;
    width: 100%;
    height: min(720px, calc(100vh - 210px));
    display: flex;
    box-shadow: 0 20px 60px rgba(30, 25, 15, .25);
}

.pai-full .pai-fab { display: none; }

@media (prefers-reduced-motion: reduce) {
    .pai-typing i { animation: none; }
    .pai-panel.open, .pai-msg { animation: none; }
}

/* ============================================================
   Qorong'i rejim (.pai-dark) — ai.html to'liq sahifasi uchun
   ============================================================ */
.pai-dark {
    --c-bg: #262624;
    --c-bg2: #30302e;
    --c-ink: #f0efea;
    --c-dim: #a3a094;
    --c-line: #3d3c38;
    --c-accent: #c96442;
    --c-accent2: #e08a68;
    --c-user: #393836;
    --c-code-bg: #1b1a18;
}

.pai-dark .pai-panel {
    box-shadow: 0 24px 70px rgba(0, 0, 0, .5);
}

.pai-dark .pai-body::-webkit-scrollbar-thumb { background: #4a4945; }

.pai-dark .pai-inputrow {
    background: #30302e;
    border-color: #45443f;
    box-shadow: 0 2px 12px rgba(0, 0, 0, .25);
}

.pai-dark .pai-inputrow:focus-within {
    border-color: #5c5a52;
    box-shadow: 0 3px 16px rgba(0, 0, 0, .35);
}

.pai-dark .pai-input { color: var(--c-ink); }
.pai-dark .pai-input::placeholder { color: #7a776c; }

.pai-dark .pai-chip {
    background: #2d2c2a;
    border-color: #45443f;
    color: var(--c-dim);
}

.pai-dark .pai-chip:hover {
    background: #35342f;
    border-color: #5c5a52;
    color: var(--c-ink);
}

.pai-dark .pai-bubble a.pai-link {
    background: #2d2c2a;
    border-color: #45443f;
    color: var(--c-ink);
}

.pai-dark .pai-bubble a.pai-link:hover {
    border-color: var(--c-accent);
    background: #35302c;
}

.pai-dark .pai-bubble code {
    background: var(--c-code-bg);
    border-color: #3d3c38;
    color: var(--c-accent2);
}

.pai-dark .pai-bubble pre { background: #1b1a18; border: 1px solid #3d3c38; }

.pai-dark .pai-err {
    background: #38251f;
    border-color: #5c352a;
    color: #eaa48c;
}

.pai-dark .pai-send:disabled { background: #45443f; }

.pai-dark .pai-note { color: #6e6b60; }
.pai-dark .pai-ibtn:hover { background: #35342f; }
