:root {
  --bg0: #f3f6f4;
  --bg1: #e7eee9;
  --ink: #14201a;
  --muted: #5b6b62;
  --line: #c9d5cd;
  --accent: #0f7a5f;
  --accent-2: #0b5c48;
  --warn: #a15c12;
  --danger: #9b2c2c;
  --ok: #0f7a5f;
  --panel: rgba(255, 255, 255, 0.92);
  --shadow: 0 12px 36px rgba(20, 32, 26, 0.06);
  --radius: 14px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Manrope", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html {
  font-size: 75%; /* giảm ~25% so với mặc định 16px */
}
html, body {
  margin: 0;
  height: 100%;
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(1200px 600px at 10% -10%, #d9ebe3 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #efe7d6 0%, transparent 50%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
}

body.booting {
  display: flex;
  align-items: center;
  justify-content: center;
}

body.logged-out {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

body.logged-in {
  display: block;
  height: 100%;
  overflow: hidden;
}

.boot-splash {
  display: none;
  color: var(--muted);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}
body.booting .boot-splash { display: block; }

a { color: var(--accent-2); text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app-shell {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: 0 0 auto;
}

.brand {
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand span {
  display: block;
  margin-top: 2px;
  font-family: var(--font-body);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.nav a, .btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  transition: 160ms ease;
}

.nav a.active, .btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn:hover, .nav a:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.grid {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

@media (max-width: 980px) {
  body.logged-in { overflow: auto; height: auto; }
  .app-shell { height: auto; overflow: visible; }
  .grid { grid-template-columns: 1fr; min-height: 70vh; }
}

.sidebar {
  padding: 14px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.sidebar h2 {
  margin: 0 0 8px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}

.server-search {
  width: 100%;
  margin-bottom: 10px;
}

.server-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.server-item {
  text-align: left;
  border: 1px solid transparent;
  background: #f7faf8;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}

.server-item.active {
  border-color: var(--accent);
  background: #e7f4ef;
}

.server-item strong { display: block; font-size: 0.95rem; }
.server-item small { color: var(--muted); font-family: var(--font-mono); font-size: 0.72rem; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  max-height: 140px;
  overflow: auto;
}

.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 0.82rem;
  cursor: pointer;
}

.chip:hover { border-color: var(--accent); color: var(--accent-2); }

.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.messages {
  flex: 1;
  padding: 16px 18px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.msg {
  max-width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  line-height: 1.55;
}

.msg.enter {
  animation: rise 180ms ease;
}

.msg.streaming {
  animation: none;
  will-change: contents;
}

.msg.user {
  align-self: flex-end;
  max-width: 70%;
  background: #143028;
  color: #f4fbf7;
  white-space: pre-wrap;
}

.msg.assistant {
  align-self: stretch;
  width: 100%;
  background: #fbfdfc;
  border: 1px solid var(--line);
  white-space: normal;
}

.msg.meta {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 0;
  white-space: pre-wrap;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg.assistant .md {
  font-size: 0.98rem;
  color: var(--ink);
}
.msg.assistant .md > *:first-child { margin-top: 0; }
.msg.assistant .md > *:last-child { margin-bottom: 0; }
.msg.assistant .md h1,
.msg.assistant .md h2,
.msg.assistant .md h3,
.msg.assistant .md h4 {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin: 1.1em 0 0.45em;
}
.msg.assistant .md h1 { font-size: 1.35rem; }
.msg.assistant .md h2 { font-size: 1.18rem; }
.msg.assistant .md h3 { font-size: 1.05rem; }
.msg.assistant .md p { margin: 0.55em 0; }
.msg.assistant .md ul,
.msg.assistant .md ol {
  margin: 0.45em 0;
  padding-left: 1.35em;
}
.msg.assistant .md li { margin: 0.25em 0; }
.msg.assistant .md strong { font-weight: 700; }
.msg.assistant .md code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: #eef4f0;
  border: 1px solid #d7e3db;
  border-radius: 6px;
  padding: 0.1em 0.35em;
}
.msg.assistant .md pre {
  margin: 0.75em 0;
  padding: 12px 14px;
  overflow: auto;
  background: #12231c;
  color: #e8f5ef;
  border-radius: 12px;
  font-size: 0.84rem;
  line-height: 1.45;
}
.msg.assistant .md pre code {
  background: transparent;
  border: 0;
  padding: 0;
  color: inherit;
  font-size: inherit;
}
.msg.assistant .md blockquote {
  margin: 0.7em 0;
  padding: 0.2em 0 0.2em 0.9em;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
.msg.assistant .md table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.7em 0;
  font-size: 0.9rem;
}
.msg.assistant .md th,
.msg.assistant .md td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}
.msg.assistant .md hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1em 0;
}

.composer {
  border-top: 1px solid var(--line);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  flex: 0 0 auto;
}

.composer textarea {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 12px;
  background: #fff;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 16px 0;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.toolbar .btn {
  margin-left: auto;
  padding: 6px 12px;
  font-size: 0.82rem;
}

.ssh-status {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
}
.ssh-status.muted { color: var(--muted); }
.ssh-status.warn { color: var(--warn); border-color: #ead2a8; background: #fff8eb; }
.ssh-status.ok { color: var(--ok); border-color: #b9ddd0; background: #eef8f3; }
.ssh-status.bad { color: var(--danger); border-color: #efc2c2; background: #fdecec; }

select, .field {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
}

.login-wrap {
  width: min(420px, 100%);
  padding: 28px;
}

.login-wrap h1 {
  font-family: var(--font-display);
  margin: 0 0 8px;
  font-size: 2rem;
}

.login-wrap p { color: var(--muted); margin: 0 0 18px; }

.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.form-row label { font-size: 0.85rem; color: var(--muted); }
.form-row input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}

#adminApp {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

#adminApp .panel {
  display: flex;
  flex-direction: column;
  min-height: min-content;
}

#adminApp .table-wrap {
  flex: 1 1 auto;
  min-height: 240px;
  max-height: none;
  overflow: auto;
}

.table-wrap { overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
td.mono, .mono { font-family: var(--font-mono); font-size: 0.8rem; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 16px; }
.alert {
  padding: 10px 12px;
  border-radius: 10px;
  background: #fdecec;
  color: var(--danger);
  margin-bottom: 12px;
}
.hidden { display: none !important; }
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.answer-preview { max-width: 520px; max-height: 160px; overflow: auto; white-space: pre-wrap; }

.auto-summary {
  margin: 8px 16px 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}
.auto-summary.ok { background: #eef8f3; border-color: #b9ddd0; color: var(--ok); }
.auto-summary.bad { background: #fdecec; border-color: #efc2c2; color: var(--danger); }
.auto-summary.warn { background: #fff8eb; border-color: #ead2a8; color: var(--warn); }
.auto-summary.muted { color: var(--muted); }

.auto-hint {
  margin: 0 16px 10px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

#tab-automation td:nth-child(2) {
  min-width: 280px;
  max-width: 420px;
  white-space: normal;
  line-height: 1.35;
  font-size: 0.86rem;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.badge.pass { background: #eef8f3; color: var(--ok); }
.badge.fail { background: #fdecec; color: var(--danger); }
.badge.pending { background: #f3f6f4; color: var(--muted); }

.tags { white-space: normal; }
.tag {
  display: inline-block;
  margin: 1px 3px 1px 0;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.7rem;
  border: 1px solid var(--line);
  background: #f7faf8;
  color: var(--muted);
}
.tag-danger { background: #fdecec; border-color: #efc2c2; color: var(--danger); }
.tag-rare { background: #fff8eb; border-color: #ead2a8; color: var(--warn); }
.tag-llm { background: #eef2ff; border-color: #c7d2fe; color: #3730a3; }
.tag-allow { background: #eef8f3; border-color: #b9ddd0; color: var(--ok); }
.tag-safe { background: #eef8f3; border-color: #b9ddd0; color: var(--ok); }
.tag-site-security { background: #f3eef8; border-color: #d4c4e8; color: #5b3d7a; }
