/**
 * Flex AI Engine - Stylesheet
 * Professional dark theme with refined aesthetics
 */

/* === Reset & Base === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg-primary: #090b10;
    --bg-secondary: #111420;
    --bg-tertiary: #181c2e;
    --bg-elevated: #1c2036;
    --bg-input: #0d0f16;
    --bg-hover: #1e2340;
    --text-primary: #e8eaf0;
    --text-secondary: #9ba1b4;
    --text-muted: #5c6178;
    --accent: #5b9fff;
    --accent-hover: #4b8dee;
    --accent-glow: rgba(91, 159, 255, 0.12);
    --accent-dim: rgba(91, 159, 255, 0.08);
    --accent-gradient: linear-gradient(135deg, #5b9fff 0%, #7c6fff 100%);
    --success: #34d399;
    --success-bg: rgba(52, 211, 153, 0.1);
    --error: #f87171;
    --error-bg: rgba(248, 113, 113, 0.1);
    --warning: #fbbf24;
    --warning-bg: rgba(251, 191, 36, 0.08);
    --border: #1e2235;
    --border-light: #272c42;
    --radius: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.2);
    --shadow: 0 4px 24px rgba(0,0,0,.25), 0 1px 4px rgba(0,0,0,.15);
    --shadow-lg: 0 12px 48px rgba(0,0,0,.35), 0 2px 8px rgba(0,0,0,.2);
    --shadow-glow: 0 0 30px rgba(91,159,255,.06);
    --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;
    --transition: 0.2s cubic-bezier(.4,0,.2,1);
}

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.65;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-size: 14px;
    letter-spacing: 0.01em;
}

::selection {
    background: rgba(91,159,255,.3);
    color: #fff;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); text-decoration: none; }

/* === Alerts === */
.alert {
    padding: 14px 20px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.5;
    display: flex;
    align-items: center;
    gap: 10px;
    backdrop-filter: blur(8px);
    animation: alertSlideIn 0.3s ease-out;
}
@keyframes alertSlideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.alert-success {
    background: linear-gradient(135deg, rgba(52,211,153,.12) 0%, rgba(52,211,153,.06) 100%);
    border: 1px solid rgba(52,211,153,.2);
    color: var(--success);
}
.alert-error {
    background: linear-gradient(135deg, rgba(248,113,113,.12) 0%, rgba(248,113,113,.06) 100%);
    border: 1px solid rgba(248,113,113,.2);
    color: var(--error);
}
.alert-warning {
    background: linear-gradient(135deg, rgba(251,191,36,.1) 0%, rgba(251,191,36,.05) 100%);
    border: 1px solid rgba(251,191,36,.2);
    color: var(--warning);
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 22px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
    letter-spacing: 0.02em;
    position: relative;
    overflow: hidden;
}
.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,.04) 0%, transparent 60%);
    pointer-events: none;
}
.btn:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.btn:active { transform: translateY(0); }
.btn-primary {
    background: var(--accent-gradient);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 12px rgba(91,159,255,.25);
}
.btn-primary:hover {
    box-shadow: 0 4px 20px rgba(91,159,255,.35);
    border-color: transparent;
}
.btn-danger {
    background: rgba(248,113,113,.08);
    color: var(--error);
    border-color: rgba(248,113,113,.2);
}
.btn-danger:hover {
    background: rgba(248,113,113,.15);
    border-color: rgba(248,113,113,.35);
}
.btn-small { padding: 6px 14px; font-size: 12px; border-radius: 8px; }
.btn-full { width: 100%; justify-content: center; padding: 12px 22px; }

/* === Forms === */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 11px 16px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font);
    transition: all var(--transition);
}
.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim), var(--shadow-glow);
}
.form-group textarea { resize: vertical; min-height: 70px; line-height: 1.6; }
.form-group select { cursor: pointer; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 200px; }

/* === Cards === */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    transition: border-color var(--transition);
}
.card:hover { border-color: var(--border-light); }
.card h3 {
    margin-bottom: 20px;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}
.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 16px;
    flex-wrap: wrap;
}
.card-header-row h3 { margin-bottom: 0; }

/* === Tables === */
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th {
    padding: 10px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-tertiary);
}
.table th:first-child { border-radius: 8px 0 0 0; }
.table th:last-child { border-radius: 0 8px 0 0; }
.table td {
    padding: 12px 16px;
    text-align: left;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    transition: background var(--transition);
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--accent-dim); }
.table .actions { white-space: nowrap; display: flex; gap: 6px; }

