/* ===== Variables & Reset ===== */
:root {
    --bg-primary: #0f0f17;
    --bg-secondary: #161622;
    --bg-card: #1c1c2e;
    --bg-input: #1a1a2a;
    --bg-hover: #252540;
    --text-primary: #eeeef5;
    --text-secondary: #9898b0;
    --text-muted: #5e5e78;
    --accent: #7c5cfc;
    --accent-hover: #9b7fff;
    --accent-glow: rgba(124, 92, 252, 0.25);
    --border: rgba(255, 255, 255, 0.07);
    --border-hover: rgba(255, 255, 255, 0.14);
    --success: #34d399;
    --warning: #fbbf24;
    --error: #f87171;
    --radius: 10px;
    --radius-lg: 16px;
    --transition: 0.2s ease;
    --font: 'Inter', -apple-system, sans-serif;
    --sidebar-w: 280px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100%;
    overflow: hidden;
}
a { text-decoration: none; color: var(--accent); }
a:hover { color: var(--accent-hover); }

/* ===== App Layout ===== */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    transition: var(--transition);
    z-index: 100;
}

.sidebar-header {
    padding: 18px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 32px;
    height: 32px;
    color: var(--accent);
}

.logo-text {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: var(--transition);
    display: none;
}

.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-hover); }

.sidebar-section {
    flex: 1;
    overflow-y: auto;
    padding: 12px 8px;
}

.sidebar-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
    padding: 8px 12px 10px;
}

.skill-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.skill-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-secondary);
    border: 1px solid transparent;
}

.skill-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.skill-item.active {
    background: rgba(124, 92, 252, 0.12);
    color: var(--accent);
    border-color: rgba(124, 92, 252, 0.2);
}

.skill-item-icon {
    font-size: 1.15rem;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}

.skill-item-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer {
    padding: 12px 8px;
    border-top: 1px solid var(--border);
}

.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius);
    border: none;
    background: none;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.sidebar-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.model-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.model-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    min-width: 0;
}

/* ===== Welcome Screen ===== */
.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    overflow-y: auto;
}

.welcome-inner {
    max-width: 560px;
    text-align: center;
}

.welcome-icon { margin-bottom: 24px; }

.welcome-inner h1 {
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 12px;
    background: linear-gradient(135deg, #7c5cfc, #00d4ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-inner > p {
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1.7;
    margin-bottom: 36px;
}

.welcome-features {
    display: flex;
    flex-direction: column;
    gap: 16px;
    text-align: left;
    margin-bottom: 32px;
}

.welcome-feature {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.wf-icon {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, #7c5cfc, #00d4ff);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
}

.welcome-feature strong {
    display: block;
    font-size: 0.95rem;
    margin-bottom: 2px;
}

.welcome-feature p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0;
}

.setup-alert {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.2);
    border-radius: var(--radius);
    color: var(--warning);
    font-size: 0.88rem;
}

.setup-alert svg { flex-shrink: 0; }
.setup-alert span { flex: 1; }

/* ===== Skill Workspace ===== */
.skill-workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.workspace-header {
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
    flex-shrink: 0;
    gap: 16px;
}

.ws-skill-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.ws-skill-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.ws-skill-info h2 {
    font-size: 1.05rem;
    font-weight: 700;
    white-space: nowrap;
}

.ws-skill-info p {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 400px;
}

.ws-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.model-select {
    padding: 7px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.82rem;
    cursor: pointer;
    outline: none;
}

.model-select:focus { border-color: var(--accent); }

