/* ==========================================
   CSS variables & Design System
   ========================================== */
:root {
    --bg-base: #06080F;
    --bg-panel: rgba(13, 17, 33, 0.45);
    --border-glass: rgba(255, 255, 255, 0.05);
    --border-glass-glow: rgba(99, 102, 241, 0.15);
    
    --c-indigo: #6366F1;
    --c-purple: #8B5CF6;
    --c-pink: #EC4899;
    --c-cyan: #06B6D4;
    --c-emerald: #10B981;
    --c-rose: #F43F5E;
    
    --c-text-primary: #F3F4F6;
    --c-text-secondary: #9CA3AF;
    --c-text-muted: #6B7280;
    
    --font-sans: 'Outfit', sans-serif;
    --font-mono: 'Fira Code', monospace;
    
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================
   Base styles
   ========================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-base);
    color: var(--c-text-primary);
    font-family: var(--font-sans);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    position: relative;
}

/* Shifting neon glow meshes */
.ambient-background {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.ambient-background::before,
.ambient-background::after {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    filter: blur(140px);
    opacity: 0.12;
    animation: drift 25s infinite alternate ease-in-out;
}

.ambient-background::before {
    background: radial-gradient(circle, var(--c-indigo) 0%, transparent 70%);
    top: -10%;
    left: -10%;
}

.ambient-background::after {
    background: radial-gradient(circle, var(--c-purple) 0%, transparent 70%);
    bottom: -10%;
    right: -10%;
    animation-delay: -10s;
}

@keyframes drift {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(150px, 80px) scale(1.2); }
}

/* ==========================================
   Reusable UI Elements
   ========================================== */
.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: 20px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    transition: var(--transition-smooth);
}

.glass-panel:hover {
    border-color: rgba(99, 102, 241, 0.15);
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge.blue { background: rgba(59, 130, 246, 0.15); color: #60A5FA; border: 1px solid rgba(59, 130, 246, 0.3); }
.badge.purple { background: rgba(139, 92, 246, 0.15); color: #A78BFA; border: 1px solid rgba(139, 92, 246, 0.3); }
.badge.pink { background: rgba(236, 72, 153, 0.15); color: #F472B6; border: 1px solid rgba(236, 72, 153, 0.3); }
.badge.bg-dark { background: rgba(255, 255, 255, 0.05); color: var(--c-text-secondary); border: 1px solid var(--border-glass); }

.pulse-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
}

.pulse-indicator.red {
    background-color: var(--c-rose);
    box-shadow: 0 0 10px var(--c-rose);
    animation: pulse-red 2s infinite;
}

.pulse-indicator.green {
    background-color: var(--c-emerald);
    box-shadow: 0 0 10px var(--c-emerald);
    animation: pulse-green 2s infinite;
}

@keyframes pulse-red {
    0% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(244, 63, 94, 0); }
    100% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(244, 63, 94, 0); }
}

@keyframes pulse-green {
    0% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* ==========================================
   Layout architecture
   ========================================== */
.app-container {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: 100vh;
    width: 100vw;
    padding: 20px;
    gap: 20px;
}

/* Sidebar navigation */
.sidebar {
    display: flex;
    flex-direction: column;
    padding: 24px;
    height: 100%;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 40px;
}

.brand-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--c-indigo) 0%, var(--c-purple) 100%);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

.brand-logo svg {
    color: #fff;
    width: 24px;
    height: 24px;
}

.brand-text h1 {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(to right, #fff, #c7d2fe);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-text span {
    font-size: 0.75rem;
    color: var(--c-text-muted);
    font-weight: 500;
}

.nav-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: none;
    border: none;
    color: var(--c-text-secondary);
    padding: 12px 16px;
    border-radius: 12px;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: var(--transition-smooth);
}

.nav-item svg {
    width: 20px;
    height: 20px;
}

.nav-item:hover, .nav-item.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.15) 0%, transparent 100%);
    border-left: 3px solid var(--c-indigo);
    padding-left: 13px;
}

