/* ═══════════════════════════════════════════════
   Thesis & Research Assistant — Premium SaaS
   Linear × Stripe × Vercel × Notion
   ═══════════════════════════════════════════════ */

/* ─── Design Tokens ─── */
.ta-wrap {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  --ta-primary: #6366f1;
  --ta-primary-hover: #4f46e5;
  --ta-primary-soft: rgba(99,102,241,0.08);
  --ta-primary-glow: rgba(99,102,241,0.15);
  --ta-success: #22c55e;
  --ta-success-bg: rgba(34,197,94,0.06);
  --ta-success-border: rgba(34,197,94,0.2);
  --ta-warning: #f59e0b;
  --ta-danger: #ef4444;
  --ta-bg: #f8fafc;
  --ta-card: #ffffff;
  --ta-border: #e5e7eb;
  --ta-border-focus: #c7d2fe;
  --ta-text: #0f172a;
  --ta-text-2: #475569;
  --ta-text-3: #94a3b8;
  --ta-r: 14px;
  --ta-r-sm: 10px;
  --ta-r-xs: 6px;
  --ta-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 18px rgba(0,0,0,0.04);
  --ta-shadow-lg: 0 4px 24px rgba(0,0,0,0.08);
  --ta-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --ta-ease: cubic-bezier(0.4,0,0.2,1);
  --ta-sidebar-w: 260px;
  --ta-chat-w: 380px;

  font-family: var(--ta-font);
  color: var(--ta-text);
  max-width: 100%;
  min-height: 80vh;
}

*, *::before, *::after { box-sizing: border-box; }

/* ─── Utilities ─── */
.ta-hidden { display: none !important; }
.ta-required { color: var(--ta-danger); }

/* ─── Screen Container ─── */
.ta-screen { animation: taFadeIn 0.35s var(--ta-ease); }
@keyframes taFadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Hero Section ─── */
.ta-hero {
  text-align: center;
  padding: 48px 24px 32px;
}
.ta-hero-icon {
  width: 48px; height: 48px;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--ta-primary), #8b5cf6);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.ta-hero-icon svg { width: 24px; height: 24px; }
.ta-hero-title {
  font-size: 28px; font-weight: 800; letter-spacing: -0.02em;
  color: var(--ta-text); margin: 0 0 10px;
}
.ta-hero-subtitle {
  font-size: 15px; color: var(--ta-text-2); max-width: 520px; margin: 0 auto; line-height: 1.6;
}

/* ─── Welcome Grid ─── */
.ta-welcome-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 24px 32px;
}
.ta-card {
  background: var(--ta-card);
  border: 1px solid var(--ta-border);
  border-radius: var(--ta-r);
  padding: 28px 24px;
  transition: all 200ms var(--ta-ease);
}
.ta-card-hover:hover {
  border-color: var(--ta-border-focus);
  box-shadow: var(--ta-shadow);
  transform: translateY(-2px);
}
.ta-welcome-card { cursor: pointer; text-align: center; }
.ta-welcome-card-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}
.ta-welcome-card-icon svg { width: 20px; height: 20px; }
.ta-welcome-card-title { font-size: 16px; font-weight: 700; margin: 0 0 8px; }
.ta-welcome-card-desc { font-size: 13px; color: var(--ta-text-2); line-height: 1.5; margin: 0; }

/* ─── Login Notice ─── */
.ta-login-notice {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  max-width: 480px; margin: 0 auto 32px;
  padding: 12px 20px;
  background: var(--ta-primary-soft);
  border: 1px solid rgba(99,102,241,0.15);
  border-radius: var(--ta-r-sm);
  font-size: 13px; color: var(--ta-text-2);
}
.ta-login-notice a { color: var(--ta-primary); font-weight: 600; text-decoration: none; }
.ta-login-notice a:hover { text-decoration: underline; }

