:root {
  --canvas: #CEC8BC;
  --sidebar: #EDE7DB;
  --surface: #F4EFE6;
  --divider: #E4DAD0;
  --divider-2: #D8CFBF;
  --accent: #7A5840;
  --accent-deep: #5D4130;
  --accent-rgb: 122, 88, 64;
  --text: #2C2820;
  --text-body: #4A4439;
  --text-secondary: #6B6156;
  --text-muted: #655A4E;
  --text-placeholder: #B5A99A;
  --error: #B43C28;
  --r-sm: 6px;
  --r-md: 10px;
  --r-sheet: 16px;
}

* { box-sizing: border-box; }

html, body {
  min-height: 100%;
  background: var(--canvas);
  margin: 0;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--text);
}

textarea, input, button { font-family: 'Inter', system-ui, sans-serif; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--divider-2); border-radius: 3px; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.wordmark {
  font-family: 'Lora', Georgia, serif;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.028em;
  color: var(--text);
}

.app {
  width: 100%;
  min-height: 100vh;
  display: flex;
  background: var(--canvas);
}

.app-frame {
  width: 100%;
  min-height: 100vh;
  background: var(--surface);
  display: flex;
}

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

.sidebar-header {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--divider);
}

.nav {
  padding: 6px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 400;
  color: var(--text-muted);
  border-left: 2px solid transparent;
  cursor: pointer;
  background: none;
  border-top: none;
  border-bottom: none;
  border-right: none;
  width: 100%;
  text-align: left;
}

.nav-item svg { flex-shrink: 0; width: 20px; height: 20px; }

.nav-item.active {
  font-weight: 600;
  color: var(--accent-deep);
  background: rgba(var(--accent-rgb), 0.14);
  border-left-color: var(--accent-deep);
}

/* ── Mobile top bar ── */
.mobile-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  background: var(--sidebar);
  border-bottom: 1px solid var(--divider);
}

.mobile-tabs {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.mobile-tab {
  padding: 6px 12px;
  border: none;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.mobile-tab.active {
  background: var(--accent-deep);
  color: var(--surface);
}

/* ── Main content ── */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.view { display: none; flex: 1; min-height: 0; flex-direction: column; }
.view.active { display: flex; }

/* ── Chat ── */
.chat-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-scroll {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 24px 28px;
}

.chat-empty {
  color: var(--text-muted);
  font-family: 'Lora', Georgia, serif;
  font-style: italic;
  font-size: 15px;
  padding: 24px 0;
}

.chat-turn {
  margin-bottom: 32px;
}
.chat-turn:last-child {
  margin-bottom: 0;
}

.chat-query {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
}

.chat-query-bubble {
  max-width: 72%;
  background: var(--sidebar);
  border-radius: 10px 10px 2px 10px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
}

.chat-answer {
  animation: fadeUp 220ms ease-out both;
}

/* ── Prose (shared markdown rendering: chat answers + note bodies) ── */
.prose h2, .prose h3 {
  font-family: 'Lora', Georgia, serif;
  font-weight: 500;
  color: var(--text);
  margin: 20px 0 8px;
  line-height: 1.3;
}
.prose h3 { font-size: 18px; }
.prose h2 { font-size: 20px; }
.prose blockquote {
  font-style: italic;
  color: var(--accent);
  border-left: 2px solid var(--accent);
  padding-left: 16px;
  margin: 16px 0;
}
.prose a { color: var(--accent); text-decoration: none; border-bottom: 1px solid rgba(var(--accent-rgb), 0.35); }
.prose img { max-width: 100%; border-radius: 8px; margin: 12px 0; display: block; }
.prose hr { border: none; border-top: 1px solid var(--divider); margin: 20px 0; }
.prose table { border-collapse: collapse; margin: 0 0 16px; width: 100%; }
.prose th, .prose td { border: 1px solid var(--divider); padding: 6px 10px; text-align: left; }
.prose th { font-weight: 600; background: var(--sidebar); }

.chat-answer-text {
  font-family: 'Lora', Georgia, serif;
  font-size: 15px;
  color: var(--text-body);
  line-height: 1.8;
  max-width: 560px;
}
.chat-answer-text p { margin: 0 0 16px; }
.chat-answer-text ul { margin: 0 0 16px; padding-left: 20px; }
.chat-answer-text li { margin-bottom: 4px; }
.chat-answer-text table { font-size: 14px; }
.chat-answer-text th { font-family: 'Inter', sans-serif; }

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--sidebar);
  border: 1px solid var(--divider);
  border-radius: 999px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  margin-top: 12px;
}
.copy-btn.copied { color: var(--accent); }

.source-row {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--divider);
  font-size: 13px;
  color: var(--text);
  font-family: 'Lora', Georgia, serif;
  line-height: 1.4;
  background: var(--sidebar);
  border-left: none;
  border-top: none;
  border-right: none;
  text-align: left;
  width: 100%;
  display: block;
}
.source-row:last-child { border-bottom: none; }

