/* --- Design System & CSS Variables --- */
:root {
    --bg-dark: #070a13;
    --bg-card: rgba(13, 20, 38, 0.45);
    --bg-card-hover: rgba(22, 32, 59, 0.6);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-color-active: rgba(0, 242, 254, 0.4);
    
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    /* Brand Accent Colors */
    --color-cyan: #00f2fe;
    --color-cyan-glow: rgba(0, 242, 254, 0.15);
    --color-purple: #9d4edd;
    --color-purple-glow: rgba(157, 78, 221, 0.15);
    --color-emerald: #10b981;
    --color-emerald-glow: rgba(16, 185, 129, 0.15);
    --color-blue: #3b82f6;
    --color-blue-glow: rgba(59, 130, 246, 0.15);
    --color-gold: #f59e0b;
    --color-gold-glow: rgba(245, 158, 11, 0.15);
    --color-red: #ef4444;
    
    --font-heading: 'Outfit', sans-serif;
    --font-sans: 'Plus Jakarta Sans', sans-serif;
    --font-mono: 'JetBrains Mono', sans-serif;
    
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    position: relative;
}

/* --- Background Glow Effects --- */
.glow-bg {
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    filter: blur(140px);
    opacity: 0.12;
    pointer-events: none;
    z-index: 0;
}

.glow-bg.bg-cyan {
    background: var(--color-cyan);
    top: -200px;
    left: -200px;
}

.glow-bg.bg-purple {
    background: var(--color-purple);
    bottom: -200px;
    right: -200px;
}

/* --- Custom 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);
}

/* --- Header --- */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 2.5rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(7, 10, 19, 0.8);
    backdrop-filter: blur(12px);
    z-index: 10;
    position: relative;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.logo-box {
    background: linear-gradient(135deg, var(--color-cyan), var(--color-purple));
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 15px rgba(0, 242, 254, 0.3);
}

.logo-text-a1 {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.15rem;
    color: #fff;
    letter-spacing: -0.5px;
}

.logo-title h1 {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.2px;
}

.agency-tag {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.nav-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: var(--transition-smooth);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid transparent;
}

.nav-back-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--border-color);
}

/* --- Layout Container --- */
.app-container {
    display: grid;
    grid-template-columns: 320px 1fr 380px;
    gap: 1.5rem;
    padding: 1.5rem 2rem;
    flex: 1;
    z-index: 5;
    position: relative;
    max-height: calc(100vh - 80px);
    overflow: hidden;
}

@media (max-width: 1200px) {
    .app-container {
        grid-template-columns: 300px 1fr;
        max-height: none;
        overflow: auto;
    }
    .live-panel {
        grid-column: span 2;
        height: 500px !important;
    }
}

@media (max-width: 900px) {
    .app-container {
        grid-template-columns: 1fr;
        padding: 1.5rem 1rem;
        gap: 1.25rem;
    }
    .control-panel, .canvas-panel, .live-panel {
        grid-column: span 1;
    }
}

@media (max-width: 600px) {
    .app-header {
        padding: 1rem;
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }
    .nav-back-btn {
        width: 100%;
        justify-content: center;
    }
    .node-canvas {
        padding: 1.5rem 1rem;
        overflow-x: auto;
        align-items: center;
        gap: 1.5rem;
    }
    .canvas-panel {
        min-height: auto;
    }
    .node {
        width: 280px;
        flex-shrink: 0;
    }
}

/* --- Glass Card Panels --- */
.glass-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    transition: var(--transition-smooth);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.panel-icon {
    opacity: 0.85;
}

.panel-icon.icon-cyan { color: var(--color-cyan); filter: drop-shadow(0 0 5px var(--color-cyan-glow)); }
.panel-icon.icon-purple { color: var(--color-purple); filter: drop-shadow(0 0 5px var(--color-purple-glow)); }

.panel-header h2 {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 600;
}

/* --- Form Fields & Controls --- */
.control-panel {
    padding: 1.25rem;
    gap: 1.25rem;
    overflow-y: auto;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

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

select, textarea {
    background: rgba(7, 10, 19, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 0.75rem;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    outline: none;
    transition: var(--transition-smooth);
}

select:focus, textarea:focus {
    border-color: var(--color-cyan);
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.1);
}

textarea[readonly] {
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.2);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.4;
    resize: none;
}

