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

:root {
    /* Premium Dark Theme Colors */
    --bg-main: #050507;
    --bg-glass: rgba(18, 18, 24, 0.65);
    --bg-glass-hover: rgba(30, 30, 40, 0.8);
    --bg-panel: rgba(12, 12, 16, 0.8);
    
    --border-light: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(255, 255, 255, 0.15);
    
    /* Agent Accent Colors */
    --accent-mab: #00f2fe;    /* Teal/Cyan */
    --accent-sab1: #4facfe;   /* Blue */
    --accent-sab2: #a18cd1;   /* Purple */
    --accent-sab3: #f6d365;   /* Amber */
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    /* Glows */
    --glow-mab: 0 0 20px rgba(0, 242, 254, 0.2);
    --glow-sab1: 0 0 20px rgba(79, 172, 254, 0.2);
    --glow-sab2: 0 0 20px rgba(161, 140, 209, 0.2);
    --glow-sab3: 0 0 20px rgba(246, 211, 101, 0.2);
}

body.light-mode {
    --bg-main: #f8fafc;
    --bg-glass: rgba(255, 255, 255, 0.85);
    --bg-glass-hover: rgba(240, 244, 248, 0.9);
    --bg-panel: rgba(255, 255, 255, 0.95);
    
    --border-light: rgba(0, 0, 0, 0.1);
    --border-highlight: rgba(0, 0, 0, 0.2);
    
    --text-main: #0f172a;
    --text-muted: #64748b;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    overflow: hidden;
    /* Subtle noise texture */
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.03'/%3E%3C/svg%3E");
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Syne', sans-serif;
    font-weight: 600;
}

/* Glassmorphism Utilities */
.glass-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-light);
    border-radius: 16px;
}

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

/* --- Sidebar --- */
.sidebar {
    width: 280px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    padding: 24px 0;
    z-index: 10;
}

.logo-container {
    padding: 0 24px 32px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-container h1 {
    font-size: 1.5rem;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 16px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    font-weight: 500;
    overflow: hidden;
}

.nav-item svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

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

.nav-item.active {
    color: var(--text-main);
    background: var(--bg-glass);
    border: 1px solid var(--border-highlight);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* Nav Item Accents */
.nav-item[data-tab="mab"].active { border-left: 3px solid var(--accent-mab); }
.nav-item[data-tab="sab1"].active { border-left: 3px solid var(--accent-sab1); }
.nav-item[data-tab="sab2"].active { border-left: 3px solid var(--accent-sab2); }
.nav-item[data-tab="sab3"].active { border-left: 3px solid var(--accent-sab3); }

/* Animated Working Dot in Sidebar */
.nav-dot {
    position: absolute;
    right: 16px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-mab);
    box-shadow: 0 0 10px var(--accent-mab);
    animation: pulse 1.5s infinite;
}
.nav-item[data-tab="sab1"] .nav-dot { background: var(--accent-sab1); box-shadow: 0 0 10px var(--accent-sab1); }
.nav-item[data-tab="sab2"] .nav-dot { background: var(--accent-sab2); box-shadow: 0 0 10px var(--accent-sab2); }
.nav-item[data-tab="sab3"] .nav-dot { background: var(--accent-sab3); box-shadow: 0 0 10px var(--accent-sab3); }

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.5; }
    50% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(0.95); opacity: 0.5; }
}

/* --- Main Content Area --- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* --- Pipeline Stepper (Global) --- */
.campaign-pipeline {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 32px;
    background: var(--bg-glass);
    border-bottom: 1px solid var(--border-light);
    gap: 12px;
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 5;
    pointer-events: none;
}

.campaign-pipeline.pipeline-running, .campaign-pipeline.pipeline-done {
    opacity: 1;
    transform: translateY(0);
    position: relative;
    pointer-events: auto;
}

.pipeline-step {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.3s;
}

.step-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.pipeline-line {
    height: 2px;
    width: 40px;
    background: var(--border-light);
    transition: all 0.3s;
}

/* Active Step */
.pipeline-step.active {
    color: var(--text-main);
}
.pipeline-step.active .step-dot {
    border-color: var(--accent-mab);
    box-shadow: var(--glow-mab);
    background: rgba(0, 242, 254, 0.1);
}
.pipeline-step.active .step-dot::after {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-mab);
    animation: pulse 1.5s infinite;
}

