/* ============================================================
   bizLM — Main Stylesheet
   ============================================================ */

/* ── CSS Variables ───────────────────────────────────────── */
:root {
  --primary:        #6366f1;
  --primary-dark:   #4f46e5;
  --primary-light:  #a5b4fc;
  --primary-bg:     #eef2ff;
  --secondary:      #10b981;
  --danger:         #ef4444;
  --warning:        #f59e0b;
  --info:           #3b82f6;

  --sidebar-bg:     #1e1b4b;
  --sidebar-hover:  rgba(255,255,255,0.08);
  --sidebar-active: rgba(99,102,241,0.3);
  --sidebar-text:   #c7d2fe;
  --sidebar-muted:  #818cf8;

  --navbar-bg:      #ffffff;
  --navbar-border:  #e2e8f0;
  --navbar-h:       60px;

  --bg:             #f8fafc;
  --card-bg:        #ffffff;
  --border:         #e2e8f0;
  --border-focus:   #6366f1;

  --text:           #1e293b;
  --text-muted:     #64748b;
  --text-light:     #94a3b8;

  --radius-sm:      6px;
  --radius:         10px;
  --radius-lg:      16px;
  --radius-xl:      24px;
  --radius-full:    9999px;

  --shadow-sm:      0 1px 2px rgba(0,0,0,.06);
  --shadow:         0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:      0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
  --shadow-lg:      0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
  --shadow-xl:      0 20px 25px -5px rgba(0,0,0,.1), 0 10px 10px -5px rgba(0,0,0,.04);

  --transition:     0.18s ease;
  --transition-md:  0.25s ease;

  --sidebar-w:      240px;
  --font:           'Inter', system-ui, -apple-system, sans-serif;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

img { max-width: 100%; height: auto; display: block; }

h1,h2,h3,h4,h5,h6 { line-height: 1.3; font-weight: 600; color: var(--text); }
h1 { font-size: 1.875rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.0625rem; }

p { color: var(--text-muted); line-height: 1.7; }

ul, ol { padding-left: 1.25rem; }

hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

/* ── Layout: App Shell ───────────────────────────────────── */
.layout-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-body {
  display: flex;
  flex: 1;
  min-height: calc(100vh - var(--navbar-h));
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: var(--navbar-h);
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
  transition: transform var(--transition-md);
}

.sidebar-section { padding: 1.25rem 0 0.5rem; }

.sidebar-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
  padding: 0 1rem 0.5rem;
}

.sidebar-nav { list-style: none; padding: 0; }

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 1rem;
  color: var(--sidebar-text);
  font-size: 0.875rem;
  font-weight: 450;
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
}

.sidebar-nav li a:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar-nav li a.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 500;
}

.sidebar-nav li a svg { flex-shrink: 0; opacity: .75; }
.sidebar-nav li a.active svg { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,.08);
}

.sidebar-plan {
  background: rgba(99,102,241,.2);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

.sidebar-plan-label {
  font-size: 11px;
  color: var(--sidebar-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.sidebar-plan-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--primary-light);
  margin-top: 2px;
}

/* ── Main Content ────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  padding: 2rem;
  margin-top: var(--navbar-h);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Navbar ──────────────────────────────────────────────── */
.navbar {
  height: var(--navbar-h);
  background: var(--navbar-bg);
  border-bottom: 1px solid var(--navbar-border);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  box-shadow: var(--shadow-sm);
}

.navbar-brand { flex-shrink: 0; }

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
}

.brand-icon {
  color: var(--primary);
  font-size: 1.25rem;
  letter-spacing: -2px;
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.03em;
}

.navbar-center { flex: 1; max-width: 500px; margin: 0 auto; }

.global-search {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 0 0.875rem;
  gap: 0.5rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.global-search:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

.global-search .search-icon { color: var(--text-muted); font-size: 0.875rem; }

.global-search input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  padding: 0.5rem 0;
  font-size: 0.875rem;
  font-family: var(--font);
  color: var(--text);
}

.navbar-end {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.nav-icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}

.nav-icon-btn:hover { background: var(--bg); color: var(--text); }

/* ── User Menu ───────────────────────────────────────────── */
.nav-user-menu { position: relative; }

.user-avatar-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  overflow: hidden;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--transition);
}

.user-avatar-btn:hover { opacity: .85; }

.avatar-img { width: 100%; height: 100%; object-fit: cover; }

.avatar-initials {
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.02em;
}

.avatar-sm {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 220px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: 0.5rem 0;
  display: none;
  z-index: 300;
}

.user-dropdown.open { display: block; animation: fadeInDown .15s ease; }

.dropdown-header { padding: 0.75rem 1rem; }

