:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #dde1e6;
  --text: #1a1d21;
  --muted: #6b7280;
  --accent: #f6821f;
  --accent-dark: #c2570a;
  --user-bubble: #2563eb;
  --user-bubble-text: #ffffff;
  --assistant-bubble: #eef1f4;
  --safe-accent: #2f9e44;
  --safe-accent-dark: #1f7a34;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1c1f24;
    --border: #2c313a;
    --text: #edeff2;
    --muted: #9aa2ad;
    --assistant-bubble: #262b32;
  }
}

* { box-sizing: border-box; }

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

.topbar {
  padding: 1rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 1100px;
  margin: 0 auto;
}

.logo { font-size: 2rem; }

.topbar h1 { margin: 0; font-size: 1.25rem; }
.topbar p { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.85rem; }

.layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1rem;
  max-width: 1100px;
  margin: 1rem auto;
  padding: 0 1rem;
  align-items: start;
}

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
}

.chat-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  height: 70vh;
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.bubble {
  max-width: 80%;
  padding: 0.6rem 0.85rem;
  border-radius: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  font-size: 0.92rem;
}

.bubble.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 2px;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border-bottom-left-radius: 2px;
}

.bubble.error {
  align-self: flex-start;
  background: #fee2e2;
  color: #7f1d1d;
  border: 1px solid #fca5a5;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

.retry-btn {
  border: 1px solid #fca5a5;
  background: #ffffff;
  color: #7f1d1d;
  font-weight: 600;
  font-size: 0.72rem;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
}

.retry-btn:hover { background: #fee2e2; }
.retry-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.bubble p { margin: 0 0 0.5em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 0.5em; padding-left: 1.2em; }
.bubble ul:last-child, .bubble ol:last-child { margin-bottom: 0; }
.bubble li { margin: 0.15em 0; }
.bubble code {
  background: rgba(127, 127, 127, 0.18);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
}

.bubble .sources {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}

.chat-form textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  font-family: inherit;
  font-size: 0.92rem;
  background: var(--bg);
  color: var(--text);
}

.chat-form button {
  border: none;
  background: var(--accent);
  color: #1a1d21;
  font-weight: 600;
  padding: 0 1.1rem;
  border-radius: 8px;
  cursor: pointer;
}

.chat-form button:hover { background: var(--accent-dark); color: #fff; }
.chat-form button:disabled { opacity: 0.6; cursor: not-allowed; }

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.attack-console,
.sample-console {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.attack-console h2,
.sample-console h2 { margin: 0 0 0.4rem; font-size: 1rem; }
.console-note { margin: 0 0 0.75rem; color: var(--muted); font-size: 0.8rem; line-height: 1.4; }

.preset-buttons { display: flex; flex-direction: column; gap: 0.5rem; }

.preset-btn {
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.82rem;
}

.preset-btn:hover { border-color: var(--accent); }

.preset-btn .label { display: block; font-weight: 600; }
.preset-btn .field { display: block; color: var(--muted); font-size: 0.72rem; margin-top: 0.15rem; }

.sample-btn:hover { border-color: var(--safe-accent); }
.sample-btn .label { display: block; font-weight: 600; }
