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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3350;
  --text: #e8eaf6;
  --text-muted: #7c83a8;
  --accent: #6c7fff;
  --accent-dim: #3d4580;
  --green: #4caf82;
  --green-dim: #1e4035;
  --purple: #a78bfa;
  --purple-dim: #2e2148;
  --orange: #fb923c;
  --orange-dim: #3d1f0a;
  --red: #f87171;
  --red-dim: #3b1212;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
}

/* ── SIDEBAR ── */
#sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.sidebar-header h3 { font-size: 13px; font-weight: 600; color: var(--text); }
#history-count { font-size: 11px; color: var(--text-muted); }

#history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

#history-list::-webkit-scrollbar { width: 4px; }
#history-list::-webkit-scrollbar-track { background: transparent; }
#history-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.history-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 4px;
  position: relative;
}

.history-item:hover { background: var(--surface2); }
.history-item.active { background: var(--accent-dim); }

.history-topic {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.history-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
  align-items: center;
}

.depth-tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.depth-tag.quick    { background: var(--green-dim); color: var(--green); }
.depth-tag.standard { background: var(--accent-dim); color: var(--accent); }
.depth-tag.deep     { background: var(--purple-dim); color: var(--purple); }

.history-delete {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  background: none;
  border: none;
  color: var(--red);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 4px;
  transition: opacity 0.15s, background 0.15s;
}

.history-item:hover .history-delete {
  opacity: 1;
}

.history-delete:hover { background: var(--red-dim); }

.history-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 24px 12px;
  line-height: 1.8;
}

/* ── MAIN ── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
}

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

.logo-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.logo-icon img { width: 100%; height: 100%; object-fit: contain; display: block; }
.logo-icon svg { width: 18px; height: 18px; fill: white; }

header h1 { font-size: 16px; font-weight: 700; color: var(--text); }
.tagline { font-size: 12px; color: var(--text-muted); margin-left: auto; }

/* ── SEARCH PANEL ── */
#search-panel {
  padding: 20px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

#topic-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

#topic-input:focus { border-color: var(--accent); }
#topic-input::placeholder { color: var(--text-muted); }

#research-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}

#research-btn:hover:not(:disabled) { opacity: 0.85; }
#research-btn:active:not(:disabled) { transform: scale(0.97); }
#research-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.depth-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.depth-row label { font-size: 12px; color: var(--text-muted); }

.depth-options { display: flex; gap: 6px; }

.depth-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.depth-btn:hover { border-color: var(--accent); color: var(--text); }
.depth-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* ── CONTENT AREA ── */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

#content::-webkit-scrollbar { width: 6px; }
#content::-webkit-scrollbar-track { background: transparent; }
#content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── EMPTY STATE ── */
#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  gap: 12px;
}

.empty-icon {
  width: 56px;
  height: 56px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-icon svg { width: 28px; height: 28px; stroke: var(--text-muted); fill: none; }

#empty-state h2 { font-size: 16px; font-weight: 600; color: var(--text); }
#empty-state p  { font-size: 13px; max-width: 300px; }

.example-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.example-topic {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.example-topic:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

/* ── LOADING ── */
#loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 16px;
  color: var(--text-muted);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-topic {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

/* ── DIGEST VIEW ── */
#digest-view { display: none; }
#digest-view.visible { display: block; }

.digest-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
}

.digest-title-block h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.digest-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.review-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-save {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-save:hover { opacity: 0.85; }
.btn-save:disabled { opacity: 0.45; cursor: default; }

.btn-discard {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-discard:hover { border-color: var(--red); color: var(--red); }

/* ── CARDS GRID ── */
.cards-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 640px) {
  .cards-grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  animation: fadeIn 0.3s ease;
}

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

.card-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
  padding: 3px 8px;
  border-radius: 4px;
  display: inline-block;
}

.card-summary { grid-column: 1 / -1; }
.card-summary .card-label { background: var(--accent-dim); color: var(--accent); }
.card-summary p { font-size: 14px; line-height: 1.7; color: var(--text); }

.card-points .card-label { background: var(--green-dim); color: var(--green); }
.card-points ul { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.card-points li {
  font-size: 13px;
  color: var(--text);
  padding-left: 16px;
  position: relative;
  line-height: 1.5;
}
.card-points li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}

.card-concepts .card-label { background: var(--purple-dim); color: var(--purple); }
.concept-item { margin-bottom: 10px; }
.concept-item:last-child { margin-bottom: 0; }
.concept-term { font-size: 12px; font-weight: 600; color: var(--purple); margin-bottom: 2px; }
.concept-def { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

.card-related .card-label { background: var(--orange-dim); color: var(--orange); }
.related-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.related-tag {
  background: var(--orange-dim);
  border: 1px solid var(--orange);
  color: var(--orange);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.related-tag:hover { background: var(--orange); color: var(--bg); }

.confidence-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}
.confidence-badge.high   { background: var(--green-dim);  color: var(--green); }
.confidence-badge.medium { background: var(--accent-dim); color: var(--accent); }
.confidence-badge.low    { background: var(--orange-dim); color: var(--orange); }

/* ── SAVE TOAST ── */
#toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--green);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.25s;
  pointer-events: none;
  z-index: 100;
}
#toast.show { opacity: 1; transform: none; }

/* ── ERROR ── */
.error-banner {
  background: var(--red-dim);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--red);
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.error-banner button {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--red);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}