/* ===== Chat Area ===== */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.chat-messages {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.chat-msg {
    display: flex;
    gap: 12px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.msg-avatar.user {
    background: linear-gradient(135deg, #3b82f6, #06b6d4);
}

.msg-avatar.assistant {
    background: linear-gradient(135deg, #7c5cfc, #a855f7);
}

.msg-avatar.assistant.openai {
    background: linear-gradient(135deg, #10a37f, #1a7f5a);
}

.msg-body {
    flex: 1;
    min-width: 0;
}

.msg-role {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.msg-content {
    font-size: 0.92rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.msg-content p { margin-bottom: 10px; }
.msg-content p:last-child { margin-bottom: 0; }

.msg-content pre {
    background: #1e1e2e;
    border-radius: 8px;
    padding: 14px;
    overflow-x: auto;
    margin: 10px 0;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.82rem;
    line-height: 1.6;
    border: 1px solid var(--border);
}

.msg-content code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    background: rgba(124, 92, 252, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.84rem;
    color: var(--accent);
}

.msg-content pre code {
    background: none;
    padding: 0;
    color: #cdd6f4;
}

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

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

.msg-content strong { color: #fff; }

.msg-content h1, .msg-content h2, .msg-content h3 {
    margin: 16px 0 8px;
    color: #fff;
}

.msg-content h1 { font-size: 1.3rem; }
.msg-content h2 { font-size: 1.15rem; }
.msg-content h3 { font-size: 1.02rem; }

.msg-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 14px;
    margin: 10px 0;
    color: var(--text-secondary);
}

.msg-image {
    max-width: 300px;
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
}

.msg-loading {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.msg-loading span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: bounce 1.4s infinite ease-in-out;
}

.msg-loading span:nth-child(1) { animation-delay: 0s; }
.msg-loading span:nth-child(2) { animation-delay: 0.16s; }
.msg-loading span:nth-child(3) { animation-delay: 0.32s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

.msg-error {
    color: var(--error);
    font-size: 0.88rem;
    padding: 10px 14px;
    background: rgba(248, 113, 113, 0.08);
    border: 1px solid rgba(248, 113, 113, 0.2);
    border-radius: 8px;
}

.msg-files {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.msg-file-badge {
    display: inline-flex;
    align-items: center;
    padding: 5px 10px;
    background: rgba(124, 92, 252, 0.12);
    border: 1px solid rgba(124, 92, 252, 0.2);
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
}

.main-content.drag-over {
    outline: 2px dashed var(--accent);
    outline-offset: -4px;
    background: rgba(124, 92, 252, 0.03);
}

/* ===== Input Area ===== */
.input-area {
    padding: 12px 24px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

/* Files Preview (multi-file) */
.files-preview {
    max-width: 800px;
    margin: 0 auto 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.files-preview-list {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}

.file-preview-item {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-width: 180px;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.file-preview-item img {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.file-preview-item .file-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(124, 92, 252, 0.15);
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent);
    flex-shrink: 0;
    text-transform: uppercase;
}

.file-preview-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
}

.file-preview-remove {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--error);
    color: #fff;
    border: none;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s;
}

.file-preview-item:hover .file-preview-remove {
    opacity: 1;
}

.clear-all-files {
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    white-space: nowrap;
    transition: var(--transition);
}

.clear-all-files:hover {
    color: var(--error);
    background: rgba(248, 113, 113, 0.1);
}

.file-count-badge {
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 2px 0;
}

.input-bar {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px 8px 6px 4px;
    transition: var(--transition);
}

.input-bar:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition);
    flex-shrink: 0;
}

.upload-btn:hover {
    color: var(--accent);
    background: rgba(124, 92, 252, 0.1);
}

.input-bar textarea {
    flex: 1;
    padding: 8px 4px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.92rem;
    resize: none;
    outline: none;
    line-height: 1.5;
    max-height: 150px;
    min-height: 38px;
}

.send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: none;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-hint {
    max-width: 800px;
    margin: 6px auto 0;
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* ===== Settings Modal ===== */
.settings-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.settings-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.settings-modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    max-width: 520px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    transform: scale(0.95);
    transition: var(--transition);
}

.settings-overlay.active .settings-modal {
    transform: scale(1);
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.settings-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.settings-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 4px;
    transition: var(--transition);
}

.settings-close:hover { color: var(--text-primary); }

.settings-body {
    padding: 24px;
}

.setting-group {
    margin-bottom: 20px;
}

.setting-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.optional-tag {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--warning);
    margin-left: 6px;
}

.setting-group input,
.setting-group select {
    width: 100%;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition);
}

.setting-group input:focus,
.setting-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.key-input-wrap {
    display: flex;
    gap: 6px;
}

.key-input-wrap input { flex: 1; }

.toggle-vis {
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-hover);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.82rem;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}

.toggle-vis:hover { color: var(--text-primary); }

.setting-hint {
    display: block;
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-top: 6px;
    line-height: 1.5;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 8px;
    font-family: var(--font);
    font-size: 0.88rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, #7c5cfc, #00d4ff);
    color: #fff;
}

.btn-primary:hover { opacity: 0.9; }

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover { border-color: var(--accent); }

.btn-sm { padding: 7px 14px; font-size: 0.82rem; }

.btn-save-settings { width: 100%; justify-content: center; margin-top: 8px; }

/* ===== Proxy Guide ===== */
.proxy-guide {
    padding: 20px 24px;
    border-top: 1px solid var(--border);
}

.proxy-guide h3 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.proxy-guide p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.proxy-guide .code-block {
    background: #1e1e2e;
    border-radius: 8px;
    padding: 14px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.78rem;
    color: #a6e3a1;
    overflow-x: auto;
    margin-bottom: 12px;
    white-space: pre;
    line-height: 1.6;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--accent);
    color: #fff;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 0.88rem;
    font-weight: 500;
    box-shadow: 0 8px 32px var(--accent-glow);
    transform: translateY(80px);
    opacity: 0;
    transition: var(--transition);
    z-index: 3000;
}

.toast.show { transform: translateY(0); opacity: 1; }

/* ===== Utility ===== */
.hidden { display: none !important; }

/* ===== Mobile Toggle ===== */
.mobile-toggle {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 101;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        z-index: 200;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    }

    .sidebar.open { left: 0; }

    .mobile-toggle { display: flex; }

    .workspace-header {
        padding: 14px 16px 14px 60px;
        flex-wrap: wrap;
    }

    .ws-skill-info p { display: none; }

    .chat-area { padding: 16px; }
    .input-area { padding: 10px 16px 14px; }

    .welcome-screen { padding: 24px 16px; }
    .welcome-inner h1 { font-size: 1.4rem; }

    .settings-modal { margin: 16px; }
}