.rag-badge {
    background: rgba(0, 242, 254, 0.05);
    border: 1px dashed rgba(0, 242, 254, 0.2);
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-cyan);
    font-size: 0.8rem;
    font-weight: 500;
}

.divider {
    height: 1px;
    background: var(--border-color);
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.range-val {
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
    text-align: right;
}

input[type="range"] {
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    height: 4px;
    border-radius: 2px;
    outline: none;
}

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

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

/* --- Buttons --- */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.85rem;
    border-radius: 10px;
    border: none;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition-smooth);
    color: #fff;
    width: 100%;
    margin-top: auto;
}

.btn-primary {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.btn-primary:hover {
    opacity: 0.95;
    transform: translateY(-1px);
}

.btn-glow {
    box-shadow: 0 4px 20px rgba(0, 242, 254, 0.25);
}

.btn-glow:hover {
    box-shadow: 0 6px 25px rgba(0, 242, 254, 0.4);
}

.btn:disabled {
    background: var(--text-muted);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
    opacity: 0.5;
}

/* --- Canvas Editor Panel --- */
.canvas-panel {
    position: relative;
    min-height: 500px;
}

.node-canvas {
    flex: 1;
    position: relative;
    overflow: hidden;
    background-image: radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px);
    background-size: 20px 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    padding: 2rem 4rem;
}