/* === Badges === */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    background: var(--accent-glow);
    color: var(--accent);
    border: 1px solid rgba(91,159,255,.15);
}
.badge-success { background: var(--success-bg); color: var(--success); border-color: rgba(52,211,153,.15); }
.badge-error { background: var(--error-bg); color: var(--error); border-color: rgba(248,113,113,.15); }
.badge-warning { background: var(--warning-bg); color: var(--warning); border-color: rgba(251,191,36,.15); }

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 26px 20px;
    text-align: center;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--accent-gradient);
    opacity: 0;
    transition: opacity var(--transition);
}
.stat-card:hover {
    border-color: var(--border-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}
.stat-card:hover::before { opacity: 1; }
.stat-number {
    font-size: 34px;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.1;
}
.stat-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 8px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* === Grid === */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 20px; }

/* === Pagination === */
.pagination {
    display: flex;
    gap: 6px;
    margin-top: 20px;
    flex-wrap: wrap;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* === Chunks === */
.chunk-item {
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    transition: all var(--transition);
    background: var(--bg-tertiary);
}
.chunk-item:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow-sm);
}
.chunk-meta {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
    font-size: 12px;
}
.chunk-text {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.65;
}

/* === Results Box === */
.result-box {
    margin-top: 20px;
    padding: 20px;
    border-radius: var(--radius);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
}
.result-box ul { margin-top: 10px; padding-left: 20px; }
.result-box li { font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; line-height: 1.5; }
.result-success { border-color: rgba(52,211,153,.25); background: linear-gradient(135deg, rgba(52,211,153,.06) 0%, var(--bg-tertiary) 100%); }
.result-error { border-color: rgba(248,113,113,.25); background: linear-gradient(135deg, rgba(248,113,113,.06) 0%, var(--bg-tertiary) 100%); }
.result-label { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.result-answer { white-space: pre-wrap; line-height: 1.75; font-size: 14px; }
.result-sources { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.result-sources h4 { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.result-sources ul { padding-left: 16px; }
.result-sources li { font-size: 13px; margin-bottom: 6px; }

/* === Text helpers === */
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.link { color: var(--accent); transition: color var(--transition); }
.link:hover { color: var(--accent-hover); }

/* === Code === */
code, pre { font-family: var(--font-mono); }
code {
    background: var(--bg-tertiary);
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 12px;
    border: 1px solid var(--border);
    color: var(--accent);
}
pre {
    background: var(--bg-tertiary);
    padding: 18px;
    border-radius: var(--radius);
    overflow-x: auto;
    border: 1px solid var(--border);
    font-size: 13px;
    line-height: 1.6;
}
pre code { padding: 0; background: none; border: none; color: var(--text-secondary); }

/* === API list === */
.api-list { list-style: none; padding: 0; }
.api-list li {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-secondary);
}
.api-list li:last-child { border-bottom: none; }

/* === Filter form === */
.filter-form { display: flex; gap: 8px; align-items: center; }
.filter-form input,
.filter-form select {
    padding: 8px 14px;
    font-size: 13px;
    min-width: 200px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: var(--font);
}
.filter-form input:focus,
.filter-form select:focus { outline: none; border-color: var(--accent); }

/* ================================================================
   LOGIN PAGE
   ================================================================ */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background:
        radial-gradient(ellipse at 50% 0%, rgba(91,159,255,.08) 0%, transparent 60%),
        var(--bg-primary);
}
.login-container { max-width: 440px; width: 100%; padding: 20px; }
.login-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    padding: 48px 40px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}
.login-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--accent-gradient);
}
.login-logo { text-align: center; margin-bottom: 36px; }
.login-logo h1 {
    font-size: 30px;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}
.login-logo p { color: var(--text-muted); font-size: 14px; margin-top: 6px; }

/* ================================================================
   ADMIN LAYOUT
   ================================================================ */
.admin-body { overflow: hidden; }
.admin-wrapper { display: flex; height: 100vh; }

.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.sidebar-logo {
    padding: 24px 24px 20px;
    border-bottom: 1px solid var(--border);
}
.sidebar-logo h2 {
    font-size: 20px;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}
.sidebar-menu { list-style: none; padding: 12px 10px; flex: 1; }
.sidebar-menu li { margin-bottom: 2px; }
.sidebar-menu li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 500;
    transition: all var(--transition);
    text-decoration: none;
    border-radius: var(--radius);
}
.sidebar-menu li a:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.sidebar-menu li a.active {
    background: var(--accent-glow);
    color: var(--accent);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--accent);
}
.sidebar-divider { height: 1px; background: var(--border); margin: 10px 16px; }

.admin-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: var(--bg-primary);
}
.admin-header {
    padding: 20px 36px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(10px);
}
.admin-header h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.01em;
}
.admin-user {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    background: var(--bg-tertiary);
    padding: 6px 14px;
    border-radius: 100px;
    border: 1px solid var(--border);
}
.admin-content { padding: 28px 36px; flex: 1; }

