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

:root {
    --bg-base: #030407;
    --bg-surface: rgba(10, 12, 18, 0.65);
    --bg-panel: rgba(16, 18, 28, 0.45);
    
    --accent-blue: #00f0ff;
    --accent-green: #00ffaa;
    --accent-red: #ff2a55;
    --accent-purple: #b538ff;
    --accent-yellow: #ffb800;
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-tertiary: #475569;
    
    --border-light: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(0, 240, 255, 0.4);
    
    --glass-blur: blur(32px);
    --shadow-glow: 0 8px 32px rgba(0, 0, 0, 0.5), inset 0 1px 1px rgba(255, 255, 255, 0.1);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-base);
    background-image: radial-gradient(circle at 50% -10%, #0d1b2a 0%, var(--bg-base) 90%);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    justify-content: center;
    overflow: hidden;
    position: relative;
    -webkit-font-smoothing: antialiased;
}

/* Background animated mesh */
.animated-bg {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-image: 
        radial-gradient(circle at 15% 25%, rgba(181, 56, 255, 0.08) 0px, transparent 45%),
        radial-gradient(circle at 85% 75%, rgba(0, 240, 255, 0.08) 0px, transparent 45%),
        radial-gradient(circle at 50% 50%, rgba(0, 255, 170, 0.03) 0px, transparent 60%);
    z-index: 0;
    pointer-events: none;
    animation: pulseBg 20s ease-in-out infinite alternate;
}

@keyframes pulseBg {
    0% { transform: scale(1) translate(0, 0); opacity: 0.7; }
    50% { transform: scale(1.05) translate(2%, 2%); opacity: 1; }
    100% { transform: scale(1.1) translate(-2%, -2%); opacity: 0.8; }
}

/* 3-Column Layout for Incubator */
.layout-wrapper {
    width: 100%;
    max-width: 1800px;
    margin: 1.5rem;
    display: grid;
    grid-template-columns: 350px 1fr 350px;
    gap: 1.5rem;
    height: calc(100% - 3rem);
    position: relative;
    z-index: 10;
}

@media (max-width: 1200px) {
    .layout-wrapper {
        grid-template-columns: 280px 1fr 280px;
        gap: 1rem;
    }
}

@media (max-width: 900px) {
    body {
        height: auto;
        overflow: auto;
    }
    .layout-wrapper {
        display: flex;
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        margin: 0;
        padding: 1rem;
    }
    .chat-container {
        min-height: 60vh;
        flex: none;
    }
    .vitals-container, .sensors-container {
        height: auto;
        max-height: none;
        overflow: visible;
    }
}

/* Glass Panels */
.glass-panel {
    background: var(--bg-surface);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-light);
    border-radius: 20px;
    box-shadow: var(--shadow-glow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}
.glass-panel::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
    z-index: 1;
}

/* Header/Controls */
.header-actions {
    display: flex;
    gap: 0.75rem;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-light);
    flex-wrap: wrap;
}

.glass-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
    padding: 0.6rem 1rem;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    font-weight: 500;
    transition: all 0.2s ease;
    flex: 1;
}

.glass-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.glass-btn.active {
    background: rgba(14, 165, 233, 0.15);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
    box-shadow: 0 0 15px rgba(14, 165, 233, 0.2);
}

.glass-btn.danger:hover {
    background: rgba(244, 63, 94, 0.15);
    border-color: var(--accent-red);
    color: var(--accent-red);
}

/* --- Left Column: Vitals --- */
.vitals-container {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
}

.vitals-container::-webkit-scrollbar { width: 4px; }
.vitals-container::-webkit-scrollbar-thumb { background-color: var(--border-light); border-radius: 4px; }

.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-tertiary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
    transition: color 0.2s ease;
    flex-shrink: 0;
}

.section-title:hover {
    color: var(--text-secondary);
}

.section-title .caret {
    transition: transform 0.3s ease;
}

.section-title.collapsed .caret {
    transform: rotate(-90deg);
}

.section-content {
    transition: max-height 0.4s cubic-bezier(0, 1, 0, 1), opacity 0.3s ease, margin 0.3s ease, padding 0.3s ease;
    max-height: 2000px;
    opacity: 1;
    overflow: hidden;
    flex-shrink: 0;
}

.section-content.collapsed {
    max-height: 0;
    opacity: 0;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    border: none;
}

.vital-card {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.vital-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    font-weight: 500;
}

.vital-val {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 400;
    color: var(--text-secondary);
}

.progress-track {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    background-size: 200% 100%;
    animation: flowGradient 3s linear infinite;
    box-shadow: 0 0 12px currentColor;
}

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

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

