:root {
    --bg-base: #0B0F17;
    --bg-surface: #121826;
    --bg-surface-elevated: #1B2234;
    --bg-surface-hover: #222B42;
    --border-color: #232D42;
    --border-color-focus: #3B82F6;
    --text-primary: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    --primary: #3B82F6;
    --primary-hover: #2563EB;
    --primary-glow: rgba(59, 130, 246, 0.25);
    --success: #10B981;
    --success-glow: rgba(16, 185, 129, 0.2);
    --warning: #F59E0B;
    --danger: #EF4444;
    --terminal-bg: #090D14;
    --terminal-border: #1E293B;
    --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --sidebar-width: 320px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-full: 9999px;
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Login Page
   ========================================================================== */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(circle at 50% 20%, #162036 0%, #0B0F17 70%);
    overflow: hidden;
    position: relative;
}

.login-glow {
    position: absolute;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.15) 0%, transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    filter: blur(40px);
}

.login-wrapper {
    position: relative;
    z-index: 10;
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.login-card {
    background: rgba(18, 24, 38, 0.85);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 36px 32px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.login-header {
    text-align: center;
    margin-bottom: 28px;
}

.logo-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    background: linear-gradient(135deg, #1E293B 0%, #0F172A 100%);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--primary);
    margin-bottom: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.login-header h2 {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.login-header p {
    font-size: 0.88rem;
    color: var(--text-muted);
}

.alert-error {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #FCA5A5;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 20px;
}

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

.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-container {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    pointer-events: none;
}

.input-container input {
    width: 100%;
    padding: 12px 14px 12px 42px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s ease;
}

.input-container input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
    background: #1e263a;
}

.btn-toggle-pw {
    position: absolute;
    right: 12px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 4px;
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
    font-family: var(--font-sans);
}

.btn-block {
    width: 100%;
    padding: 13px;
    font-size: 0.95rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: white;
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.35);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #60A5FA 0%, var(--primary) 100%);
    box-shadow: 0 6px 18px rgba(59, 130, 246, 0.5);
    transform: translateY(-1px);
}

.login-footer {
    margin-top: 24px;
    text-align: center;
    font-size: 0.76rem;
    color: var(--text-muted);
}

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

.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ==========================================================================
   Sidebar
   ========================================================================== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 20;
}

.sidebar.hidden {
    margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-header {
    padding: 20px 18px;
    border-bottom: 1px solid var(--border-color);
}

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

.brand-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, #1E293B 0%, #0F172A 100%);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-text h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.badge-subtle {
    background: rgba(59, 130, 246, 0.15);
    color: #60A5FA;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

/* Telemetry Panel */
.telemetry-panel {
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(11, 15, 23, 0.4);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.panel-header h4 {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.74rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: var(--radius-full);
}

.status-indicator.online {
    background: rgba(16, 185, 129, 0.12);
    color: #34D399;
}

.status-indicator.offline {
    background: rgba(239, 68, 68, 0.12);
    color: #F87171;
}

.status-indicator .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: currentColor;
    box-shadow: 0 0 8px currentColor;
}

.metric-card {
    background: var(--bg-surface-elevated);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    margin-bottom: 9px;
}

.metric-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    margin-bottom: 6px;
}

.metric-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.metric-value {
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-weight: 600;
}

.progress-bar {
    width: 100%;
    height: 5px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, #60A5FA 100%);
    border-radius: 3px;
    transition: width 0.4s ease;
}

.metric-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.detail-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.74rem;
}

.detail-label {
    color: var(--text-muted);
}

.detail-value {
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

/* Quick Prompts */
.quick-prompts {
    padding: 16px 18px;
    flex: 1;
    overflow-y: auto;
}

.prompt-chips {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.prompt-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.82rem;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-sans);
}

.prompt-chip:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    border-color: rgba(59, 130, 246, 0.4);
    transform: translateX(2px);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 14px 18px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(11, 15, 23, 0.6);
}

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

.user-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #3B82F6 0%, #8B5CF6 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: white;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}