/* ─── Topbar ─── */
.ta-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px;
  background: var(--ta-card);
  border-bottom: 1px solid var(--ta-border);
  position: sticky; top: 0; z-index: 100;
}
.ta-topbar-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  background: none; border: 1px solid var(--ta-border);
  border-radius: var(--ta-r-sm);
  font-size: 13px; font-weight: 500; color: var(--ta-text-2);
  cursor: pointer; transition: all 150ms var(--ta-ease);
  font-family: var(--ta-font);
}
.ta-topbar-btn:hover { background: var(--ta-bg); border-color: var(--ta-border-focus); color: var(--ta-text); }
.ta-topbar-btn svg { width: 14px; height: 14px; }
.ta-topbar-title { font-size: 14px; font-weight: 600; color: var(--ta-text); }
.ta-topbar-actions { display: flex; gap: 8px; }

/* ─── Setup Form ─── */
.ta-setup-container {
  display: flex; justify-content: center; padding: 32px 24px;
}
.ta-setup-card {
  background: var(--ta-card);
  border: 1px solid var(--ta-border);
  border-radius: var(--ta-r);
  box-shadow: var(--ta-shadow);
  padding: 36px 32px;
  width: 100%; max-width: 560px;
}
.ta-setup-title { font-size: 20px; font-weight: 700; margin: 0 0 6px; }
.ta-setup-subtitle { font-size: 14px; color: var(--ta-text-2); margin: 0 0 28px; }

.ta-field { margin-bottom: 20px; }
.ta-label { display: block; font-size: 13px; font-weight: 600; color: var(--ta-text); margin-bottom: 6px; }
.ta-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--ta-border);
  border-radius: var(--ta-r-sm);
  font-size: 14px;
  font-family: var(--ta-font);
  color: var(--ta-text);
  background: var(--ta-card);
  transition: border-color 150ms var(--ta-ease), box-shadow 150ms var(--ta-ease);
  outline: none;
}
.ta-input:focus { border-color: var(--ta-primary); box-shadow: 0 0 0 3px var(--ta-primary-glow); }
.ta-textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
.ta-help { display: block; font-size: 12px; color: var(--ta-text-3); margin-top: 4px; }

/* ─── Buttons ─── */
.ta-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px;
  border: none; border-radius: var(--ta-r-sm);
  font-size: 14px; font-weight: 600;
  font-family: var(--ta-font);
  cursor: pointer; transition: all 200ms var(--ta-ease);
  white-space: nowrap;
}
.ta-btn svg { flex-shrink: 0; }
.ta-btn-primary {
  background: var(--ta-primary); color: #fff;
}
.ta-btn-primary:hover { background: var(--ta-primary-hover); box-shadow: 0 2px 12px rgba(99,102,241,0.3); }
.ta-btn-outline {
  background: none; border: 1px solid var(--ta-border); color: var(--ta-text-2);
}
.ta-btn-outline:hover { background: var(--ta-bg); border-color: var(--ta-border-focus); color: var(--ta-text); }
.ta-btn-ghost {
  background: none; color: var(--ta-text-2); padding: 8px 14px;
}
.ta-btn-ghost:hover { background: var(--ta-bg); color: var(--ta-text); }
.ta-btn-sm { padding: 7px 14px; font-size: 13px; }
.ta-btn-lg { padding: 12px 28px; font-size: 15px; }
.ta-btn[disabled] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.ta-full-width { width: 100%; }

/* ─── Spinner ─── */
.ta-spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: taSpin 0.6s linear infinite;
}
@keyframes taSpin { to { transform: rotate(360deg); } }

/* ─── Topics Grid ─── */
.ta-topics-container { max-width: 900px; margin: 0 auto; padding: 24px; }
.ta-topics-header { margin-bottom: 24px; }
.ta-topics-header h2 { font-size: 22px; font-weight: 700; margin: 0 0 6px; }
.ta-topics-header p { font-size: 14px; color: var(--ta-text-2); margin: 0; }
.ta-topics-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 14px; }

