/* Pathfinder AI Chat - World Class */
:root {
    --pf: #0d9488;
    --pf2: #0f766e;
    --pf-light: #f0fdfa;
    --accent: #16416b;
    --txt: #1f2937;
    --mute: #9ca3af;
    --bg: #fff;
    --bg2: #f8fafc;
    --bdr: #f0f0f0;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

#pfin-chat-widget { position: fixed; bottom: 24px; right: 24px; z-index: 999999; font-family: var(--font); }
#pfin-chat-widget * { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== Trigger ===== */
#pfin-trigger {
    width: 56px; height: 56px; border-radius: 28px; border: none;
    background: var(--pf); color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 20px rgba(13,148,136,0.35);
    transition: transform .2s, box-shadow .2s;
}
#pfin-trigger:hover { transform: scale(1.05); box-shadow: 0 6px 28px rgba(13,148,136,0.45); }
#pfin-trigger svg { width: 26px; height: 26px; }

/* ===== Panel ===== */
#pfin-panel {
    position: fixed; bottom: 24px; right: 24px;
    width: 400px; height: 620px;
    max-width: calc(100vw - 32px); max-height: calc(100vh - 48px);
    background: var(--bg); border-radius: 24px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.03);
    display: flex; flex-direction: column; overflow: hidden;
    animation: pf-in .25s cubic-bezier(.16,1,.3,1);
}
#pfin-panel.pfin-hidden { display: none; }
@keyframes pf-in { from { opacity:0; transform: translateY(12px) scale(.95); } to { opacity:1; transform: none; } }

/* ===== Header with shimmer ===== */
#pfin-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px; border-bottom: 1px solid var(--bdr);
    background: var(--bg); position: relative; overflow: hidden;
}
#pfin-head::after {
    content: ''; position: absolute; top: 0; left: -100%; width: 60%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(13,148,136,.04), transparent);
    animation: pf-shimmer 3s ease-in-out infinite;
}
@keyframes pf-shimmer {
    0% { left: -60%; }
    100% { left: 120%; }
}
#pfin-head-info { display: flex; align-items: center; gap: 10px; z-index: 1; }
#pfin-head-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.12);
    animation: pf-pulse 2s ease-in-out infinite;
}
@keyframes pf-pulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(34,197,94,.12); }
    50% { box-shadow: 0 0 0 5px rgba(34,197,94,.2); }
}
#pfin-head-title { font-size: 15px; font-weight: 600; color: var(--txt); letter-spacing: -.01em; }
#pfin-close {
    width: 32px; height: 32px; border-radius: 8px; border: none;
    background: transparent; color: var(--mute); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, color .15s; z-index: 1;
}
#pfin-close:hover { background: var(--bg2); color: var(--txt); }
#pfin-close svg { width: 18px; height: 18px; }

/* ===== Messages ===== */
#pfin-msgs {
    flex: 1; overflow-y: auto; padding: 28px 24px;
    display: flex; flex-direction: column; gap: 28px;
    scrollbar-width: none; -ms-overflow-style: none;
}
#pfin-msgs::-webkit-scrollbar { display: none; }

.pfin-m { display: flex; flex-direction: column; animation: pf-fade .25s ease; }
@keyframes pf-fade { from { opacity:0; transform: translateY(4px); } to { opacity:1; transform: none; } }

/* User message - no bg, teal text right */
.pfin-m-user { align-items: flex-end; }
.pfin-m-user .pfin-user-text {
    color: var(--pf2); font-size: 14.5px; line-height: 1.6;
    max-width: 85%; text-align: right;
    font-weight: 500; padding: 0;
    word-wrap: break-word;
}

/* AI message */
.pfin-m-ai { align-items: flex-start; position: relative; padding-left: 0; }
.pfin-m-ai .pfin-ai-text {
    color: var(--txt); font-size: 14px; line-height: 1.8;
    max-width: 100%; padding: 0;
    word-wrap: break-word; overflow-wrap: break-word;
}

