/**
 * AI Chat Putri PI Stylesheet
 * SMP Putri Perguruan Islam Ar Risalah Padang
 */

/* ==========================================================================
   1. GLOBAL TOKENS & RESET FOR AI CHAT
   ========================================================================== */
:root {
    --ai-primary: #059669;
    --ai-primary-dark: #047857;
    --ai-primary-light: #ecfdf5;
    --ai-accent: #0d9488;
    --ai-gold: #d97706;
    --ai-navy: #0f172a;
    --ai-slate: #1e293b;
    --ai-bubble-bot: #ffffff;
    --ai-bubble-user: #2563eb;
    --ai-border: #e2e8f0;
    --ai-text: #1e293b;
    --ai-muted: #64748b;
    --ai-radius: 9px;
    --ai-shadow-lg: 0 20px 35px -10px rgba(15, 23, 42, 0.18), 0 0 1px 1px rgba(15, 23, 42, 0.05);
}

/* ==========================================================================
   2. FLOATING TRIGGER BUTTON (FAB) - POJOK KANAN BAWAH
   ========================================================================== */
#putri-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999998;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, #059669 0%, #0d9488 50%, #2563eb 100%);
    color: #ffffff;
    padding: 6px 18px 6px 6px;
    border-radius: 50px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    box-shadow: 0 10px 25px rgba(5, 150, 105, 0.38), 0 4px 10px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    transition: all 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
    outline: none;
    user-select: none;
}

#putri-fab:hover {
    transform: translateY(-4px) scale(1.03);
    box-shadow: 0 16px 32px rgba(5, 150, 105, 0.48), 0 6px 14px rgba(0, 0, 0, 0.15);
}

#putri-fab:active {
    transform: translateY(0) scale(0.97);
}

.fab-circle {
    position: relative;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #ffffff;
    color: #059669;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.25s ease;
}

.fab-circle i {
    font-size: 1.65rem;
    line-height: 1;
    color: #059669;
    transition: all 0.25s ease;
}

.fab-icon-close {
    display: none;
    font-size: 1.5rem !important;
    color: #dc2626 !important;
}

#putri-fab.is-open {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-color: rgba(255, 255, 255, 0.25);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.35);
}

#putri-fab.is-open .fab-circle {
    background: #fee2e2;
}

#putri-fab.is-open .fab-icon-chat {
    display: none;
}

#putri-fab.is-open .fab-icon-close {
    display: block;
}

.fab-status-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 12px;
    height: 12px;
    background: #22c55e;
    border: 2px solid #ffffff;
    border-radius: 50%;
    z-index: 2;
}

.fab-pulse-ring {
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px solid #34d399;
    animation: fab-ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
    pointer-events: none;
}

@keyframes fab-ping {
    0% { transform: scale(1); opacity: 0.9; }
    75%, 100% { transform: scale(1.4); opacity: 0; }
}

.fab-label {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    text-align: left;
    padding-right: 4px;
}

.fab-label small {
    font-size: 0.68rem;
    color: #d1fae5;
    font-weight: 500;
}

.fab-label span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.92rem;
    color: #ffffff;
}

/* Tooltip Popup on Load */
.fab-tooltip {
    position: absolute;
    bottom: calc(100% + 14px);
    right: 0;
    background: #0f172a;
    color: #f8fafc;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.82rem;
    font-weight: 500;
    width: 240px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
    border: 1px solid #334155;
    animation: fab-fade-in 0.3s ease;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    cursor: pointer;
    line-height: 1.45;
    z-index: 999997;
    transition: opacity 0.3s ease;
}
.fab-tooltip i {
    color: #34d399;
    font-size: 1.25rem;
    flex-shrink: 0;
    margin-top: 1px;
}
.fab-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 24px;
    border-width: 6px;
    border-style: solid;
    border-color: #0f172a transparent transparent transparent;
}
@keyframes fab-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   3. FLOATING CHAT WINDOW (POP-UP SUDUT KANAN BAWAH)
   ========================================================================== */
#putri-widget {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 395px;
    max-width: calc(100vw - 32px);
    height: 590px;
    max-height: calc(100vh - 120px);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 20px 48px -8px rgba(15, 23, 42, 0.28), 0 0 0 1px rgba(15, 23, 42, 0.08);
    border: 1px solid var(--ai-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 999999;
    transition: all 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    transform-origin: bottom right;
}

#putri-widget.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.85) translateY(24px);
    visibility: hidden;
}

/* Header */
.ai-header {
    background: linear-gradient(135deg, #065f46 0%, #047857 50%, #0f172a 100%);
    color: #ffffff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.ai-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #ffffff;
    padding: 2px;
    position: relative;
    flex-shrink: 0;
}

.ai-header-avatar svg,
.ai-header-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.ai-header-avatar .dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 11px;
    height: 11px;
    background: #22c55e;
    border: 2px solid #ffffff;
    border-radius: 50%;
}