.turn-sources {
  margin-top: 14px;
}
.turn-sources summary {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--sidebar);
  border: 1px solid var(--divider);
  border-radius: var(--r-md);
}
.turn-sources[open] summary { border-radius: var(--r-md) var(--r-md) 0 0; }
.turn-sources .sources-list { border: 1px solid var(--divider); border-top: none; border-radius: 0 0 var(--r-md) var(--r-md); overflow: hidden; }

.chat-input-row {
  padding: 12px 24px;
  border-top: 1px solid var(--divider);
  flex-shrink: 0;
}

.chat-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--divider);
  border-radius: var(--r-md);
  padding: 8px 12px;
  background: #FFFFFF;
}

.chat-input-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--text);
  outline: none;
}

.send-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--accent-deep);
  color: var(--surface);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Capture ── */
.capture-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 64px 40px;
  display: flex;
  justify-content: center;
}

.capture-surface {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
}

#capture-title {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  overflow: hidden;
  font-family: 'Lora', Georgia, serif;
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 14px;
}
#capture-title::placeholder { color: var(--text-placeholder); }

#capture-body {
  min-height: 260px;
  outline: none;
  font-family: 'Lora', Georgia, serif;
  font-size: 18px;
  line-height: 1.75;
  color: var(--text);
}

#capture-body:empty::before {
  content: attr(data-placeholder);
  color: var(--text-placeholder);
  pointer-events: none;
}

#capture-body ul { padding-left: 20px; margin: 6px 0; }
#capture-body li { margin-bottom: 3px; }
#capture-body a { color: var(--accent); text-decoration: none; border-bottom: 1px solid rgba(var(--accent-rgb), 0.35); }
#capture-body img { max-width: 100%; border-radius: 8px; margin: 8px 0; display: block; }

.capture-img-wrap { position: relative; margin: 8px 0; }
.capture-img-wrap img { margin: 0; }
.capture-img-overlay {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: rgba(44, 40, 32, 0.7);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  cursor: pointer;
  transition: opacity 120ms ease-out;
}
.capture-img-wrap:hover .capture-img-overlay { opacity: 1; }
.capture-img-overlay svg { width: 40px; height: 40px; }

.capture-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 18px;
  margin-top: 18px;
  border-top: 1px solid var(--divider);
}

.btn-primary {
  padding: 8px 20px;
  background: var(--accent-deep);
  color: var(--surface);
  border: none;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.capture-status {
  text-align: center;
  padding: 80px 24px;
  animation: fadeUp 200ms ease-out;
}

.status-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}
.status-icon.ok { background: rgba(var(--accent-rgb), 0.1); }
.status-icon.err { background: rgba(180, 60, 40, 0.09); }

.capture-status-title {
  font-family: 'Lora', Georgia, serif;
  font-size: 21px;
  color: var(--text);
  margin-bottom: 8px;
}

.capture-status-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.5;
}

/* ── Note modal ── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(44, 40, 32, 0.35);
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeIn 150ms ease-out;
}
.overlay.open { display: flex; }

.note-sheet {
  background: var(--surface);
  width: 560px;
  max-width: 92%;
  height: 86%;
  border-radius: var(--r-sheet);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(44, 40, 32, 0.2);
  animation: fadeUp 180ms ease-out;
}

.note-sheet-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}

.note-sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 26px 30px 48px;
}

.note-title {
  font-family: 'Lora', Georgia, serif;
  font-size: 26px;
  font-weight: 400;
  color: var(--text);
  line-height: 1.25;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

.note-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 18px;
}

.note-content {
  font-family: 'Lora', Georgia, serif;
  font-size: 16px;
  color: var(--text-body);
  line-height: 1.78;
}
.note-content p { margin: 0 0 16px; }
.note-content ul { padding-left: 20px; margin: 0 0 16px; }
.note-content table { font-family: 'Inter', sans-serif; font-size: 15px; }

.note-loading, .note-error {
  font-size: 13px;
  color: var(--text-muted);
  padding: 24px 0;
}

/* ── Gallery (static, phase 2) ── */
.gallery-static {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
}
.gallery-static-inner {
  max-width: 360px;
}
.gallery-static-inner p {
  font-family: 'Lora', Georgia, serif;
  font-size: 15px;
  font-style: italic;
  color: var(--text-muted);
  line-height: 1.65;
}

/* ── Responsive ── */
@media (max-width: 760px) {
  .app { padding: 0; }
  .sidebar { display: none; }
  .mobile-bar { display: flex; }
  .capture-wrap { padding: 18px 16px; }
  .chat-scroll { padding: 16px; }
  .chat-input-row { padding: 10px 14px; }
  .note-sheet { width: 100%; height: 92%; border-radius: 16px 16px 0 0; align-self: flex-end; }
  .overlay { align-items: flex-end; }
  .note-sheet-body { padding: 20px 18px 40px; }
}