/* ===== Rich Content ===== */
.pfin-ai-text p { margin: 0 0 14px; }
.pfin-ai-text p:last-child { margin-bottom: 0; }
.pfin-ai-text strong { font-weight: 700; color: var(--accent); }
.pfin-ai-text em { font-style: italic; color: #4b5563; }
.pfin-ai-text a { color: var(--pf); text-decoration: none; border-bottom: 1px solid rgba(13,148,136,.3); transition: border-color .15s; }
.pfin-ai-text a:hover { border-bottom-color: var(--pf); }

/* Headings */
.pfin-ai-text h1, .pfin-ai-text h2, .pfin-ai-text h3, .pfin-ai-text h4 {
    font-weight: 700; color: var(--accent); margin: 18px 0 8px; line-height: 1.3;
}
.pfin-ai-text h1:first-child, .pfin-ai-text h2:first-child,
.pfin-ai-text h3:first-child, .pfin-ai-text h4:first-child { margin-top: 0; }
.pfin-ai-text h1 { font-size: 16px; }
.pfin-ai-text h2 { font-size: 15px; }
.pfin-ai-text h3 { font-size: 14.5px; }
.pfin-ai-text h4 { font-size: 14px; }

/* Lists */
.pfin-ai-text ul, .pfin-ai-text ol { padding-left: 0; margin: 12px 0; }
.pfin-ai-text ul { list-style: none; }
.pfin-ai-text ul li {
    position: relative; padding-left: 16px; margin-bottom: 10px; line-height: 1.7;
}
.pfin-ai-text ul li::before {
    content: ''; position: absolute; left: 0; top: 10px;
    width: 5px; height: 5px; border-radius: 50%; background: var(--pf);
}
.pfin-ai-text ol { list-style: decimal; padding-left: 22px; }
.pfin-ai-text ol li { margin-bottom: 10px; line-height: 1.7; padding-left: 4px; }
.pfin-ai-text li:last-child { margin-bottom: 0; }

/* Inline Code */
.pfin-ai-text .ic {
    background: var(--pf-light); border: 1px solid #ccfbf1;
    padding: 2px 7px; border-radius: 5px;
    font-size: 12.5px; font-family: 'SF Mono', 'JetBrains Mono', monospace;
    color: var(--pf2); font-weight: 500;
}

/* Code Blocks */
.pfin-ai-text .cb {
    position: relative; margin: 16px 0; border-radius: 14px;
    overflow: hidden; background: #1e293b; border: 1px solid #334155;
}
.pfin-ai-text .cb .cb-lang {
    position: absolute; top: 10px; right: 14px;
    color: #64748b; font-size: 10px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .5px; font-family: var(--font);
}
.pfin-ai-text .cb pre { padding: 16px 18px; margin: 0; overflow-x: auto; }
.pfin-ai-text .cb code {
    background: none; border: none; color: #e2e8f0; padding: 0;
    font-size: 12.5px; font-family: 'SF Mono', 'JetBrains Mono', monospace;
    display: block; white-space: pre; line-height: 1.7;
}

/* Blockquotes */
.pfin-ai-text blockquote {
    border-left: 3px solid var(--pf); background: var(--pf-light);
    padding: 12px 16px; margin: 14px 0; border-radius: 0 12px 12px 0;
    font-size: 13.5px; color: #115e59; line-height: 1.6;
}

/* Tables */
.pfin-ai-text .tbl {
    margin: 16px 0; overflow-x: auto; border-radius: 14px;
    border: 1px solid #e2e8f0; background: var(--bg);
    box-shadow: 0 1px 4px rgba(0,0,0,.03);
}
.pfin-ai-text table { width: 100%; border-collapse: collapse; font-size: 13px; }
.pfin-ai-text th {
    background: #f8fafc; font-weight: 600; text-align: left;
    padding: 12px 16px; border-bottom: 2px solid #e2e8f0; color: var(--accent);
    font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
}
.pfin-ai-text td {
    padding: 12px 16px; border-bottom: 1px solid #f1f5f9;
    color: var(--txt); vertical-align: top; line-height: 1.6;
}
.pfin-ai-text tr:last-child td { border-bottom: none; }
.pfin-ai-text tr:hover td { background: #fafffe; }
.pfin-ai-text td:first-child { font-weight: 500; color: var(--accent); }

.pfin-ai-text hr { border: none; height: 1px; background: var(--bdr); margin: 18px 0; }

/* ===== Copy Button ===== */
.pfin-copy {
    position: absolute; top: 0; right: 0;
    width: 28px; height: 28px; border-radius: 8px;
    border: 1px solid var(--bdr); background: var(--bg);
    color: var(--mute); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: all .15s;
}
.pfin-copy svg { width: 13px; height: 13px; }
.pfin-m-ai:hover .pfin-copy { opacity: 1; }
.pfin-copy:hover { background: var(--bg2); color: var(--txt); border-color: #d1d5db; }
.pfin-copy.pfin-copied { background: var(--pf-light); color: var(--pf); border-color: var(--pf); }

/* ===== Thinking Indicator ===== */
.pfin-thinking {
    display: flex; align-items: center; gap: 10px;
    padding: 4px 0; animation: pf-fade .2s ease;
}
.pfin-think-bar {
    width: 52px; height: 3px; border-radius: 3px;
    background: #e5e7eb; overflow: hidden;
}
.pfin-think-fill {
    width: 100%; height: 100%; border-radius: 3px;
    background: linear-gradient(90deg, var(--pf), #5eead4, var(--pf));
    background-size: 200% 100%;
    animation: pf-think 1.2s ease-in-out infinite;
}
.pfin-think-label { font-size: 12px; color: var(--mute); font-weight: 500; }
@keyframes pf-think {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

/* ===== Welcome ===== */
.pfin-welcome {
    display: flex; flex-direction: column; align-items: center;
    text-align: center; padding: 60px 28px 28px; gap: 8px;
    flex: 1; justify-content: center;
}
.pfin-w-icon { display: none; }
.pfin-w-media {
    width: 100%; max-height: 160px; border-radius: 14px;
    overflow: hidden; margin-bottom: 16px;
}
.pfin-w-media img, .pfin-w-media video {
    width: 100%; height: 100%; max-height: 160px;
    object-fit: cover; border-radius: 14px;
    display: block;
}
.pfin-w-title { font-size: 22px; font-weight: 700; color: var(--txt); letter-spacing: -.03em; }
.pfin-w-sub { font-size: 14px; color: var(--mute); line-height: 1.5; max-width: 280px; margin-top: 4px; }

.pfin-sugs {
    width: 100%; margin-top: 32px;
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.pfin-sug {
    padding: 14px 14px; background: var(--bg);
    border: 1px solid var(--bdr); border-radius: 14px;
    font-size: 12.5px; color: #4b5563; cursor: pointer;
    font-family: var(--font); font-weight: 400; text-align: left;
    transition: all .2s; line-height: 1.4;
}
.pfin-sug:hover {
    border-color: var(--pf); color: var(--pf2);
    background: var(--pf-light);
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(13,148,136,.08);
}

/* ===== Footer with flowing dots ===== */
#pfin-foot {
    padding: 16px 20px; border-top: 1px solid var(--bdr);
    background: var(--bg); position: relative;
}
#pfin-input-row {
    display: flex; align-items: flex-end; gap: 10px;
    background: var(--bg2); border: 1.5px solid var(--bdr);
    border-radius: 16px; padding: 8px 8px 8px 18px;
    transition: border-color .2s, box-shadow .2s;
    position: relative; overflow: hidden;
}
#pfin-input-row:focus-within {
    border-color: transparent;
    background-image: linear-gradient(var(--bg2), var(--bg2)),
        linear-gradient(var(--glow-angle, 0deg), #0d9488, #6366f1, #ec4899, #f59e0b, #0d9488);
    background-origin: border-box;
    background-clip: padding-box, border-box;
    animation: pf-glow 3s linear infinite;
    box-shadow: 0 0 12px rgba(99,102,241,.08);
}
@property --glow-angle { syntax: '<angle>'; initial-value: 0deg; inherits: false; }
@keyframes pf-glow { to { --glow-angle: 360deg; } }
#pfin-input {
    flex: 1; border: none; outline: none; background: transparent;
    font-family: var(--font); font-size: 14px; line-height: 1.5;
    color: var(--txt); resize: none; min-height: 24px; max-height: 80px; padding: 6px 0;
    position: relative; z-index: 1;
}
#pfin-input::placeholder { color: #c5c9d0; }
#pfin-send {
    width: 36px; height: 36px; border-radius: 12px; border: none;
    background: var(--pf); color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: all .15s; position: relative; z-index: 1;
}
#pfin-send:disabled { opacity: .15; cursor: not-allowed; background: var(--mute); }
#pfin-send:not(:disabled):hover { background: var(--pf2); transform: scale(1.05); }
#pfin-send svg { width: 16px; height: 16px; }

/* ===== Error & Notice ===== */
.pfin-err {
    display: flex; align-items: center; gap: 10px; align-self: center;
    background: #fef2f2; border: 1px solid #fecaca; color: #dc2626;
    padding: 10px 14px; border-radius: 12px; font-size: 13px;
}
.pfin-retry {
    background: none; border: 1px solid #dc2626; color: #dc2626;
    padding: 4px 10px; border-radius: 6px; font-size: 12px;
    cursor: pointer; transition: all .15s;
}
.pfin-retry:hover { background: #dc2626; color: #fff; }
.pfin-notice {
    align-self: center; background: #fffbeb; border: 1px solid #fde68a;
    color: #92400e; padding: 10px 14px; border-radius: 12px; font-size: 13px;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
    #pfin-chat-widget { bottom: 0; right: 0; left: 0; }
    #pfin-trigger { width: 50px; height: 50px; position: fixed; bottom: 16px; right: 16px; }
    #pfin-panel {
        width: 100vw; height: 100vh; max-width: 100vw; max-height: 100vh;
        bottom: 0; right: 0; border-radius: 0;
    }
    #pfin-head { padding: 16px 18px; }
    #pfin-head-title { font-size: 14px; }
    #pfin-msgs { padding: 20px 16px; gap: 20px; }
    .pfin-m-user .pfin-user-text { font-size: 14px; max-width: 90%; }
    .pfin-m-ai .pfin-ai-text { font-size: 13.5px; line-height: 1.7; }
    .pfin-ai-text h1 { font-size: 15px; }
    .pfin-ai-text h2 { font-size: 14.5px; }
    .pfin-ai-text h3, .pfin-ai-text h4 { font-size: 13.5px; }
    .pfin-ai-text .cb pre { padding: 12px 14px; }
    .pfin-ai-text .cb code { font-size: 11.5px; }
    .pfin-ai-text .tbl { border-radius: 10px; }
    .pfin-ai-text th, .pfin-ai-text td { padding: 10px 12px; font-size: 12px; }
    .pfin-welcome { padding: 40px 20px 20px; }
    .pfin-w-title { font-size: 19px; }
    .pfin-w-sub { font-size: 13px; }
    .pfin-w-media { max-height: 120px; }
    .pfin-w-media img, .pfin-w-media video { max-height: 120px; }
    .pfin-sugs { grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 24px; }
    .pfin-sug { padding: 12px 10px; font-size: 11.5px; border-radius: 12px; }
    #pfin-foot { padding: 12px 14px; }
    #pfin-input-row { padding: 6px 6px 6px 14px; border-radius: 14px; }
    #pfin-input { font-size: 14px; }
    #pfin-send { width: 34px; height: 34px; border-radius: 10px; }
    .pfin-copy { width: 26px; height: 26px; }
    .pfin-thinking { gap: 8px; }
    .pfin-think-label { font-size: 11px; }
}

@media (max-width: 360px) {
    .pfin-sugs { grid-template-columns: 1fr; gap: 8px; }
    .pfin-sug { padding: 12px; font-size: 12px; }
    .pfin-w-title { font-size: 17px; }
    .pfin-ai-text th, .pfin-ai-text td { padding: 8px 10px; font-size: 11.5px; }
}

@media print { #pfin-chat-widget { display: none !important; } }
