/* =============================================================================
   DESIGN SYSTEM & VARIABLES
   ============================================================================= */
:root {
    --bg-dark: #070913;
    --bg-panel: rgba(13, 19, 36, 0.7);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(20, 85, 209, 0.35);
    
    --primary: #1455D1;
    --primary-glow: rgba(20, 85, 209, 0.6);
    --primary-hover: #1e6aff;
    
    --accent: #FFD700;
    --accent-glow: rgba(255, 215, 0, 0.4);
    
    --success: #00E676;
    --warning: #FF9100;
    --danger: #FF5252;
    
    --text-primary: #E2E8F0;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-display: 'Space Grotesk', var(--font-sans);
    --font-mono: 'Fira Code', monospace;
    
    --shadow-premium: 0 12px 40px -4px rgba(0, 0, 0, 0.5);
    --transition: 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-dark);
    color: var(--text-primary);
    font-family: var(--font-sans);
    overflow: hidden;
    height: 100vh;
    background-image: 
        radial-gradient(at 0% 0%, rgba(20, 85, 209, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(255, 215, 0, 0.05) 0px, transparent 50%);
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 16px;
    gap: 16px;
}

/* =============================================================================
   HEADER SECTION
   ============================================================================= */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow-premium);
}

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

.company-logo {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    border: 2px solid var(--primary);
    box-shadow: 0 0 15px var(--primary-glow);
}

.brand-text h1 {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.badge {
    background: linear-gradient(135deg, var(--primary), #4882f8);
    font-size: 10px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 10px var(--primary-glow);
}

.company-address {
    font-size: 11px;
    color: var(--text-secondary);
}

.system-status {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.3);
    padding: 8px 16px;
    border-radius: 30px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.pulse-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.status-ready {
    background-color: var(--success);
    box-shadow: 0 0 12px var(--success);
    animation: pulse 1.8s infinite;
}

.status-working {
    background-color: var(--warning);
    box-shadow: 0 0 12px var(--warning);
    animation: pulse 0.8s infinite;
}

.status-label {
    font-family: var(--font-display);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* =============================================================================
   LAYOUT PANELS
   ============================================================================= */
.main-content {
    display: grid;
    grid-template-columns: 280px 1fr 340px;
    gap: 16px;
    flex: 1;
    min-height: 0; /* Ensures container can shrink and scroll */
}

.panel {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-premium);
    transition: var(--transition);
}

.panel:hover {
    border-color: var(--border-glow);
}

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

.panel-header h2 {
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.panel-body {
    padding: 16px 20px;
}

.count-badge {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    color: var(--text-secondary);
}

/* =============================================================================
   LEFT PANEL (AGENTS DIRECTORY)
   ============================================================================= */
.search-container {
    padding-bottom: 0px !important;
}

.agent-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.agent-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition);
}

.agent-item:hover {
    background: rgba(20, 85, 209, 0.08);
    border-color: rgba(20, 85, 209, 0.3);
    transform: translateY(-2px);
}

.agent-item.active {
    background: rgba(20, 85, 209, 0.15);
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(20, 85, 209, 0.2);
}

.agent-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.agent-name {
    font-size: 13px;
    font-weight: 600;
}

.agent-caps {
    font-size: 11px;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* =============================================================================
   CENTER PANEL (VISUALIZER & TERMINAL)
   ============================================================================= */
.tab-header {
    display: flex;
    gap: 12px;
    justify-content: flex-start;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 500;
    padding: 4px 12px;
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition);
}

.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
    color: var(--primary-hover);
    background: rgba(20, 85, 209, 0.1);
    box-shadow: inset 0 0 8px rgba(20, 85, 209, 0.1);
}

.tab-content {
    display: none;
    flex: 1;
    min-height: 0;
    padding: 0;
}

.tab-content.active {
    display: flex;
}

.canvas-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(16, 24, 48, 0.4) 0%, rgba(7, 9, 19, 0.9) 100%);
}

#swarm-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.canvas-overlay {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 11px;
    color: var(--text-muted);
}

/* TERMINAL LOGS */
.terminal-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: #05070e;
    font-family: var(--font-mono);
}

.terminal-header {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    gap: 6px;
}

