:root {
    --primary: #1e293b;
    --accent: #3b82f6;
    --bg: #f8fafc;
    --border: #e2e8f0;
    --gold: #d97706;
    --surface: #ffffff;
    --danger: #ef4444;
    --success: #16a34a;
    --text: #334155;
    --text-dim: #64748b;
    --font: 'Assistant', 'Heebo', sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---------------------------------------------------------------- Header */

header {
    background: var(--surface);
    height: 68px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    justify-content: space-between;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
    flex-shrink: 0;
}

.logo {
    font-weight: 800;
    font-size: 1.3rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: -0.5px;
}
.logo i { color: var(--accent); }

.header-right { display: flex; align-items: center; gap: 14px; }

.notebook-picker {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 10px;
}
.notebook-picker i { color: var(--text-dim); font-size: 13px; }
.notebook-picker select {
    border: none;
    background: transparent;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    max-width: 220px;
    outline: none;
}

.auth-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 20px;
    background: #f1f5f9;
    color: var(--text-dim);
}
.auth-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); }
.auth-badge.ok { background: #f0fdf4; color: var(--success); }
.auth-badge.ok .dot { background: var(--success); }
.auth-badge.bad { background: #fef2f2; color: var(--danger); }
.auth-badge.bad .dot { background: var(--danger); }

/* ----------------------------------------------------------------- Layout */

.main { display: flex; flex: 1; overflow: hidden; }

nav.sidebar {
    width: 230px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 10px;
    color: var(--text-dim);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}
.nav-item i { width: 18px; text-align: center; }
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary); color: white; }

.content { flex: 1; overflow-y: auto; padding: 32px 40px; }

.page { display: none; max-width: 980px; margin: 0 auto; }
.page.active { display: block; animation: fadein 0.2s ease; }

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

.page-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
    margin: 0 0 6px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.page-title i { color: var(--accent); }
.page-subtitle { color: var(--text-dim); font-size: 14px; margin: 0 0 24px; }

/* ------------------------------------------------------------------ Cards */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px;
    margin-bottom: 18px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
.card h3 {
    margin: 0 0 14px;
    font-size: 15px;
    font-weight: 800;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
}
.card h3 i { color: var(--accent); font-size: 14px; }

/* ------------------------------------------------------------------ Forms */

label { display: block; font-size: 12.5px; font-weight: 700; color: var(--text-dim); margin-bottom: 6px; }
.field { margin-bottom: 14px; }
input[type="text"], input[type="search"], textarea, select.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    font-family: var(--font);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s, background 0.15s;
}
input[type="text"]:focus, input[type="search"]:focus, textarea:focus, select.form-control:focus {
    border-color: var(--accent);
    background: white;
}
textarea { resize: vertical; min-height: 70px; }

.options-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 14px; }

/* ----------------------------------------------------------------- Buttons */

.btn {
    background: white;
    border: 1px solid var(--border);
    padding: 9px 18px;
    border-radius: 9px;
    cursor: pointer;
    font-size: 13.5px;
    font-family: var(--font);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text);
    font-weight: 700;
}
.btn:hover:not(:disabled) { background: #f1f5f9; border-color: #cbd5e1; transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn i, .nav-item i, .list-row .actions i { display: inline-block; min-width: 1em; text-align: center; }
.list-row .actions .btn { min-width: 34px; justify-content: center; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: #334155; box-shadow: 0 4px 12px rgba(30, 41, 59, 0.25); }
.btn-accent { background: var(--accent); color: white; border-color: var(--accent); }
.btn-accent:hover:not(:disabled) { background: #2563eb; box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3); }
.btn-danger { color: var(--danger); border-color: #fca5a5; background: #fef2f2; }
.btn-danger:hover:not(:disabled) { background: #fee2e2; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }

/* ------------------------------------------------------------------- Lists */

.list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 8px;
    background: var(--bg);
    gap: 12px;
}
.list-row .info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.list-row .title { font-weight: 700; font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .meta { font-size: 12px; color: var(--text-dim); }
.list-row .actions { display: flex; gap: 6px; flex-shrink: 0; }
.list-row.selected { border-color: var(--accent); background: #eff6ff; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 6px; font-size: 11px; font-weight: 800; background: #e2e8f0; color: var(--text-dim); }
.badge.gold { background: #fffbeb; color: var(--gold); }
.badge.green { background: #f0fdf4; color: var(--success); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-dim); }
.empty-state i { font-size: 32px; margin-bottom: 10px; opacity: 0.4; display: block; }

/* -------------------------------------------------------------------- Chat */

.chat-log { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; max-height: 420px; overflow-y: auto; }
.chat-bubble { padding: 12px 16px; border-radius: 12px; font-size: 14px; line-height: 1.6; max-width: 90%; }
.chat-bubble.q { background: var(--primary); color: white; align-self: flex-end; border-bottom-left-radius: 4px; }
.chat-bubble.a { background: var(--bg); border: 1px solid var(--border); align-self: flex-start; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.ask-row { display: flex; gap: 10px; }
.ask-row input { flex: 1; }

/* ----------------------------------------------------------------- Toasts */

#toasts { position: fixed; bottom: 20px; left: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; }
.toast {
    background: var(--primary);
    color: white;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 600;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slidein 0.2s ease;
    max-width: 360px;
}
.toast.success { background: #166534; }
.toast.error { background: #991b1b; }
@keyframes slidein { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ---------------------------------------------------------------- Spinner */

.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress-note { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 13px; font-weight: 600; padding: 10px 0; }

.hint { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: 10px; padding: 12px 16px; font-size: 13px; margin-bottom: 18px; display: flex; gap: 10px; align-items: flex-start; }
.hint i { margin-top: 2px; }