.status-widget {
    margin-top: auto;
    padding: 16px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.widget-header {
    display: flex;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 6px;
}

.widget-details {
    font-size: 0.75rem;
    color: var(--c-text-muted);
    line-height: 1.4;
}

/* Main content workspace */
.main-content {
    position: relative;
    height: 100%;
    overflow: hidden;
}

.tab-view {
    display: none;
    flex-direction: column;
    height: 100%;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.tab-view.active {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

.section-header {
    margin-bottom: 24px;
}

.section-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 6px;
}

.section-header p {
    color: var(--c-text-secondary);
    font-size: 0.95rem;
}

/* ==========================================
   Dashboard Tab View
   ========================================== */
.card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.main-card {
    position: relative;
    padding: 24px;
}

.main-card h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.2rem;
    margin-bottom: 6px;
}

.main-card h3 svg {
    color: var(--c-indigo);
}

.subtitle {
    font-size: 0.85rem;
    color: var(--c-text-secondary);
    margin-bottom: 20px;
}

.model-cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
}

.model-option-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-glass);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.model-option-card:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(99, 102, 241, 0.3);
    transform: translateY(-2px);
}

.model-option-card.active {
    background: rgba(99, 102, 241, 0.05);
    border-color: var(--c-indigo);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h4 {
    font-size: 1rem;
    font-weight: 600;
}

.card-desc {
    font-size: 0.8rem;
    color: var(--c-text-secondary);
    line-height: 1.4;
    flex-grow: 1;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
}

.model-size {
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: var(--c-text-muted);
}

.btn-load {
    background: var(--c-indigo);
    border: none;
    color: #fff;
    padding: 6px 12px;
    border-radius: 8px;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn-load:hover {
    background: #4f46e5;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}

.btn-load.loading {
    background: var(--c-text-muted);
    cursor: not-allowed;
}

.dashboard-bottom-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

.arch-card {
    padding: 24px;
}

.arch-card h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.15rem;
    margin-bottom: 20px;
}

.arch-card h3 svg {
    color: var(--c-purple);
}

.parallel-diagram {
    display: grid;
    grid-template-columns: 1fr 40px 1fr 40px 1fr;
    align-items: center;
    gap: 10px;
}

.diagram-node {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-glass);
    padding: 16px;
    border-radius: 12px;
    text-align: center;
}

.diagram-node h4 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.diagram-node p {
    font-size: 0.75rem;
    color: var(--c-text-muted);
    margin-top: 8px;
    line-height: 1.4;
}

.diagram-connector {
    height: 2px;
    background: linear-gradient(90deg, var(--c-indigo) 0%, var(--c-purple) 100%);
    opacity: 0.3;
}

/* ==========================================
   Playground Tab View
   ========================================== */
.playground-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
    height: calc(100% - 20px);
}

.chat-room {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

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

.chat-meta {
    display: flex;
    align-items: center;
    gap: 16px;
}

.chat-model-badge {
    background: rgba(99, 102, 241, 0.1);
    color: var(--c-indigo);
    border: 1px solid rgba(99, 102, 241, 0.2);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-family: var(--font-mono);
    font-weight: 600;
}

.inference-stats {
    display: flex;
    gap: 16px;
    font-size: 0.75rem;
    color: var(--c-text-secondary);
}

.inference-stats span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.clear-btn {
    background: none;
    border: none;
    color: var(--c-text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    font-family: var(--font-sans);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition-smooth);
}

.clear-btn:hover {
    color: var(--c-rose);
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Chat bubble styling */
.system-bubble {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-glass);
    color: var(--c-text-secondary);
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.8rem;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    line-height: 1.5;
}

.system-bubble svg {
    color: var(--c-cyan);
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    margin-top: 2px;
}

.msg-bubble {
    max-width: 80%;
    padding: 12px 18px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-break: break-word;
}

.msg-bubble.user {
    align-self: flex-end;
    background: var(--c-indigo);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg-bubble.assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-glass);
    color: var(--c-text-primary);
    border-bottom-left-radius: 4px;
}

.chat-input-bar {
    padding: 16px 20px;
    border-top: 1px solid var(--border-glass);
    display: flex;
    gap: 12px;
    background: rgba(7, 8, 14, 0.3);
}

.chat-input-bar textarea {
    flex-grow: 1;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-glass);
    color: #fff;
    border-radius: 12px;
    padding: 12px;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    resize: none;
    outline: none;
    transition: var(--transition-smooth);
}

