/* Variables & Base Styles */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --bg-dark: #0f172a;
    --bg-light: #1e293b;
    --text-main: #f8fafc;
    --text-secondary: #94a3b8;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --assistant-bubble: rgba(255, 255, 255, 0.1);
    --user-bubble: #6366f1;
    --transition: cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar Styling */
.sidebar {
    width: 320px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 2rem;
    gap: 2rem;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    border-radius: 12px;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.4);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

/* Sidebar Navigation */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.25rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 12px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s var(--transition);
    text-align: left;
}

.nav-item:hover {
    background: var(--glass-bg);
    color: var(--text-main);
}

.nav-item.active {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.3);
    color: var(--primary-color);
}

.nav-item svg {
    transition: transform 0.3s var(--transition);
}

.nav-item:hover svg {
    transform: scale(1.1);
}

/* HF Send Button accent */
.send-btn.hf-send {
    background: linear-gradient(135deg, #f59e0b, #ef4444);
}

.send-btn.hf-send:hover {
    background: linear-gradient(135deg, #d97706, #dc2626);
    transform: scale(1.05);
}

/* Settings Drawer */
.settings-drawer {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.settings-section h3 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.input-group {
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.input-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    color: var(--text-main);
    font-family: inherit;
    transition: all 0.3s var(--transition);
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.2);
}

.input-group small {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    border: none;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s var(--transition);
}

.btn-secondary {
    width: 100%;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: var(--glass-border);
}

.info-section {
    margin-top: auto;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.footer {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
}

/* Chat Main Section */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background-image: 
        radial-gradient(at 0% 0%, hsla(253,16%,7%,1) 0, transparent 50%), 
        radial-gradient(at 50% 0%, hsla(225,39%,30%,1) 0, transparent 50%), 
        radial-gradient(at 100% 0%, hsla(339,49%,30%,1) 0, transparent 50%);
}

.chat-header {
    padding: 1.5rem 2rem;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 72px;
}

.status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.status-dot {
    width: 10px;
    height: 10px;
    background-color: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.5);
}

.status-text {
    font-weight: 600;
    font-size: 0.95rem;
}

.actions button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.2s;
}

.actions button:hover {
    background: var(--glass-bg);
    color: var(--text-main);
}

/* View Containers */
.view-container {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.view-container.hidden {
    display: none;
}

.view-container.active {
    animation: slideIn 0.4s var(--transition);
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Hugging Face Workspace */
.hf-workspace {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.hf-dot {
    background-color: #f59e0b;
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
}

.welcome-card {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 3rem;
    border-radius: 24px;
    text-align: center;
    max-width: 600px;
    width: 100%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.hf-logo-large {
    font-size: 4rem;
    margin-bottom: 1.5rem;
}

.welcome-card h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-card p {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 2rem;
}

.placeholder-content {
    padding: 1.5rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    border-left: 4px solid #f59e0b;
}

/* ── Diagram (Mermaid) Workspace ───────────────────────────────────────────── */
.diagram-dot {
    background-color: #06b6d4;
    box-shadow: 0 0 10px rgba(6, 182, 212, 0.5);
}

.export-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.export-btn:hover {
    background: rgba(6, 182, 212, 0.15);
    border-color: rgba(6, 182, 212, 0.4);
    color: #06b6d4;
}

.diagram-workspace {
    flex: 1;
    display: grid;
    grid-template-columns: 360px 1fr;
    overflow: hidden;
}

/* Left: Editor Panel */
.diagram-editor-panel {
    padding: 1.75rem;
    border-right: 1px solid var(--glass-border);
    background: rgba(15, 23, 42, 0.4);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
}

.diagram-title {
    font-size: 1.3rem;
    font-weight: 600;
}

.diagram-subtitle {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: -0.5rem;
}

/* AI Text-to-Diagram Section */
.ai-diagram-section {
    background: rgba(99, 102, 241, 0.06);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 14px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ai-diagram-section label {
    font-size: 0.83rem;
    font-weight: 600;
    color: #a5b4fc;
}

.diagram-text-input {
    width: 100%;
    padding: 0.75rem 0.9rem;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: 10px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.88rem;
    line-height: 1.6;
    resize: none;
    transition: border-color 0.3s;
}

.diagram-text-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.2);
}

.ai-diagram-options {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.ai-diagram-options select {
    flex: 0 0 auto;
    padding: 0.55rem 0.75rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.82rem;
}

.ai-diagram-options select option {
    background: var(--bg-dark);
}

.ai-diagram-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.55rem 0.9rem;
    background: linear-gradient(135deg, var(--primary-color), #a855f7);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s;
}

.ai-diagram-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.ai-diagram-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Divider */
.diagram-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.diagram-divider::before,
.diagram-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--glass-border);
}

.diagram-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chip {
    padding: 0.35rem 0.85rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.chip:hover,
.chip.active-chip {
    background: rgba(6, 182, 212, 0.15);
    border-color: rgba(6, 182, 212, 0.5);
    color: #06b6d4;
}

/* Code Editor */
.diagram-code-editor {
    width: 100%;
    flex: 1;
    min-height: 220px;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: #e2e8f0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.88rem;
    line-height: 1.7;
    resize: vertical;
    transition: border-color 0.3s;
}

.diagram-code-editor:focus {
    outline: none;
    border-color: #06b6d4;
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.15);
}

/* Render Button */
.diagram-render-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.85rem;
    background: linear-gradient(135deg, #06b6d4, #6366f1);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 20px rgba(6, 182, 212, 0.25);
}

.diagram-render-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(6, 182, 212, 0.4);
}

.diagram-hint {
    font-size: 0.78rem;
    color: var(--text-secondary);
    text-align: center;
}

.diagram-hint kbd {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 4px;
    padding: 0.1rem 0.4rem;
    font-size: 0.75rem;
    color: var(--text-main);
}

/* Right: Preview Panel */
.diagram-preview-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    overflow: auto;
    background: rgba(0, 0, 0, 0.1);
}

