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

:root {
  --bg: #F8F9FC;
  --surface: #FFFFFF;
  --surface-2: #F1F3F9;
  --border: #E2E6EF;
  --border-strong: #C8CFDF;
  --text: #0F172A;
  --muted: #64748B;
  --dim: #94A3B8;
  --accent: #2563EB;
  --accent-hover: #1D4ED8;
  --accent-soft: #EFF6FF;
  --green: #059669;
  --green-soft: #ECFDF5;
  --amber-soft: #FFFBEB;
  --amber-border: #FDE68A;
  --amber-text: #92400E;
  --danger: #DC2626;
  --serif: "Instrument Serif", Georgia, serif;
  --sans: "DM Sans", system-ui, sans-serif;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 30px rgba(15, 23, 42, 0.08);
  --sidebar-w: 240px;
}

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }

.hidden { display: none !important; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  border: none;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; padding: 12px 22px; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(37, 99, 235, 0.28); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); padding: 12px 20px; }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); padding: 8px 16px; font-weight: 500; }
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 15px; }
.btn-block { width: 100%; }

/* Nav */
.nav {
  position: sticky; top: 0; z-index: 100;
  background: rgba(248, 249, 252, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-logo { font-family: var(--serif); font-size: 24px; letter-spacing: -0.02em; }
.nav-logo em { font-style: normal; color: var(--accent); }
.nav-actions { display: flex; gap: 10px; align-items: center; }

/* Landing */
.hero {
  max-width: 920px;
  margin: 0 auto;
  padding: 72px 24px 48px;
  text-align: center;
}
.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 100px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 24px;
  animation: fadeUp 0.4s ease;
}
.hero h1 {
  font-family: var(--serif);
  font-size: clamp(2.2rem, 5vw, 3.5rem);
  font-weight: 400;
  line-height: 1.12;
  letter-spacing: -0.03em;
  margin-bottom: 18px;
  animation: fadeUp 0.45s ease;
}
.hero h1 span { color: var(--accent); font-style: italic; }
.hero-lead {
  color: var(--muted);
  font-size: 1.08rem;
  max-width: 520px;
  margin: 0 auto 32px;
  line-height: 1.7;
  animation: fadeUp 0.5s ease;
}
.hero-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-bottom: 48px; animation: fadeUp 0.55s ease; }

.preview-card {
  max-width: 600px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  text-align: left;
  overflow: hidden;
  animation: fadeUp 0.6s 0.08s ease backwards;
}
.preview-bar {
  background: var(--surface-2);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}
.preview-body { padding: 22px 24px; }
.preview-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.preview-item:last-child { border-bottom: none; }
.preview-item strong { display: block; font-size: 14px; margin-bottom: 4px; }
.preview-item span { font-size: 12px; color: var(--accent); font-weight: 500; }

.section { padding: 72px 24px; }
.section.alt { background: var(--surface); border-block: 1px solid var(--border); }
.section-inner { max-width: 1000px; margin: 0 auto; }
.section-label { text-align: center; font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); margin-bottom: 8px; }
.section-title { text-align: center; font-family: var(--serif); font-size: clamp(1.7rem, 3vw, 2.3rem); margin-bottom: 40px; font-weight: 400; }
.features-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.feature-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
}
.feature-card h3 { font-size: 15px; margin-bottom: 8px; }
.feature-card p { font-size: 14px; color: var(--muted); line-height: 1.6; }

footer {
  border-top: 1px solid var(--border);
  padding: 28px;
  text-align: center;
  font-size: 13px;
  color: var(--dim);
}

/* Modals */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
  animation: fadeUp 0.2s ease;
}
.auth-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 24px;
}
.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}
.auth-tab.active { background: var(--accent); color: #fff; }
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--sans);
  font-size: 14px;
  background: var(--bg);
  outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* App shell */
#app-shell { display: none; min-height: 100vh; flex-direction: column; }
.app-topbar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}
.app-topbar-title { font-family: var(--serif); font-size: 20px; }
.app-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 100px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-left: 10px;
}

/* Onboarding wizard */
.onboard-wrap {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 32px 20px 64px;
}
.onboard-panel {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 32px 28px;
  animation: fadeUp 0.3s ease;
}
.onboard-progress {
  display: flex;
  gap: 8px;
  margin-bottom: 28px;
}
.progress-step {
  flex: 1;
  height: 4px;
  border-radius: 4px;
  background: var(--border);
  transition: background 0.25s;
}
.progress-step.done { background: var(--accent); }
.progress-step.active { background: var(--accent); opacity: 0.65; }
.onboard-panel h2 {
  font-family: var(--serif);
  font-size: 1.75rem;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}