/* ================================================================
   FRONTEND
   ================================================================ */
.frontend-body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(ellipse at 50% -10%, rgba(91,159,255,.07) 0%, transparent 55%),
        radial-gradient(ellipse at 80% 80%, rgba(124,111,255,.04) 0%, transparent 40%),
        var(--bg-primary);
}
.frontend-container {
    max-width: 820px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}
.frontend-header {
    text-align: center;
    padding: 80px 20px 40px;
}
.frontend-header h1 {
    font-size: 42px;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 12px;
    letter-spacing: -0.03em;
    line-height: 1.1;
}
.frontend-header .subtitle {
    color: var(--text-muted);
    font-size: 16px;
    font-weight: 400;
    letter-spacing: 0.01em;
}
.frontend-main { flex: 1; }

.ask-form { margin-bottom: 28px; }
.ask-input-wrap { position: relative; }
.ask-input-wrap textarea {
    width: 100%;
    padding: 20px 110px 20px 22px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 15px;
    font-family: var(--font);
    resize: vertical;
    min-height: 88px;
    transition: all var(--transition);
    box-shadow: var(--shadow);
    line-height: 1.6;
}
.ask-input-wrap textarea::placeholder { color: var(--text-muted); }
.ask-input-wrap textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--shadow), 0 0 0 3px var(--accent-dim), var(--shadow-glow);
}
.btn-ask {
    position: absolute;
    right: 12px;
    bottom: 12px;
    padding: 12px 28px;
    border-radius: var(--radius);
    font-size: 14px;
}

.answer-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    padding: 32px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    animation: answerFadeIn 0.4s ease-out;
    position: relative;
    overflow: hidden;
}
.answer-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--accent-gradient);
}
@keyframes answerFadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
.answer-header { margin-bottom: 18px; padding-top: 4px; }
.answer-badge { display: inline-block; }
.answer-body {
    font-size: 15px;
    line-height: 1.85;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
}
.answer-sources {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}
.answer-sources h4 {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 14px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.source-item {
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    font-size: 13px;
    transition: all var(--transition);
    background: var(--bg-tertiary);
}
.source-item:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow-sm);
}
.source-item strong { color: var(--text-primary); font-weight: 600; }
.source-snippet {
    color: var(--text-muted);
    margin-top: 6px;
    font-size: 12px;
    line-height: 1.5;
}

.feedback-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.feedback-section summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    transition: color var(--transition);
    padding: 4px 0;
}
.feedback-section summary:hover { color: var(--text-secondary); }
.feedback-form { margin-top: 16px; }
.feedback-form .form-group { margin-bottom: 12px; }

/* ================================================================
   CHAT INTERFACE
   ================================================================ */
