/* TrendAI dark UI – palette taken from the TrendAI Solution Sizing tool */
:root {
  --bg: #0C0C0C;
  --bg-header: #0A0A0A;
  --bg-nav: #020607;
  --card: #141414;
  --card-2: #1A1A1A;
  --input-bg: #0C0C0C;
  --hover: #252525;
  --border: #2A2A2A;
  --border-2: #333;
  --border-3: #444;
  --text: #FFFFFF;
  --text-2: #CCCCCC;
  --text-3: #999999;
  --text-4: #666666;
  --red: #D71920;
  --red-hover: #B8151B;
  --red-bg: #1F0A0B;
  --red-border: #5A1418;
  --green: #4ADE80;
  --green-bg: #0D1A0D;
  --green-border: #14532D;
  --amber: #CCA700;
  --amber-bg: #1A1700;
  --amber-border: #3D3500;
  --teal: #1E9E8E;
  --radius: 10px;
  --radius-sm: 6px;
  --font: 'Open Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text-2);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
a { color: var(--text-2); }
a:hover { color: var(--red); }
code { font-family: var(--mono); font-size: 0.9em; color: var(--text-2); }
h2 { margin: 0; font-size: 15px; font-weight: 700; color: var(--text); }

.container { max-width: 1600px; margin: 0 auto; padding: 0 24px; width: 100%; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }

.icon {
  width: 16px; height: 16px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Header + nav ---------- */
.topbar { background: var(--bg-header); border-bottom: 1px solid #1E1E1E; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 64px; gap: 16px; }
.brand { margin: 0; line-height: 1; letter-spacing: -0.01em; white-space: nowrap; }
.brand-name, .brand-title { font-size: 20px; font-weight: 700; color: var(--text); }
.brand-tm { font-size: 13px; font-weight: 700; color: var(--text); vertical-align: super; }
.brand-sep { color: #555; font-weight: 700; margin: 0 10px; font-size: 20px; }

.status-pills { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 12px; border-radius: 999px;
  background: var(--card-2); border: 1px solid var(--border-2);
  font-size: 12px; color: var(--text-3); max-width: 280px;
}
.pill-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-4); flex: none; }
.pill.ok .dot { background: var(--green); }
.pill.warn .dot { background: var(--amber); }

.tabs { background: var(--bg-nav); border-bottom: 1px solid #222; }
.tabs-inner { display: flex; gap: 4px; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 16px; background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--text-3); font: 500 14px var(--font); cursor: pointer; transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); border-bottom-color: var(--border-3); }
.tab.active { color: var(--red); border-bottom-color: var(--red); }

.main { padding-top: 24px; padding-bottom: 24px; flex: 1; }

/* ---------- Cards, inputs, buttons ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; min-width: 0;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-actions { display: flex; align-items: center; gap: 12px; margin-top: 16px; flex-wrap: wrap; }

.input {
  width: 100%; background: var(--input-bg); border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  color: var(--text); font: 14px var(--font); padding: 9px 12px; outline: none; transition: border-color .15s;
}
.input:focus { border-color: var(--red); }
.input::placeholder { color: var(--text-4); }
.input-sm { padding: 7px 10px; font-size: 13px; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #999 50%), linear-gradient(135deg, #999 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
textarea.input { resize: vertical; line-height: 1.5; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field-row { display: grid; grid-template-columns: 2fr 1.4fr 1fr; gap: 12px; }
.label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.label code { color: var(--text-4); font-weight: 400; margin-left: 4px; }
.hint { font-size: 12px; color: var(--text-4); }
.hint em { color: var(--text-3); font-style: normal; }
.input-group { display: flex; gap: 8px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 4px 0 14px; cursor: pointer; color: var(--text-2); }
.check input { accent-color: var(--red); margin-top: 3px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  font: 500 14px var(--font); cursor: pointer; transition: background .15s, color .15s, border-color .15s; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--red-hover); }
.btn-secondary { background: var(--card-2); border-color: var(--border-2); color: var(--text-2); }
.btn-secondary:hover:not(:disabled) { color: #fff; border-color: #555; }
.btn-ghost { background: transparent; border-color: var(--border-2); color: var(--text-3); }
.btn-ghost:hover:not(:disabled) { color: #fff; border-color: #555; }
.btn-sm { padding: 6px 10px; font-size: 12px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em; border: 1px solid; white-space: nowrap;
}
.badge-neutral { color: var(--text-3); border-color: var(--border-2); background: var(--card-2); }
.badge-allow { color: var(--green); border-color: var(--green-border); background: var(--green-bg); }
.badge-block { color: #FF5A5F; border-color: var(--red-border); background: var(--red-bg); }
.badge-warn { color: var(--amber); border-color: var(--amber-border); background: var(--amber-bg); }

/* ---------- Demo layout ---------- */
.demo-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 400px;
  gap: 16px;
  height: calc(100vh - 64px - 46px - 48px - 42px);
  min-height: 620px;
}
.demo-grid > .card { display: flex; flex-direction: column; min-height: 0; }