.user-role {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.btn-logout {
    color: var(--text-muted);
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    transition: all 0.2s;
}

.btn-logout:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

/* ==========================================================================
   Main Content & Chat Area
   ========================================================================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    background-color: var(--bg-base);
    overflow: hidden;
}

/* Top Nav */
.top-nav {
    height: 60px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: rgba(18, 24, 38, 0.6);
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

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

.nav-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-title h2 {
    font-size: 1.05rem;
    font-weight: 700;
}

.pill-model {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    background: rgba(139, 92, 246, 0.15);
    color: #A78BFA;
    border: 1px solid rgba(139, 92, 246, 0.3);
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

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

.btn-secondary:hover {
    background: var(--bg-surface-hover);
    border-color: #3B82F6;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.82rem;
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

/* Empty State */
.empty-state {
    margin: auto;
    max-width: 680px;
    text-align: center;
    padding: 40px 20px;
}

.empty-icon {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.15) 0%, rgba(139, 92, 246, 0.15) 100%);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 20px;
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.empty-state h3 {
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.92rem;
    color: var(--text-secondary);
    margin-bottom: 30px;
    line-height: 1.6;
}

.empty-state code {
    background: var(--bg-surface-elevated);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    color: #60A5FA;
}

.starter-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    text-align: left;
}

.starter-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.starter-card:hover {
    background: var(--bg-surface-elevated);
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.starter-card strong {
    display: block;
    font-size: 0.88rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.starter-card span {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.4;
    display: block;
}

/* Messages Feed */
.messages-feed {
    display: flex;
    flex-direction: column;
    gap: 22px;
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
}

.message-row {
    display: flex;
    gap: 14px;
    animation: fadeIn 0.25s ease;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.message-avatar.user {
    background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
    color: white;
}

.message-avatar.assistant {
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
    color: white;
}

.message-body {
    flex: 1;
    overflow-x: hidden;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
}

.sender-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.message-time {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.message-content {
    font-size: 0.94rem;
    line-height: 1.65;
    color: #E2E8F0;
    word-break: break-word;
}

.message-content p {
    margin-bottom: 10px;
}

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

.message-content pre {
    background: var(--terminal-bg);
    border: 1px solid var(--terminal-border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.86rem;
    margin: 10px 0;
    color: #38BDF8;
}

.message-content code {
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.85em;
    color: #93C5FD;
}

.message-content pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

/* Terminal Tool Execution Card */
.tool-card {
    background: var(--terminal-bg);
    border: 1px solid var(--terminal-border);
    border-radius: var(--radius-md);
    margin: 10px 0;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.tool-header {
    background: #111726;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--terminal-border);
    font-size: 0.78rem;
}

.tool-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-secondary);
}

.tool-badge {
    padding: 2px 7px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
}

.tool-badge.running {
    background: rgba(245, 158, 11, 0.15);
    color: #FBBF24;
    animation: pulseGlow 1.5s infinite;
}

.tool-badge.success {
    background: rgba(16, 185, 129, 0.15);
    color: #34D399;
}

.tool-badge.error {
    background: rgba(239, 68, 68, 0.15);
    color: #F87171;
}

@keyframes pulseGlow {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

.tool-command {
    padding: 10px 14px;
    font-family: var(--font-mono);
    font-size: 0.86rem;
    color: #A5F3FC;
    background: #0B0E14;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    display: flex;
    align-items: center;
    gap: 8px;
}

.tool-command .prompt-symbol {
    color: #38BDF8;
    user-select: none;
}

.tool-output {
    padding: 12px 14px;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: #CBD5E1;
    max-height: 280px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    background: var(--terminal-bg);
}

.tool-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-tool-copy {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.72rem;
    padding: 3px 6px;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-tool-copy:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
}

/* Typing / Thinking indicator */
.thinking-bubble {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.thinking-dots {
    display: flex;
    gap: 4px;
}

.thinking-dots span {
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
    animation: bounce 1.2s infinite ease-in-out both;
}

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

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

/* Input Panel */
.input-panel {
    padding: 14px 24px 20px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.input-box-wrapper {
    max-width: 860px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 8px 12px 8px 16px;
    transition: all 0.2s;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

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

#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: var(--font-sans);
    resize: none;
    max-height: 160px;
    outline: none;
    line-height: 1.5;
    padding: 4px 0;
}

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

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

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.input-hints {
    max-width: 860px;
    margin: 8px auto 0;
    text-align: center;
    font-size: 0.74rem;
    color: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        height: 100vh;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
    }
    .starter-grid {
        grid-template-columns: 1fr;
    }
    .top-nav {
        padding: 0 16px;
    }
    .chat-container {
        padding: 16px;
    }
    .input-panel {
        padding: 10px 16px 16px;
    }
}