.onboard-panel > .lead { font-size: 14px; color: var(--muted); margin-bottom: 24px; line-height: 1.65; }
.onboard-step { display: none; }
.onboard-step.active { display: block; animation: fadeIn 0.25s ease; }
.onboard-actions {
  display: flex;
  gap: 10px;
  margin-top: 28px;
}
.onboard-actions .btn-primary { flex: 1; }

.topic-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.topic-chip {
  padding: 7px 14px;
  border-radius: 100px;
  border: 1px solid var(--border-strong);
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  background: var(--bg);
  user-select: none;
  transition: all 0.15s;
}
.topic-chip.selected { background: var(--accent); border-color: var(--accent); color: #fff; }
.field-hint { font-size: 12px; color: var(--dim); margin-top: 6px; }

/* Chat */
.chat-layout { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
}
.chat-messages-inner { max-width: 680px; margin: 0 auto; }
.msg { display: flex; margin-bottom: 18px; animation: fadeUp 0.2s ease; }
.msg.user { justify-content: flex-end; }
.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-family: var(--serif);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  flex-shrink: 0;
}
.msg-bubble {
  max-width: 78%;
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.bot .msg-bubble { color: var(--text); }
.msg.user .msg-bubble {
  background: var(--accent);
  color: #fff;
  padding: 12px 16px;
  border-radius: 16px 16px 4px 16px;
}
.typing-row { display: flex; align-items: center; margin-bottom: 18px; }
.typing-bubble {
  display: flex; gap: 5px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
}
.typing-bubble span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--border-strong);
  animation: pulse 1.2s ease infinite;
}
.typing-bubble span:nth-child(2) { animation-delay: 0.15s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.3s; }

.chat-input-bar {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 14px 20px 18px;
}
.chat-input-inner { max-width: 680px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.chat-input-inner textarea {
  flex: 1;
  min-height: 48px;
  max-height: 140px;
  padding: 12px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  font-family: var(--sans);
  font-size: 15px;
  resize: none;
  outline: none;
  background: var(--bg);
}
.chat-input-inner textarea:focus { border-color: var(--accent); }
.summary-actions { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.btn-accept { background: var(--green); color: #fff; padding: 10px 18px; border: none; border-radius: var(--radius-sm); font-weight: 600; font-size: 13px; cursor: pointer; }
.btn-adjust { background: transparent; border: 1px solid var(--border-strong); color: var(--muted); padding: 10px 16px; border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; }

/* Dashboard */
.dash-layout { flex: 1; display: flex; min-height: 0; }
.dash-sidebar {
  width: var(--sidebar-w);
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}
.dash-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: var(--sans);
}
.dash-nav-item:hover { background: var(--surface-2); color: var(--text); }
.dash-nav-item.active { background: var(--accent-soft); color: var(--accent); }
.dash-main { flex: 1; overflow-y: auto; padding: 24px 28px 40px; }
.dash-header { margin-bottom: 24px; }
.dash-header h1 {
  font-family: var(--serif);
  font-size: 1.85rem;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.dash-header p { color: var(--muted); font-size: 14px; }
.dash-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}
.meta-pill {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 100px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.meta-pill.green { background: var(--green-soft); color: var(--green); border-color: #A7F3D0; }
.meta-pill.amber { background: var(--amber-soft); color: var(--amber-text); border-color: var(--amber-border); }

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dash-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.dash-card.span-2 { grid-column: 1 / -1; }
.dash-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.dash-card-head h3 {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.profile-row { display: flex; gap: 10px; margin-bottom: 12px; font-size: 13px; }
.profile-row:last-child { margin-bottom: 0; }
.profile-row .label { width: 100px; flex-shrink: 0; color: var(--dim); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; padding-top: 2px; }
.profile-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.profile-tag {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 100px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.digest-panel { min-height: 280px; }
.digest-status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px;
  color: var(--muted);
  font-size: 14px;
}
.spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
.digest-content {
  font-size: 14px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}
.digest-content.empty { color: var(--dim); font-style: italic; }
.digest-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.source-badge {
  font-size: 11px;
  color: var(--dim);
  margin-top: 8px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  z-index: 500;
  max-width: min(420px, 92vw);
  transition: transform 0.25s ease;
  box-shadow: var(--shadow-md);
}
.toast.show { transform: translateX(-50%) translateY(0); }

@media (max-width: 900px) {
  .dash-layout { flex-direction: column; }
  .dash-sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
  }
  .dash-nav-item { white-space: nowrap; width: auto; }
  .dash-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .nav { padding: 0 16px; }
  .nav-actions .btn-ghost { display: none; }
  .hero { padding-top: 48px; }
  .onboard-panel { padding: 24px 18px; }
  .dash-main { padding: 16px; }
}