.chat-input-bar textarea:focus {
    border-color: rgba(99, 102, 241, 0.4);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.1);
}

.send-btn {
    background: var(--c-indigo);
    border: none;
    color: #fff;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.send-btn:hover {
    background: #4f46e5;
    transform: scale(1.03);
}

/* Chat Settings Panel */
.chat-settings {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

.chat-settings h3 {
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.setting-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--c-text-primary);
}

.setting-group textarea, .setting-group input[type="text"], .setting-group input[type="password"], .setting-group select {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-glass);
    color: #fff;
    border-radius: 8px;
    padding: 10px;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    outline: none;
    transition: var(--transition-smooth);
}

.setting-group textarea:focus, .setting-group input:focus, .setting-group select:focus {
    border-color: rgba(99, 102, 241, 0.4);
}

.setting-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.val-display {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--c-cyan);
    font-weight: bold;
}

.desc {
    font-size: 0.7rem;
    color: var(--c-text-muted);
    line-height: 1.3;
}

/* Slider styling */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.08);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--c-indigo);
    cursor: pointer;
    box-shadow: 0 0 8px var(--c-indigo);
    transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* ==========================================
   Training Tab View
   ========================================== */
.training-layout {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 20px;
    height: calc(100% - 20px);
}

.training-settings {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

.training-params-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.training-params-grid .setting-group {
    gap: 4px;
}

.training-params-grid input[type="number"] {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-glass);
    color: #fff;
    border-radius: 8px;
    padding: 8px 10px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    outline: none;
}

.action-buttons {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.primary-btn {
    flex-grow: 1;
    background: linear-gradient(135deg, var(--c-indigo) 0%, var(--c-purple) 100%);
    border: none;
    color: #fff;
    padding: 12px;
    border-radius: 10px;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition-smooth);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.2);
}

.primary-btn:hover {
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}

.danger-btn {
    flex-grow: 1;
    background: rgba(244, 63, 94, 0.1);
    border: 1px solid rgba(244, 63, 94, 0.3);
    color: var(--c-rose);
    padding: 12px;
    border-radius: 10px;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition-smooth);
}

.danger-btn:hover {
    background: rgba(244, 63, 94, 0.2);
}

.training-progress {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow: hidden;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chart-wrapper {
    flex-grow: 1;
    min-height: 200px;
    max-height: 320px;
    position: relative;
}

.live-console {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-glass);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    height: 180px;
    overflow: hidden;
}

.console-header {
    background: rgba(0, 0, 0, 0.2);
    padding: 8px 16px;
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: var(--c-text-muted);
    border-bottom: 1px solid var(--border-glass);
    display: flex;
    align-items: center;
    gap: 6px;
}

.console-header svg {
    width: 14px;
    height: 14px;
}

.console-body {
    flex-grow: 1;
    overflow-y: auto;
    padding: 12px 16px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--c-emerald);
    line-height: 1.5;
    word-break: break-all;
    white-space: pre-wrap;
}

/* ==========================================
   Export / Deploy Tab View
   ========================================== */
.export-card {
    max-width: 680px;
    margin: 0 auto;
    padding: 32px;
    position: relative;
}

.export-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
    border-bottom: 1px solid var(--border-glass);
    padding-bottom: 20px;
}

.hf-avatar {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: linear-gradient(135deg, #FBBF24 0%, #F59E0B 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 1.3rem;
}

.export-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.disabled-input {
    background: rgba(255, 255, 255, 0.01) !important;
    border-color: rgba(255, 255, 255, 0.02) !important;
    color: var(--c-text-muted) !important;
    cursor: not-allowed;
}

.pulse-hover:hover {
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.4);
}

/* ==========================================
   Overlay Loader (Shared across tabs)
   ========================================== */
.loader-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(7, 8, 14, 0.9);
    border-radius: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 100;
    backdrop-filter: blur(8px);
}

.loader-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(99, 102, 241, 0.1);
    border-top-color: var(--c-indigo);
    border-radius: 50%;
    animation: spin 1s infinite linear;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loader-overlay h4 {
    font-size: 1.1rem;
    font-weight: 600;
}

.loader-overlay p {
    font-size: 0.8rem;
    color: var(--c-text-secondary);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.1);
}