.fill-red { background: linear-gradient(90deg, #ff2a55, #ff6b8b, #ff2a55); color: var(--accent-red); }
.fill-blue { background: linear-gradient(90deg, #00f0ff, #73f8ff, #00f0ff); color: var(--accent-blue); }
.fill-green { background: linear-gradient(90deg, #00ffaa, #6affc8, #00ffaa); color: var(--accent-green); }
.fill-purple { background: linear-gradient(90deg, #b538ff, #d788ff, #b538ff); color: var(--accent-purple); }
.fill-yellow { background: linear-gradient(90deg, #ffb800, #ffdb66, #ffb800); color: var(--accent-yellow); }

/* --- Middle Column: Telemetry Log --- */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
    font-family: 'JetBrains Mono', monospace;
}

.chat-container::-webkit-scrollbar { width: 6px; }
.chat-container::-webkit-scrollbar-thumb { background-color: var(--border-light); border-radius: 10px; }

.message {
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    opacity: 0;
    transform: translateY(10px);
}

@keyframes slideUp {
    0% { opacity: 0; transform: translateY(10px) scale(0.98); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

.message.user-message { align-items: flex-end; }
.message.agi-message { align-items: flex-start; }
.message.system-message { align-items: center; margin: 1rem 0; }

.bubble {
    padding: 0.8rem 1rem;
    border-radius: 8px;
    line-height: 1.5;
    font-size: 0.85rem;
    word-wrap: break-word;
    max-width: 85%;
}

.user-message .bubble {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
}

.agi-message .bubble {
    background: linear-gradient(135deg, rgba(0, 240, 255, 0.1) 0%, rgba(0, 0, 0, 0.2) 100%);
    border: 1px solid rgba(0, 240, 255, 0.2);
    border-left: 3px solid var(--accent-blue);
    color: var(--text-primary);
    box-shadow: 0 4px 20px rgba(0, 240, 255, 0.08), inset 0 0 10px rgba(0, 240, 255, 0.05);
}

.system-message .bubble {
    color: var(--text-tertiary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Input Area */
.input-area {
    padding: 1.5rem;
    border-top: 1px solid var(--border-light);
    background: rgba(0, 0, 0, 0.2);
}

.input-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.input-box {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.85rem;
    width: 200px;
    outline: none;
}
.input-box::placeholder { color: var(--text-tertiary); }

.tone-controls { display: flex; gap: 0.5rem; }

.tone-label {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid transparent;
    transition: all 0.2s ease;
}
.tone-label:hover { background: rgba(255, 255, 255, 0.1); }
.tone-label input { display: none; }
.tone-icon { opacity: 0.5; filter: grayscale(1); transition: all 0.2s; font-size: 1.1rem; }

.tone-label:has(input:checked) {
    background: rgba(0, 240, 255, 0.1);
    border-color: rgba(0, 240, 255, 0.3);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.2);
}
.tone-label:has(input:checked) .tone-icon {
    opacity: 1; filter: grayscale(0); transform: scale(1.15);
}

.textarea-wrapper {
    display: flex;
    align-items: flex-end;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 0.5rem;
    transition: all 0.3s ease;
}
.textarea-wrapper:focus-within {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 1px var(--accent-blue);
}

#input-text {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    padding: 0.75rem;
    resize: none;
    height: 48px;
    max-height: 150px;
    outline: none;
    line-height: 1.5;
}
#input-text::placeholder { color: var(--text-tertiary); }

#send-btn {
    background: var(--accent-blue);
    border: none;
    color: white;
    width: 40px; height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-left: 0.5rem;
    margin-bottom: 4px;
    transition: all 0.2s ease;
}
#send-btn:hover {
    transform: scale(1.05) translateY(-1px);
    box-shadow: 0 4px 15px rgba(0, 240, 255, 0.5);
}

/* --- Right Column: Sensors --- */
.sensors-container {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
}

.sensors-container::-webkit-scrollbar { width: 4px; }
.sensors-container::-webkit-scrollbar-thumb { background-color: var(--border-light); border-radius: 4px; }

.sensor-card {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    overflow: hidden;
}

.sensor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-light);
}

.sensor-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sensor-status {
    font-size: 0.7rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-tertiary);
}

.sensor-body {
    padding: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
}

canvas {
    width: 100%;
    height: 100px;
    border-radius: 8px;
}
#retina-canvas {
    height: auto;
    aspect-ratio: 320/240;
}

.system-status {
    margin-top: auto;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-light);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.status-row {
    display: flex;
    justify-content: space-between;
}

/* Custom UI Polish */
.custom-select, .custom-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(0, 240, 255, 0.2);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    padding: 6px;
    border-radius: 6px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.custom-select:focus, .custom-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.3);
}

.cognitive-pulse {
    animation: cognitivePulse 2s ease-in-out infinite alternate;
}

@keyframes cognitivePulse {
    0% { text-shadow: 0 0 5px rgba(0, 240, 255, 0.2); transform: scale(1); }
    100% { text-shadow: 0 0 20px rgba(0, 240, 255, 0.8), 0 0 30px rgba(0, 240, 255, 0.5); transform: scale(1.05); }
}

/* Fix input range sliders */
input[type=range] {
    -webkit-appearance: none;
    background: transparent;
}
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 14px;
    width: 14px;
    border-radius: 50%;
    background: var(--accent-blue);
    box-shadow: 0 0 10px var(--accent-blue);
    margin-top: -4px;
    cursor: pointer;
}