.ta-topic-card {
  background: var(--ta-card);
  border: 1px solid var(--ta-border);
  border-radius: var(--ta-r);
  padding: 20px;
  cursor: pointer;
  transition: all 200ms var(--ta-ease);
  position: relative;
}
.ta-topic-card:hover { border-color: var(--ta-primary); box-shadow: 0 2px 16px rgba(99,102,241,0.1); }
.ta-topic-card-selected { border-color: var(--ta-primary); background: var(--ta-primary-soft); }
.ta-topic-title { font-size: 15px; font-weight: 700; color: var(--ta-text); margin: 0 0 8px; line-height: 1.4; }
.ta-topic-desc { font-size: 13px; color: var(--ta-text-2); margin: 0 0 12px; line-height: 1.5; }
.ta-topic-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ta-topic-field {
  font-size: 11px; font-weight: 600; color: var(--ta-primary);
  background: var(--ta-primary-soft);
  padding: 3px 8px; border-radius: 4px;
}
.ta-topic-difficulty {
  font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: 4px;
}
.ta-topic-difficulty-easy { color: var(--ta-success); background: var(--ta-success-bg); }
.ta-topic-difficulty-medium { color: var(--ta-warning); background: rgba(245,158,11,0.1); }
.ta-topic-difficulty-hard { color: var(--ta-danger); background: rgba(239,68,68,0.08); }
.ta-topic-keywords { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.ta-topic-kw {
  font-size: 10px; color: var(--ta-text-3);
  background: var(--ta-bg); padding: 2px 6px; border-radius: 3px;
}
.ta-topic-select-check {
  position: absolute; top: 16px; right: 16px;
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--ta-border);
  display: flex; align-items: center; justify-content: center;
  transition: all 150ms var(--ta-ease);
}
.ta-topic-card-selected .ta-topic-select-check {
  border-color: var(--ta-primary); background: var(--ta-primary); color: #fff;
}

/* ─── Workspace Layout ─── */
.ta-workspace-layout {
  display: flex;
  height: calc(100vh - 50px);
  overflow: hidden;
}

/* ─── Chapter Sidebar ─── */
.ta-chapter-sidebar {
  width: var(--ta-sidebar-w);
  min-width: var(--ta-sidebar-w);
  background: var(--ta-card);
  border-right: 1px solid var(--ta-border);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.ta-chapter-sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--ta-border);
}
.ta-chapter-sidebar-title { font-size: 14px; font-weight: 700; margin: 0; }

.ta-progress-ring {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 3px solid var(--ta-border);
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.ta-progress-ring::before {
  content: '';
  position: absolute; top: -3px; right: -3px; bottom: -3px; left: -3px; inset: -3px;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--ta-primary);
  transform: rotate(-90deg);
  transition: all 400ms var(--ta-ease);
}
.ta-progress-pct { font-size: 10px; font-weight: 700; color: var(--ta-primary); }