.chat-body {
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
}
.chat-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* --- Chat Sidebar --- */
.chat-sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
}
.chat-sidebar-header {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.chat-sidebar-header h2 {
    font-size: 18px;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
}
.chat-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}
.btn-new-chat {
    display: block;
    text-align: center;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px dashed var(--border-light);
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: all var(--transition);
    margin-bottom: 24px;
}
.btn-new-chat:hover {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}
.chat-sidebar-info { flex: 1; }
.chat-lang-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.lang-dot {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    padding: 6px 10px;
    border-radius: 6px;
    transition: all var(--transition);
}
.lang-dot:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.lang-dot::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}
.lang-dot-php::before { background: #777bb4; }
.lang-dot-html::before { background: #e34c26; }
.lang-dot-css::before { background: #264de4; }
.lang-dot-js::before { background: #f7df1e; }
.lang-dot-py::before { background: #3776ab; }
.lang-dot-sql::before { background: #00758f; }
.chat-sidebar-footer {
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.chat-admin-link {
    display: block;
    text-align: center;
    padding: 8px;
    font-size: 12px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 6px;
    transition: all var(--transition);
}
.chat-admin-link:hover {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* --- Chat Main Area --- */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 32px 24px;
    scroll-behavior: smooth;
}

/* --- Welcome Screen --- */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 60vh;
    padding: 40px 20px;
}
.chat-welcome-icon {
    font-size: 48px;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 20px;
    font-family: var(--font-mono);
    background: var(--accent-dim);
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid rgba(91,159,255,.2);
}
.chat-welcome h2 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 10px;
}
.chat-welcome p {
    font-size: 15px;
    color: var(--text-muted);
    margin-bottom: 32px;
    max-width: 440px;
}
.chat-examples {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
    max-width: 640px;
    width: 100%;
}
.chat-example-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    text-align: left;
    font-family: var(--font);
    font-size: 13px;
    color: var(--text-secondary);
    transition: all var(--transition);
}
.chat-example-btn:hover {
    border-color: var(--border-light);
    background: var(--bg-tertiary);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    color: var(--text-primary);
}
.chat-example-icon {
    font-size: 18px;
    flex-shrink: 0;
}

/* --- Chat Messages --- */
.chat-msg {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    max-width: 820px;
    margin-left: auto;
    margin-right: auto;
    animation: msgFadeIn 0.3s ease-out;
}
@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.chat-msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 2px;
}
.chat-msg-user .chat-msg-avatar {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.chat-msg-ai .chat-msg-avatar {
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(91,159,255,.2);
}
.chat-msg-content {
    flex: 1;
    min-width: 0;
}
.chat-msg-text {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-primary);
    background: var(--bg-secondary);
    padding: 14px 18px;
    border-radius: var(--radius) var(--radius-lg) var(--radius-lg) var(--radius-lg);
    border: 1px solid var(--border);
    word-wrap: break-word;
}
.chat-msg-badges {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}
.badge-lang {
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(91,159,255,.2);
}
.badge-mode {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(52,211,153,.2);
}
.chat-msg-time {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    padding-left: 2px;
}

/* --- Chat Code Block --- */
.chat-code-wrap {
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border-light);
    background: #0a0c12;
}
.chat-code-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
}
.code-lang {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.btn-copy {
    padding: 4px 14px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    transition: all var(--transition);
    font-family: var(--font);
}
.btn-copy:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--text-muted);
}
.btn-copy.copied {
    background: var(--success-bg);
    color: var(--success);
    border-color: rgba(52,211,153,.3);
}
.chat-code-block {
    padding: 20px;
    margin: 0;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.7;
    color: #c9d1d9;
    background: #0a0c12;
    border: none;
    border-radius: 0;
    tab-size: 4;
    white-space: pre;
}
.chat-code-block code {
    padding: 0;
    background: none;
    border: none;
    color: inherit;
    font-size: inherit;
}

/* --- Chat Input Bar --- */
.chat-input-bar {
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}
.chat-form { max-width: 820px; margin: 0 auto; }
.chat-input-wrap {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
    transition: all var(--transition);
}
.chat-input-wrap:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim), var(--shadow-glow);
}
.chat-input-wrap textarea {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font);
    resize: none;
    padding: 8px 4px;
    min-height: 24px;
    max-height: 200px;
    line-height: 1.5;
    outline: none;
}
.chat-input-wrap textarea::placeholder { color: var(--text-muted); }
.btn-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--accent-gradient);
    color: white;
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--transition);
}
.btn-send:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-glow);
}
.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}
.chat-input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 0 4px;
}
.chat-hint {
    font-size: 11px;
    color: var(--text-muted);
}
.chat-clear-link {
    font-size: 11px;
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition);
}
.chat-clear-link:hover { color: var(--accent); }

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 768px) {
    .admin-wrapper { flex-direction: column; }
    .sidebar {
        width: 100%;
        min-width: unset;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .sidebar-logo { padding: 16px 20px; }
    .sidebar-menu {
        display: flex;
        flex-wrap: wrap;
        padding: 8px;
        gap: 4px;
    }
    .sidebar-menu li { margin-bottom: 0; }
    .sidebar-menu li a {
        padding: 8px 12px;
        font-size: 12px;
        border-radius: 8px;
    }
    .sidebar-menu li a.active { box-shadow: inset 0 -2px 0 var(--accent); }
    .sidebar-divider { display: none; }
    .admin-content { padding: 20px 16px; }
    .admin-header { padding: 16px; }
    .admin-header h1 { font-size: 17px; }
    .grid-2 { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-row { flex-direction: column; }
    .table td, .table th { padding: 10px 12px; }

    /* Chat responsive */
    .chat-sidebar { display: none; }
    .chat-messages { padding: 20px 16px; }
    .chat-input-bar { padding: 12px 16px 16px; }
    .chat-examples { grid-template-columns: 1fr; }
    .chat-welcome h2 { font-size: 22px; }
    .chat-welcome-icon { width: 60px; height: 60px; font-size: 32px; }
    .chat-code-block { font-size: 12px; padding: 14px; }
    .chat-msg { gap: 8px; }
    .chat-msg-avatar { width: 30px; height: 30px; font-size: 10px; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .card { padding: 20px 16px; }
    .grid-2 { grid-template-columns: 1fr; }
    .chat-input-wrap { padding: 6px 8px; }
    .chat-input-wrap textarea { font-size: 13px; }
    .btn-send { width: 36px; height: 36px; }
    .chat-example-btn { padding: 10px 12px; font-size: 12px; }
}