.ai-header-info h4 {
    margin: 0;
    font-size: 1.02rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-badge {
    background: rgba(255, 255, 255, 0.18);
    font-size: 0.68rem;
    padding: 2px 7px;
    border-radius: 4px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.ai-header-info p {
    margin: 2px 0 0;
    font-size: 0.74rem;
    color: #a7f3d0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-header-btn {
    background: rgba(255, 255, 255, 0.12);
    border: 0;
    color: #ffffff;
    width: 32px;
    height: 32px;
    border-radius: var(--ai-radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.2s;
    font-size: 1rem;
    text-decoration: none;
}

.ai-header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    color: #ffffff;
}

/* Chat Body (Messages Container) */
.ai-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

.ai-body::-webkit-scrollbar {
    width: 6px;
}
.ai-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

/* Welcome Announcement Box */
.ai-welcome-box {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: var(--ai-radius);
    padding: 14px;
    color: #065f46;
    font-size: 0.85rem;
    line-height: 1.55;
    margin-bottom: 4px;
}

.ai-welcome-box h5 {
    margin: 0 0 6px;
    font-size: 0.94rem;
    font-weight: 700;
    color: #047857;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Quick Topic Chips */
.ai-chips-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}

.ai-chips-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--ai-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ai-chips-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ai-chip {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #1e293b;
    padding: 6px 12px;
    border-radius: 50px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.ai-chip:hover {
    background: #ecfdf5;
    border-color: #059669;
    color: #059669;
    transform: translateY(-1px);
}

/* Message Rows & Bubbles */
.ai-msg-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    animation: ai-slide-up 0.25s ease-out;
}

@keyframes ai-slide-up {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-msg-row.user {
    flex-direction: row-reverse;
}

.ai-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.ai-msg-avatar img,
.ai-msg-avatar svg {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ai-msg-bubble {
    max-width: 84%;
    padding: 12px 14px;
    border-radius: var(--ai-radius);
    font-size: 0.88rem;
    line-height: 1.6;
    word-break: break-word;
    position: relative;
    box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

.ai-msg-row.bot .ai-msg-bubble {
    background: #ffffff;
    color: var(--ai-text);
    border: 1px solid #e2e8f0;
    border-left: 3px solid #059669;
}

.ai-msg-row.user .ai-msg-bubble {
    background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 100%);
    color: #ffffff;
    border-bottom-right-radius: 2px;
}

.ai-msg-bubble p {
    margin: 0 0 8px;
}
.ai-msg-bubble p:last-child {
    margin-bottom: 0;
}

.ai-msg-bubble ul,
.ai-msg-bubble ol {
    margin: 4px 0 8px;
    padding-left: 20px;
}

.ai-msg-bubble li {
    margin-bottom: 4px;
}

.ai-msg-bubble strong {
    color: inherit;
    font-weight: 700;
}

.ai-msg-bubble h2,
.ai-msg-bubble h3,
.ai-msg-bubble h4 {
    margin: 10px 0 4px;
    font-size: 0.95rem;
    font-weight: 700;
    color: #065f46;
}

.ai-msg-bubble blockquote {
    margin: 6px 0;
    padding: 4px 10px;
    border-left: 3px solid #0d9488;
    background: #f0fdf4;
    font-style: italic;
    color: #047857;
}

/* Copy Action & Time */
.ai-msg-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 6px;
    padding-top: 4px;
    font-size: 0.7rem;
    color: var(--ai-muted);
    border-top: 1px solid #f1f5f9;
}

.ai-msg-row.user .ai-msg-meta {
    color: rgba(255,255,255,0.7);
    border-top-color: rgba(255,255,255,0.15);
    justify-content: flex-end;
}

.ai-copy-btn {
    background: none;
    border: 0;
    color: var(--ai-muted);
    cursor: pointer;
    font-size: 0.76rem;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    transition: 0.2s;
}
.ai-copy-btn:hover {
    background: #f1f5f9;
    color: var(--ai-primary);
}

/* Typing Indicator Animation */
.ai-typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 14px;
    background: #ffffff;
    border: 1px solid var(--ai-border);
    border-radius: var(--ai-radius);
    width: fit-content;
}

.ai-typing-indicator span {
    font-size: 0.78rem;
    color: var(--ai-muted);
    margin-right: 4px;
    font-weight: 500;
}

.ai-dot {
    width: 6px;
    height: 6px;
    background: #059669;
    border-radius: 50%;
    animation: ai-bounce 1.4s infinite ease-in-out both;
}
.ai-dot:nth-child(2) { animation-delay: -0.32s; }
.ai-dot:nth-child(3) { animation-delay: -0.16s; }

@keyframes ai-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Footer / Input Bar */
.ai-footer {
    padding: 12px 14px;
    background: #ffffff;
    border-top: 1px solid var(--ai-border);
    flex-shrink: 0;
}

.ai-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: var(--ai-radius);
    padding: 6px 10px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ai-input-wrapper:focus-within {
    border-color: #059669;
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.12);
    background: #ffffff;
}

.ai-input {
    flex: 1;
    border: 0;
    background: transparent;
    padding: 6px 2px;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--ai-text);
    resize: none;
    outline: none;
    min-height: 24px;
    max-height: 120px;
    line-height: 1.4;
}