.ta-chapter-list { flex: 1; padding: 12px; }
.ta-chapter-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 12px;
  background: none; border: 1px solid transparent;
  border-radius: var(--ta-r-sm);
  cursor: pointer;
  transition: all 150ms var(--ta-ease);
  font-family: var(--ta-font);
  text-align: left;
  margin-bottom: 4px;
}
.ta-chapter-item:hover { background: var(--ta-bg); }
.ta-chapter-item-active { background: var(--ta-primary-soft) !important; border-color: rgba(99,102,241,0.2) !important; }
.ta-chapter-num {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--ta-bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--ta-text-2);
  flex-shrink: 0;
  transition: all 150ms var(--ta-ease);
}
.ta-chapter-item-active .ta-chapter-num { background: var(--ta-primary); color: #fff; }
.ta-chapter-completed .ta-chapter-num { background: var(--ta-success); color: #fff; }
.ta-chapter-info { flex: 1; min-width: 0; }
.ta-chapter-name { font-size: 13px; font-weight: 600; color: var(--ta-text); }
.ta-chapter-status { font-size: 11px; color: var(--ta-text-3); margin-top: 2px; }
.ta-chapter-completed .ta-chapter-status { color: var(--ta-success); }
.ta-chapter-check {
  width: 20px; height: 20px;
  display: none; align-items: center; justify-content: center;
  color: var(--ta-success);
}
.ta-chapter-completed .ta-chapter-check { display: flex; }

.ta-chapter-sidebar-actions { padding: 12px; border-top: 1px solid var(--ta-border); }

/* ─── Main Chapter Area ─── */
.ta-chapter-main { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }

.ta-chapter-placeholder {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--ta-text-3); gap: 12px;
}
.ta-chapter-placeholder h3 { font-size: 16px; font-weight: 600; color: var(--ta-text-2); margin: 0; }
.ta-chapter-placeholder p { font-size: 13px; margin: 0; }

.ta-chapter-view { flex: 1; display: flex; flex-direction: column; }
.ta-chapter-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--ta-border);
  background: var(--ta-card);
}
.ta-chapter-view-title { font-size: 18px; font-weight: 700; margin: 0 0 4px; }
.ta-chapter-meta { font-size: 12px; color: var(--ta-text-3); }
.ta-chapter-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ─── Editor ─── */
.ta-chapter-editor { flex: 1; padding: 28px; overflow-y: auto; }
.ta-editor-content {
  max-width: 740px;
  margin: 0 auto;
  font-size: 15px;
  line-height: 1.8;
  color: var(--ta-text);
  outline: none;
  min-height: 400px;
}
.ta-editor-content h2 { font-size: 20px; font-weight: 700; margin: 32px 0 12px; color: var(--ta-text); }
.ta-editor-content h3 { font-size: 16px; font-weight: 600; margin: 24px 0 10px; color: var(--ta-text); }
.ta-editor-content p { margin: 0 0 14px; }
.ta-editor-content ul, .ta-editor-content ol { margin: 0 0 14px; padding-left: 24px; }
.ta-editor-content li { margin-bottom: 4px; }
.ta-editor-content table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 13px; }
.ta-editor-content th, .ta-editor-content td { border: 1px solid var(--ta-border); padding: 8px 12px; text-align: left; }
.ta-editor-content th { background: var(--ta-bg); font-weight: 600; }
.ta-editor-content strong { font-weight: 700; }
.ta-editor-content em { font-style: italic; }

.ta-chapter-footer {
  padding: 12px 28px;
  border-top: 1px solid var(--ta-border);
  background: var(--ta-card);
}
.ta-chapter-nav { display: flex; justify-content: space-between; }

/* ─── Chat Panel ─── */
.ta-chat-panel {
  width: var(--ta-chat-w);
  min-width: var(--ta-chat-w);
  background: var(--ta-card);
  border-left: 1px solid var(--ta-border);
  display: flex; flex-direction: column;
}
.ta-chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--ta-border);
}
.ta-chat-header-info { display: flex; align-items: center; gap: 12px; }
.ta-chat-avatar {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--ta-primary), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.ta-chat-name { font-size: 14px; font-weight: 700; }
.ta-chat-status { font-size: 11px; color: var(--ta-text-3); }
.ta-chat-close {
  background: none; border: none; cursor: pointer;
  color: var(--ta-text-3); padding: 4px; border-radius: 6px;
  transition: all 150ms var(--ta-ease);
}
.ta-chat-close:hover { background: var(--ta-bg); color: var(--ta-text); }

.ta-chat-messages {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.ta-chat-welcome {
  text-align: center; padding: 32px 16px;
}
.ta-chat-welcome-icon {
  width: 44px; height: 44px; margin: 0 auto 10px;
  border-radius: 12px;
  background: var(--ta-primary-soft);
  display: flex; align-items: center; justify-content: center;
  color: var(--ta-primary);
}
.ta-chat-welcome h4 { font-size: 15px; font-weight: 700; margin: 0 0 6px; }
.ta-chat-welcome p { font-size: 13px; color: var(--ta-text-2); margin: 0 0 16px; line-height: 1.5; }
.ta-chat-suggestions { display: flex; flex-direction: column; gap: 6px; }
.ta-chat-suggestion {
  display: block; width: 100%;
  padding: 10px 14px;
  background: var(--ta-bg);
  border: 1px solid var(--ta-border);
  border-radius: var(--ta-r-sm);
  font-size: 12px; color: var(--ta-text-2);
  cursor: pointer; text-align: left;
  font-family: var(--ta-font);
  transition: all 150ms var(--ta-ease);
}
.ta-chat-suggestion:hover { border-color: var(--ta-primary); color: var(--ta-primary); background: var(--ta-primary-soft); }

.ta-chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px; line-height: 1.6;
  word-wrap: break-word;
}
.ta-chat-msg-user {
  align-self: flex-end;
  background: var(--ta-primary); color: #fff;
  border-bottom-right-radius: 4px;
}
.ta-chat-msg-assistant {
  align-self: flex-start;
  background: var(--ta-bg); border: 1px solid var(--ta-border);
  border-bottom-left-radius: 4px;
}
.ta-chat-msg-assistant p { margin: 0 0 8px; }
.ta-chat-msg-assistant p:last-child { margin-bottom: 0; }
.ta-chat-msg-assistant strong { font-weight: 700; }
.ta-chat-msg-assistant ul, .ta-chat-msg-assistant ol { margin: 4px 0 8px; padding-left: 18px; }