.dropdown-name { display: block; font-weight: 600; font-size: 0.875rem; }

.dropdown-email { display: block; font-size: 0.75rem; color: var(--text-muted); margin-top: 1px; }

.dropdown-divider { border-color: var(--border); margin: 0.375rem 0; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  color: var(--text);
  transition: background var(--transition);
}

.dropdown-item:hover { background: var(--bg); color: var(--text); }

.dropdown-item-danger { color: var(--danger) !important; }
.dropdown-item-danger:hover { background: #fef2f2; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 1.125rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.card-title { font-size: 0.9375rem; font-weight: 600; }

.card-body { padding: 1.25rem; }

.card-footer {
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* ── Notebook Cards ──────────────────────────────────────── */
.notebooks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.notebook-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: box-shadow var(--transition), transform var(--transition);
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.notebook-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.notebook-card-color {
  height: 6px;
  flex-shrink: 0;
}

.notebook-card-body {
  padding: 1.125rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.notebook-card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.375rem;
  line-height: 1.4;
}

.notebook-card-desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.5;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.notebook-card-footer {
  padding: 0.75rem 1.125rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
}

.notebook-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.notebook-meta-item {
  display: flex;
  align-items: center;
  gap: 3px;
}

.notebook-actions { display: flex; gap: 0.25rem; }

/* ── Stat Cards ──────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  margin-bottom: 0.875rem;
}

.stat-value { font-size: 2rem; font-weight: 700; color: var(--text); line-height: 1; }

.stat-label { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
  outline: none;
}

.btn:focus-visible { box-shadow: 0 0 0 3px rgba(99,102,241,.35); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }

.btn-secondary {
  background: var(--card-bg);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { background: #dc2626; color: #fff; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-sm { padding: 0.325rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-icon { padding: 0.5rem; border-radius: var(--radius); }

.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.375rem;
}

.form-label .required { color: var(--danger); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 0.5625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--card-bg);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

.form-control::placeholder { color: var(--text-light); }

.form-control.is-invalid { border-color: var(--danger); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px rgba(239,68,68,.15); }

textarea.form-control { resize: vertical; min-height: 100px; }

select.form-control { cursor: pointer; }

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.3125rem;
}

.form-error {
  font-size: 0.75rem;
  color: var(--danger);
  margin-top: 0.3125rem;
  display: flex;
  align-items: center;
  gap: 3px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.input-group {
  display: flex;
  align-items: stretch;
}

.input-group .form-control { border-radius: var(--radius) 0 0 var(--radius); }
.input-group .input-addon {
  padding: 0 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  white-space: nowrap;
}

.input-prefix {
  padding: 0 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  font-size: 0.875rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  white-space: nowrap;
}
.input-prefix + .form-control { border-radius: 0 var(--radius) var(--radius) 0; }

.form-check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.form-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin-top: 1px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.form-check-label { font-size: 0.875rem; color: var(--text-muted); cursor: pointer; }

/* ── Alerts / Flash ──────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1.25rem;
  border: 1px solid transparent;
}

.alert-success { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.alert-error   { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.alert-warning { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.alert-info    { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }

.alert-close {
  background: none;
  border: none;
  cursor: pointer;
  opacity: .6;
  font-size: 1.125rem;
  line-height: 1;
  color: inherit;
  flex-shrink: 0;
}
.alert-close:hover { opacity: 1; }

/* ── Badges / Tags ───────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1875rem 0.625rem;
  border-radius: var(--radius-full);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.badge-primary { background: var(--primary-bg); color: var(--primary-dark); }
.badge-success { background: #f0fdf4; color: #15803d; }
.badge-danger  { background: #fef2f2; color: #b91c1c; }
.badge-warning { background: #fffbeb; color: #b45309; }
.badge-muted   { background: #f1f5f9; color: var(--text-muted); }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: default;
}

/* ── Tables ──────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--bg); }

/* ── Modals ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-md);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--card-bg);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  transform: translateY(12px) scale(.98);
  transition: transform var(--transition-md);
}

.modal-overlay.open .modal { transform: none; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 1rem; font-weight: 700; }

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 1.25rem;
  transition: background var(--transition);
}

.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body { padding: 1.5rem; }

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  background: var(--bg);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* ── Notebook View (3-panel) ─────────────────────────────── */
.notebook-layout {
  display: grid;
  grid-template-columns: 260px 1fr 380px;
  height: calc(100vh - var(--navbar-h));
  overflow: hidden;
  margin-top: var(--navbar-h);
}

.nb-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
}

.nb-panel:last-child { border-right: none; }

.nb-panel-header {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
}

.nb-panel-title {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}

.nb-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}

/* Sources Panel */
.source-item {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 2px;
}

