:root {
  --bg: #0f1115;
  --panel: #161a22;
  --panel-2: #1d222c;
  --border: #262c38;
  --text: #e6e9ef;
  --muted: #8a93a6;
  --accent: #6aa9ff;
  --accent-2: #9b87ff;
  --user: #2c3447;
  --error: #ff6b6b;
  --ok: #5dd39e;
  --max-width: 860px;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  background: var(--accent);
  color: #0b1020;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
button:hover:not(:disabled) { filter: brightness(1.1); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button.ghost:hover:not(:disabled) { background: var(--panel-2); }
button.danger { background: var(--error); color: #1a0a0a; }

input, textarea, select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.center-card {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 420px;
}
.card h1 { margin: 0 0 6px 0; font-size: 22px; }
.card .sub { color: var(--muted); margin: 0 0 20px 0; font-size: 14px; }
.field { margin-bottom: 14px; }
.error { color: var(--error); font-size: 13px; margin-top: 8px; min-height: 18px; }
.spaced { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 16px; }

/* --- Chat layout --- */

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sidebar-header .brand { font-weight: 700; letter-spacing: 0.3px; }
.sidebar-header .brand small { color: var(--muted); font-weight: 400; margin-left: 6px; font-size: 11px; }
.brand-icon { width: 84px; height: 84px; border-radius: 50%; flex-shrink: 0; display: block; }
.mobile-bar .brand-icon { width: 24px; height: 24px; }
.role-avatar { width: 18px; height: 18px; border-radius: 50%; vertical-align: middle; margin-right: 6px; }
.msg .role { display: flex; align-items: center; }

.new-btn {
  margin: 12px;
  padding: 10px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #0b1020;
  border-radius: 8px;
  font-weight: 600;
  border: none;
  cursor: pointer;
}

.conv-search-wrap { padding: 0 12px 8px; }
.conv-search {
  width: 100%;
  padding: 6px 10px;
  font-size: 13px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}
.conv-search::placeholder { color: var(--muted); }

.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.conv-item {
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 2px;
  overflow: hidden;
}
.conv-item .conv-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .conv-snippet {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: var(--panel-2); border-left: 2px solid var(--accent); padding-left: 10px; }
.empty-list { color: var(--muted); padding: 12px; font-size: 13px; }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.sidebar-footer .who { font-weight: 600; color: var(--text); }
.sidebar-footer .row { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 8px; }
.sidebar-footer a { font-size: 12px; }

.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.messages-inner { max-width: var(--max-width); margin: 0 auto; width: 100%; display: flex; flex-direction: column; gap: 18px; }

.msg { display: flex; flex-direction: column; gap: 6px; }
.msg .role { font-size: 12px; color: var(--muted); }
.msg .body {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user .body { background: var(--user); }
.msg .citations { font-size: 12px; color: var(--muted); margin-top: 4px; }
.msg .citations code { background: var(--panel-2); padding: 1px 6px; border-radius: 4px; margin-right: 6px; }

.context {
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.context .src { color: var(--accent); }

.composer {
  border-top: 1px solid var(--border);
  padding: 16px;
  background: var(--panel);
}
.composer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 200px;
  resize: none;
}
.composer button { height: 44px; }

.empty {
  color: var(--muted);
  text-align: center;
  margin-top: 80px;
}
.empty h2 { color: var(--text); margin-bottom: 8px; }

/* --- Admin --- */

.admin-shell { padding: 24px; max-width: 1100px; margin: 0 auto; }
.admin-shell h1 { margin: 0 0 4px 0; }
.admin-shell .muted { color: var(--muted); margin-bottom: 24px; }
.admin-back { display: inline-block; margin-bottom: 14px; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab {
  padding: 8px 14px;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.panel h3 { margin-top: 0; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-grow { flex-grow: 1; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--accent); background: var(--panel-2); color: var(--text); }
.dropzone input { display: none; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--panel); border: 1px solid var(--border); padding: 10px 14px; border-radius: 8px; font-size: 14px; }
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--error); }

/* --- Responsive --- */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.open { display: flex; position: fixed; inset: 0; z-index: 10; }
  .messages { padding: 12px; }
  .composer { padding: 12px; }
  .menu-btn { display: inline-flex; }
}
.menu-btn { display: none; background: transparent; border: 1px solid var(--border); color: var(--text); padding: 6px 10px; border-radius: 6px; }
.mobile-bar { display: none; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--panel); align-items: center; gap: 10px; }
@media (max-width: 720px) { .mobile-bar { display: flex; } }