/* Done Step */
.pipeline-step.done {
    color: var(--text-main);
}
.pipeline-step.done .step-dot {
    border-color: var(--accent-mab);
    background: var(--accent-mab);
}
.pipeline-step.done .step-dot::after {
    content: '✓';
    color: #000;
    font-size: 12px;
    font-weight: bold;
}
.pipeline-step.done + .pipeline-line {
    background: var(--accent-mab);
}

/* Error Step */
.pipeline-step.error { color: #ef4444; }
.pipeline-step.error .step-dot { border-color: #ef4444; background: rgba(239, 68, 68, 0.1); }
.pipeline-step.error .step-dot::after { content: '!'; color: #ef4444; font-weight: bold; }

/* --- Tab Content --- */
.tab-content {
    display: none;
    flex: 1;
    overflow: hidden;
}
.tab-content.active {
    display: flex;
    flex-direction: row; /* For split views like MAB */
    animation: fadeIn 0.4s ease;
}

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

/* --- Chat Areas --- */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* Chat Bubbles */
.chat-message {
    display: flex;
    gap: 16px;
    max-width: 85%;
    animation: slideUp 0.3s ease;
}

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

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message.agent {
    align-self: flex-start;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
    background: var(--bg-glass);
    border: 1px solid var(--border-highlight);
}

.chat-message.user .chat-avatar { background: rgba(255,255,255,0.1); }
.chat-message.agent.mab .chat-avatar { border-color: var(--accent-mab); box-shadow: var(--glow-mab); }
.chat-message.agent.sab1 .chat-avatar { border-color: var(--accent-sab1); box-shadow: var(--glow-sab1); }
.chat-message.agent.sab2 .chat-avatar { border-color: var(--accent-sab2); box-shadow: var(--glow-sab2); }
.chat-message.agent.sab3 .chat-avatar { border-color: var(--accent-sab3); box-shadow: var(--glow-sab3); }

.chat-content {
    background: var(--bg-glass);
    padding: 16px 20px;
    border-radius: 16px;
    border: 1px solid var(--border-light);
    line-height: 1.6;
    font-size: 0.95rem;
    position: relative;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.chat-message.user .chat-content {
    background: rgba(255,255,255,0.05);
    border-radius: 16px 4px 16px 16px;
}

.chat-message.agent .chat-content {
    border-radius: 4px 16px 16px 16px;
}

/* Agent Specific Background Tints */
.chat-message.agent.mab .chat-content { background: linear-gradient(135deg, rgba(0,242,254,0.05), var(--bg-glass)); }
.chat-message.agent.sab1 .chat-content { background: linear-gradient(135deg, rgba(79,172,254,0.05), var(--bg-glass)); }
.chat-message.agent.sab2 .chat-content { background: linear-gradient(135deg, rgba(161,140,209,0.05), var(--bg-glass)); }
.chat-message.agent.sab3 .chat-content { background: linear-gradient(135deg, rgba(246,211,101,0.05), var(--bg-glass)); }

/* From MAB Instruction Bubble in SAB tabs */
.chat-message.from-mab .chat-content {
    border: 1px solid var(--accent-mab);
    background: rgba(0, 242, 254, 0.05);
    border-radius: 12px;
}
.chat-message.from-mab .mab-delegate {
    border-color: var(--accent-mab);
}
.from-mab-text {
    font-style: italic;
    color: #e2e8f0;
}
.mab-badge {
    background: rgba(0, 242, 254, 0.1) !important;
    color: var(--accent-mab) !important;
    border: 1px solid rgba(0, 242, 254, 0.2);
}

.chat-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.agent-badge {
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(255,255,255,0.1);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Markdown styling inside bubbles */
.message-text pre {
    background: #000;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid var(--border-highlight);
}
.message-text code { font-family: monospace; background: rgba(255,255,255,0.1); padding: 2px 4px; border-radius: 4px; }
.message-text pre code { background: none; padding: 0; }
.message-text p { margin-bottom: 8px; }
.message-text p:last-child { margin-bottom: 0; }
.message-text ul, .message-text ol { margin: 8px 0 8px 24px; }

/* Campaign Bubble Streaming State */
.campaign-bubble .chat-content::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 14px;
    background: currentColor;
    margin-left: 4px;
    animation: blink 1s step-end infinite;
    vertical-align: text-bottom;
}
@keyframes blink { 50% { opacity: 0; } }

/* Input Area */
.chat-input-container {
    padding: 24px 32px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border-light);
}

.input-wrapper {
    display: flex;
    gap: 12px;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-highlight);
    border-radius: 16px;
    padding: 8px 16px;
    transition: all 0.3s ease;
}
.input-wrapper:focus-within {
    border-color: var(--accent-mab);
    box-shadow: var(--glow-mab);
    background: rgba(0,0,0,0.4);
}

textarea.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    padding: 12px 0;
    max-height: 150px;
    outline: none;
}
textarea.chat-input::placeholder { color: var(--text-muted); }

.send-btn {
    background: var(--accent-mab);
    color: #000;
    border: none;
    border-radius: 12px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    align-self: flex-end;
    margin-bottom: 4px;
    transition: all 0.3s ease;
}
.send-btn:hover {
    transform: scale(1.05);
    box-shadow: var(--glow-mab);
}
.send-btn svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; fill: none; }

