:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --text-dim: #98a0ad;
  --accent: #6aa7ff;
  --accent-fg: #0b1220;
  --danger: #ff6b6b;
  --ok: #5ad17a;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,.35);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --surface-2: #f1f3f7;
    --border: #e3e6ec;
    --text: #1a1d23;
    --text-dim: #5b6573;
    --accent: #2a6df4;
    --accent-fg: #ffffff;
    --shadow: 0 4px 24px rgba(0,0,0,.06);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  height: 100%;
}

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

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: var(--radius);
  padding: .55rem 1rem;
  cursor: pointer;
  font-weight: 600;
  transition: opacity .15s, transform .05s;
}
button:hover { opacity: .9; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }

button.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
button.danger { background: var(--danger); color: white; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
textarea, select {
  width: 100%;
  padding: .55rem .75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.row { display: flex; gap: .75rem; align-items: center; }
.row > * { flex: 1; }
.col { display: flex; flex-direction: column; gap: .75rem; }

.muted { color: var(--text-dim); font-size: .9rem; }
.error { color: var(--danger); font-size: .9rem; }
.ok    { color: var(--ok); font-size: .9rem; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar .brand { font-weight: 700; letter-spacing: -.01em; }
.topbar nav { display: flex; gap: .5rem; }
.topbar nav a {
  padding: .35rem .7rem;
  border-radius: 6px;
  color: var(--text-dim);
}
.topbar nav a.active { background: var(--surface-2); color: var(--text); }

/* Login */
.center-form {
  min-height: calc(100vh - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.center-form .card { width: 100%; max-width: 380px; }

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th, .table td {
  padding: .6rem .5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: .95rem;
}
.table th { color: var(--text-dim); font-weight: 600; }
.table .actions { display: flex; gap: .4rem; justify-content: flex-end; }
.table .actions button { padding: .3rem .6rem; font-size: .85rem; }

/* Chat */
.chat-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: calc(100vh - 60px);
}
.chat-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
}
.chat-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.msg { max-width: 760px; }
.msg.user { align-self: flex-end; }
.msg.bot  { align-self: flex-start; }
.msg .bubble {
  padding: .75rem 1rem;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.5;
}
.msg.user .bubble { background: var(--accent); color: var(--accent-fg); }
.msg.bot  .bubble { background: var(--surface-2); border: 1px solid var(--border); }
.msg .sources {
  margin-top: .35rem;
  font-size: .82rem;
  color: var(--text-dim);
}

.chat-input {
  display: flex;
  gap: .5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.chat-input textarea {
  resize: none;
  height: 44px;
  max-height: 200px;
}

.sidebar-item {
  display: block;
  padding: .55rem .65rem;
  border-radius: 8px;
  color: var(--text);
  font-size: .9rem;
  border: 1px solid transparent;
  cursor: pointer;
}
.sidebar-item:hover { background: var(--surface-2); }
.sidebar-item .when { color: var(--text-dim); font-size: .75rem; }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--accent); background: var(--surface-2); }
.dropzone.has-file { border-style: solid; color: var(--text); }

/* Mobile */
@media (max-width: 760px) {
  .chat-shell { grid-template-columns: 1fr; }
  .chat-sidebar { display: none; }
}