.ai-input::placeholder {
    color: #94a3b8;
}

.ai-btn-icon {
    background: transparent;
    border: 0;
    color: #64748b;
    width: 32px;
    height: 32px;
    border-radius: var(--ai-radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.2s;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.ai-btn-icon:hover {
    background: #f1f5f9;
    color: #059669;
}

.ai-btn-icon.active {
    background: #fee2e2;
    color: #ef4444;
    animation: ai-pulse-red 1.2s infinite;
}

@keyframes ai-pulse-red {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.ai-send-btn {
    background: #059669;
    color: #ffffff;
    border: 0;
    width: 34px;
    height: 34px;
    border-radius: var(--ai-radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.2s;
    flex-shrink: 0;
    font-size: 1.1rem;
}

.ai-send-btn:hover {
    background: #047857;
    transform: scale(1.05);
}

.ai-send-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    transform: none;
}

.ai-disclaimer {
    margin-top: 6px;
    font-size: 0.68rem;
    color: #94a3b8;
    text-align: center;
}

/* ==========================================================================
   4. DEDICATED FULL-SCREEN CHAT PAGE (?p=chat-ai)
   ========================================================================== */
.ai-page-hero {
    background: linear-gradient(135deg, #064e3b 0%, #065f46 45%, #0f172a 100%);
    color: #ffffff;
    padding: 48px 5vw 40px;
    border-radius: var(--ai-radius);
    margin-bottom: 28px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(6, 78, 59, 0.2);
}

.ai-page-hero::before {
    content: '';
    position: absolute;
    top: -50px;
    right: -50px;
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, rgba(52, 211, 153, 0.2) 0%, transparent 70%);
    border-radius: 50%;
}

.ai-page-hero-inner {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 30px;
    flex-wrap: wrap;
}

.ai-page-hero-text h1 {
    margin: 0 0 10px;
    font-size: 2.1rem;
    font-weight: 800;
    line-height: 1.25;
}

.ai-page-hero-text p {
    margin: 0;
    font-size: 1.05rem;
    color: #d1fae5;
    max-width: 680px;
    line-height: 1.6;
}

.ai-page-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.15);
    padding: 6px 14px;
    border-radius: 50px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-bottom: 12px;
    color: #a7f3d0;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.ai-page-layout {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 28px;
    align-items: flex-start;
}

@media (max-width: 960px) {
    .ai-page-layout {
        grid-template-columns: 1fr;
    }
}

.ai-page-chat-card {
    background: #ffffff;
    border-radius: var(--ai-radius);
    border: 1px solid var(--ai-border);
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.04);
    height: 720px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ai-page-sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.ai-side-card {
    background: #ffffff;
    border-radius: var(--ai-radius);
    border: 1px solid var(--ai-border);
    padding: 22px;
    box-shadow: 0 4px 15px rgba(15, 23, 42, 0.03);
}

.ai-side-card h3 {
    margin: 0 0 14px;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--ai-navy);
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-side-card p {
    margin: 0 0 12px;
    font-size: 0.88rem;
    line-height: 1.6;
    color: #475569;
}

.ai-side-card ul {
    margin: 0;
    padding-left: 20px;
    font-size: 0.88rem;
    color: #475569;
    line-height: 1.6;
}

.ai-side-card li {
    margin-bottom: 8px;
}

.ai-contact-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #25d366;
    color: #ffffff;
    text-decoration: none;
    padding: 10px 16px;
    border-radius: var(--ai-radius);
    font-weight: 700;
    font-size: 0.9rem;
    transition: 0.2s;
    margin-top: 10px;
    justify-content: center;
}

.ai-contact-btn:hover {
    background: #20ba5a;
    color: #ffffff;
}

.top-ai-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, #059669 0%, #0d9488 100%);
    color: #ffffff !important;
    padding: 6px 14px;
    border-radius: 50px;
    font-size: 0.84rem;
    font-weight: 700;
    text-decoration: none;
    transition: 0.2s;
    box-shadow: 0 4px 12px rgba(5, 150, 105, 0.25);
}

.top-ai-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(5, 150, 105, 0.35);
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
    #putri-widget {
        bottom: 12px;
        right: 10px;
        left: 10px;
        width: calc(100vw - 20px);
        max-width: calc(100vw - 20px);
        height: min(620px, calc(100dvh - 24px));
        max-height: calc(100dvh - 24px);
        border-radius: 16px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    }
    #putri-fab {
        bottom: 16px;
        right: 16px;
        padding: 4px;
        border-radius: 50%;
    }
    .fab-label {
        display: none;
    }
    .fab-circle {
        width: 52px;
        height: 52px;
    }
    .fab-circle i {
        font-size: 1.75rem;
    }
    .fab-tooltip {
        display: none !important;
    }
}