.canvas-connections {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.connection-line {
    fill: none;
    stroke: rgba(255, 255, 255, 0.08);
    stroke-width: 2.5;
    transition: var(--transition-smooth);
}

.connection-line.active {
    stroke: var(--color-cyan);
    filter: drop-shadow(0 0 4px rgba(0, 242, 254, 0.5));
}

/* --- Node Styling --- */
.node {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: rgba(18, 25, 47, 0.85);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.85rem 1.25rem;
    width: 280px;
    position: relative;
    z-index: 2;
    transition: var(--transition-smooth);
    margin: 0 auto;
}

.node:hover {
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.node.active {
    background: rgba(0, 242, 254, 0.03);
    border-color: var(--color-cyan);
    box-shadow: 0 0 20px rgba(0, 242, 254, 0.15);
}

.node.active-log {
    animation: nodePulse 1.5s infinite alternate;
}

@keyframes nodePulse {
    0% {
        box-shadow: 0 0 10px rgba(157, 78, 221, 0.1);
    }
    100% {
        box-shadow: 0 0 25px rgba(157, 78, 221, 0.3);
        border-color: var(--color-purple);
    }
}

.node-badge {
    position: absolute;
    top: -8px;
    right: 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.6rem;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    text-transform: uppercase;
}

.node-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
}

.node-icon.bg-blue { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.node-icon.bg-purple { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
.node-icon.bg-cyan { background: linear-gradient(135deg, #06b6d4, #0891b2); }
.node-icon.bg-emerald { background: linear-gradient(135deg, #10b981, #047857); }
.node-icon.bg-gold { background: linear-gradient(135deg, #f59e0b, #b45309); }

.node-info h3 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.node-info p {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.node-dot {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--bg-dark);
    border: 2px solid var(--border-color);
    left: 50%;
    transform: translateX(-50%);
}

.node-dot.in {
    top: -5px;
}

.node-dot.out {
    bottom: -5px;
}

.node.active .node-dot {
    border-color: var(--color-cyan);
    background: var(--color-cyan);
}

/* --- Right Side: Live Logs / Transcript --- */
.live-panel {
    display: flex;
    flex-direction: column;
}

.tabs-header {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.15);
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 1rem;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition-smooth);
    border-bottom: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

.tab-btn.active {
    color: var(--color-cyan);
    border-bottom-color: var(--color-cyan);
    background: rgba(255, 255, 255, 0.02);
}

.ping-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-cyan);
    display: inline-block;
}

.glow-dot {
    box-shadow: 0 0 8px var(--color-cyan);
    animation: pulseDot 1.5s infinite;
}

@keyframes pulseDot {
    0% { opacity: 0.4; }
    50% { opacity: 1; }
    100% { opacity: 0.4; }
}

.tab-content {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
}

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

/* --- Live Call Interface (Transcript) --- */
.audio-wave-container {
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.call-duration {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.live-indicator {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.pulse-dot.bg-red {
    background: var(--color-red);
}

.live-indicator.active {
    color: var(--color-red);
}

.live-indicator.active .pulse-dot {
    animation: recordingPulse 1.2s infinite;
}

@keyframes recordingPulse {
    0% { transform: scale(0.9); opacity: 0.6; }
    50% { transform: scale(1.2); opacity: 1; box-shadow: 0 0 8px rgba(239, 68, 68, 0.6); }
    100% { transform: scale(0.9); opacity: 0.6; }
}

.audio-waves {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 24px;
}

.wave-bar {
    width: 2px;
    height: 4px;
    background: var(--text-muted);
    border-radius: 1px;
    transition: height 0.15s ease;
}

/* Active audio animations */
.audio-waves.animating-ai .wave-bar {
    background: var(--color-cyan);
    animation: waveMotion 1.2s infinite ease-in-out;
}

.audio-waves.animating-user .wave-bar {
    background: var(--color-purple);
    animation: waveMotion 0.8s infinite ease-in-out;
}

.audio-waves.animating-ai .wave-bar:nth-child(2n) { animation-delay: 0.1s; }
.audio-waves.animating-ai .wave-bar:nth-child(3n) { animation-delay: 0.25s; }
.audio-waves.animating-ai .wave-bar:nth-child(4n) { animation-delay: 0.4s; }

.audio-waves.animating-user .wave-bar:nth-child(2n) { animation-delay: 0.15s; }
.audio-waves.animating-user .wave-bar:nth-child(3n) { animation-delay: 0.3s; }

@keyframes waveMotion {
    0%, 100% { height: 4px; }
    50% { height: 22px; }
}

.transcript-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.empty-state {
    margin: auto;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-muted);
    max-width: 240px;
}

.empty-icon {
    opacity: 0.4;
}

.empty-state p {
    font-size: 0.8rem;
    line-height: 1.4;
}

/* Dialog Bubbles */
.dialog-bubble {
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: 14px;
    font-size: 0.85rem;
    line-height: 1.45;
    animation: bubbleSlideIn 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}

@keyframes bubbleSlideIn {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.dialog-bubble.ai {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    align-self: flex-start;
    border-top-left-radius: 2px;
}

.dialog-bubble.user {
    background: linear-gradient(135deg, rgba(157, 78, 221, 0.15), rgba(157, 78, 221, 0.05));
    border: 1px solid rgba(157, 78, 221, 0.25);
    color: #e9d5ff;
    align-self: flex-end;
    border-top-right-radius: 2px;
}

.dialog-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
    display: block;
}

.dialog-bubble.ai .dialog-label { color: var(--color-cyan); }
.dialog-bubble.user .dialog-label { color: #c084fc; }

/* --- Console / System Logs Panel --- */
.console-logs {
    flex: 1;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.3);
    padding: 1.25rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    line-height: 1.5;
}

.log-entry {
    display: flex;
    gap: 0.5rem;
}

.log-time {
    color: var(--text-muted);
    flex-shrink: 0;
}

.log-text {
    word-break: break-all;
}

.log-entry.system { color: var(--text-secondary); }
.log-entry.websocket-tx { color: var(--color-cyan); }
.log-entry.websocket-rx { color: #c084fc; }
.log-entry.db-query { color: var(--color-gold); }
.log-entry.webhook { color: var(--color-emerald); }
.log-entry.error { color: var(--color-red); }

/* --- Footer --- */
.app-footer {
    text-align: center;
    padding: 1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    background: rgba(7, 10, 19, 0.9);
    z-index: 10;
    position: relative;
}

/* Height-based Responsiveness for Short Screens */
@media (max-height: 768px) {
    .app-container {
        max-height: none;
        overflow: visible;
    }
}