.ta-chat-typing {
  align-self: flex-start;
  display: flex; gap: 4px; padding: 12px 16px;
  background: var(--ta-bg); border: 1px solid var(--ta-border);
  border-radius: 14px; border-bottom-left-radius: 4px;
}
.ta-chat-typing-dot {
  width: 6px; height: 6px;
  background: var(--ta-text-3);
  border-radius: 50%;
  animation: taBounce 1.4s infinite;
}
.ta-chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ta-chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes taBounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }

.ta-chat-input-area {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--ta-border);
}
.ta-chat-input-wrap {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--ta-bg);
  border: 1px solid var(--ta-border);
  border-radius: 12px;
  padding: 4px 4px 4px 14px;
  transition: border-color 150ms var(--ta-ease);
}
.ta-chat-input-wrap:focus-within { border-color: var(--ta-primary); }
.ta-chat-input {
  flex: 1;
  border: none; background: none; outline: none;
  font-size: 13px; font-family: var(--ta-font);
  resize: none; max-height: 100px;
  padding: 8px 0;
  color: var(--ta-text);
}
.ta-chat-send {
  width: 34px; height: 34px; flex-shrink: 0;
  border: none; border-radius: 8px;
  background: var(--ta-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 150ms var(--ta-ease);
}
.ta-chat-send:hover { background: var(--ta-primary-hover); }

/* ─── Toast ─── */
.ta-toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 24px;
  background: var(--ta-text); color: #fff;
  border-radius: var(--ta-r-sm);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--ta-shadow-lg);
  opacity: 0; pointer-events: none;
  transition: all 300ms var(--ta-ease);
  z-index: 10000;
}
.ta-toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.ta-toast-success { background: #16a34a; }
.ta-toast-error { background: #dc2626; }

/* ─── Loading skeleton ─── */
.ta-skeleton {
  background: linear-gradient(90deg, var(--ta-bg) 25%, #e5e7eb 50%, var(--ta-bg) 75%);
  background-size: 200% 100%;
  animation: taShimmer 1.5s infinite;
  border-radius: var(--ta-r-sm);
}
@keyframes taShimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ─── Responsive ─── */
@media (max-width: 1024px) {
  .ta-chat-panel { position: fixed; right: 0; top: 50px; bottom: 0; z-index: 200; box-shadow: var(--ta-shadow-lg); }
}
@media (max-width: 768px) {
  .ta-chapter-sidebar { display: none; }
  .ta-workspace-layout { flex-direction: column; }
  .ta-chat-panel { width: 100%; min-width: 100%; }
  .ta-topics-grid { grid-template-columns: 1fr; }
  .ta-welcome-grid { grid-template-columns: 1fr; }
  .ta-hero-title { font-size: 22px; }
  .ta-chapter-header { flex-direction: column; }
  .ta-chapter-actions { width: 100%; }
  .ta-chapter-actions .ta-btn { flex: 1; }
  .ta-setup-card { padding: 24px 20px; }
}

/* ─── Print ─── */
@media print {
  .ta-topbar, .ta-chapter-sidebar, .ta-chat-panel,
  .ta-chapter-actions, .ta-chapter-footer, .ta-chapter-nav { display: none !important; }
  .ta-workspace-layout { display: block !important; }
  .ta-chapter-main { width: 100% !important; }
  .ta-editor-content { max-width: 100%; }
}
