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

:root {
  /* White + pastel purple palette */
  --bg:           #FFFFFF;
  --bg-2:         #F7F5FC;
  --bg-3:         #EEE9F8;
  --bg-4:         #E4DCF2;
  --border:       #DDD6EF;
  --border-2:     #C5BBDF;

  --text:         #1E1830;
  --text-muted:   #6A5E85;
  --text-dim:     #A89DC0;

  /* Pastel purple accent */
  --purple:       #8B6FBE;
  --purple-hi:    #9B7FCE;
  --purple-dim:   rgba(139, 111, 190, 0.08);
  --purple-dim-2: rgba(139, 111, 190, 0.15);
  --purple-dim-3: rgba(139, 111, 190, 0.28);

  --green:        #52a876;

  --sidebar-w:    252px;
  --panel-w:      316px;
  --r:            5px;
}

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 13.5px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Scrollbars ────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Layout ────────────────────────────────────────────────────────────── */
.app  { display: flex; height: 100vh; overflow: hidden; }
.main { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* Logo */
.logo { display: flex; align-items: center; gap: 9px; }

.logo-mark {
  width: 30px; height: 30px;
  border: 1.5px solid var(--purple-dim-3);
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 18px;
  font-style: italic;
  font-weight: 400;
  color: var(--purple);
  line-height: 1;
}

.logo-wordmark {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 20px;
  font-weight: 500;
  font-style: italic;
  color: var(--text);
  letter-spacing: 0.02em;
  line-height: 1;
}

/* Language toggle */
.lang-toggle {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  flex-shrink: 0;
  transition: border-color 0.15s;
}
.lang-toggle:hover { border-color: var(--purple-dim-3); }

.lang-opt {
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.lang-opt.active {
  background: var(--purple-dim-2);
  color: var(--purple);
}

.lang-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  flex-shrink: 0;
}

/* Nav */
.nav {
  padding: 18px 10px 12px;
  flex: 0 0 auto;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  padding: 0 10px 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px 9px 12px;
  border: none;
  border-left: 2px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  text-align: left;
  border-radius: 0 var(--r) var(--r) 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  margin-bottom: 1px;
}
.nav-item:hover { color: var(--text); background: var(--bg-3); }
.nav-item.active {
  color: var(--purple);
  border-left-color: var(--purple);
  background: var(--purple-dim);
  font-weight: 500;
}

.nav-icon { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; line-height: 1; }
.nav-text { flex: 1; }

.badge {
  margin-left: auto;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-4);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 22px;
  text-align: center;
}
.nav-item.active .badge {
  color: var(--purple);
  background: var(--purple-dim);
  border-color: var(--purple-dim-2);
}

/* ── Session History ───────────────────────────────────────────────────────── */
.history-section {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding: 14px 10px 8px;
  display: flex;
  flex-direction: column;
}

.history-list { display: flex; flex-direction: column; gap: 2px; }

.history-empty {
  font-size: 11.5px;
  color: var(--text-dim);
  font-style: italic;
  padding: 6px 10px;
}

.history-item {
  display: flex;
  align-items: stretch;
  border: 1px solid transparent;
  border-radius: var(--r);
  transition: background 0.12s, border-color 0.12s;
}
.history-item:hover {
  background: var(--bg-3);
  border-color: var(--border);
}

