:root {
  --bg: #f5f5f5; --card: #fff; --text: #1a1a1a; --muted: #6b7280;
  --border: #d1d5db; --grey-light: #f3f4f6;
  --blue: #2563eb; --blue-h: #1d4ed8; --green: #16a34a; --green-h: #15803d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.5;
}

.tag {
  font-size: .75rem; padding: 2px 10px; border-radius: 10px;
  background: var(--grey-light); color: var(--muted);
  border: 1px solid var(--border);
}

.page { max-width: 1100px; margin: 1.5rem auto; padding: 0 1rem; display: flex; gap: 1rem; }
.main { flex: 1; min-width: 0; }
.side { width: 272px; flex-shrink: 0; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.04);
  margin-bottom: 1rem; overflow: hidden;
}
.card-header {
  background: var(--grey-light); padding: .75rem 1rem;
  font-weight: 600; font-size: 1rem; border-bottom: 1px solid var(--border);
}
.card-body { padding: 1rem; }

.status { font-size: .85rem; color: var(--muted); margin-top: .5rem; min-height: 1.2rem; }

.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .5rem 1rem; border: 1px solid var(--border);
  border-radius: 6px; font-size: .85rem; font-weight: 500;
  background: #fff; color: var(--text); cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap; font-family: inherit;
}
.btn:hover { background: var(--grey-light); }
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-h); }
.btn-primary:disabled { background: #93c5fd; cursor: not-allowed; border-color: #93c5fd; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Chat */
.msg { padding: .75rem 1rem; border-radius: 8px; margin-bottom: .5rem; font-size: .9rem; line-height: 1.6; }
.msg.user { background: #eff6ff; border: 1px solid #dbeafe; color: #1e40af; }
.msg.bot  { background: var(--grey-light); border: 1px solid var(--border); color: var(--text); }
.msg p { margin: 0; } .msg p + p { margin-top: .5rem; }
.msg b { color: #111; }
.msg code { background: #e5e7eb; padding: 1px 5px; border-radius: 3px; font-size: .85em; color: #b91c1c; }
.msg ul, .msg ol { margin: .25rem 0; padding-left: 1.25rem; }
.msg li { margin: .1rem 0; }

/* History */
.hitem { padding: 6px 8px; border-radius: 4px; cursor: pointer; margin-bottom: 3px; font-size: .8rem; color: var(--muted); }
.hitem:hover { background: var(--grey-light); }

/* DARK */
body.dark {
  --bg: #0f0f1a; --card: #18182a; --text: #e0e0e0; --muted: #888;
  --border: #2a2a40; --grey-light: #1e1e30;
}
body.dark header { background: var(--card) !important; border-color: var(--border) !important; color: var(--muted) !important; }
body.dark header b { color: var(--text) !important; }
body.dark .msg.user { background: #0a1e2e; border: 1px solid #1e3a5f; color: #93c5fd; }
body.dark .msg.bot { background: var(--grey-light); border: 1px solid var(--border); color: #d0d0f0; }
body.dark .msg b { color: #fff; }
body.dark .msg code { background: #2a2a44; color: #f8c291; }
body.dark .btn { background: var(--card); color: var(--text); }
body.dark .btn:hover { background: var(--border); }
body.dark .btn-primary { background: var(--blue); color: #fff; }
body.dark .btn-primary:hover { background: var(--blue-h); }