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

:root {
  --primary:   #6366f1;
  --primary-d: #4f46e5;
  --danger:    #ef4444;
  --success:   #22c55e;
  --warning:   #f59e0b;
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --text:      #1e293b;
  --muted:     #64748b;
  --radius:    12px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
}

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

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

.topbar {
  background: linear-gradient(135deg, var(--primary), var(--primary-d));
  color: #fff;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 2px 8px rgba(99,102,241,.4);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-brand svg { width: 24px; height: 24px; }

.main-content {
  flex: 1;
  padding: 28px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ── Breadcrumb ──────────────────────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.breadcrumb-item {
  font-size: .875rem;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  transition: background .15s, color .15s;
  white-space: nowrap;
}

.breadcrumb-item:hover { background: var(--border); color: var(--text); }
.breadcrumb-item.active { color: var(--primary); font-weight: 600; cursor: default; background: none; }

.breadcrumb-sep { color: var(--border); font-size: 1.1rem; }

/* ── Page Header ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 12px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
}

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

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}

.btn:hover { opacity: .88; }
.btn:active { transform: scale(.97); }

.btn-primary  { background: var(--primary); color: #fff; }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-success  { background: var(--success); color: #fff; }
.btn-ghost    { background: transparent; color: var(--muted); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--border); color: var(--text); }
.btn-sm       { padding: 5px 12px; font-size: .8rem; border-radius: 6px; }
.btn-icon     { padding: 6px; border-radius: 7px; }

/* ── View Toggle ─────────────────────────────────────────────────────────── */
.view-toggle {
  display: flex;
  background: var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.view-toggle-btn {
  padding: 5px 12px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background .15s, color .15s;
}

.view-toggle-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
}

/* ── Entity Grid Cards ───────────────────────────────────────────────────── */
.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}

.entity-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  cursor: pointer;
  transition: box-shadow .2s, transform .15s;
  border: 1.5px solid transparent;
  position: relative;
}

.entity-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  border-color: var(--primary);
}

.entity-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  margin-bottom: 14px;
}

.entity-card-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.entity-card-desc {
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: 14px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.entity-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.entity-card-badge {
  font-size: .75rem;
  font-weight: 600;
  color: var(--primary);
  background: rgba(99,102,241,.1);
  padding: 3px 10px;
  border-radius: 999px;
}

.entity-card-actions {
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity .15s;
}

.entity-card:hover .entity-card-actions { opacity: 1; }

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead { background: #f8fafc; }
thead th {
  padding: 13px 18px;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  text-align: left;
  border-bottom: 1.5px solid var(--border);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

tbody td {
  padding: 14px 18px;
  font-size: .875rem;
  vertical-align: middle;
}

.td-actions { display: flex; gap: 8px; }

.td-title { font-weight: 600; }
.td-muted { color: var(--muted); font-size: .8rem; }
.td-content-preview {
  max-width: 320px;
  color: var(--muted);
  font-size: .8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Empty State ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: .5;
}

.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text);
  margin-bottom: 6px;
}

.empty-state p { font-size: .875rem; margin-bottom: 20px; }

/* ── Instagram-style Learn Card ──────────────────────────────────────────── */
.insta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
}

.insta-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1.5px solid var(--border);
  transition: box-shadow .2s, transform .15s;
}

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

/* Card header — profile row */
.insta-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.insta-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.insta-card-meta { flex: 1; min-width: 0; }