.terminal-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.terminal-dot.red { background-color: #ff5f56; }
.terminal-dot.yellow { background-color: #ffbd2e; }
.terminal-dot.green { background-color: #27c93f; }

.terminal-title {
    color: var(--text-muted);
    font-size: 11px;
    margin-left: 10px;
    flex: 1;
}

.btn-clear {
    margin-left: auto;
}

.terminal-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 12px;
    line-height: 1.6;
}

.log-line {
    padding: 4px 8px;
    border-radius: 4px;
    word-break: break-all;
}

.log-line.system { color: #81a1c1; }
.log-line.info { color: #a3be8c; }
.log-line.warning { color: var(--warning); }
.log-line.error { color: var(--danger); background: rgba(255, 82, 82, 0.05); }
.log-line.success { color: var(--success); font-weight: 600; }
.log-line.command { color: #88c0d0; background: rgba(136, 192, 208, 0.05); }
.log-line.thought { color: #eceff4; border-left: 2px solid var(--primary); padding-left: 10px; margin-left: 5px; }
.log-line.plan { color: #b48ead; border-left: 2px dotted #b48ead; padding-left: 10px; }
.log-line.action_result { color: #ebcb8b; }

/* =============================================================================
   RIGHT PANEL (CONTROLLER & SETTINGS)
   ============================================================================= */
.right-panel {
    gap: 16px;
    background: none;
    border: none;
    box-shadow: none;
}

.right-panel:hover {
    border-color: transparent;
}

.sub-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-premium);
}

.control-panel {
    flex: 2;
}

.keys-panel {
    flex-shrink: 0;
}

.explorer-panel {
    flex: 1;
    min-height: 200px;
}

.collapsable {
    cursor: pointer;
}

.collapsed {
    display: none !important;
}

.toggle-icon {
    font-size: 12px;
    transition: transform 0.2s ease;
}

.collapsable.active .toggle-icon {
    transform: rotate(180deg);
}

/* =============================================================================
   FORM CONTROLS
   ============================================================================= */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-field {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    border-radius: 10px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 13px;
    transition: var(--transition);
}

.input-field:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 10px var(--primary-glow);
}

.textarea-field {
    resize: none;
    height: 70px;
}

.select-field {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg fill='white' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

/* AUTONOMOUS TOGGLE */
.toggle-group {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 10px;
    background: rgba(255, 82, 82, 0.03);
    border: 1px dashed rgba(255, 82, 82, 0.2);
    border-radius: 10px;
    margin-bottom: 16px;
}

.toggle-container {
    position: relative;
    width: 44px;
    height: 24px;
}

.toggle-checkbox {
    display: none;
}

.toggle-label {
    display: block;
    width: 100%;
    height: 100%;
    background-color: var(--text-muted);
    border-radius: 30px;
    cursor: pointer;
    position: relative;
    transition: background-color 0.3s ease;
}

.toggle-label::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    background-color: white;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: transform 0.3s ease;
}

.toggle-checkbox:checked + .toggle-label {
    background-color: var(--danger);
}

.toggle-checkbox:checked + .toggle-label::after {
    transform: translateX(20px);
}

.toggle-text {
    display: flex;
    flex-direction: column;
}

.toggle-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--danger);
}

.toggle-desc {
    font-size: 10px;
    color: var(--text-secondary);
}

/* BUTTONS */
.btn {
    font-family: var(--font-display);
    font-weight: 600;
    padding: 10px 16px;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 13px;
    transition: var(--transition);
}

.btn-sm {
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 6px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #3b74f7);
    color: white;
    box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(20, 85, 209, 0.8);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* =============================================================================
   WORKSPACE FILE EXPLORER
   ============================================================================= */
.file-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.01);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    transition: var(--transition);
}

.file-item:hover {
    background: rgba(20, 85, 209, 0.05);
    border-color: var(--border-glow);
}

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

.file-path {
    font-weight: 500;
}

.file-size {
    font-size: 10px;
    color: var(--text-muted);
}

.empty-state {
    text-align: center;
    padding: 30px;
    color: var(--text-muted);
    font-size: 12px;
}

/* =============================================================================
   MODAL DIALOG
   ============================================================================= */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-backdrop.active {
    display: flex;
}

.modal-container {
    width: 70%;
    height: 75%;
    background: #080c16;
    border: 1px solid var(--border-glow);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
    animation: scaleUp 0.3s ease;
}

.modal-header {
    padding: 16px 24px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-filename {
    font-family: var(--font-display);
    font-size: 16px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
}

.modal-body {
    flex: 1;
    overflow: auto;
    padding: 24px;
    font-family: var(--font-mono);
    font-size: 13px;
    background: #04060a;
}

/* =============================================================================
   KEYFRAME ANIMATIONS
   ============================================================================= */
@keyframes pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(0, 230, 118, 0.7);
    }
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 8px rgba(0, 230, 118, 0);
    }
    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(0, 230, 118, 0);
    }
}

@keyframes scaleUp {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.loading-spinner {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 13px;
}
