:root {
    --bg-dark: #0f111a;
    --card-bg: rgba(22, 28, 45, 0.45);
    --border-color: rgba(255, 255, 255, 0.08);
    --primary: #5b21b6;
    --primary-glow: rgba(124, 58, 237, 0.5);
    --primary-light: #8b5cf6;
    --accent: #06b6d4;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --success: #10b981;
    --error: #ef4444;
    --sidebar-width: 260px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    transition: background-color 0.3s ease, border-color 0.3s ease, transform 0.2s ease;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    background-image: 
        radial-gradient(at 10% 10%, rgba(91, 33, 182, 0.15) 0px, transparent 50%),
        radial-gradient(at 90% 85%, rgba(6, 182, 212, 0.1) 0px, transparent 50%);
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

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

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background: rgba(15, 17, 26, 0.85);
    backdrop-filter: blur(15px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.brand-logo {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: bold;
    box-shadow: 0 0 20px var(--primary-glow);
}

.brand-title {
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    background: linear-gradient(to right, #ffffff, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-grow: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1rem;
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-muted);
    font-weight: 500;
    text-decoration: none;
}

.nav-item:hover, .nav-item.active {
    background: rgba(124, 58, 237, 0.15);
    color: var(--text-main);
    border-left: 3px solid var(--primary-light);
}

.nav-item i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

/* Main Content Area */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: rgba(15, 17, 26, 0.4);
}

.top-bar {
    height: 70px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    backdrop-filter: blur(10px);
}

.page-title {
    font-size: 1.25rem;
    font-weight: 700;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: var(--success);
    padding: 0.4rem 0.8rem;
    border-radius: 30px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-badge.error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--error);
}

.status-dot {
    width: 8px;
    height: 8px;
    background-color: currentColor;
    border-radius: 50%;
    animation: pulse 1.5s infinite alternate;
}

@keyframes pulse {
    0% { transform: scale(0.85); opacity: 0.6; }
    100% { transform: scale(1.2); opacity: 1; }
}

/* Scrollable Inner Content */
.content-body {
    flex-grow: 1;
    overflow-y: auto;
    padding: 2rem;
}

.tab-pane {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.tab-pane.active {
    display: block;
}

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

/* Glass Cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

.glass-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(255,255,255,0.03) 0%, transparent 100%);
    pointer-events: none;
}

.card-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.card-title {
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 500;
}

.card-icon {
    font-size: 1.5rem;
    color: var(--primary-light);
}

.card-value {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.card-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Analytics Graph/Logs section */
.dashboard-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

@media (max-width: 1024px) {
    .dashboard-row {
        grid-template-columns: 1fr;
    }
}

.table-container {
    overflow-x: auto;
    margin-top: 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    padding: 1rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

td {
    padding: 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    font-size: 0.9rem;
}

tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

/* Forms & Inputs */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.input-group {
    position: relative;
}

.input-group i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.input-group input, .input-group select, .form-group select, .form-group textarea {
    width: 100%;
    padding: 0.8rem 1rem 0.8rem 2.5rem;
    background: rgba(15, 17, 26, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-main);
    font-size: 0.95rem;
}

.form-group select, .form-group textarea {
    padding-left: 1rem;
}

.input-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.2);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.3);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.5);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    box-shadow: none;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    box-shadow: none;
}

/* Prompt Editor Split pane */
.editor-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    height: calc(100vh - 210px);
}

@media (max-width: 768px) {
    .editor-container {
        grid-template-columns: 1fr;
        height: auto;
    }
}

.prompt-textarea {
    height: 100%;
    resize: none;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    background: rgba(10, 12, 18, 0.7) !important;
}

.preview-panel {
    border: 1px solid var(--border-color);
    background: rgba(10, 12, 18, 0.4);
    border-radius: 10px;
    padding: 1.5rem;
    overflow-y: auto;
    font-size: 0.95rem;
    line-height: 1.6;
}

.preview-panel h1, .preview-panel h2, .preview-panel h3 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    color: var(--primary-light);
}

.preview-panel p {
    margin-bottom: 1rem;
}

.preview-panel ul, .preview-panel ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

/* Chat Session Explorer */
.chat-explorer {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1.5rem;
    height: calc(100vh - 170px);
}

.chat-sessions-list {
    background: rgba(15, 17, 26, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.session-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

.session-item:hover, .session-item.active {
    background: rgba(124, 58, 237, 0.1);
}

.session-item .sender-id {
    font-weight: 700;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
    color: var(--text-main);
    word-break: break-all;
}

.session-item .session-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.chat-window {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    backdrop-filter: blur(10px);
}

.chat-window-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(15, 17, 26, 0.5);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-window-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.msg-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.msg-wrapper.user {
    align-self: flex-end;
}

.msg-wrapper.bot {
    align-self: flex-start;
}

.msg-bubble {
    padding: 0.9rem 1.2rem;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    word-break: break-word;
}

.msg-wrapper.user .msg-bubble {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    border-bottom-right-radius: 4px;
}

.msg-wrapper.bot .msg-bubble {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
}

.msg-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
    display: flex;
    gap: 0.5rem;
}

.msg-wrapper.user .msg-meta {
    justify-content: flex-end;
}

/* Tool Toggle Switch */
.switch-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: rgba(255,255,255,0.02);
    border-radius: 12px;
    margin-bottom: 1rem;
}

.switch-label-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.switch-title {
    font-weight: 600;
    font-size: 0.95rem;
}

.switch-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border-radius: 34px;
    border: 1px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--success);
}

input:checked + .slider:before {
    transform: translateX(24px);
}

.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: rgba(16, 185, 129, 0.95);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.error {
    background: rgba(239, 68, 68, 0.95);
}
