@import url('https://fonts.googleapis.com/css2?family=Inter:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

/* ═══════════════════════════════════════════════════════════════════════════
   AI Model Selector Pro — Chat UI
   Design: Claude AI-inspired glassmorphism, dark/light modes, mobile-first
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Design tokens (dark mode default) ────────────────────────────────────── */
.aimp-root,
.aimp-root[data-theme="dark"] {
    --bg:           #0d0e17;
    --bg-secondary: #12131f;
    --surface:      rgba(255,255,255,0.04);
    --surface-h:    rgba(255,255,255,0.08);
    --glass:        rgba(255,255,255,0.05);
    --glass-border: rgba(255,255,255,0.10);
    --border:       rgba(255,255,255,0.09);
    --accent:       #7c6cfc;
    --accent-dim:   rgba(124,108,252,0.18);
    --accent-glow:  rgba(124,108,252,0.45);
    --accent-text:  #a89dfd;
    --text:         #e8e6f0;
    --text-muted:   #8890a6;
    --text-faint:   #555d72;
    --user-bubble:  rgba(124,108,252,0.22);
    --ai-bubble:    rgba(255,255,255,0.05);
    --input-bg:     rgba(255,255,255,0.06);
    --input-border: rgba(255,255,255,0.12);
    --scrollbar:    rgba(255,255,255,0.10);
    --sidebar-bg:   #0b0c16;
    --shadow:       0 8px 40px rgba(0,0,0,0.5);
    --shadow-sm:    0 2px 12px rgba(0,0,0,0.3);
    --radius:       14px;
    --radius-sm:    8px;
    --radius-pill:  999px;
}

/* Light mode tokens */
.aimp-root[data-theme="light"] {
    --bg:           #f5f4fc;
    --bg-secondary: #edeaf8;
    --surface:      rgba(255,255,255,0.8);
    --surface-h:    rgba(255,255,255,0.95);
    --glass:        rgba(255,255,255,0.70);
    --glass-border: rgba(0,0,0,0.08);
    --border:       rgba(0,0,0,0.08);
    --accent:       #6c5ce7;
    --accent-dim:   rgba(108,92,231,0.12);
    --accent-glow:  rgba(108,92,231,0.30);
    --accent-text:  #6c5ce7;
    --text:         #1e1b2e;
    --text-muted:   #6e6a85;
    --text-faint:   #a9a4c0;
    --user-bubble:  rgba(108,92,231,0.12);
    --ai-bubble:    rgba(255,255,255,0.9);
    --input-bg:     rgba(255,255,255,0.75);
    --input-border: rgba(0,0,0,0.12);
    --scrollbar:    rgba(0,0,0,0.12);
    --sidebar-bg:   #e8e5f5;
    --shadow:       0 8px 40px rgba(0,0,0,0.12);
    --shadow-sm:    0 2px 12px rgba(0,0,0,0.06);
}

/* ── Reset & base ─────────────────────────────────────────────────────────── */
.aimp-root *,
.aimp-root *::before,
.aimp-root *::after { box-sizing: border-box; margin: 0; padding: 0; }

.aimp-root {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
    display: flex;
    height: var(--aimp-height, 600px);
    min-height: 400px;
    box-shadow: var(--shadow);
    transition: background .3s, color .3s;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.aimp-sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width .3s, min-width .3s, transform .3s;
    overflow: hidden;
    z-index: 10;
}
.aimp-sidebar.collapsed { width: 0; min-width: 0; }

.aimp-sidebar-header {
    padding: 18px 16px 12px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.aimp-brand {
    display: flex; align-items: center; gap: 8px;
    font-size: 14px; font-weight: 700; color: var(--accent);
    white-space: nowrap;
}
.aimp-brand-icon {
    width: 28px; height: 28px; border-radius: 8px;
    background: var(--accent); display: flex; align-items: center; justify-content: center;
    font-size: 15px; flex-shrink: 0;
}

.aimp-new-chat-btn {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    margin: 12px; padding: 10px 14px; border-radius: var(--radius-sm);
    background: var(--accent-dim); border: 1px solid var(--accent-glow);
    color: var(--accent-text); font-size: 13px; font-weight: 600;
    cursor: pointer; transition: background .2s, transform .15s;
    white-space: nowrap;
}
.aimp-new-chat-btn:hover { background: rgba(124,108,252,0.28); transform: translateY(-1px); }

.aimp-conv-list {
    flex: 1; overflow-y: auto; padding: 4px 8px 12px;
    scrollbar-width: thin; scrollbar-color: var(--scrollbar) transparent;
}
.aimp-conv-section-label {
    font-size: 10px; font-weight: 700; color: var(--text-faint);
    text-transform: uppercase; letter-spacing: .7px;
    padding: 10px 8px 4px;
}
.aimp-conv-item {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 10px; border-radius: 8px; cursor: pointer;
    transition: background .15s; position: relative;
    font-size: 13px; color: var(--text-muted); white-space: nowrap;
    overflow: hidden;
}
.aimp-conv-item:hover { background: var(--surface-h); color: var(--text); }
.aimp-conv-item.active { background: var(--accent-dim); color: var(--accent-text); font-weight: 500; }
.aimp-conv-item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.aimp-conv-item-del {
    display: none; background: none; border: none; color: var(--text-faint);
    cursor: pointer; font-size: 14px; padding: 2px; border-radius: 4px;
    flex-shrink: 0;
}
.aimp-conv-item:hover .aimp-conv-item-del { display: flex; }
.aimp-conv-item-del:hover { color: #f87171; background: rgba(248,113,113,.15); }

.aimp-sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    font-size: 11px; color: var(--text-faint); text-align: center;
}

/* ── Main area ────────────────────────────────────────────────────────────── */
.aimp-main {
    flex: 1; display: flex; flex-direction: column; overflow: hidden;
    position: relative;
}

/* ── Top bar ──────────────────────────────────────────────────────────────── */
.aimp-topbar {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 20px; border-bottom: 1px solid var(--border);
    background: rgba(0,0,0,0.15);
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}
.aimp-root[data-theme="light"] .aimp-topbar { background: rgba(255,255,255,0.6); }

.aimp-sidebar-toggle {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 6px; border-radius: 6px;
    display: flex; align-items: center; font-size: 18px;
    transition: background .15s, color .15s;
}
.aimp-sidebar-toggle:hover { background: var(--surface-h); color: var(--text); }

.aimp-topbar-title {
    flex: 1; font-size: 14px; font-weight: 600; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── Model selector ───────────────────────────────────────────────────────── */
.aimp-model-selector { position: relative; }
.aimp-model-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 7px 12px; border-radius: var(--radius-pill);
    background: var(--glass); border: 1px solid var(--glass-border);
    color: var(--text); font-size: 12px; font-weight: 600;
    cursor: pointer; transition: background .2s, border-color .2s;
    white-space: nowrap;
}
.aimp-model-btn:hover { background: var(--surface-h); border-color: var(--accent); }
.aimp-model-btn .aimp-chevron { font-size: 10px; color: var(--text-muted); transition: transform .2s; }
.aimp-model-btn.open .aimp-chevron { transform: rotate(180deg); }

.aimp-model-dropdown {
    position: absolute; top: calc(100% + 6px); right: 0;
    width: 260px; background: var(--bg-secondary);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); z-index: 100; overflow: hidden;
    opacity: 0; transform: translateY(-6px) scale(.97);
    pointer-events: none; transition: opacity .18s, transform .18s;
}
.aimp-model-dropdown.open { opacity: 1; transform: none; pointer-events: auto; }

.aimp-model-option {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 14px; cursor: pointer;
    transition: background .15s; border-bottom: 1px solid var(--border);
}
.aimp-model-option:last-child { border-bottom: none; }
.aimp-model-option:hover { background: var(--surface-h); }
.aimp-model-option.selected { background: var(--accent-dim); }
.aimp-model-option-icon { font-size: 20px; flex-shrink: 0; }
.aimp-model-option-info { flex: 1; min-width: 0; }
.aimp-model-option-name { font-size: 13px; font-weight: 600; color: var(--text); }
.aimp-model-option-meta { display: flex; gap: 6px; margin-top: 2px; }
.aimp-speed-badge,
.aimp-cost-badge {
    font-size: 10px; font-weight: 600; padding: 1px 6px;
    border-radius: var(--radius-pill);
}
.aimp-speed-badge { background: rgba(52,211,153,.15); color: #34d399; }
.aimp-cost-badge  { background: rgba(251,191,36,.15);  color: #fbbf24; }
.aimp-model-option-check { color: var(--accent); font-size: 14px; }

/* Theme & clear buttons */
.aimp-theme-btn,
.aimp-clear-btn {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 7px; border-radius: 8px; font-size: 16px;
    display: flex; align-items: center; transition: background .15s, color .15s;
}
.aimp-theme-btn:hover,
.aimp-clear-btn:hover { background: var(--surface-h); color: var(--text); }

/* ── Messages area ────────────────────────────────────────────────────────── */
.aimp-messages {
    flex: 1; overflow-y: auto; padding: 24px 20px;
    display: flex; flex-direction: column; gap: 4px;
    scrollbar-width: thin; scrollbar-color: var(--scrollbar) transparent;
}
.aimp-messages::-webkit-scrollbar { width: 4px; }
.aimp-messages::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 4px; }

/* Welcome / empty state */
.aimp-welcome {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 40px 20px; gap: 16px;
}
.aimp-welcome-icon {
    width: 64px; height: 64px; border-radius: 20px;
    background: linear-gradient(135deg, var(--accent) 0%, #a78bfa 100%);
    display: flex; align-items: center; justify-content: center;
    font-size: 32px; box-shadow: 0 0 40px var(--accent-glow);
    animation: aimp-float 3s ease-in-out infinite;
}
@keyframes aimp-float {
    0%,100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}
.aimp-welcome h2 { font-size: 22px; font-weight: 700; color: var(--text); }
.aimp-welcome p  { font-size: 14px; color: var(--text-muted); max-width: 340px; line-height: 1.6; }

/* Prompt chips */
.aimp-prompt-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.aimp-chip {
    padding: 8px 14px; border-radius: var(--radius-pill);
    background: var(--glass); border: 1px solid var(--glass-border);
    color: var(--text-muted); font-size: 12px; font-weight: 500;
    cursor: pointer; transition: all .2s;
}
.aimp-chip:hover { background: var(--accent-dim); border-color: var(--accent); color: var(--accent-text); transform: translateY(-2px); }

/* Message rows */
.aimp-msg-row {
    display: flex; gap: 10px; align-items: flex-start;
    animation: aimp-msg-in .25s ease;
}
@keyframes aimp-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}
.aimp-msg-row.user-row { flex-direction: row-reverse; }

.aimp-avatar {
    width: 32px; height: 32px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; flex-shrink: 0; font-weight: 700;
}
.aimp-avatar.user-avatar {
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    color: #fff;
}
.aimp-avatar.ai-avatar {
    background: linear-gradient(135deg, #1a1d27, #2a2d3e);
    border: 1px solid var(--border);
}

.aimp-bubble {
    max-width: 72%; padding: 12px 16px; border-radius: 16px;
    font-size: 14px; line-height: 1.65; position: relative;
}
.aimp-msg-row.user-row .aimp-bubble {
    background: var(--user-bubble);
    border: 1px solid rgba(124,108,252,0.25);
    border-top-right-radius: 4px;
    color: var(--text);
}
.aimp-msg-row.ai-row .aimp-bubble {
    background: var(--ai-bubble);
    border: 1px solid var(--border);
    border-top-left-radius: 4px;
    color: var(--text);
}

/* Bubble actions */
.aimp-bubble-actions {
    display: none; gap: 6px; margin-top: 8px;
}
.aimp-msg-row:hover .aimp-bubble-actions { display: flex; }
.aimp-bubble-action-btn {
    background: none; border: 1px solid var(--border);
    color: var(--text-muted); font-size: 11px; font-weight: 500;
    padding: 3px 8px; border-radius: 6px; cursor: pointer;
    display: flex; align-items: center; gap: 4px;
    transition: background .15s, color .15s;
}
.aimp-bubble-action-btn:hover { background: var(--surface-h); color: var(--text); }
.aimp-bubble-action-btn.copied { color: #34d399; border-color: #34d399; }

/* Formatted content */
.aimp-bubble pre {
    background: rgba(0,0,0,0.3); border-radius: 8px;
    padding: 12px; overflow-x: auto; font-size: 12px;
    margin: 8px 0; border: 1px solid var(--border);
}
.aimp-root[data-theme="light"] .aimp-bubble pre { background: rgba(0,0,0,0.06); }
.aimp-bubble code { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 12px; }
.aimp-bubble p  { margin: 0 0 8px; }
.aimp-bubble p:last-child { margin-bottom: 0; }
.aimp-bubble ul,
.aimp-bubble ol { padding-left: 20px; margin: 8px 0; }
.aimp-bubble li { margin: 4px 0; }
.aimp-bubble strong { font-weight: 600; color: var(--text); }
.aimp-bubble h1,.aimp-bubble h2,.aimp-bubble h3 { font-weight: 700; margin: 12px 0 6px; color: var(--text); }

/* Typing indicator */
.aimp-typing-row { align-items: center; }
.aimp-typing {
    display: flex; gap: 5px; align-items: center;
    padding: 14px 16px; background: var(--ai-bubble);
    border: 1px solid var(--border); border-radius: 16px; border-top-left-radius: 4px;
}
.aimp-typing span {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--accent); display: inline-block;
    animation: aimp-bounce .9s ease-in-out infinite;
}
.aimp-typing span:nth-child(2) { animation-delay: .15s; }
.aimp-typing span:nth-child(3) { animation-delay: .30s; }
@keyframes aimp-bounce {
    0%,80%,100% { transform: scale(.7); opacity: .5; }
    40%          { transform: scale(1);  opacity: 1; }
}

/* ── Input area ───────────────────────────────────────────────────────────── */
.aimp-input-area {
    padding: 16px 20px 20px;
    border-top: 1px solid var(--border);
    background: rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}
.aimp-root[data-theme="light"] .aimp-input-area { background: rgba(255,255,255,0.5); }

.aimp-input-wrapper {
    display: flex; align-items: flex-end; gap: 10px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 16px; padding: 10px 14px;
    transition: border-color .25s, box-shadow .25s;
}
.aimp-input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim), 0 0 20px var(--accent-glow);
}

#aimp-textarea {
    flex: 1; background: none; border: none; outline: none;
    resize: none; font-family: inherit; font-size: 14px;
    color: var(--text); line-height: 1.5; max-height: 180px;
    overflow-y: auto; min-height: 22px;
    scrollbar-width: thin; scrollbar-color: var(--scrollbar) transparent;
}
#aimp-textarea::placeholder { color: var(--text-faint); }

