:root {
    --bg: #080e1c;
    --panel: rgba(15, 22, 40, 0.75);
    --border: rgba(255, 255, 255, 0.08);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --purple: #8b5cf6;
    --green: #10b981;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --user-bubble: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    --ai-bubble: rgba(30, 41, 59, 0.9);
    --tab-active-bg: rgba(59, 130, 246, 0.15);
    --table-head: rgba(59, 130, 246, 0.12);
    --table-row-odd: rgba(255,255,255,0.02);
    --table-row-even: rgba(255,255,255,0.04);
    --table-hover: rgba(59, 130, 246, 0.08);
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* ── BACKGROUND GLOWS ── */
.bg-fx { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.glow {
    position: absolute;
    width: 700px; height: 700px;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.2;
    animation: drift 22s infinite alternate ease-in-out;
}
.glow-1 { top: -150px; left: -150px; background: var(--primary); }
.glow-2 { bottom: -150px; right: -150px; background: var(--purple); animation-delay: -11s; }
@keyframes drift {
    from { transform: translate(0, 0); }
    to   { transform: translate(80px, 40px); }
}

/* ── HEADER ── */
header {
    padding: 18px 32px;
    border-bottom: 1px solid var(--border);
    background: rgba(8, 14, 28, 0.6);
    backdrop-filter: blur(16px);
    position: sticky; top: 0; z-index: 100;
}
.header-content { display: flex; align-items: center; gap: 14px; max-width: 1300px; margin: 0 auto; }
.logo { height: 44px; object-fit: contain; filter: drop-shadow(0 0 8px rgba(59,130,246,0.3)); }
.header-text { display: flex; flex-direction: column; }
h1 { font-size: 1.25rem; font-weight: 700; background: linear-gradient(to right, #fff, #94a3b8); -webkit-background-clip: text; background-clip: text; color: transparent; }
.header-sub { font-size: 0.75rem; color: var(--primary); font-weight: 500; letter-spacing: 0.05em; text-transform: uppercase; }

/* ── TABS ── */
.tab-nav {
    display: flex;
    gap: 4px;
    padding: 16px 32px 0;
    max-width: 1300px;
    margin: 0 auto;
    width: 100%;
}
.tab-btn {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 20px;
    background: transparent;
    border: 1px solid var(--border);
    border-bottom: none;
    color: var(--muted);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 10px 10px 0 0;
    transition: all 0.2s ease;
}
.tab-btn svg { width: 16px; height: 16px; }
.tab-btn:hover { color: var(--text); background: var(--tab-active-bg); }
.tab-btn.active {
    color: var(--primary);
    background: var(--tab-active-bg);
    border-color: var(--primary);
    border-bottom: 1px solid var(--panel);
}

/* ── MAIN CONTAINER ── */
.container {
    flex: 1;
    padding: 0 32px 32px;
    max-width: 1300px;
    margin: 0 auto;
    width: 100%;
}

/* ── PANELS ── */
.panel { display: none; }
.panel.active { display: block; animation: fadeInUp 0.3s ease; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.glass-panel {
    background: var(--panel);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 0 16px 16px 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

/* ── CHAT PANEL ── */
.chat-wrapper { display: flex; flex-direction: column; height: 76vh; }
.chat-header {
    padding: 20px 28px;
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.chat-header h2 { font-size: 1.1rem; font-weight: 600; }
.chat-subtitle { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.status-indicator { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--green); font-weight: 500; }
.dot { width: 8px; height: 8px; background: var(--green); border-radius: 50%; box-shadow: 0 0 8px var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(16,185,129,0.6); } 70% { box-shadow: 0 0 0 6px rgba(16,185,129,0); } 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); } }

/* Chat history */
.chat-history { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 18px; scroll-behavior: smooth; }
.chat-history::-webkit-scrollbar { width: 5px; }
.chat-history::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

.message { display: flex; gap: 14px; max-width: 82%; animation: msgIn 0.25s ease-out; }
@keyframes msgIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
.user-message { align-self: flex-end; flex-direction: row-reverse; }
.system-message { align-self: flex-start; }

.avatar {
    width: 38px; height: 38px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.75rem; flex-shrink: 0;
}
.system-message .avatar { background: linear-gradient(135deg, var(--purple), var(--primary)); color: #fff; }
.user-message .avatar { background: #1e2d48; color: var(--text); }

.message-content { padding: 13px 18px; border-radius: 16px; line-height: 1.6; font-size: 0.925rem; word-break: break-word; }
.user-message .message-content { background: var(--user-bubble); color: #fff; border-top-right-radius: 4px; box-shadow: 0 4px 20px rgba(59,130,246,0.25); }
.system-message .message-content { background: var(--ai-bubble); border: 1px solid var(--border); border-top-left-radius: 4px; }
.message-content.error { border-color: rgba(239,68,68,0.4); color: #fca5a5; }

/* Typing indicator */
.typing-wrap { display: flex; align-items: center; gap: 14px; animation: msgIn 0.25s ease-out; }
.typing-bubble { display: flex; gap: 5px; padding: 14px 18px; background: var(--ai-bubble); border: 1px solid var(--border); border-radius: 16px; border-top-left-radius: 4px; }
.typing-dot { width: 6px; height: 6px; background: var(--muted); border-radius: 50%; animation: bounce 1.4s infinite ease-in-out both; }
.typing-dot:nth-child(1) { animation-delay: -.32s; }
.typing-dot:nth-child(2) { animation-delay: -.16s; }
@keyframes bounce { 0%,80%,100%{transform:scale(0)} 40%{transform:scale(1)} }

/* Input */
.input-area { padding: 18px 24px; border-top: 1px solid var(--border); }
form { display: flex; gap: 10px; background: rgba(0,0,0,0.25); border: 1px solid var(--border); border-radius: 14px; padding: 6px; transition: border-color 0.2s, box-shadow 0.2s; }
form:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }
input { flex: 1; background: transparent; border: none; color: var(--text); font-family: inherit; font-size: 0.95rem; padding: 8px 14px; outline: none; }
input::placeholder { color: var(--muted); }
button[type=submit] { width: 42px; height: 42px; background: var(--primary); color: #fff; border: none; border-radius: 10px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s; flex-shrink: 0; }
button[type=submit]:hover { background: var(--primary-hover); transform: translateY(-2px); box-shadow: 0 4px 14px rgba(59,130,246,0.4); }
button[type=submit]:active { transform: translateY(0); }
button[type=submit]:disabled { background: #334155; cursor: not-allowed; transform: none; box-shadow: none; }
button[type=submit] svg { width: 18px; height: 18px; }

/* ── DATABASE PANEL ── */
.db-wrapper { display: flex; flex-direction: column; min-height: 76vh; }
.db-header { padding: 20px 28px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.db-header h2 { font-size: 1.1rem; font-weight: 600; }
.db-subtitle { font-size: 0.8rem; color: var(--muted); margin-top: 3px; }

.refresh-btn {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 16px; border-radius: 10px;
    background: rgba(59,130,246,0.1); border: 1px solid rgba(59,130,246,0.3);
    color: var(--primary); font-family: inherit; font-size: 0.85rem; font-weight: 500;
    cursor: pointer; transition: all 0.2s;
}
.refresh-btn:hover { background: rgba(59,130,246,0.2); transform: translateY(-1px); }
.refresh-btn svg { width: 16px; height: 16px; }

/* Table */
.table-scroll { flex: 1; overflow-x: auto; padding: 20px 24px; }
.table-scroll::-webkit-scrollbar { height: 5px; }
.table-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; min-width: 900px; }
thead tr { background: var(--table-head); position: sticky; top: 0; }
th { padding: 12px 14px; text-align: left; font-weight: 600; color: var(--primary); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; border-bottom: 1px solid var(--border); }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--text); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr:nth-child(odd) td { background: var(--table-row-odd); }
tr:nth-child(even) td { background: var(--table-row-even); }
tbody tr { transition: background 0.15s; }
tbody tr:hover td { background: var(--table-hover); }

.badge {
    display: inline-block; padding: 2px 10px;
    border-radius: 20px; font-size: 0.75rem; font-weight: 600;
}
.badge-blue { background: rgba(59,130,246,0.2); color: #93c5fd; }
.badge-green { background: rgba(16,185,129,0.2); color: #6ee7b7; }
.badge-yellow { background: rgba(234,179,8,0.2); color: #fde047; }
.badge-red { background: rgba(239,68,68,0.2); color: #fca5a5; }
.badge-gray { background: rgba(148,163,184,0.15); color: #cbd5e1; }

/* Pagination */
.pagination {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    padding: 18px 24px; border-top: 1px solid var(--border); flex-wrap: wrap;
}
.page-info { font-size: 0.85rem; color: var(--muted); margin: 0 12px; }
.page-btn {
    min-width: 36px; height: 36px; padding: 0 10px;
    border-radius: 8px; border: 1px solid var(--border);
    background: transparent; color: var(--muted);
    font-family: inherit; font-size: 0.85rem;
    cursor: pointer; transition: all 0.2s;
    display: flex; align-items: center; justify-content: center;
}
.page-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); background: rgba(59,130,246,0.1); }
.page-btn.current { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.page-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.page-btn svg { width: 14px; height: 14px; }

/* Loading / empty states */
.loading-state, .empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 60px; gap: 14px; color: var(--muted); font-size: 0.9rem;
}
.spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 768px) {
    header { padding: 14px 16px; }
    .tab-nav { padding: 12px 16px 0; }
    .container { padding: 0 16px 24px; }
    .chat-wrapper, .db-wrapper { min-height: 80vh; border-radius: 0 12px 12px; }
    h1 { font-size: 1rem; }
}