.history-item-body {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  border-radius: var(--r) 0 0 var(--r);
  padding: 8px 6px 8px 10px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.history-delete {
  flex-shrink: 0;
  background: transparent;
  border: none;
  border-radius: 0 var(--r) var(--r) 0;
  padding: 0 8px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  color: var(--text-dim);
  font-family: inherit;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s;
}
.history-item:hover .history-delete { opacity: 1; }
.history-delete:hover { color: #c0392b; }

.history-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.history-panel-pill {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--purple-dim);
  color: var(--purple);
  border: 1px solid var(--purple-dim-2);
}
.history-panel-pill[data-panel="divorce"] {
  background: rgba(82, 168, 118, 0.08);
  color: var(--green);
  border-color: rgba(82, 168, 118, 0.2);
}
.history-panel-pill[data-panel="custody"] {
  background: rgba(180, 140, 90, 0.08);
  color: #9a7040;
  border-color: rgba(180, 140, 90, 0.2);
}

.history-date {
  font-size: 10.5px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.history-preview {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.session-restored-note {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  letter-spacing: 0.03em;
  padding: 0 0 20px;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px rgba(82, 168, 118, 0.5);
  flex-shrink: 0;
}

/* ── Source Panel ──────────────────────────────────────────────────────── */
.source-panel {
  width: var(--panel-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.panel-header {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}


.panel-header h2 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 21px;
  font-weight: 500;
  font-style: italic;
  color: var(--text);
  line-height: 1.2;
  letter-spacing: 0.01em;
  padding-top: 2px;
}

.panel-subtitle {
  font-size: 11.5px;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.btn-upload {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  background: var(--purple-dim);
  color: var(--purple);
  border: 1px solid var(--purple-dim-2);
  border-radius: var(--r);
  cursor: pointer;
  font-size: 11.5px;
  font-weight: 500;
  font-family: inherit;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
  margin-top: 2px;
}
.btn-upload:hover {
  background: var(--purple-dim-2);
  border-color: var(--purple-dim-3);
}

/* Source list */
.source-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 52px 20px;
  gap: 10px;
}

.empty-icon {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 40px;
  color: var(--border-2);
  line-height: 1;
  margin-bottom: 4px;
}

.empty-state p {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}

.empty-state span {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.65;
  max-width: 220px;
}

.source-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  cursor: default;
}
.source-item:last-child { border-bottom: none; }
.source-item:hover { background: var(--bg-3); }

.source-icon { font-size: 17px; flex-shrink: 0; opacity: 0.75; }

.source-info { flex: 1; min-width: 0; }
.source-name {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.source-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
  letter-spacing: 0.01em;
}

/* ── Folder Accordion ──────────────────────────────────────────────────── */
.folder { border-bottom: 1px solid var(--border); }
.folder:last-child { border-bottom: none; }

.folder-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 12px 9px 10px;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s;
}
.folder-header:hover { background: var(--bg-3); }

.folder-chevron {
  font-size: 13px;
  color: var(--text-dim);
  transition: transform 0.18s ease;
  flex-shrink: 0;
  width: 12px;
  text-align: center;
  line-height: 1;
  display: inline-block;
}
.folder.open .folder-chevron { transform: rotate(90deg); }

.folder-icon { font-size: 13px; flex-shrink: 0; line-height: 1; }

.folder-name {
  flex: 1;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}
.folder.open .folder-name,
.folder.has-files .folder-name { color: var(--text); }

.folder-count {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-4);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 8px;
  min-width: 18px;
  text-align: center;
}
.folder.has-files .folder-count {
  color: var(--purple);
  background: var(--purple-dim);
  border-color: var(--purple-dim-2);
}

.folder-add {
  width: 20px; height: 20px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: inherit;
  padding: 0;
  opacity: 0;
  transition: opacity 0.12s, background 0.12s, color 0.12s, border-color 0.12s;
}
.folder-header:hover .folder-add { opacity: 1; }
.folder-add:hover {
  background: var(--purple-dim);
  border-color: var(--purple-dim-2);
  color: var(--purple);
}

.folder-body { }

.folder-file {
  padding: 8px 14px 8px 28px;
  border-top: 1px solid var(--border);
  cursor: default;
  transition: background 0.1s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.folder-file:hover { background: var(--bg-3); }
.folder-file .source-info { flex: 1; min-width: 0; }
.file-delete {
  flex-shrink: 0;
  width: 18px; height: 18px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  border-radius: 3px;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
}
.folder-file:hover .file-delete { opacity: 1; }
.file-delete:hover { color: #c0392b; background: rgba(192,57,43,0.08); }

.file-status {
  font-size: 10px;
  color: var(--purple);
  font-weight: 500;
  letter-spacing: 0.03em;
}
.file-status.processing { color: var(--text-dim); font-style: italic; }
.file-status.error      { color: #c0392b; }

.folder-empty {
  padding: 9px 14px 9px 28px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-dim);
  font-style: italic;
}

/* ── Divider ───────────────────────────────────────────────────────────── */
.divider { width: 1px; background: var(--border); flex-shrink: 0; }

/* ── Chat Panel ────────────────────────────────────────────────────────── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: radial-gradient(ellipse at 70% 10%, #F3F0FA 0%, var(--bg) 55%);
}

.chat-header {
  padding: 16px 26px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: transparent;
}
.chat-header-info { display: flex; align-items: center; gap: 14px; }

.chat-header h3 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 19px;
  font-weight: 500;
  font-style: italic;
  letter-spacing: 0.02em;
  color: var(--text);
}

.context-pill {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 3px;
  background: var(--purple-dim);
  border: 1px solid var(--purple-dim-2);
  color: var(--purple);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.btn-clear {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 5px 11px;
  border-radius: var(--r);
  cursor: pointer;
  font-size: 11.5px;
  font-family: inherit;
  letter-spacing: 0.02em;
  transition: border-color 0.15s, color 0.15s;
}
.btn-clear:hover { border-color: var(--border-2); color: var(--text-muted); }

/* ── Messages ──────────────────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 30px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.message {
  display: flex;
  gap: 14px;
  max-width: 740px;
  animation: msgIn 0.22s ease-out;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user {
  flex-direction: row-reverse;
  margin-left: auto;
}

/* Avatar */
.avatar {
  width: 26px; height: 26px;
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 3px;
}

.message.assistant .avatar {
  background: var(--purple-dim);
  border: 1px solid var(--purple-dim-2);
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 13px;
  color: var(--purple);
  line-height: 1;
  font-weight: 400;
}

.message.user .avatar {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

/* AI responses — document excerpt style */
.message.assistant .bubble {
  background: transparent;
  border: none;
  border-left: 2px solid var(--purple-dim-3);
  border-radius: 0;
  padding: 1px 0 4px 20px;
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
  flex: 1;
}

/* User messages */
.message.user .bubble {
  background: var(--purple-dim);
  border: 1px solid var(--purple-dim-2);
  border-radius: var(--r);
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
}

.bubble p + p { margin-top: 10px; }

/* Markdown rendered inside assistant bubbles */
.message.assistant .bubble p { margin-top: 10px; }
.message.assistant .bubble p:first-child { margin-top: 0; }
.message.assistant .bubble ul,
.message.assistant .bubble ol {
  margin: 10px 0;
  padding-left: 20px;
}
.message.assistant .bubble li { margin-bottom: 4px; }
.message.assistant .bubble li > ul,
.message.assistant .bubble li > ol { margin: 4px 0; }
.message.assistant .bubble strong { font-weight: 600; color: var(--text); }
.message.assistant .bubble em { font-style: italic; }
.message.assistant .bubble h1,
.message.assistant .bubble h2,
.message.assistant .bubble h3 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 500;
  font-style: italic;
  color: var(--text);
  margin: 16px 0 6px;
  line-height: 1.3;
}
.message.assistant .bubble h1 { font-size: 18px; }
.message.assistant .bubble h2 { font-size: 16px; }
.message.assistant .bubble h3 { font-size: 15px; }
.message.assistant .bubble h1:first-child,
.message.assistant .bubble h2:first-child,
.message.assistant .bubble h3:first-child { margin-top: 0; }
.message.assistant .bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}
.message.assistant .bubble code {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
}

.bubble-note {
  font-size: 11.5px;
  color: var(--text-dim);
  font-style: italic;
  margin-top: 16px !important;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Citations */
.citations {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.citations-label {
  font-size: 9.5px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-bottom: 8px;
}

.citation-tag {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-style: italic;
  font-size: 13.5px;
  color: var(--text-muted);
  margin: 2px 14px 2px 0;
  transition: color 0.15s;
}
.citation-tag::before {
  content: '§';
  font-style: normal;
  color: var(--purple);
  font-size: 12px;
  font-family: 'Cormorant Garamond', serif;
  flex-shrink: 0;
}
.citation-tag:hover { color: var(--text); }

/* Typing indicator */
.typing .bubble {
  display: flex !important;
  align-items: center;
  gap: 5px;
  padding: 6px 0 6px 20px !important;
  border-left: 2px solid var(--purple-dim-3) !important;
  background: transparent !important;
  border-radius: 0 !important;
}

.dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: bounce 1.3s ease-in-out infinite;
}
.dot:nth-child(2) { animation-delay: 0.18s; }
.dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes bounce {
  0%,80%,100% { transform: scale(0.7); opacity: 0.3; }
  40%         { transform: scale(1.1); opacity: 0.85; }
}

/* ── Chat Input ────────────────────────────────────────────────────────── */
.chat-input-area {
  padding: 14px 26px 20px;
  border-top: 1px solid var(--border);
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--r);
  padding: 10px 10px 10px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.chat-input-row:focus-within {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-dim);
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  resize: none;
  max-height: 140px;
  line-height: 1.55;
}
.chat-input::placeholder { color: var(--text-dim); font-style: italic; }

.btn-send {
  width: 30px; height: 30px;
  background: var(--purple-dim);
  border: 1px solid var(--purple-dim-2);
  border-radius: var(--r);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--purple);
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
.btn-send:hover {
  background: var(--purple-dim-2);
  border-color: var(--purple-dim-3);
}
.btn-send:disabled {
  background: var(--bg-3);
  border-color: var(--border);
  color: var(--text-dim);
  cursor: not-allowed;
}

.input-hint {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 8px;
  letter-spacing: 0.01em;
}
.input-hint kbd {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 10px;
  color: var(--text-muted);
}

/* ── Reduced motion ────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .message { animation: none; }
  .dot     { animation: none; opacity: 0.5; }
}