.insta-card-topic {
  font-size: .8rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.insta-card-number {
  font-size: .72rem;
  color: var(--muted);
}

.insta-card-dot-menu { color: var(--muted); cursor: pointer; font-size: 1.2rem; padding: 4px; }

/* Card content area */
.insta-card-body {
  min-height: 220px;
  padding: 24px 20px 20px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.insta-card-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 10px;
  line-height: 1.3;
  color: inherit;
}

.insta-card-content {
  font-size: .875rem;
  line-height: 1.65;
  color: inherit;
  opacity: .9;
}

/* Content theme gradients */
.theme-0 { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #fff; }
.theme-1 { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); color: #fff; }
.theme-2 { background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); color: #fff; }
.theme-3 { background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%); color: #1e293b; }
.theme-4 { background: linear-gradient(135deg, #fa709a 0%, #fee140 100%); color: #1e293b; }
.theme-5 { background: linear-gradient(135deg, #a18cd1 0%, #fbc2eb 100%); color: #1e293b; }
.theme-6 { background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%); color: #1e293b; }
.theme-7 { background: linear-gradient(135deg, #2af598 0%, #009efd 100%); color: #fff; }

/* Card footer */
.insta-card-footer {
  border-top: 1px solid var(--border);
  padding: 10px 14px;
}

.insta-card-actions-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.insta-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 7px;
  border: none;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}

.insta-action-btn.edit  { background: rgba(99,102,241,.1); color: var(--primary); }
.insta-action-btn.edit:hover  { background: rgba(99,102,241,.18); }
.insta-action-btn.del   { background: rgba(239,68,68,.08); color: var(--danger); }
.insta-action-btn.del:hover   { background: rgba(239,68,68,.15); }
.insta-action-btn.script-toggle { background: rgba(16,185,129,.08); color: #059669; }
.insta-action-btn.script-toggle:hover { background: rgba(16,185,129,.16); }
.insta-action-btn.script-empty { background: transparent; color: var(--muted); cursor: default; opacity: .5; }

/* Audio player */
.audio-player {
  margin-top: 6px;
  background: #f8fafc;
  border-radius: 8px;
  padding: 8px 10px;
}

.audio-player audio {
  width: 100%;
  height: 32px;
  outline: none;
}

.audio-player audio::-webkit-media-controls-panel { background: #f8fafc; }

.no-audio-badge {
  font-size: .75rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(2px);
  animation: fade-in .18s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.modal {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slide-up .22s ease;
}

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

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

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

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

.modal-body { padding: 20px 24px; }
.modal-footer {
  padding: 14px 24px 20px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ── Form ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: .825rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.form-label span { color: var(--danger); }

.form-control {
  width: 100%;
  padding: 9px 13px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  font-family: inherit;
}

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

textarea.form-control { min-height: 110px; resize: vertical; line-height: 1.5; }

.form-hint { font-size: .78rem; color: var(--muted); margin-top: 4px; }

/* Audio upload area */
.audio-upload-area {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.audio-upload-area:hover, .audio-upload-area.drag-over {
  border-color: var(--primary);
  background: rgba(99,102,241,.04);
}

.audio-upload-area input[type="file"] { display: none; }

.audio-upload-icon { font-size: 2rem; margin-bottom: 6px; }
.audio-upload-text { font-size: .85rem; color: var(--muted); }
.audio-upload-text strong { color: var(--primary); }

.audio-preview-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  background: #f8fafc;
  border-radius: 8px;
  padding: 8px 12px;
}

.audio-preview-row audio { flex: 1; height: 32px; }

.audio-remove-btn {
  padding: 4px 8px;
  border-radius: 6px;
  border: none;
  background: rgba(239,68,68,.1);
  color: var(--danger);
  cursor: pointer;
  font-size: .75rem;
  font-weight: 600;
}

/* ── Card detail view in modal ───────────────────────────────────────────── */
.card-detail-preview {
  border-radius: 12px;
  overflow: hidden;
  border: 1.5px solid var(--border);
  margin-bottom: 16px;
}

/* ── Badge ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}

.badge-primary { background: rgba(99,102,241,.12); color: var(--primary); }
.badge-muted   { background: var(--border); color: var(--muted); }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: .875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slide-up .25s ease;
  max-width: 340px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast.success { background: #16a34a; }
.toast.error   { background: #dc2626; }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2.5px solid rgba(0,0,0,.1);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  gap: 12px;
  color: var(--muted);
  font-size: .875rem;
}

/* ── Color chips for avatar ──────────────────────────────────────────────── */
.av-0 { background: linear-gradient(135deg, #667eea, #764ba2); }
.av-1 { background: linear-gradient(135deg, #f093fb, #f5576c); }
.av-2 { background: linear-gradient(135deg, #4facfe, #00f2fe); }
.av-3 { background: linear-gradient(135deg, #43e97b, #38f9d7); }
.av-4 { background: linear-gradient(135deg, #fa709a, #fee140); }
.av-5 { background: linear-gradient(135deg, #a18cd1, #fbc2eb); }
.av-6 { background: linear-gradient(135deg, #ffecd2, #fcb69f); }
.av-7 { background: linear-gradient(135deg, #2af598, #009efd); }

/* icon bg colors for entity cards */
.ic-cat    { background: rgba(99,102,241,.12); }
.ic-course { background: rgba(245,158,11,.12); }
.ic-chap   { background: rgba(34,197,94,.12); }
.ic-topic  { background: rgba(239,68,68,.12); }

/* ── Existing audio bar (shown when editing a card that already has audio) ── */
.existing-audio-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: linear-gradient(135deg, rgba(99,102,241,.06), rgba(99,102,241,.02));
  border: 1.5px solid rgba(99,102,241,.25);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.existing-audio-label {
  font-size: .78rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: .03em;
}

.existing-audio-player {
  width: 100%;
  height: 36px;
  outline: none;
}

.existing-audio-hint {
  font-size: .72rem;
  color: var(--muted);
}

/* ── Audio tabs (Upload / Record) ────────────────────────────────────────── */
.audio-tabs {
  display: flex;
  border-bottom: 1.5px solid var(--border);
  margin-bottom: 14px;
  gap: 0;
}

.audio-tab {
  padding: 8px 18px;
  font-size: .82rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2.5px solid transparent;
  margin-bottom: -1.5px;
  transition: color .15s, border-color .15s;
}

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

.audio-tab-panel { display: none; }
.audio-tab-panel.active { display: block; }

/* ── Voice Recorder ──────────────────────────────────────────────────────── */
.recorder-box {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
}

.rec-start-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  border-radius: 9px;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s;
}
.rec-start-btn:hover { opacity: .88; }

.recording-ui { display: none; }
.recording-ui.active { display: block; }

.rec-live {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
}

.rec-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--danger);
  animation: rec-pulse 1s ease infinite;
}

@keyframes rec-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .4; transform: scale(.75); }
}

.rec-timer {
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  letter-spacing: .04em;
}

.rec-bars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 28px;
  margin-bottom: 14px;
}

.rec-bar {
  width: 4px;
  border-radius: 3px;
  background: var(--danger);
  animation: bar-bounce .55s ease infinite alternate;
}
.rec-bar:nth-child(1) { animation-delay: 0s;   animation-duration: .4s; }
.rec-bar:nth-child(2) { animation-delay: .1s;  animation-duration: .55s; }
.rec-bar:nth-child(3) { animation-delay: .2s;  animation-duration: .35s; }
.rec-bar:nth-child(4) { animation-delay: .05s; animation-duration: .5s; }
.rec-bar:nth-child(5) { animation-delay: .15s; animation-duration: .45s; }

@keyframes bar-bounce {
  from { height: 4px;  opacity: .5; }
  to   { height: 22px; opacity: 1; }
}

.rec-stop-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: 8px;
  border: 2px solid var(--danger);
  background: transparent;
  color: var(--danger);
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.rec-stop-btn:hover { background: rgba(239,68,68,.08); }

.rec-result { display: none; margin-top: 14px; }
.rec-result.active { display: block; }

.rec-result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 10px;
}

.rec-result-row audio { flex: 1; height: 32px; }

.rec-use-btn {
  padding: 6px 14px;
  border-radius: 7px;
  border: none;
  background: var(--success);
  color: #fff;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
}

.rec-discard-btn {
  padding: 6px 12px;
  border-radius: 7px;
  border: none;
  background: rgba(239,68,68,.1);
  color: var(--danger);
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
}

/* ── AI Generate Panel ───────────────────────────────────────────────────── */
.ai-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, #f0f0ff, #fdf4ff);
  border: 1.5px solid #c4b5fd;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

.ai-bar-label {
  font-size: .8rem;
  font-weight: 600;
  color: #6d28d9;
  flex: 1;
}

.btn-ai {
  background: linear-gradient(135deg, #7c3aed, #6366f1);
  color: #fff;
  border: none;
  padding: 7px 16px;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: opacity .15s;
}
.btn-ai:hover { opacity: .88; }
.btn-ai:disabled { opacity: .5; cursor: not-allowed; }

.ai-panel {
  background: #faf5ff;
  border: 1.5px solid #c4b5fd;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
  display: none;
}
.ai-panel.open { display: block; }

.ai-panel-title {
  font-size: .85rem;
  font-weight: 700;
  color: #6d28d9;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-model-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.ai-model-chip {
  padding: 4px 12px;
  border-radius: 999px;
  border: 1.5px solid #c4b5fd;
  background: #fff;
  font-size: .75rem;
  font-weight: 600;
  color: #7c3aed;
  cursor: pointer;
  transition: background .15s;
}
.ai-model-chip.selected {
  background: #7c3aed;
  color: #fff;
  border-color: #7c3aed;
}

.ai-key-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.ai-key-input {
  flex: 1;
  padding: 7px 11px;
  border: 1.5px solid #c4b5fd;
  border-radius: 7px;
  font-size: .8rem;
  background: #fff;
  outline: none;
  font-family: monospace;
  letter-spacing: .04em;
}
.ai-key-input:focus { border-color: #7c3aed; }

.ai-key-save {
  padding: 7px 12px;
  border-radius: 7px;
  border: none;
  background: #7c3aed;
  color: #fff;
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.ai-generate-target {
  margin-bottom: 10px;
}

.ai-generate-btn-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Script / voice notes section */
.script-field-wrap {
  position: relative;
}

.script-ai-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  padding: 3px 10px;
  border-radius: 6px;
  border: none;
  background: linear-gradient(135deg, #7c3aed, #6366f1);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: opacity .15s;
}
.script-ai-btn:hover { opacity: .88; }
.script-ai-btn:disabled { opacity:.5; cursor:not-allowed; }

/* API key settings button in topbar */
.topbar-settings-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 8px;
  border: 1.5px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.1);
  color: #fff;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.topbar-settings-btn:hover { background: rgba(255,255,255,.2); }

/* ── Topbar auth area ────────────────────────────────────────────────────── */
.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-username {
  font-size: .82rem;
  font-weight: 600;
  color: rgba(255,255,255,.85);
}

.topbar-icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 8px;
  border: 1.5px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.1);
  color: #fff;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.topbar-icon-btn:hover { background: rgba(255,255,255,.2); }

.topbar-logout-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 8px;
  border: 1.5px solid rgba(239,68,68,.45);
  background: rgba(239,68,68,.18);
  color: #fca5a5;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.topbar-logout-btn:hover { background: rgba(239,68,68,.3); color: #fff; }

/* ── Login Overlay ───────────────────────────────────────────────────────── */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(0,0,0,.28);
  width: 100%;
  max-width: 380px;
  padding: 40px 36px;
}

.login-header {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo { font-size: 3rem; margin-bottom: 10px; }

.login-header h1 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
}

.login-header p { font-size: .875rem; color: var(--muted); }

.login-error {
  background: rgba(239,68,68,.08);
  border: 1.5px solid rgba(239,68,68,.25);
  color: #dc2626;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .825rem;
  font-weight: 500;
  margin-bottom: 14px;
}

/* ── Settings Tabs ───────────────────────────────────────────────────────── */
.settings-tabs {
  display: flex;
  border-bottom: 1.5px solid var(--border);
  margin-bottom: 20px;
}

.settings-tab {
  padding: 8px 20px;
  font-size: .85rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2.5px solid transparent;
  margin-bottom: -1.5px;
  transition: color .15s, border-color .15s;
}

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

.settings-panel { display: none; }
.settings-panel.active { display: block; }

/* ── Audio Script in card grid ───────────────────────────────────────────── */
.audio-script-section {
  margin-top: 10px;
  background: #f8fafc;
  border-radius: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
}

.audio-script-label {
  font-size: .7rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.audio-script-text {
  font-size: .82rem;
  line-height: 1.65;
  color: var(--text);
  white-space: pre-wrap;
}

.audio-script-empty {
  font-size: .78rem;
  color: var(--muted);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .main-content { padding: 16px; }
  .entity-grid { grid-template-columns: 1fr; }
  .insta-grid  { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .topbar-username { display: none; }
}