/* --- Right Sidebar / Activity Stream --- */
.right-sidebar {
    width: 320px;
    border-left: 1px solid var(--border-light);
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-light);
}
.sidebar-header h3 { font-size: 1rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }

.activity-stream {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.activity-item {
    padding: 12px 16px;
    background: rgba(255,255,255,0.03);
    border-radius: 8px;
    font-size: 0.85rem;
    border-left: 3px solid var(--border-highlight);
    animation: slideLeft 0.3s ease;
    line-height: 1.4;
}

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

.activity-item[data-agent="mab"] { border-left-color: var(--accent-mab); }
.activity-item[data-agent="sab1"] { border-left-color: var(--accent-sab1); }
.activity-item[data-agent="sab2"] { border-left-color: var(--accent-sab2); }
.activity-item[data-agent="sab3"] { border-left-color: var(--accent-sab3); }

.activity-item.status-info { background: rgba(255,255,255,0.05); }
.activity-item.status-success { border-left-color: #10b981; background: rgba(16, 185, 129, 0.05); }
.activity-item.status-error { border-left-color: #ef4444; background: rgba(239, 68, 68, 0.05); }
.activity-item.status-working { 
    background: linear-gradient(90deg, rgba(255,255,255,0.05) 0%, transparent 100%);
    background-size: 200% 100%;
    animation: shimmer 2s infinite linear;
}

@keyframes shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

.activity-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}
.activity-agent { font-weight: 600; text-transform: uppercase; font-size: 0.75rem; }
.activity-time { color: var(--text-muted); font-size: 0.7rem; }
.activity-text { color: #e2e8f0; }

/* --- Page Layouts (Performance, Sessions, About) --- */
.page-container {
    padding: 40px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    overflow-y: auto;
}
.page-header {
    margin-bottom: 32px;
}
.page-header h2 { font-size: 2rem; margin-bottom: 8px; }
.page-header p { color: var(--text-muted); }

/* Performance KPIs */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}
.kpi-card {
    background: var(--bg-glass);
    border: 1px solid var(--border-light);
    border-radius: 16px;
    padding: 24px;
    position: relative;
    overflow: hidden;
    transition: transform 0.3s;
}
.kpi-card:hover { transform: translateY(-5px); border-color: var(--accent-mab); }
.kpi-title { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 8px; font-weight: 500;}
.kpi-value { font-size: 2.5rem; font-weight: 700; font-family: 'Syne', sans-serif; color: var(--text-main); }

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-glass);
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border-light);
}
.data-table th, .data-table td {
    padding: 16px 24px;
    text-align: left;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.data-table th { background: rgba(0,0,0,0.2); font-weight: 600; color: var(--text-muted); text-transform: uppercase; font-size: 0.8rem; }
.data-table tr:hover td { background: rgba(255,255,255,0.02); }

/* Buttons */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
}
.btn-primary { background: var(--accent-mab); color: #000; }
.btn-primary:hover { box-shadow: var(--glow-mab); transform: translateY(-1px); }

/* AMD Hero */
.amd-hero {
    background: linear-gradient(135deg, rgba(0,0,0,0.8), rgba(239, 68, 68, 0.1)), url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.03'/%3E%3C/svg%3E");
    border: 1px solid var(--border-highlight);
    border-radius: 16px;
    padding: 40px;
    margin-bottom: 32px;
}
.amd-hero h3 { font-size: 1.8rem; margin-bottom: 12px; color: #fff; }

/* Session Cards */
.session-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.session-card {
    background: var(--bg-glass);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s;
}
.session-card:hover { border-color: var(--accent-sab1); transform: translateY(-2px); }
.session-card.active { border-color: var(--accent-mab); box-shadow: var(--glow-mab); }

/* Settings Form */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; color: var(--text-muted); font-size: 0.9rem; }
.form-group select, .form-group input, .form-group textarea {
    width: 100%;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 12px 16px;
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
}
.form-group select:focus, .form-group input:focus, .form-group textarea:focus {
    border-color: var(--accent-mab);
    outline: none;
}

/* ============================================================
   LAYOUT FIX — Match actual HTML class names in index.html
   ============================================================ */

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.header-title { display: flex; flex-direction: column; gap: 4px; }
.page-title { font-size: 1.4rem; font-family: 'Syne', sans-serif; font-weight: 600; }
.platform-label { font-size: 0.8rem; color: var(--text-muted); }
.header-controls { display: flex; align-items: center; gap: 16px; }

/* Platform Selector */
.platform-selector { display: flex; gap: 6px; }
.platform-btn {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--border-light);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
}
.platform-btn:hover { border-color: var(--accent-mab); color: var(--text-main); }
.platform-btn.active { background: var(--accent-mab); color: #000; border-color: var(--accent-mab); font-weight: 600; }

/* Theme toggle */
.theme-toggle {
    background: var(--bg-glass);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--text-main);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}
