:root {
  --bg: #0a0a0a;
  --bg-sidebar: #111111;
  --bg-elev: #161616;
  --bg-user: #1c1c1c;
  --line: #242424;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --faint: #71717a;
  --accent: #7ee0a8;
  --accent-dim: #143524;
  --pass: #34d399;
  --warn: #fbbf24;
  --fail: #f87171;
  --info: #7dd3fc;
  --sidebar-w: 268px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  display: flex;
  height: 100%;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(126, 224, 168, 0.05), transparent 60%),
    var(--bg);
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 16px 14px 20px;
  min-height: 100%;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-dim);
}

.brand-name { font-size: 15px; }

#close-sidebar { display: none; }

.sidebar-label {
  margin: 0 8px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

.saved-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}
.saved-list:empty { display: none; }

.saved-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 10px;
}

.saved-item button.run {
  flex: 1;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-item button.run:hover,
.saved-item button.run:focus-visible { background: #1a1a1a; outline: none; }

.saved-item.is-active button.run { background: #1a1a1a; color: var(--accent); }

.saved-item button.remove {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: 0;
  background: transparent;
  color: var(--faint);
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.saved-item button.remove:hover,
.saved-item button.remove:focus-visible { color: var(--text); background: #1a1a1a; outline: none; }

.saved-empty {
  margin: 4px 8px 0;
  color: var(--muted);
  font-size: 13px;
}

.saved-empty[hidden],
#backdrop[hidden] { display: none; }

.shell {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.shell[data-mode="welcome"] {
  display: grid;
  grid-template-rows: auto 1fr auto auto 1fr auto;
  grid-template-columns: minmax(0, 1fr);
}
.shell[data-mode="welcome"] .topbar { grid-row: 1; }
.shell[data-mode="welcome"] .thread {
  grid-row: 3;
  flex: none;
  overflow: visible;
  padding-top: 12px;
  padding-bottom: 8px;
}
.shell[data-mode="welcome"] .composer { grid-row: 4; padding-top: 0; }
.shell[data-mode="welcome"] .footer { grid-row: 6; }
.shell[data-mode="results"] {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 10, 10, 0.9);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:hover,
.icon-btn:focus-visible { background: #1a1a1a; outline: 2px solid var(--accent); outline-offset: 1px; }

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 28px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 840px;
  width: 100%;
  margin: 0 auto;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 100%;
}

.msg.user { align-items: flex-end; }

.bubble {
  max-width: min(100%, 640px);
  padding: 12px 16px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.assistant .bubble {
  background: transparent;
  padding: 2px 2px 0;
  color: var(--text);
}

.msg.user .bubble {
  background: var(--bg-user);
  border: 1px solid var(--line);
  border-bottom-right-radius: 6px;
  color: var(--text);
}

.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px 14px;
  border-left: 3px solid var(--faint);
  min-width: 0;
}

.card[data-status="pass"] { border-left-color: var(--pass); }
.card[data-status="warn"] { border-left-color: var(--warn); }
.card[data-status="fail"] { border-left-color: var(--fail); }
.card[data-status="info"] { border-left-color: var(--info); }

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.card-title {
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.badge {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: #1f1f1f;
  color: var(--muted);
}

.badge.pass { color: var(--pass); background: rgba(52, 211, 153, 0.1); }
.badge.warn { color: var(--warn); background: rgba(251, 191, 36, 0.1); }
.badge.fail { color: var(--fail); background: rgba(248, 113, 113, 0.12); }
.badge.info { color: var(--info); background: rgba(125, 211, 252, 0.1); }

.card p {
  margin: 0;
  font-size: 14px;
  color: var(--text);
}

.card .details {
  margin: 8px 0 0;
  padding: 0 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}

.records {
  margin: 10px 0 0;
  padding: 8px 10px;
  background: #0c0c0c;
  border: 1px solid #1d1d1d;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.45;
  color: #d4d4d8;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.recs {
  margin: 4px 0 0;
  padding: 12px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.recs h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.recs ol {
  margin: 0;
  padding-left: 18px;
  font-size: 14px;
}

.recs li { margin: 0 0 6px; }
.recs li:last-child { margin-bottom: 0; }

.note {
  margin: 0;
  font-size: 12px;
  color: var(--faint);
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-user);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.btn:hover,
.btn:focus-visible { border-color: var(--accent); outline: none; }
.btn[disabled] { opacity: 0.6; cursor: default; }

.typing {
  display: flex;
  gap: 5px;
  padding: 8px 2px;
}
.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

.composer {
  display: flex;
  gap: 8px;
  align-items: center;
  max-width: 840px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 20px 0;
}

.composer input {
  flex: 1;
  min-width: 0;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--text);
  font: inherit;
  padding: 14px 16px;
  border-radius: 16px;
  outline: none;
}

.composer input::placeholder { color: var(--faint); }
.composer input:focus { border-color: #3f3f46; box-shadow: 0 0 0 3px rgba(126, 224, 168, 0.12); }
.composer input:disabled { opacity: 0.7; }

#send-btn {
  appearance: none;
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #052e16;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#send-btn:hover,
#send-btn:focus-visible { filter: brightness(1.05); outline: 2px solid var(--accent); outline-offset: 2px; }
#send-btn:disabled { opacity: 0.45; cursor: default; filter: none; }

.footer {
  max-width: 840px;
  width: 100%;
  margin: 0 auto;
  padding: 10px 20px calc(14px + var(--safe-bottom));
  color: var(--faint);
  font-size: 11px;
  text-align: center;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 20;
}


.card.wide { grid-column: 1 / -1; }

.card-head.with-logo {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 8px;
}
.card-head-text { min-width: 0; flex: 1; }
.card-head-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.bimi-logo {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.bimi-logo[hidden] { display: none; }
.card .details,
.card .records,
.card-link { overflow-wrap: anywhere; word-break: break-word; }
.details.links { list-style: none; padding-left: 0; }
.link-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 4px 10px;
  margin: 0 0 6px;
}
.link-row:last-child { margin-bottom: 0; }
.card-link {
  color: var(--info);
  text-decoration: none;
  min-width: 0;
}
.card-link:hover,
.card-link:focus-visible { text-decoration: underline; outline: none; }


.extra-label {
  margin: 8px 2px 0;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.not-published {
  margin: 6px 2px 10px;
  font-size: 13px;
  color: var(--muted);
}

.msg.user {
  scroll-margin-top: 8px;
}

.spf-tree {
  list-style: none;
  margin: 10px 0 0;
  padding: 0 0 0 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: #d4d4d8;
}

.spf-tree .spf-tree {
  margin: 4px 0 4px 14px;
  padding-left: 10px;
  border-left: 1px solid #2a2a2a;
}

.spf-tree li { margin: 0 0 2px; }
.spf-tree summary {
  cursor: pointer;
  overflow-wrap: anywhere;
}
.spf-tree summary:hover,
.spf-tree summary:focus-visible { color: var(--text); outline: none; }

.tree-flag {
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: 1px;
}
.tree-flag.void { color: var(--warn); background: rgba(251, 191, 36, 0.1); }
.tree-flag.miss, .tree-flag.err { color: var(--fail); background: rgba(248, 113, 113, 0.12); }
.tree-flag.macro { color: var(--info); background: rgba(125, 211, 252, 0.1); }

@media (max-width: 800px) {
  .topbar { display: flex; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(var(--sidebar-w), 88vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.4);
  }
  .sidebar.is-open { transform: translateX(0); }
  #close-sidebar { display: inline-flex; }
  .cards { grid-template-columns: 1fr; }
  .thread { padding: 16px 14px 10px; }
  .composer { padding: 8px 14px 0; }
  .footer { padding: 8px 14px calc(12px + var(--safe-bottom)); }
  .bubble { max-width: 100%; }
}

@media (min-width: 801px) {
  .brand.compact { display: none; }
}