.diagram-output {
    width: 100%;
    max-width: 820px;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.diagram-output svg {
    max-width: 100%;
    height: auto;
    border-radius: 16px;
    animation: fadeIn 0.4s ease;
}

.diagram-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: var(--text-secondary);
    text-align: center;
}

.diagram-placeholder small {
    font-size: 0.8rem;
    opacity: 0.6;
}

.diagram-error {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    width: 100%;
    white-space: pre-wrap;
}

/* Image Generation Workspace */
.img-dot {
    background-color: #a855f7;
    box-shadow: 0 0 10px rgba(168, 85, 247, 0.5);
}

.img-workspace {
    flex: 1;
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 0;
    overflow: hidden;
}

/* Left: Prompt Panel */
.img-prompt-panel {
    padding: 2rem;
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
    background: rgba(15, 23, 42, 0.3);
}

.img-title {
    font-size: 1.5rem;
    font-weight: 600;
}

.img-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: -1rem;
}

.img-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.img-form label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.img-prompt-input {
    width: 100%;
    padding: 0.85rem 1rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
    min-height: 100px;
    line-height: 1.6;
    transition: border-color 0.3s;
}

.img-prompt-input:focus {
    outline: none;
    border-color: #a855f7;
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.2);
}

.img-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.option-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.option-group label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.option-group select,
.option-group input[type="number"] {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.9rem;
    transition: border-color 0.3s;
}

.option-group select:focus,
.option-group input[type="number"]:focus {
    outline: none;
    border-color: #a855f7;
}

.option-group select option {
    background: var(--bg-dark);
}

.img-generate-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.9rem;
    background: linear-gradient(135deg, #a855f7, #6366f1);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 20px rgba(168, 85, 247, 0.3);
}

.img-generate-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(168, 85, 247, 0.45);
}

.img-generate-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.btn-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Right: Output Panel */
.img-output-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    gap: 1rem;
}

.img-output-placeholder {
    width: 100%;
    max-width: 560px;
    aspect-ratio: 1 / 1;
    background: var(--glass-bg);
    border: 2px dashed var(--glass-border);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.img-output-result {
    width: 100%;
    max-width: 560px;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.img-placeholder-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: var(--text-secondary);
    text-align: center;
    padding: 2rem;
}

.generated-image {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 20px;
    animation: fadeIn 0.5s ease;
}

.img-actions {
    display: flex;
    gap: 0.75rem;
}

.img-actions .btn {
    padding: 0.65rem 1.5rem;
    font-size: 0.9rem;
}

/* FLUX Loader animation */
.flux-loader {
    display: flex;
    gap: 6px;
    align-items: flex-end;
    height: 40px;
}

.flux-bar {
    width: 8px;
    border-radius: 4px;
    background: linear-gradient(135deg, #a855f7, #6366f1);
    animation: fluxPulse 1.2s ease-in-out infinite;
}

.flux-bar:nth-child(1) { animation-delay: 0s;    height: 20px; }
.flux-bar:nth-child(2) { animation-delay: 0.15s; height: 32px; }
.flux-bar:nth-child(3) { animation-delay: 0.3s;  height: 26px; }
.flux-bar:nth-child(4) { animation-delay: 0.45s; height: 16px; }

@keyframes fluxPulse {
    0%, 100% { opacity: 0.4; transform: scaleY(1); }
    50%       { opacity: 1;   transform: scaleY(1.3); }
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 10px;
}

.message {
    max-width: 80%;
    animation: fadeIn 0.4s var(--transition);
    line-height: 1.6;
}

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

.message.user {
    align-self: flex-end;
}

.message.assistant {
    align-self: flex-start;
}

.message-content {
    padding: 1rem 1.25rem;
    border-radius: 18px;
    font-size: 0.95rem;
    position: relative;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.user .message-content {
    background: var(--user-bubble);
    color: white;
    border-bottom-right-radius: 4px;
}

.assistant .message-content {
    background: var(--assistant-bubble);
    backdrop-filter: blur(5px);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
}

/* Markdown Styling */
.message-content p {
    margin-bottom: 0.75rem;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85em;
}

.message-content pre {
    background: #1e1e1e !important;
    padding: 1rem;
    border-radius: 12px;
    margin: 1rem 0;
    overflow-x: auto;
}

.message-content pre code {
    background: transparent;
    padding: 0;
    font-size: 0.9rem;
}

/* Input Area */
.chat-input-area {
    padding: 1.5rem 2rem 2.5rem;
    background: transparent;
}

.input-container {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    position: relative;
    background: var(--glass-bg);
    backdrop-filter: blur(15px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    display: flex;
    align-items: flex-end;
    padding: 0.75rem 1rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    transition: all 0.3s;
}

.input-container:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 10px 40px rgba(99, 102, 241, 0.15);
}

#user-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    padding: 0.5rem;
    resize: none;
    max-height: 200px;
}

#user-input:focus {
    outline: none;
}

.send-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-left: 0.5rem;
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
    transform: none;
}

/* Typing Indicator */
.typing {
    display: flex;
    gap: 4px;
    padding: 10px;
}

.typing span {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing span:nth-child(1) { animation-delay: -0.32s; }
.typing span:nth-child(2) { animation-delay: -0.16s; }

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

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        display: none; /* In a real app we'd add a toggle */
    }
    .message {
        max-width: 90%;
    }
}