.source-item:hover { background: var(--bg); }
.source-item.active { background: var(--primary-bg); }

.source-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  flex-shrink: 0;
  font-weight: 700;
  color: #fff;
}

.source-icon-pdf      { background: #ef4444; }
.source-icon-text     { background: #6366f1; }
.source-icon-url      { background: #3b82f6; }
.source-icon-youtube  { background: #ef4444; }

.source-info { min-width: 0; flex: 1; }

.source-title {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-meta { font-size: 0.6875rem; color: var(--text-muted); margin-top: 1px; }

/* Notes Panel */
.note-editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--card-bg);
}

.note-title-input {
  width: 100%;
  border: none;
  outline: none;
  font-size: 1.25rem;
  font-weight: 700;
  font-family: var(--font);
  color: var(--text);
  padding: 1.25rem 1.25rem 0.5rem;
  background: transparent;
  line-height: 1.3;
}

.note-title-input::placeholder { color: var(--border); }

.quill-wrapper { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

.ql-toolbar.ql-snow {
  border: none !important;
  border-bottom: 1px solid var(--border) !important;
  padding: 0.375rem 0.75rem !important;
  background: var(--bg);
}

.ql-container.ql-snow {
  border: none !important;
  font-size: 0.9375rem;
  font-family: var(--font);
  flex: 1;
  overflow-y: auto;
}

.ql-editor { padding: 1.25rem; min-height: 200px; }

.note-actions-bar {
  padding: 0.5rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--bg);
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.notes-list {
  border-top: 1px solid var(--border);
  max-height: 240px;
  overflow-y: auto;
}

.note-list-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.note-list-item:hover { background: var(--bg); }
.note-list-item.active { background: var(--primary-bg); }

.note-list-item:last-child { border-bottom: none; }

.note-list-title {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-list-meta { font-size: 0.6875rem; color: var(--text-muted); flex-shrink: 0; }

/* Chat Panel */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.chat-message {
  display: flex;
  gap: 0.625rem;
  animation: fadeInUp .2s ease;
}

.chat-message.user { flex-direction: row-reverse; }

.chat-bubble {
  max-width: 80%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  line-height: 1.6;
}

.chat-message.user .chat-bubble {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
}

.chat-message.assistant .chat-bubble {
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.chat-bubble p { color: inherit; margin-bottom: 0.5rem; }
.chat-bubble p:last-child { margin-bottom: 0; }

.chat-bubble strong { font-weight: 600; }

.chat-timestamp {
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-align: center;
  margin: 0.25rem 0;
}

.chat-input-area {
  padding: 0.875rem;
  border-top: 1px solid var(--border);
  background: var(--card-bg);
  flex-shrink: 0;
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-bottom: 0.75rem;
}

.chat-suggestion {
  background: var(--primary-bg);
  color: var(--primary);
  border: 1px solid var(--primary-light);
  border-radius: var(--radius-full);
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background var(--transition);
}

.chat-suggestion:hover { background: var(--primary); color: #fff; }

.chat-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.chat-textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  font-family: var(--font);
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  transition: border-color var(--transition);
}

.chat-textarea:focus { border-color: var(--primary); }

.chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: background var(--transition);
  flex-shrink: 0;
}

.chat-send-btn:hover { background: var(--primary-dark); }

.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.625rem 1rem;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }

/* ── Auth Pages ──────────────────────────────────────────── */
.layout-auth {
  min-height: 100vh;
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4338ca 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.auth-card {
  background: var(--card-bg);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 460px;
  overflow: hidden;
}

.auth-header {
  padding: 2rem 2rem 1.5rem;
  text-align: center;
}

.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  margin-bottom: 1.5rem;
}

.auth-logo-icon {
  color: var(--primary);
  font-size: 1.5rem;
  letter-spacing: -3px;
}

.auth-logo-text {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.04em;
}

.auth-title { font-size: 1.375rem; font-weight: 700; color: var(--text); }

.auth-subtitle { font-size: 0.875rem; color: var(--text-muted); margin-top: 0.375rem; }

.auth-body { padding: 0 2rem 2rem; }

.auth-footer {
  padding: 1.125rem 2rem;
  background: var(--bg);
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ── Activity Feed ───────────────────────────────────────── */
.activity-feed { list-style: none; padding: 0; }

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.activity-item:last-child { border-bottom: none; }

.activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  margin-top: 5px;
  flex-shrink: 0;
}

.activity-text { font-size: 0.875rem; color: var(--text); flex: 1; }
.activity-time { font-size: 0.75rem; color: var(--text-muted); flex-shrink: 0; }

/* ── Source Tabs (Add Source Modal) ──────────────────────── */
.source-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.source-tab {
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: var(--font);
}

.source-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.source-tab-content { display: none; }
.source-tab-content.active { display: block; }

/* ── File Drop Zone ──────────────────────────────────────── */
.file-drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.75rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  min-height: 120px;
}

.file-drop-zone:hover  { border-color: var(--primary); background: var(--primary-bg); }
.file-drop-zone:hover svg { color: var(--primary) !important; }
.file-drop-zone.has-file { border-color: var(--secondary); background: #f0fdf4; }

.file-drop-text {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.file-drop-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.file-name-display {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--secondary);
  margin-top: 0.25rem;
  word-break: break-all;
}

/* ── Color Picker ────────────────────────────────────────── */
.color-picker { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform var(--transition);
}

.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: #fff; box-shadow: 0 0 0 2px var(--text); }

/* ── Search & Filters ────────────────────────────────────── */
.search-bar {
  display: flex;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 0.875rem;
  gap: 0.5rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-bar:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

.search-bar input {
  border: none;
  background: transparent;
  outline: none;
  padding: 0.5625rem 0;
  font-size: 0.875rem;
  font-family: var(--font);
  color: var(--text);
  width: 100%;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 0.375rem 0.875rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
}

.filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── Pagination ──────────────────────────────────────────── */
.pagination { display: flex; justify-content: center; margin-top: 2rem; }

.pagination ul {
  display: flex;
  list-style: none;
  gap: 0.25rem;
  padding: 0;
}

.pagination li a,
.pagination li.active span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 0.875rem;
  color: var(--text);
  transition: all var(--transition);
}

.pagination li a:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }

.pagination li.active a {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ── Dropdown (generic) ──────────────────────────────────── */
.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 160px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 400;
  display: none;
  padding: 0.375rem 0;
}

.dropdown-menu.open { display: block; animation: fadeInDown .12s ease; }

.dropdown-menu a, .dropdown-menu button {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.5rem 0.875rem;
  font-size: 0.8125rem;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  text-align: left;
  transition: background var(--transition);
  text-decoration: none;
}

.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--bg); }

.dropdown-menu .danger { color: var(--danger); }
.dropdown-menu .danger:hover { background: #fef2f2; }

/* ── Empty States ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-muted);
}

.empty-state-icon { font-size: 3rem; margin-bottom: 1rem; opacity: .4; }

.empty-state h3 { font-size: 1.0625rem; color: var(--text); margin-bottom: 0.5rem; }

.empty-state p { font-size: 0.875rem; max-width: 320px; margin: 0 auto 1.25rem; }

/* ── Profile / Settings ──────────────────────────────────── */
.avatar-upload {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.avatar-preview {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
  flex-shrink: 0;
  border: 3px solid var(--border);
}

.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }

/* ── Source Preview ──────────────────────────────────────── */
.source-content-view {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  font-size: 0.9375rem;
  line-height: 1.8;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 600px;
  overflow-y: auto;
}

/* ── Tab Nav ─────────────────────────────────────────────── */
.tab-nav {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.tab-nav-item {
  padding: 0.75rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  text-decoration: none;
}

.tab-nav-item:hover { color: var(--text); }
.tab-nav-item.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Loading Spinner ─────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

.spinner-dark {
  border-color: rgba(99,102,241,.2);
  border-top-color: var(--primary);
}

/* ── Tooltip ─────────────────────────────────────────────── */
[data-tooltip] { position: relative; }

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  font-size: 0.6875rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  z-index: 600;
}

[data-tooltip]:hover::after { opacity: 1; }

/* ── Misc Utility ────────────────────────────────────────── */
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-muted { color: var(--text-muted); }
.text-small { font-size: 0.8125rem; }
.fw-600 { font-weight: 600; }
.mb-0 { margin-bottom: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

/* ── Animations ──────────────────────────────────────────── */
@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: none; }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* ── Notebook Color Strip ────────────────────────────────── */
.color-strip { height: 4px; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1200px) {
  .notebook-layout {
    grid-template-columns: 240px 1fr 340px;
  }
}

@media (max-width: 1024px) {
  :root { --sidebar-w: 220px; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-w)));
  }
  .sidebar.open { transform: none; }

  .main-content { margin-left: 0; padding: 1.25rem; }

  .notebook-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }

  .nb-panel:not(.active) { display: none; }

  .form-row { grid-template-columns: 1fr; }

  .stats-grid { grid-template-columns: 1fr 1fr; }

  .global-search { display: none; }

  .auth-card { max-width: 100%; }
  .auth-body, .auth-header { padding-left: 1.25rem; padding-right: 1.25rem; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .notebooks-grid { grid-template-columns: 1fr; }
}
