:root {
    --primary: #6366F1;
    --primary-hover: #4F46E5;
    --secondary: #818CF8;
    --background: #0A0A1A;
    --surface: rgba(30, 30, 50, 0.6);
    --surface-hover: rgba(45, 45, 75, 0.8);
    --border: rgba(99, 102, 241, 0.2);
    --text-main: #FFFFFF;
    --text-muted: #94A3B8;

    --accent: #F43F5E;
    --success: #10B981;
    --warning: #F59E0B;

    --radius: 12px;
    --font-sans: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

body {
    background-color: var(--background);
    color: var(--text-main);
    font-family: var(--font-sans);
    height: 100vh;
    overflow: hidden;
    background-image:
        radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 85% 30%, rgba(244, 63, 94, 0.05) 0%, transparent 50%);
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Glassmorphism Classes */
.glass-header {
    background: rgba(10, 10, 26, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.card {
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
}

/* Header */
.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    font-weight: 700;
    font-size: 0.8rem;
    padding: 0.4rem 0.5rem;
    border-radius: 8px;
    letter-spacing: 1px;
}

.brand h1 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.connection-manager {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    max-width: 600px;
}

.input-glass {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: var(--font-mono);
    outline: none;
    transition: all 0.2s;
}

.input-glass:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.status-badge {
    padding: 0.4rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.status-badge::before {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-badge.disconnected {
    background: rgba(244, 63, 94, 0.1);
    color: var(--accent);
}

.status-badge.disconnected::before {
    background: var(--accent);
}

.status-badge.connecting {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.status-badge.connecting::before {
    background: var(--warning);
    box-shadow: 0 0 8px var(--warning);
}

.status-badge.connected {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.status-badge.connected::before {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

/* Buttons */
.btn {
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.15);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

/* Toggle */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.toggle-switch input {
    display: none;
}

.slider {
    width: 36px;
    height: 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    position: relative;
    transition: 0.3s;
}

.slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    left: 2px;
    bottom: 2px;
    background: white;
    transition: 0.3s;
}

.toggle-switch input:checked+.slider {
    background: var(--primary);
}

.toggle-switch input:checked+.slider::before {
    transform: translateX(16px);
}

.label-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Workspace Layout */
.workspace {
    flex: 1;
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 1.5rem;
    padding: 1.5rem;
    overflow: hidden;
}

.panel-left {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow: hidden;
}

.builder-card {
    flex: 2;
    min-height: 250px;
}

.templates-card {
    flex: 1;
    min-height: 150px;
    overflow: hidden;
}

.panel-right {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.log-card {
    flex: 1;
    overflow: hidden;
}

/* Card Internals */
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h2 {
    font-size: 0.95rem;
    font-weight: 600;
}

.badge {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.2rem 0.5rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-family: var(--font-mono);
}

.pill-selector {
    display: flex;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    padding: 2px;
}

.pill {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.3rem 0.75rem;
    font-size: 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
}

.pill.active {
    background: var(--primary);
    color: white;
}

/* Editor */
.builder-content {
    flex: 1;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.code-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    color: #A5B4FC;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    padding: 1rem;
    resize: none;
    outline: none;
    line-height: 1.5;
}

.code-input:focus {
    border-color: rgba(99, 102, 241, 0.4);
}

.builder-actions {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.spacer {
    flex: 1;
}

/* Template List */
.template-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.empty-state {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
}

.template-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    margin: 0.25rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    transition: background 0.2s;
}

.template-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.template-info h4 {
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.2rem;
}

.template-info p {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.btn-delete {
    background: transparent;
    color: var(--text-muted);
    border: none;
    cursor: pointer;
    padding: 0.2rem;
    border-radius: 4px;
}

.btn-delete:hover {
    color: var(--accent);
    background: rgba(244, 63, 94, 0.1);
}

/* Conversation Log */
.log-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.log-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.log-message.system {
    align-self: center;
    align-items: center;
    margin: 1rem 0;
}

.log-message.system .content {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    padding: 0.4rem 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.log-message.system .time {
    display: none;
}

.log-message.outbound {
    align-self: flex-end;
}

.log-message.inbound {
    align-self: flex-start;
}

.log-message .meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    padding: 0 0.2rem;
}

.log-message.outbound .meta {
    justify-content: flex-end;
}

.log-message .direction-icon {
    width: 12px;
    height: 12px;
}

.log-message.outbound .direction-icon {
    color: var(--primary);
}

.log-message.inbound .direction-icon {
    color: var(--success);
}

.log-message .bubble {
    padding: 0.8rem 1rem;
    border-radius: 12px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    word-break: break-all;
    white-space: pre-wrap;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.log-message.outbound .bubble {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-bottom-right-radius: 2px;
}

.log-message.inbound .bubble {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-bottom-left-radius: 2px;
}

.log-message.error .bubble {
    background: rgba(244, 63, 94, 0.1);
    border: 1px solid rgba(244, 63, 94, 0.2);
    color: var(--accent);
}

.latency {
    font-family: var(--font-mono);
    color: var(--warning);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

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

.modal-card {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 350px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

.modal-card h3 {
    margin-bottom: 0.5rem;
}

.modal-card p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.mt-3 {
    margin-top: 1rem;
}

.mt-4 {
    margin-top: 1.5rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}