:root {
    --bg: #0f0f13;
    --bg2: #1a1a23;
    --bg3: #25253a;
    --border: #2a2a3e;
    --text: #e4e4ec;
    --text2: #9090a8;
    --primary: #7c3aed;
    --primary-hover: #6d28d9;
    --primary-light: #a78bfa;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #22c55e;
    --user-bubble: #7c3aed;
    --ai-bubble: #25253a;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* ── Auth ── */
.auth-wrapper {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 20px;
}
.auth-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%; max-width: 420px;
    box-shadow: var(--shadow);
}
.auth-header { text-align: center; margin-bottom: 28px; }
.auth-header h1 { font-size: 28px; color: var(--primary-light); margin-bottom: 4px; }
.auth-header p { color: var(--text2); font-size: 14px; }
.auth-error {
    background: rgba(239,68,68,0.15);
    color: var(--danger);
    padding: 10px 14px; border-radius: var(--radius-sm);
    margin-bottom: 16px; font-size: 13px;
}
.auth-form { display: none; }
.auth-form.active { display: block; }
.auth-form h2 { font-size: 18px; margin-bottom: 16px; color: var(--text); }

/* ── Forms ── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 4px; }
.form-group input, .form-group textarea, .form-group select {
    width: 100%; padding: 10px 12px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text);
    font-size: 14px; outline: none; transition: border-color 0.15s;
}
.form-group input:focus, .form-group textarea:focus { border-color: var(--primary); }
.form-group textarea { resize: vertical; font-family: inherit; }
.form-footer { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text2); }
.form-footer a { color: var(--primary-light); text-decoration: none; }
.form-footer a:hover { text-decoration: underline; }
.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; }
.form-actions { display: flex; gap: 8px; align-items: center; }

.toggle-row {
    display: flex; align-items: center; gap: 6px;
    font-size: 13px; color: var(--text2); cursor: pointer;
}
.toggle-row input[type="checkbox"] { accent-color: var(--primary); }

/* ── Buttons ── */
.btn {
    padding: 10px 20px; border: none; border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 500; cursor: pointer;
    transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg3); }
.btn-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Layout ── */
.app-layout { display: flex; height: 100vh; }
.sidebar {
    width: 280px; min-width: 280px;
    background: var(--bg2); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; overflow-y: auto;
}
.sidebar-header { padding: 16px 16px 12px; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { font-size: 16px; color: var(--primary-light); }
.user-badge { font-size: 12px; color: var(--text2); margin-top: 2px; display: block; }
.sidebar-section { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.sidebar-section h3 { font-size: 11px; text-transform: uppercase; color: var(--text2); margin-bottom: 8px; letter-spacing: 0.5px; }
.sidebar-footer { padding: 12px 16px; display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }

.char-item, .conv-item {
    padding: 8px 10px; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 13px; margin-bottom: 4px;
    transition: background 0.15s; position: relative;
}
.char-item:hover, .conv-item:hover { background: var(--bg3); }
.char-item.active, .conv-item.active { background: var(--primary); color: white; }
.char-item .char-name { font-weight: 500; }
.char-item .char-greeting { font-size: 11px; color: var(--text2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.char-item.active .char-greeting { color: rgba(255,255,255,0.7); }
.char-item .char-actions { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); opacity: 0; transition: opacity 0.15s; }
.char-item:hover .char-actions { opacity: 1; }
.char-actions .char-card-view { font-size: 14px; cursor: pointer; color: var(--text2); padding: 2px 4px; }
.char-actions .char-card-view:hover { color: var(--primary-light); }
.conv-item { display: flex; justify-content: space-between; align-items: center; }
.conv-item .conv-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .conv-delete { font-size: 11px; opacity: 0; transition: opacity 0.15s; color: var(--danger); }
.conv-item:hover .conv-delete { opacity: 1; }

/* ── Chat ── */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; color: var(--text2);
}
.chat-empty .empty-icon { font-size: 48px; margin-bottom: 16px; }
.chat-empty h2 { font-size: 20px; margin-bottom: 8px; color: var(--text); }
.chat-active { display: flex; flex-direction: column; height: 100%; }
.chat-header { padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--bg2); }
.chat-header h3 { font-size: 16px; }
.chat-messages {
    flex: 1; overflow-y: auto; padding: 20px;
    display: flex; flex-direction: column; gap: 12px;
}
.message { max-width: 75%; padding: 12px 16px; border-radius: 16px; font-size: 14px; line-height: 1.5; word-wrap: break-word; }
.message.user { align-self: flex-end; background: var(--user-bubble); color: white; border-bottom-right-radius: 4px; }
.message.assistant { align-self: flex-start; background: var(--ai-bubble); color: var(--text); border-bottom-left-radius: 4px; }
.message .media-badge { font-size: 11px; margin-bottom: 4px; opacity: 0.7; }
.message img, .message audio { max-width: 100%; border-radius: 8px; margin-top: 6px; }

.chat-input-area { padding: 12px 20px 16px; border-top: 1px solid var(--border); background: var(--bg2); }
.chat-input-row { display: flex; gap: 8px; align-items: center; }
.chat-input {
    flex: 1; padding: 10px 14px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 20px; color: var(--text); font-size: 14px;
    outline: none; transition: border-color 0.15s;
}
.chat-input:focus { border-color: var(--primary); }
.attach-btn {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--bg); border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 18px; color: var(--text2);
    transition: all 0.15s;
}
.attach-btn:hover { background: var(--bg3); color: var(--text); }
.chat-actions { display: flex; gap: 16px; margin-top: 8px; padding-left: 4px; }
.attach-preview { padding: 8px 0; font-size: 12px; color: var(--text2); }

/* ── Modal ── */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-content { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; width: 90%; max-width: 800px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); position: relative; }
.modal-close { position: absolute; top: 12px; right: 16px; font-size: 24px; cursor: pointer; color: var(--text2); }
.modal-close:hover { color: var(--text); }
.admin-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.admin-tab { padding: 8px 16px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text2); cursor: pointer; font-size: 13px; }
.admin-tab.active { background: var(--primary); color: white; border-color: var(--primary); }
.admin-panel { display: none; }
.admin-panel.active { display: block; }
.admin-panel h3 { font-size: 16px; margin-bottom: 12px; }
.admin-panel h4 { font-size: 14px; margin: 16px 0 8px; color: var(--text2); }
.admin-form { margin-top: 8px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 12px; }
.data-table th, .data-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--text2); font-weight: 500; }
.data-table tr:hover td { background: var(--bg3); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat-card { background: var(--bg3); padding: 16px; border-radius: var(--radius-sm); text-align: center; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--primary-light); }
.stat-card .stat-label { font-size: 12px; color: var(--text2); margin-top: 4px; }

/* ── Loading ── */
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.typing { animation: pulse 1.4s infinite; }

/* ── Card Modal ── */
.card-modal-content { max-width: 580px; }
.card-modal-content h2 { font-size: 20px; margin-bottom: 12px; color: var(--primary-light); }
.card-avatar { width: 80px; height: 80px; border-radius: 50%; margin-bottom: 12px; object-fit: cover; }
.card-section { margin-bottom: 12px; }
.card-section h4 { font-size: 12px; text-transform: uppercase; color: var(--text2); margin-bottom: 4px; letter-spacing: 0.3px; }
.card-section p, .card-section pre { font-size: 13px; line-height: 1.5; color: var(--text); }
.card-section pre { white-space: pre-wrap; background: var(--bg); padding: 8px; border-radius: var(--radius-sm); margin: 0; }

/* ── Utilities ── */
.hidden { display: none !important; }