.aimp-send-btn {
    width: 36px; height: 36px; border-radius: 10px; border: none;
    background: var(--accent); color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; flex-shrink: 0;
    transition: background .2s, transform .15s, box-shadow .2s;
}
.aimp-send-btn:hover:not(:disabled) {
    background: #9b8dfd; transform: scale(1.06);
    box-shadow: 0 4px 14px var(--accent-glow);
}
.aimp-send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

.aimp-input-footer {
    display: flex; align-items: center; justify-content: space-between;
    margin-top: 8px; padding: 0 2px;
}
.aimp-input-hint { font-size: 11px; color: var(--text-faint); }
.aimp-char-count { font-size: 11px; color: var(--text-faint); }

/* ── Error banner ─────────────────────────────────────────────────────────── */
.aimp-error-banner {
    margin: 0 20px 12px;
    padding: 10px 14px; border-radius: 8px;
    background: rgba(248,113,113,.12); border: 1px solid rgba(248,113,113,.3);
    color: #f87171; font-size: 13px;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.aimp-error-banner button { background: none; border: none; color: #f87171; cursor: pointer; font-size: 16px; }

/* ── Loading skeleton ─────────────────────────────────────────────────────── */
.aimp-skeleton {
    background: linear-gradient(90deg, var(--surface) 25%, var(--surface-h) 50%, var(--surface) 75%);
    background-size: 200% 100%;
    animation: aimp-shimmer 1.4s infinite;
    border-radius: 6px; height: 14px; margin: 4px 0;
}
@keyframes aimp-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .aimp-sidebar {
        position: absolute; top: 0; left: 0; bottom: 0;
        transform: translateX(0); z-index: 50;
    }
    .aimp-sidebar.collapsed { transform: translateX(-100%); width: 260px; min-width: 260px; }
    .aimp-bubble { max-width: 88%; }
    .aimp-topbar { padding: 12px 14px; }
    .aimp-messages { padding: 16px 14px; }
    .aimp-input-area { padding: 12px 14px 16px; }
    .aimp-welcome h2 { font-size: 18px; }
}

/* ── Scrollbar (webkit) ───────────────────────────────────────────────────── */
.aimp-conv-list::-webkit-scrollbar,
.aimp-messages::-webkit-scrollbar { width: 4px; }
.aimp-conv-list::-webkit-scrollbar-thumb,
.aimp-messages::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 4px; }

/* ── Login notice ─────────────────────────────────────────────────────────── */
.aimp-login-notice {
    text-align: center; padding: 20px; color: var(--text-muted);
    border: 1px dashed var(--border); border-radius: var(--radius);
    font-size: 14px;
}
