:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --danger: #f87171;
  --good: #4ade80;
  --border: #334155;
}

* { 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", Roboto, "Helvetica Neue", Arial, sans-serif;
}

#topbar {
  display: flex;
  align-items: center;
  padding: 0 24px;
  height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 700;
  font-size: 18px;
  margin-right: 32px;
}

.badge {
  display: inline-block;
  background: var(--accent);
  color: #0b1120;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
  font-weight: 700;
  text-transform: uppercase;
}

#topbar nav { display: flex; gap: 4px; flex: 1; }
.nav-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.nav-btn:hover { color: var(--text); background: var(--panel-2); }
.nav-btn.active { color: var(--text); background: var(--panel-2); }

.user { display: flex; gap: 12px; align-items: center; }
.user #who { color: var(--muted); font-size: 13px; }

main { padding: 24px; max-width: 1100px; margin: 0 auto; }

.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 16px;
}

.muted { color: var(--muted); font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; }
.hint code {
  background: var(--panel-2);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

.error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
}

button {
  background: var(--accent);
  color: #0b1120;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.05); }
button:disabled { opacity: 0.6; cursor: not-allowed; }

#logout, #chat-new, #history-refresh, #tasks-refresh {
  background: var(--panel-2);
  color: var(--text);
}

input, textarea, select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  width: 100%;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

/* Login */
.login-card {
  max-width: 380px;
  margin: 80px auto 0;
}
.login-card h1 { margin: 0 0 4px; }
#login-form button { width: 100%; margin-top: 4px; }

/* Chat */
.chat-shell {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px - 48px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.msg {
  max-width: 80%;
  padding: 12px 14px;
  border-radius: 10px;
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 14px;
}
.msg.user { align-self: flex-end; background: var(--accent-2); color: #0b1120; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--border); }

.chat-input {
  border-top: 1px solid var(--border);
  padding: 14px;
  background: var(--panel-2);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-input textarea {
  resize: vertical;
  background: var(--panel);
}
.chat-input .row { display: flex; gap: 10px; align-items: end; }
.chat-input .ability { flex: 1; margin-bottom: 0; }

/* Analyse */
.analyze-output {
  margin-top: 16px;
  padding: 14px;
  background: var(--panel-2);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  white-space: pre-wrap;
  min-height: 80px;
  max-height: 60vh;
  overflow-y: auto;
}
.analyze-section { margin-bottom: 12px; }
.analyze-section .label {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-size: 11px;
  margin-bottom: 4px;
}
.analyze-section .body {
  background: var(--panel);
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* History */
.history-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}
.history-list li {
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.history-list .meta { color: var(--muted); font-size: 12px; }
