:root {
  --brand: #0f5c4d;
  --brand-2: #13806b;
  --sand: #f4efe6;
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #1d2523;
  --muted: #69736f;
  --line: #e4e2db;
  --bot: #f1f4f2;
  --user: #0f5c4d;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); display: flex; flex-direction: column; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em; background: #eef0ec; padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }

/* Top bar */
.topbar { height: 64px; display: flex; align-items: center; gap: 24px; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand div { display: flex; flex-direction: column; line-height: 1.05; }
.brand strong { font-size: 16px; letter-spacing: .2px; }
.brand span { font-size: 11px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); }
.nav { display: flex; gap: 18px; font-size: 14px; }
.nav a { color: var(--muted); cursor: default; }
.nav a.active { color: var(--ink); font-weight: 600; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--ok-bg); color: var(--ok); border: 1px solid #abefc6; white-space: nowrap; }
.pill.inline { background: #eef4ff; color: #3538cd; border-color: #c7d7fe; }

/* Buttons */
.btn { font: inherit; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 8px 12px; border-radius: 10px; cursor: pointer; }
.btn:hover { border-color: #cfccc2; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-2); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: transparent; }
.btn-sm { font-size: 12.5px; padding: 5px 9px; border-radius: 8px; }

/* Layout */
.layout { flex: none; display: grid; grid-template-columns: minmax(0, 1fr) 430px; grid-template-rows: minmax(0, 1fr); height: calc(100vh - 65px); min-height: 560px; gap: 20px; padding: 20px 24px; min-height: 0; max-width: 1440px; width: 100%; margin: 0 auto; }
.layout.lab-hidden { grid-template-columns: minmax(0, 860px); justify-content: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.chat-col { display: flex; flex-direction: column; min-height: 0; gap: 14px; }
.hero h1 { margin: 4px 0 2px; font-size: 22px; letter-spacing: -.2px; }
.hero p { margin: 0; color: var(--muted); font-size: 14px; }

/* Chat */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
body { min-height: 640px; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.chat-head .btn { margin-left: auto; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: var(--sand); display: grid; place-items: center; font-weight: 700; }
.chat-title { font-weight: 600; }
.chat-sub { font-size: 12px; color: var(--muted); }
.messages { flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 12px; height: 0; min-height: 300px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 82%; padding: 10px 14px; border-radius: 14px; background: var(--bot); line-height: 1.5; font-size: 14.5px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.bot .bubble { border-bottom-left-radius: 4px; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.bubble pre { background: #1f2a27; color: #e7efe9; padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; white-space: pre-wrap; }
.bubble pre code { background: none; padding: 0; color: inherit; }
.bubble table { border-collapse: collapse; font-size: 12.5px; margin: 6px 0; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; white-space: nowrap; background: #fff; }
.bubble a { color: var(--brand-2); }
.typing::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--muted); }
@keyframes blink { 50% { opacity: 0; } }
.meta { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

.blocked { max-width: 82%; border: 1px solid #fecdca; background: var(--danger-bg); border-radius: 14px; padding: 12px 14px; font-size: 14px; }
.blocked .b-head { display: flex; align-items: center; gap: 8px; color: var(--danger); font-weight: 600; margin-bottom: 4px; }
.blocked .b-body { color: #55160c; white-space: pre-wrap; }
.blocked .b-meta { font-size: 11.5px; color: #912018; margin-top: 6px; opacity: .85; }

.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; font: inherit; font-size: 14.5px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; max-height: 160px; outline: none; }
.composer textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(19, 128, 107, .15); }
.disclaimer { font-size: 11.5px; color: var(--muted); text-align: center; padding: 0 12px 10px; }

/* Lab */
.lab { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.lab-head { padding: 14px 16px 6px; }
.lab-title { font-weight: 700; }
.tabs { display: flex; gap: 4px; padding: 0 12px; border-bottom: 1px solid var(--line); }
.tab { font: inherit; font-size: 13px; background: none; border: none; padding: 10px 10px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
.tab-panel { padding: 12px 14px 18px; overflow-y: auto; flex: 1; }
.tab-panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 16px 0 8px; }
.tab-panel h3:first-child { margin-top: 2px; }

.attack { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.attack-head { display: flex; align-items: center; gap: 8px; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--danger-bg); color: var(--danger); letter-spacing: .3px; }
.tag.safe { background: var(--ok-bg); color: var(--ok); }
.attack-title { font-weight: 600; font-size: 14px; }
.attack-desc { font-size: 12.5px; color: var(--muted); margin: 4px 0 8px; }
.attack-items { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 12.5px; border: 1px solid var(--line); background: #fafaf7; border-radius: 999px; padding: 5px 10px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.chip:hover { border-color: var(--brand-2); color: var(--brand); }
.chip .edit { opacity: .55; font-size: 11px; }
.chip .edit:hover { opacity: 1; text-decoration: underline; }

.kv { display: grid; grid-template-columns: 96px 1fr; gap: 4px 10px; font-size: 12.5px; }
.kv div:nth-child(odd) { color: var(--muted); }
.list-row { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; font-size: 12.5px; }
.list-row.bad { border-color: #fecdca; background: var(--danger-bg); }
.list-row.warn { border-color: #fedf89; background: var(--warn-bg); }
.list-row pre { margin: 6px 0 0; font-size: 11.5px; white-space: pre-wrap; max-height: 160px; overflow: auto; background: #f7f7f4; padding: 6px 8px; border-radius: 6px; }
.badge { font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 5px; margin-left: 6px; text-transform: uppercase; }
.badge.internal { background: var(--danger); color: #fff; }
.badge.untrusted { background: var(--warn); color: #fff; }

.review-box { margin-top: 12px; font-size: 13px; }
.review-box summary { cursor: pointer; color: var(--brand); }
.review-box form { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.review-box input, .review-box textarea { font: inherit; font-size: 13px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; }

.switch { display: flex; align-items: center; gap: 10px; font-size: 13.5px; padding: 9px 0; border-bottom: 1px solid var(--line); cursor: pointer; flex-wrap: wrap; }
.switch input { display: none; }
.switch span { width: 34px; height: 20px; border-radius: 999px; background: #d0d5dd; position: relative; flex: none; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--brand-2); }
.switch input:checked + span::after { transform: translateX(14px); }
.switch input:disabled + span { opacity: .45; }
.switch em { flex-basis: 100%; padding-left: 44px; font-style: normal; }
.settings-actions { margin: 12px 0; }
.api-box { background: #f7f7f4; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 5px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--danger); color: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.25); font-size: 14px; max-width: min(92vw, 640px); z-index: 50; }

@media (max-width: 1000px) {
  html, body { height: auto; }
  .layout, .layout.lab-hidden { grid-template-columns: 1fr; padding: 12px 16px; flex: none; }
  .chat-col { min-height: auto; }
  .layout { grid-template-rows: auto; height: auto; }
  .nav { display: none; }
  .lab { max-height: none; }
  .chat { min-height: 70vh; }
  .topbar { padding: 10px 16px; gap: 12px; height: auto; }
  .top-actions .btn { white-space: nowrap; }
  .pill { display: none; }
}

/* ================= Theme: paper + charcoal, Geist, mono labels ================= */
:root {
  --paper: #f1eee7; --paper-2: #e8e4da; --char: #232323; --char-2: #1b1b1b; --char-3: #2b2b2b;
  --brand: #232323; --brand-2: #000; --accent: #ff5f1f; --tan: #d6a878;
  --bg: var(--paper); --card: #f7f5ef; --ink: #232323; --muted: #6f6b63; --line: rgba(35,35,35,.14);
  --bot: #fbfaf6; --user: #232323;
  --danger: #d9431e; --danger-bg: #fbe9e1; --ok: #2f7a4f; --ok-bg: #e4efe6; --warn: #9a6a1c; --warn-bg: #f6ecd9;
  --radius: 0px; --shadow: none;
  --sans: "Geist", "GeistSans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", "GeistMono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-family: var(--sans);
}
body { background: var(--paper); }
code { font-family: var(--mono); background: var(--paper-2); border-radius: 0; }
.mono, .nav a, .pill, .btn, .tab, .tag, .chip, .eyebrow, .chat-sub, .disclaimer, .tab-panel h3, .meta, .b-meta, .api-box, .small.muted, .attack-desc { font-family: var(--mono); }
/* Floating dark nav bar */
.topbar { height: 64px; background: transparent; border: none; padding: 12px 24px; }
.topbar .brand, .topbar .nav, .topbar .top-actions { background: var(--char); color: #fff; padding: 8px 14px; height: 40px; display: flex; align-items: center; }
.topbar .brand { gap: 10px; }
.brand strong { font-family: var(--mono); font-weight: 500; font-size: 13px; letter-spacing: 1px; text-transform: uppercase; color: #fff; }
.brand span { font-family: var(--mono); color: rgba(255,255,255,.55); font-size: 10px; letter-spacing: 1px; }
.brand div { flex-direction: row; gap: 6px; align-items: baseline; }
.topbar .nav { margin-left: -24px; gap: 22px; }
.nav a { color: rgba(255,255,255,.62); font-size: 12px; text-transform: uppercase; }
.nav a.active { color: #fff; position: relative; }
.nav a.active::after { content: ""; position: absolute; right: -7px; top: -2px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.topbar .top-actions { gap: 8px; padding: 4px; }
.pill { background: transparent; color: #9fe0b4; border: 1px dashed rgba(159,224,180,.45); border-radius: 0; font-size: 10.5px; text-transform: uppercase; }
.btn { border-radius: 0; font-size: 12.5px; text-transform: uppercase; letter-spacing: .3px; border: 1px solid var(--char); background: transparent; color: var(--ink); }
.btn:hover { background: var(--char); color: #fff; border-color: var(--char); }
.topbar .btn { background: var(--paper); color: var(--char); border-color: var(--paper); }
.topbar .btn:hover { background: #fff; color: #000; }
.btn-primary { background: var(--char); color: #fff; border-color: var(--char); }
.btn-primary:hover { background: #000; }
/* Hero */
.hero { padding: 6px 0 8px; }
.eyebrow { font-size: 12.5px; text-transform: uppercase; color: var(--ink); margin-bottom: 10px; letter-spacing: .2px; }
.hero h1 { font-family: var(--sans); font-weight: 500; font-size: 40px; line-height: 1; letter-spacing: -1px; margin: 0 0 10px; }
.hero h1 em { font-style: normal; }
.hero p { font-family: var(--mono); font-size: 13px; color: var(--muted); }
/* Chat card */
.card { border-radius: 0; border: 1px solid var(--char); background: var(--card); box-shadow: none; }
.chat-head { border-bottom: 1px dashed var(--line); }
.avatar { border-radius: 0; background: var(--char); color: #fff; font-family: var(--mono); font-size: 16px; width: 36px; height: 36px; }
.chat-title { font-family: var(--sans); font-weight: 500; font-size: 17px; letter-spacing: -.2px; }
.chat-title .muted { font-family: var(--mono) !important; font-size: 11.5px !important; letter-spacing: .5px !important; }
.chat-sub { font-size: 11.5px; text-transform: uppercase; }
.status-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-right: 7px; vertical-align: 1px; }
.messages { background-image: radial-gradient(rgba(35,35,35,.10) 1px, transparent 1px); background-size: 18px 18px; }
.bubble { border-radius: 0; border: 1px solid var(--line); background: var(--bot); font-size: 15px; }
.msg.bot .bubble { border-bottom-left-radius: 0; }
.msg.user .bubble { background: var(--char); color: #fff; border-color: var(--char); border-bottom-right-radius: 0; }
.bubble pre { background: var(--char); color: #ece9e2; border-radius: 0; }
.bubble th, .bubble td { background: #fff; border-color: var(--line); }
.composer { border-top: 1px dashed var(--line); }
.composer textarea { border-radius: 0; border: 1px solid var(--char); background: #fff; font-family: var(--sans); }
.composer textarea:focus { box-shadow: none; border-color: #000; }
.blocked { border-radius: 0; background: var(--danger-bg); border: 1px solid var(--danger); }
.blocked .b-head { font-family: var(--mono); font-size: 12.5px; text-transform: uppercase; font-weight: 500; color: var(--danger); }
.blocked .b-body { color: #3a1408; }
.blocked .b-meta { color: #8a3a22; }
/* Security Lab: the dark half */
.lab { background: var(--char); color: #ece9e2; border-color: var(--char); background-image: radial-gradient(rgba(255,255,255,.07) 1px, transparent 1px); background-size: 18px 18px; }
.lab .muted, .lab .attack-desc { color: rgba(236,233,226,.55); }
.lab-title { font-family: var(--sans); font-weight: 500; font-size: 22px; letter-spacing: -.4px; }
.tabs { border-bottom: 1px dashed rgba(255,255,255,.18); }
.tab { color: rgba(236,233,226,.55); font-size: 11.5px; text-transform: uppercase; }
.tab.active { color: #fff; border-bottom-color: var(--accent); font-weight: 500; }
.tab-panel h3 { color: rgba(236,233,226,.5); font-size: 11px; }
.attack { background: rgba(27,27,27,.85); border: 1px solid rgba(255,255,255,.12); border-radius: 0; }
.attack-title { font-weight: 500; color: #fff; }
.tag { background: transparent; color: var(--tan); border: 1px solid rgba(214,168,120,.5); border-radius: 0; font-weight: 400; }
.tag.safe { color: #9fe0b4; border-color: rgba(159,224,180,.45); background: transparent; }
.chip { background: transparent; border: 1px solid rgba(255,255,255,.22); border-radius: 0; color: #ece9e2; font-size: 12px; text-transform: uppercase; }
.chip:hover { background: var(--paper); color: var(--char); border-color: var(--paper); }
.kv div:nth-child(odd) { color: rgba(236,233,226,.5); }
.list-row { border: 1px solid rgba(255,255,255,.14); border-radius: 0; background: rgba(27,27,27,.85); }
.list-row.bad { background: rgba(217,67,30,.14); border-color: rgba(255,95,31,.55); }
.list-row.warn { background: rgba(214,168,120,.10); border-color: rgba(214,168,120,.5); }
.list-row pre, .api-box { background: #141414; color: #d9d5cc; border: 1px solid rgba(255,255,255,.12); border-radius: 0; }
.lab code { background: #141414; color: var(--tan); }
.badge { border-radius: 0; font-family: var(--mono); font-weight: 400; }
.review-box summary { color: var(--tan); font-family: var(--mono); font-size: 12px; text-transform: uppercase; }
.review-box input, .review-box textarea { background: #141414; color: #ece9e2; border: 1px solid rgba(255,255,255,.2); border-radius: 0; }
.lab .btn { color: #ece9e2; border-color: rgba(255,255,255,.3); }
.lab .btn:hover, .lab .btn-primary { background: var(--paper); color: var(--char); border-color: var(--paper); }
.switch { border-bottom: 1px dashed rgba(255,255,255,.14); }
.switch span { border-radius: 0; background: #3a3a3a; }
.switch span::after { border-radius: 0; }
.switch input:checked + span { background: var(--accent); }
.toast { border-radius: 0; background: var(--char); color: #fff; border-left: 4px solid var(--accent); font-family: var(--mono); font-size: 13px; }
@media (max-width: 1000px) {
  .topbar .nav { display: none; }
  .topbar { padding: 10px 16px; }
  .topbar .brand, .topbar .top-actions { height: 40px; }
}

/* Spiral artwork */
.spiral-svg { width: 100%; height: 100%; display: block; }
.spiral-svg text { font-family: var(--mono); text-transform: uppercase; letter-spacing: 1px; fill: currentColor; }
.spiral-rot { animation: spiral-spin linear infinite; }
@keyframes spiral-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spiral-rot { animation: none; } }
.lab { position: relative; }
.lab > *:not(.lab-art) { position: relative; z-index: 1; }
.lab-art { position: absolute; inset: -20% -60%; color: #ece9e2; opacity: .13; pointer-events: none; z-index: 0; overflow: hidden; }
.lab .lab-head, .lab .tabs { background: transparent; }
.art { display: none; background: var(--char); color: #ece9e2; border-color: var(--char); position: relative; overflow: hidden;
  background-image: radial-gradient(rgba(255,255,255,.07) 1px, transparent 1px); background-size: 18px 18px; }
.art-spiral { position: absolute; inset: -12% -30%; }
.art-caption { position: absolute; left: 16px; bottom: 14px; z-index: 1; font-family: var(--mono); font-size: 11.5px; text-transform: uppercase; background: var(--paper); color: var(--char); padding: 6px 10px; }
.layout.lab-hidden { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); justify-content: stretch; }
.layout.lab-hidden .art { display: block; }
@media (max-width: 1000px) { .layout.lab-hidden .art { display: none; } }
