:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #262b36;
  --text: #e6e6e6;
  --muted: #8b93a1;
  --accent: #4f8cff;
  --user-bubble: #2563eb;
  --assistant-bubble: #1f2430;
  --error: #ef4444;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.screen { height: 100%; }
.hidden { display: none !important; }

/* Auth screen */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 320px;
}
.auth-box h1 {
  margin: 0 0 20px;
  font-size: 20px;
  text-align: center;
}
.tabs {
  display: flex;
  margin-bottom: 16px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.tab-btn {
  flex: 1;
  padding: 8px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
}
.tab-btn.active {
  background: var(--accent);
  color: white;
}
.tab-panel { display: none; flex-direction: column; gap: 10px; }
.tab-panel.active { display: flex; }

input, button {
  font: inherit;
}
input {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0d0f13;
  color: var(--text);
}
button {
  padding: 10px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
}
button:hover { opacity: 0.9; }
.error { color: var(--error); font-size: 13px; min-height: 16px; margin: 0; }
.success { color: #22c55e; font-size: 13px; margin: 0; }

/* App screen */
#app-screen {
  display: flex;
  height: 100%;
}
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
}
.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sidebar-header h2 { margin: 0; font-size: 16px; }
.sidebar-header-actions { display: flex; gap: 6px; }
.sidebar-header button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 10px;
  font-size: 12px;
}
#new-chat-form { display: flex; gap: 6px; }
#new-chat-form input { flex: 1; min-width: 0; }
#new-chat-form button { width: 36px; padding: 10px 0; }
#chat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}
#chat-list li {
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#chat-list li:hover { background: #1d222c; }
#chat-list li.active { background: var(--accent); color: white; }

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
#chat-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: white;
}
.msg-assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
}
.msg-tool-call, .msg-tool-result {
  align-self: flex-start;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--muted);
  font-size: 13px;
  font-family: ui-monospace, Consolas, monospace;
}
.msg-pending { align-self: flex-start; color: var(--muted); }
.msg-error { align-self: flex-start; color: var(--error); }

#send-form {
  display: flex;
  gap: 10px;
  padding: 16px;
  border-top: 1px solid var(--border);
}
#message-input { flex: 1; min-width: 0; }

/* Admin modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: min(700px, 90vw);
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-header button {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  padding: 0 4px;
}
#admin-users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
#admin-users-table th, #admin-users-table td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}
#admin-users-table td.actions { display: flex; gap: 6px; flex-wrap: wrap; }
#admin-users-table button {
  padding: 4px 8px;
  font-size: 12px;
}