.theme-toggle:hover { border-color: var(--accent-mab); }

/* Content Area — wraps all tabs, takes remaining height */
.content-area {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

/* Tab visibility */
.tab-content {
    display: none;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}
.tab-content.active {
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease;
}

/* Campaign tab: split — chat left + activity right */
.campaign-tab {
    display: flex;
    flex-direction: row;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Left: chat container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    border-right: 1px solid var(--border-light);
}

/* Chat messages scrollable area */
.chat-messages {
    flex: 1;
    overflow-y: auto !important;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
    min-height: 0;
}

/* Chat input area */
.chat-input-area {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 24px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
}
.input-group { flex: 1; }
.input-group textarea,
.chat-input-area textarea {
    width: 100%;
    background: rgba(0,0,0,0.25);
    border: 1px solid var(--border-highlight);
    border-radius: 12px;
    padding: 12px 16px;
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    min-height: 44px;
    max-height: 120px;
}
.input-group textarea:focus,
.chat-input-area textarea:focus {
    border-color: var(--accent-mab);
    box-shadow: var(--glow-mab);
}

/* Send / Attach / Run buttons */
.send-btn {
    background: var(--accent-mab);
    color: #000;
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}
.send-btn:hover { box-shadow: var(--glow-mab); transform: translateY(-1px); }

.attach-btn {
    background: var(--bg-glass);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
    flex-shrink: 0;
}
.attach-btn:hover { border-color: var(--accent-mab); color: var(--text-main); }

.run-campaign-btn {
    background: linear-gradient(135deg, #00f2fe, #4facfe);
    color: #000;
    border: none;
    border-radius: 10px;
    padding: 10px 20px;
    font-weight: 700;
    font-family: 'Syne', sans-serif;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
    letter-spacing: 0.3px;
}
.run-campaign-btn:hover { box-shadow: 0 0 20px rgba(0,242,254,0.4); transform: translateY(-1px); }

/* Right: activity panel */
.activity-panel {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    overflow: hidden;
    min-height: 0;
}

.activity-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.activity-title {
    font-family: 'Syne', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-main);
}
.activity-timer {
    font-size: 0.8rem;
    color: var(--accent-mab);
    font-family: monospace;
    background: rgba(0,242,254,0.08);
    padding: 3px 8px;
    border-radius: 6px;
}

/* Activity messages — SCROLLABLE */
.activity-messages {
    flex: 1;
    overflow-y: auto !important;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
}

/* Individual activity message */
.activity-message {
    padding: 10px 14px;
    border-radius: 10px;
    background: rgba(255,255,255,0.03);
    border-left: 3px solid var(--border-highlight);
    animation: slideLeft 0.3s ease;
    font-size: 0.83rem;
    line-height: 1.5;
    word-break: break-word;
}
.activity-message.mab { border-left-color: var(--accent-mab); }
.activity-message.sab1 { border-left-color: var(--accent-sab1); }
.activity-message.sab2 { border-left-color: var(--accent-sab2); }
.activity-message.sab3 { border-left-color: var(--accent-sab3); }
.activity-message.info { background: rgba(255,255,255,0.05); }
.activity-message.success { border-left-color: #10b981; background: rgba(16,185,129,0.05); }
.activity-message.error { border-left-color: #ef4444; background: rgba(239,68,68,0.05); }
.activity-message.working {
    background: linear-gradient(90deg, rgba(255,255,255,0.05) 0%, transparent 100%);
}
.activity-message .timestamp {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.activity-message .message { color: #e2e8f0; }

/* SAB tabs: same split, with right-panel (agent info) instead of activity */
.right-panel {
    width: 280px;
    flex-shrink: 0;
    background: var(--bg-panel);
    border-left: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 20px;
    gap: 12px;
}
.right-panel-title {
    font-family: 'Syne', sans-serif;
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 4px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-size: 0.8rem;
}
.right-panel-content { display: flex; flex-direction: column; gap: 12px; }
.agent-info-card {
    background: var(--bg-glass);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 16px;
    transition: border-color 0.2s;
}
.agent-info-card:hover { border-color: var(--border-highlight); }
.agent-name { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }
.agent-role { font-size: 0.85rem; color: var(--text-muted); }
.agent-status {
    display: inline-block;
    margin-top: 8px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.agent-status.idle { background: rgba(255,255,255,0.08); color: var(--text-muted); }
.agent-status.working { background: rgba(0,242,254,0.1); color: var(--accent-mab); animation: pulse 1.5s infinite; }

/* Settings / Performance / History / AMD tabs */
.settings-tab {
    flex: 1;
    overflow-y: auto;
    padding: 32px 40px;
    min-height: 0;
}
.settings-header { margin-bottom: 32px; }
.settings-header h2 { font-size: 1.8rem; margin-bottom: 8px; }
.text-muted { color: var(--text-muted); }

/* Agent config cards in settings */
.agent-config-card {
    background: var(--bg-glass);
    border: 1px solid var(--border-light);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 20px;
    transition: border-color 0.2s;
}
.agent-config-card:hover { border-color: var(--border-highlight); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.save-btn {
    background: var(--accent-mab);
    color: #000;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
}
.save-btn:hover { box-shadow: var(--glow-mab); }

/* KPI cards in Performance tab */
.kpi-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}
.kpi-card { transition: transform 0.3s, border-color 0.3s; }
.kpi-card:hover { transform: translateY(-4px); border-color: var(--accent-mab); }
.kpi-label { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 8px; }
.kpi-value { font-size: 2rem; font-family: 'Syne', sans-serif; font-weight: 700; }
.kpi-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* Performance grid */
.performance-grid { display: flex; flex-direction: column; gap: 32px; }
.performance-chart, .benchmark-results, .performance-stats {
    background: var(--bg-glass);
    border: 1px solid var(--border-light);
    border-radius: 16px;
    padding: 24px;
}
.performance-chart h3, .benchmark-results h3, .performance-stats h3 {
    margin-bottom: 16px;
    font-size: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.chart-container { height: 200px; display: flex; align-items: center; justify-content: center; }
.benchmark-table { width: 100%; border-collapse: collapse; }
.benchmark-table th, .benchmark-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 0.9rem; }
.benchmark-table th { color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; }
.stats-grid { display: flex; gap: 32px; }
.stat-item { display: flex; flex-direction: column; gap: 4px; }
.stat-label { color: var(--text-muted); font-size: 0.8rem; }
.stat-value { font-weight: 600; }

/* AMD features grid */
.amd-features { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 32px; }
.feature-card { background: var(--bg-glass); border: 1px solid var(--border-light); border-radius: 12px; padding: 20px; transition: all 0.2s; }
.feature-card:hover { border-color: var(--accent-mab); transform: translateY(-2px); }
.feature-card h4 { margin-bottom: 8px; font-size: 1rem; }
.feature-card p { color: var(--text-muted); font-size: 0.85rem; }
.feature-badge { display: inline-block; margin-top: 10px; padding: 2px 10px; background: rgba(0,242,254,0.1); color: var(--accent-mab); border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.amd-endpoints, .amd-get-started { background: var(--bg-glass); border: 1px solid var(--border-light); border-radius: 12px; padding: 24px; margin-bottom: 20px; }
.amd-endpoints h3, .amd-get-started h3 { margin-bottom: 16px; }
.amd-endpoints ul, .amd-get-started ol { padding-left: 20px; display: flex; flex-direction: column; gap: 10px; color: var(--text-muted); font-size: 0.9rem; }
.amd-endpoints li strong { color: var(--text-main); }

/* History session cards */
.history-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.session-card { display: flex; align-items: center; justify-content: space-between; }
.session-info h3 { font-size: 0.95rem; margin-bottom: 4px; }
.session-info p { font-size: 0.8rem; color: var(--text-muted); }
.session-actions { display: flex; gap: 8px; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-danger { background: rgba(239,68,68,0.15); color: #ef4444; border: 1px solid rgba(239,68,68,0.2); }
.btn-danger:hover { background: rgba(239,68,68,0.3); }
.btn-secondary { background: rgba(255,255,255,0.08); color: var(--text-muted); border: 1px solid var(--border-light); }
.btn-secondary:hover { background: rgba(255,255,255,0.15); color: var(--text-main); }

/* Tool registry */
.tool-registry-section { margin-top: 32px; }
.tool-registry-section h3 { margin-bottom: 16px; }
.registry-table { width: 100%; border-collapse: collapse; background: var(--bg-glass); border-radius: 12px; overflow: hidden; border: 1px solid var(--border-light); }
.registry-table th, .registry-table td { padding: 12px 20px; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 0.9rem; }
.registry-table th { background: rgba(0,0,0,0.2); color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; }
.tool-status { padding: 2px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.tool-status.installed { background: rgba(16,185,129,0.1); color: #10b981; }
.tool-status.uninstalled { background: rgba(239,68,68,0.1); color: #ef4444; }
.add-tool-btn { margin-top: 12px; background: transparent; border: 1px dashed var(--border-highlight); border-radius: 8px; padding: 10px 20px; color: var(--text-muted); cursor: pointer; font-family: 'Inter', sans-serif; transition: all 0.2s; }
.add-tool-btn:hover { border-color: var(--accent-mab); color: var(--accent-mab); }
.performance-controls { display: flex; gap: 12px; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 1000; backdrop-filter: blur(4px); }
.modal-content { background: #0d0d12; border: 1px solid var(--border-highlight); border-radius: 20px; width: 560px; max-width: 90vw; max-height: 90vh; overflow-y: auto; }
.modal-lg { width: 800px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 24px 28px; border-bottom: 1px solid var(--border-light); }
.modal-title { font-size: 1.2rem; font-family: 'Syne', sans-serif; }
.modal-close { background: transparent; border: none; color: var(--text-muted); font-size: 1.5rem; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text-main); }
.modal-body { padding: 24px 28px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 12px; padding: 16px 28px; border-top: 1px solid var(--border-light); }

/* Output section */
.output-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.output-actions { display: flex; gap: 8px; }
.output-content { background: rgba(0,0,0,0.3); border-radius: 12px; padding: 20px; font-size: 0.9rem; line-height: 1.7; max-height: 60vh; overflow-y: auto; white-space: pre-wrap; }

/* Sidebar logo */
.sidebar-header { padding: 0 24px 32px; }
.sidebar-logo { font-family: 'Syne', sans-serif; font-size: 1.5rem; font-weight: 700; color: var(--text-main); }
.sidebar-logo span { color: var(--accent-mab); }
.nav-group { display: flex; flex-direction: column; gap: 4px; padding: 0 16px; flex: 1; }

/* fetch models btn */
.fetch-models-btn { background: var(--bg-glass); border: 1px solid var(--border-light); border-radius: 6px; padding: 3px 10px; color: var(--text-muted); cursor: pointer; font-size: 0.75rem; font-family: 'Inter', sans-serif; }
.fetch-models-btn:hover { border-color: var(--accent-mab); color: var(--text-main); }
.model-input-container { position: relative; }

/* ============================================================
   CRITICAL LAYOUT OVERRIDE — ensures flex chain works end-to-end
   ============================================================ */
html, body { height: 100%; overflow: hidden; }

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    height: 100vh;
}

.content-area {
    flex: 1 1 0;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

/* Tab must stretch to fill content-area */
.tab-content {
    display: none;
    width: 100%;
    min-height: 0;
}
.tab-content.active {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    animation: fadeIn 0.25s ease;
}

/* Campaign split layout */
.campaign-tab {
    display: flex;
    flex-direction: row;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
}

/* Chat left panel */
.chat-container {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* Scrollable chat area */
#mab-chat-messages,
#sab1-chat-messages,
#sab2-chat-messages,
#sab3-chat-messages {
    flex: 1 1 0;
    overflow-y: auto !important;
    min-height: 0;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

/* Activity panel right column - ALWAYS visible in campaign tab */
.activity-panel {
    width: 320px;
    min-width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: rgba(10, 10, 14, 0.95);
    border-left: 1px solid rgba(255,255,255,0.08);
    overflow: hidden;
    min-height: 0;
}

/* Scrollable activity messages */
#activity-messages {
    flex: 1 1 0;
    overflow-y: auto !important;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}

/* Settings / History / AMD / Performance tabs */
.settings-tab {
    flex: 1 1 0;
    overflow-y: auto !important;
    min-height: 0;
    padding: 32px 40px;
}

/* ============================================================
   MOBILE RESPONSIVE — screens ≤ 768px
   ============================================================ */
@media (max-width: 768px) {

    /* Stack app vertically: content on top, nav on bottom */
    .app-container {
        flex-direction: column;
    }

    /* --- Sidebar → Bottom Navigation Bar --- */
    .sidebar {
        width: 100%;
        height: 64px;
        min-height: 64px;
        flex-direction: row;
        border-right: none;
        border-top: 1px solid var(--border-light);
        padding: 0;
        order: 2;
        background: var(--bg-panel);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        position: sticky;
        bottom: 0;
        z-index: 100;
    }

    /* Hide the logo header on mobile */
    .sidebar-header { display: none; }

    /* Nav group becomes a horizontal row */
    .nav-group {
        flex-direction: row;
        padding: 0;
        gap: 0;
        width: 100%;
        align-items: stretch;
    }

    /* Each nav item takes equal width */
    .nav-item {
        flex: 1;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 8px 4px;
        border-radius: 0;
        font-size: 0.6rem;
        border: none !important;
    }

    .nav-item[data-tab="mab"].active,
    .nav-item[data-tab="sab1"].active,
    .nav-item[data-tab="sab2"].active,
    .nav-item[data-tab="sab3"].active,
    .nav-item[data-tab="performance"].active,
    .nav-item[data-tab="history"].active,
    .nav-item[data-tab="settings"].active,
    .nav-item[data-tab="about"].active {
        border-left: none !important;
        border-top: 2px solid var(--accent-mab) !important;
        color: var(--accent-mab);
        background: var(--bg-glass);
    }
    .nav-item[data-tab="mab"].active { border-top-color: var(--accent-mab) !important; color: var(--accent-mab); }
    .nav-item[data-tab="sab1"].active { border-top-color: var(--accent-sab1) !important; color: var(--accent-sab1); }
    .nav-item[data-tab="sab2"].active { border-top-color: var(--accent-sab2) !important; color: var(--accent-sab2); }
    .nav-item[data-tab="sab3"].active { border-top-color: var(--accent-sab3) !important; color: var(--accent-sab3); }

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

    /* Hide long labels; use short via after */
    .nav-item[data-tab="history"] .nav-label,
    .nav-item[data-tab="about"] .nav-label { display: none; }
    .nav-item[data-tab="history"]::after { content: "History"; font-size: 0.6rem; color: inherit; }
    .nav-item[data-tab="about"]::after { content: "AMD"; font-size: 0.6rem; color: inherit; }

    /* --- Main content fills remaining space --- */
    .main-content {
        flex: 1;
        order: 1;
        height: calc(100vh - 64px);
        overflow: hidden;
    }

    /* --- Header: compact, wraps controls --- */
    .header {
        padding: 10px 14px;
        flex-wrap: wrap;
        gap: 8px;
    }
    .header-title { flex: 1; min-width: 0; }
    .page-title { font-size: 1rem; }
    .header-controls {
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
    }

    /* Platform buttons: horizontally scrollable */
    .platform-selector {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: nowrap;
        flex: 1;
    }
    .platform-selector::-webkit-scrollbar { display: none; }
    .platform-btn { white-space: nowrap; padding: 5px 10px; font-size: 0.72rem; }

    /* --- Pipeline Stepper: scroll horizontally, hide labels --- */
    .campaign-pipeline {
        padding: 10px 14px;
        gap: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
    }
    .campaign-pipeline::-webkit-scrollbar { display: none; }
    .pipeline-step span { display: none; }
    .pipeline-line { width: 20px; }

    /* --- Campaign Tab: stack vertically --- */
    .campaign-tab { flex-direction: column; }

    .chat-container {
        flex: 1 1 0;
        min-height: 0;
        border-right: none;
        border-bottom: 1px solid var(--border-light);
    }

    /* Activity panel: fixed height strip at bottom of chat */
    .activity-panel {
        width: 100%;
        min-width: 0;
        height: 160px;
        min-height: 160px;
        flex-shrink: 0;
        border-left: none;
        border-top: 1px solid var(--border-light);
    }
    .activity-header { padding: 10px 14px; }

    /* Right panel (SAB agent info): horizontal scroll strip */
    .right-panel {
        width: 100%;
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 10px 14px;
        gap: 8px;
        height: auto;
        max-height: 110px;
        border-left: none;
        border-top: 1px solid var(--border-light);
        flex-shrink: 0;
    }
    .right-panel::-webkit-scrollbar { display: none; }
    .right-panel-title { display: none; }
    .right-panel-content { flex-direction: row; flex-wrap: nowrap; gap: 8px; }
    .agent-info-card { padding: 8px 12px; min-width: 110px; flex-shrink: 0; }

    /* Chat messages */
    #mab-chat-messages,
    #sab1-chat-messages,
    #sab2-chat-messages,
    #sab3-chat-messages { padding: 14px; gap: 12px; }

    .chat-message { max-width: 95%; }

    /* Input area */
    .chat-input-area { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
    .input-group textarea { font-size: 0.9rem; min-height: 40px; }
    .run-campaign-btn { width: 100%; text-align: center; order: 10; }

    /* --- Settings: single column --- */
    .settings-tab { padding: 16px; }
    .settings-header { margin-bottom: 16px; }
    .settings-header h2 { font-size: 1.3rem; }
    .settings-grid { grid-template-columns: 1fr !important; gap: 14px; }
    .agent-config-card { padding: 14px; }
    .card-header { flex-wrap: wrap; gap: 8px; }

    /* --- Performance: 2-col KPIs --- */
    .kpi-cards { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 20px; }
    .kpi-value { font-size: 1.5rem; }
    .kpi-card { padding: 16px; }
    .performance-controls { flex-direction: column; gap: 8px; }
    .benchmark-results { overflow-x: auto; }
    .benchmark-table { min-width: 460px; }
    .stats-grid { flex-direction: column; gap: 10px; }

    /* --- AMD Info --- */
    .amd-hero { padding: 20px 16px; }
    .amd-hero h3 { font-size: 1.2rem; }
    .amd-features { grid-template-columns: 1fr; gap: 10px; }

    /* --- History --- */
    .history-list { grid-template-columns: 1fr; gap: 12px; }
    .session-card { flex-direction: column; align-items: flex-start; gap: 10px; }

    /* --- Tool Registry --- */
    .tool-registry-section { overflow-x: auto; }
    .registry-table { min-width: 380px; }

    /* --- Modals: near full screen --- */
    .modal-content { width: 95vw; max-width: 95vw; border-radius: 16px; max-height: 88vh; }
    .modal-lg { width: 95vw; }
    .modal-header, .modal-body, .modal-footer { padding: 14px 16px; }
    .output-actions { flex-wrap: wrap; gap: 6px; }

    /* Switch toggle */
    .switch { flex-shrink: 0; }
}

/* Tablet: 769px – 1024px */
@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar { width: 220px; }
    .activity-panel { width: 260px; min-width: 260px; }
    .right-panel { width: 240px; }
    .settings-grid { grid-template-columns: 1fr; }
    .kpi-cards { grid-template-columns: repeat(2, 1fr); }
}

/* Very small phones (≤ 375px) */
@media (max-width: 375px) {
    .nav-item .nav-label { display: none; }
    .platform-btn { padding: 5px 7px; font-size: 0.68rem; }
    .kpi-cards { grid-template-columns: 1fr; }
    .header { padding: 8px 10px; }
    .chat-input-area { padding: 8px 10px; }
}