/* Library */
.library-groups { overflow-y: auto; margin: 12px -6px 0; padding: 0 6px; flex: 1; }
.lib-group { border-top: 1px solid var(--border); }
.lib-group:first-child { border-top: 0; }
.lib-group summary {
  list-style: none; cursor: pointer; padding: 10px 2px; display: flex; align-items: center; justify-content: space-between;
  color: var(--text); font-weight: 600; font-size: 13px;
}
.lib-group summary::-webkit-details-marker { display: none; }
.lib-group summary::after { content: '+'; color: var(--text-4); font-weight: 400; font-size: 16px; }
.lib-group[open] summary::after { content: '−'; }
.lib-group .count { color: var(--text-4); font-weight: 400; margin-left: 6px; }
.lib-desc { font-size: 12px; color: var(--text-4); margin: -4px 0 8px; }
.lib-items { display: flex; flex-direction: column; gap: 6px; padding-bottom: 12px; }
.lib-item {
  text-align: left; background: var(--card-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; cursor: pointer; color: var(--text-2); font: 13px var(--font);
  display: flex; flex-direction: column; gap: 4px; transition: border-color .15s, background .15s;
}
.lib-item:hover { border-color: #555; background: var(--hover); color: #fff; }
.lib-item.selected { border-color: var(--red); }
.lib-item-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.lib-item-label { font-weight: 600; }
.lib-tech { font-family: var(--mono); font-size: 11px; color: var(--text-4); }
.lib-tech b { color: var(--red); font-weight: 500; }

/* Chat */
.chat { padding: 0; }
.chat-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.segmented { display: inline-flex; background: var(--input-bg); border: 1px solid var(--border-2); border-radius: 8px; padding: 3px; }
.seg { background: none; border: 0; color: var(--text-3); font: 600 12px var(--font); padding: 6px 14px; border-radius: 6px; cursor: pointer; }
.seg:hover { color: #fff; }
.seg.active[data-mode="enforce"] { background: var(--red); color: #fff; }
.seg.active[data-mode="monitor"] { background: var(--amber); color: #111; }
.seg.active[data-mode="off"] { background: #3A3A3A; color: #fff; }

.messages { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.empty-state { margin: auto; text-align: center; max-width: 440px; padding: 24px; }
.empty-icon { width: 44px; height: 44px; fill: none; stroke: var(--red); stroke-width: 1.5; margin-bottom: 8px; }
.empty-title { color: var(--text); font-weight: 600; font-size: 15px; margin: 0 0 6px; }

.msg { display: flex; flex-direction: column; gap: 6px; max-width: 82%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant, .msg.system { align-self: flex-start; }
.bubble { padding: 10px 14px; border-radius: 12px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user .bubble { background: #26262B; color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.user.is-blocked .bubble { border: 1px solid var(--red-border); }
.msg.assistant .bubble { background: var(--card-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; color: var(--text-2); }
.msg.system .bubble { background: var(--red-bg); border: 1px solid var(--red-border); color: #FFB3B5; display: flex; gap: 10px; align-items: flex-start; }
.msg.system.warn .bubble { background: var(--amber-bg); border-color: var(--amber-border); color: #E8D27A; }
.msg.system.info .bubble { background: var(--card-2); border-color: var(--border-2); color: var(--text-3); }
.msg.system .icon { margin-top: 2px; }
.msg-meta { display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--text-4); flex-wrap: wrap; }
.msg-meta .badge { cursor: pointer; }
.msg-meta .badge:hover { filter: brightness(1.25); }
.msg.active-verdict .bubble { box-shadow: 0 0 0 1px var(--red); }

.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: var(--input-bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px; overflow-x: auto; margin: 8px 0; }
.bubble code { background: var(--input-bg); padding: 1px 5px; border-radius: 4px; }
.bubble pre code { background: none; padding: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.bubble h3, .bubble h4 { color: #fff; margin: 10px 0 6px; font-size: 14px; }
.bubble .md-image { color: var(--amber); font-family: var(--mono); font-size: 12px; }

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-4); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.composer { border-top: 1px solid var(--border); padding: 12px 16px; }
.composer-input { min-height: 72px; max-height: 240px; }
.composer-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 12px; }
#char-count.over { color: var(--amber); }

/* Verdict */
.verdict-body { overflow-y: auto; flex: 1; margin: 0 -6px; padding: 0 6px; }
.v-hero {
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px; border: 1px solid;
  display: flex; align-items: center; gap: 14px;
}
.v-hero.allow { background: var(--green-bg); border-color: var(--green-border); }
.v-hero.block { background: var(--red-bg); border-color: var(--red-border); }
.v-hero.error { background: var(--amber-bg); border-color: var(--amber-border); }
.v-hero-icon { width: 36px; height: 36px; flex: none; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.v-hero.allow .v-hero-icon { stroke: var(--green); }
.v-hero.block .v-hero-icon { stroke: #FF5A5F; }
.v-hero.error .v-hero-icon { stroke: var(--amber); }
.v-action { font-size: 26px; font-weight: 700; line-height: 1.1; letter-spacing: .02em; }
.v-hero.allow .v-action { color: var(--green); }
.v-hero.block .v-action { color: #FF5A5F; }
.v-hero.error .v-action { color: var(--amber); font-size: 20px; }
.v-hero-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.v-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.v-stat { background: var(--card-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.v-stat-label { font-size: 11px; color: var(--text-4); text-transform: uppercase; letter-spacing: .04em; }
.v-stat-value { font-family: var(--mono); color: #fff; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-stat-value.red { color: #FF5A5F; }
.v-stat-value.green { color: var(--green); }

.v-section { margin-bottom: 16px; }
.v-section-title { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 700; color: var(--text); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; }
.v-reasons { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.v-reasons li { background: var(--card-2); border: 1px solid var(--border); border-left: 3px solid var(--red); border-radius: 6px; padding: 7px 10px; font-family: var(--mono); font-size: 12px; color: var(--text-2); overflow-wrap: anywhere; }
.v-reasons li.none { border-left-color: var(--green); font-family: var(--font); color: var(--text-3); }

.score-row { display: grid; grid-template-columns: 118px 1fr 48px; gap: 10px; align-items: center; padding: 4px 0; font-size: 12px; }
.score-name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-row.hit .score-name { color: #fff; font-weight: 600; }
.score-track { height: 8px; background: #222; border-radius: 4px; overflow: hidden; }
.score-fill { height: 100%; width: 0; border-radius: 4px; background: #5A5A5A; transition: width .5s ease; }
.score-fill.high { background: var(--red); }
.score-val { font-family: var(--mono); text-align: right; color: var(--text-3); }
.score-row.hit .score-val { color: #FF5A5F; font-weight: 600; }
.score-row.score-head { padding: 0 0 2px; font-size: 10.5px; color: var(--text-4); text-transform: uppercase; letter-spacing: .04em; }
.score-row.score-head span:nth-child(2) { grid-column: 2 / 4; text-align: right; }

.v-kv { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid #1F1F1F; font-size: 12px; }
.v-kv:last-child { border-bottom: 0; }
.v-kv span:first-child { color: var(--text-4); flex: none; }
.v-kv span:last-child { color: var(--text-2); font-family: var(--mono); text-align: right; overflow-wrap: anywhere; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.v-note { font-size: 12px; color: var(--text-4); background: var(--card-2); border: 1px dashed var(--border-2); border-radius: 6px; padding: 8px 10px; }

details.raw { background: var(--card-2); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; }
details.raw summary { cursor: pointer; padding: 8px 12px; font-size: 12px; font-weight: 600; color: var(--text-2); display: flex; justify-content: space-between; align-items: center; }
details.raw summary::-webkit-details-marker { display: none; }
details.raw pre { margin: 0; padding: 10px 12px; border-top: 1px solid var(--border); font: 11.5px/1.5 var(--mono); color: var(--text-2); overflow-x: auto; max-height: 360px; white-space: pre-wrap; overflow-wrap: anywhere; }
.copy-btn { background: none; border: 1px solid var(--border-2); color: var(--text-3); border-radius: 4px; font: 11px var(--font); padding: 2px 8px; cursor: pointer; }
.copy-btn:hover { color: #fff; border-color: #555; }

.v-tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.v-tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 6px 10px; color: var(--text-3); font: 600 12px var(--font); cursor: pointer; }
.v-tab.active { color: var(--red); border-bottom-color: var(--red); }

/* ---------- Settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; max-width: 1200px; margin: 0 auto; }
.settings-wide { grid-column: 1 / -1; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.preset { background: var(--card-2); border: 1px solid var(--border-2); color: var(--text-3); border-radius: 999px; padding: 4px 12px; font: 12px var(--font); cursor: pointer; }
.preset:hover { color: #fff; border-color: #555; }
.test-ok { color: var(--green); }
.test-err { color: #FF5A5F; }

/* ---------- Footer / toast ---------- */
.footer { display: flex; justify-content: space-between; gap: 16px; padding-top: 12px; padding-bottom: 16px; font-size: 12px; color: var(--text-4); flex-wrap: wrap; }
.footer a { color: var(--text-3); }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--card-2); border: 1px solid var(--border-2); color: #fff; border-radius: 8px;
  padding: 10px 16px; font-size: 13px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.5);
}

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .demo-grid { grid-template-columns: 280px minmax(0, 1fr) 360px; }
}
@media (max-width: 1080px) {
  .demo-grid { grid-template-columns: minmax(0, 1fr); height: auto; }
  .library { max-height: 360px; }
  .chat { min-height: 560px; }
  .verdict { max-height: none; }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .container { padding: 0 16px; }
  .brand-name, .brand-title, .brand-sep { font-size: 16px; }
  .status-pills { display: none; }
  .field-row { grid-template-columns: 1fr; }
  .msg { max-width: 94%; }
  .v-stats { grid-template-columns: 1fr 1fr; }
}
