:root {
  --bg: #05070d;
  --panel: rgba(9, 15, 27, .76);
  --panel-strong: rgba(12, 20, 34, .94);
  --glass: rgba(255,255,255,.075);
  --border: rgba(196, 213, 238, .16);
  --border-strong: rgba(66, 217, 255, .42);
  --text: #f7fbff;
  --muted: #96a7bd;
  --soft: #d7e3f0;
  --cyan: #42d9ff;
  --blue: #74a7ff;
  --green: #48e6a3;
  --amber: #f5c45c;
  --red: #ff6d8a;
  --shadow: 0 24px 70px rgba(0,0,0,.38);
}

* { box-sizing: border-box; }
html { background: var(--bg); scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 6%, rgba(66,217,255,.26), transparent 24%),
    radial-gradient(circle at 86% 10%, rgba(72,230,163,.16), transparent 22%),
    radial-gradient(circle at 65% 94%, rgba(116,167,255,.18), transparent 30%),
    linear-gradient(145deg, #05070d 0%, #08101d 58%, #05070d 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.65), transparent 72%);
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
h1, h2, h3, p { margin: 0; }

.aurora {
  position: fixed;
  inset: -20%;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 24%, rgba(66,217,255,.18), transparent 18%),
    radial-gradient(circle at 76% 18%, rgba(72,230,163,.13), transparent 17%),
    radial-gradient(circle at 52% 74%, rgba(116,167,255,.16), transparent 24%);
  filter: blur(20px);
  animation: auroraDrift 16s ease-in-out infinite alternate;
}

@keyframes auroraDrift {
  from { transform: translate3d(-2%, -1%, 0) rotate(-2deg); }
  to { transform: translate3d(2%, 1.5%, 0) rotate(2deg); }
}

.brain-shell {
  position: relative;
  z-index: 1;
  width: min(1540px, calc(100% - 28px));
  margin: 0 auto;
  padding: 14px 0 36px;
}

.app-header,
.search-dock,
.filters-panel,
.results-panel,
.detail-panel,
.kb-card {
  border: 1px solid var(--border);
  background: linear-gradient(145deg, rgba(255,255,255,.105), rgba(255,255,255,.045));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 72px;
  border-radius: 22px;
  padding: 13px 15px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(66,217,255,.34);
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(66,217,255,.22), rgba(72,230,163,.1));
  color: #e9fbff;
  font-size: 12px;
  font-weight: 950;
  box-shadow: 0 14px 30px rgba(66,217,255,.12);
}

.brand strong { display: block; font-size: 17px; }
.brand small { display: block; color: var(--muted); }

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.header-actions a,
.mini,
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid rgba(116,167,255,.28);
  border-radius: 13px;
  background: linear-gradient(135deg, rgba(116,167,255,.18), rgba(66,217,255,.08));
  color: var(--text);
  padding: 8px 11px;
  font-weight: 850;
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}

.header-actions a:hover,
.mini:hover,
.chip:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
}

.subtle,
.ghost {
  background: rgba(255,255,255,.055);
  color: var(--soft);
}

.search-dock {
  position: sticky;
  top: 10px;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(420px, .45fr);
  gap: 12px;
  align-items: end;
  margin-top: 12px;
  border-radius: 22px;
  padding: 14px;
}

label,
.eyebrow,
.panel-title span {
  display: block;
  margin-bottom: 7px;
  color: #cbf5ff;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .02em;
  text-transform: uppercase;
}

input[type="search"],
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(2,7,16,.64);
  color: var(--text);
  outline: none;
}

input[type="search"] {
  min-height: 58px;
  padding: 0 18px;
  font-size: 18px;
}

select {
  min-height: 43px;
  padding: 0 11px;
  margin-bottom: 12px;
}

input[type="search"]:focus,
select:focus {
  border-color: rgba(66,217,255,.55);
  box-shadow: 0 0 0 4px rgba(66,217,255,.1);
}

.quick-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.quick-stats div {
  min-height: 58px;
  border: 1px solid rgba(196,213,238,.12);
  border-radius: 16px;
  padding: 10px;
  background: rgba(2,7,16,.32);
}

.quick-stats span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.quick-stats strong {
  display: block;
  margin-top: 3px;
  font-size: 25px;
}

.brain-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 390px;
  gap: 12px;
  margin-top: 12px;
  align-items: start;
}

.filters-panel,
.detail-panel {
  position: sticky;
  top: 114px;
  border-radius: 22px;
  padding: 14px;
}

.filters-panel { max-height: calc(100vh - 132px); overflow: auto; }

.panel-title,
.tags-head,
.results-head,
.card-top,
.detail-top,
.detail-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  min-height: 32px;
  border-radius: 999px;
  padding: 6px 9px;
  background: rgba(255,255,255,.055);
  font-size: 12px;
}

.chip.active {
  border-color: rgba(72,230,163,.44);
  background: rgba(72,230,163,.13);
  color: #dcfff0;
}

.results-panel {
  min-height: 620px;
  border-radius: 22px;
  padding: 14px;
}

.results-head {
  align-items: end;
  margin-bottom: 11px;
}

.results-head h1 {
  margin-top: 4px;
  font-size: clamp(24px, 4vw, 38px);
  line-height: 1;
  letter-spacing: 0;
}

.meta {
  max-width: 48ch;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  line-height: 1.35;
}

.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.kb-card {
  position: relative;
  min-height: 190px;
  border-radius: 18px;
  padding: 14px;
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
  animation: rise .24s ease both;
}

.kb-card:hover,
.kb-card.active {
  transform: translateY(-3px);
  border-color: rgba(66,217,255,.42);
  background: linear-gradient(145deg, rgba(66,217,255,.12), rgba(255,255,255,.055));
}

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

.kb-title {
  font-size: 19px;
  line-height: 1.16;
  letter-spacing: 0;
}

.badges,
.tags,
.detail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badges { margin-top: 8px; }
.tags { margin-top: 12px; }

.badge,
.tag {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  border: 1px solid rgba(196,213,238,.14);
  border-radius: 999px;
  background: rgba(255,255,255,.055);
  color: #dce8f5;
  padding: 5px 8px;
  font-size: 12px;
  line-height: 1.1;
}

.badge.source { color: #bfefff; }
.badge.confidence { color: #dcfff0; }

.excerpt {
  margin-top: 10px;
  color: var(--soft);
  line-height: 1.45;
}

.detail-panel {
  min-height: calc(100vh - 132px);
}

.detail-empty {
  min-height: 460px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  text-align: center;
  color: var(--muted);
}

.detail-empty h2 { color: var(--text); }

.detail-content {
  display: grid;
  gap: 13px;
  animation: rise .22s ease both;
}

.detail-top h2 {
  font-size: 23px;
  line-height: 1.12;
}

.detail-section {
  border: 1px solid rgba(196,213,238,.12);
  border-radius: 16px;
  padding: 12px;
  background: rgba(2,7,16,.32);
}

.detail-section span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.detail-section p,
.detail-section li {
  color: var(--soft);
  line-height: 1.5;
}

.detail-section ul {
  margin: 0;
  padding-left: 18px;
}

.command {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid rgba(196,213,238,.12);
  border-radius: 14px;
  background: rgba(0,0,0,.28);
}

.command code {
  white-space: pre-wrap;
  word-break: break-word;
  color: #eef3f8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
}

.empty {
  grid-column: 1 / -1;
  padding: 18px;
  border-radius: 16px;
  border: 1px dashed var(--border);
  background: rgba(255,255,255,.04);
  color: var(--muted);
  text-align: center;
}

.skeleton {
  min-height: 190px;
  border-radius: 18px;
  border: 1px solid rgba(196,213,238,.12);
  background:
    linear-gradient(90deg, transparent, rgba(255,255,255,.08), transparent),
    rgba(255,255,255,.045);
  background-size: 220% 100%;
  animation: shimmer 1.1s ease-in-out infinite;
}

@keyframes shimmer {
  from { background-position: 120% 0; }
  to { background-position: -120% 0; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px);
  z-index: 50;
  padding: 12px 15px;
  border: 1px solid rgba(72,230,163,.34);
  border-radius: 16px;
  background: rgba(8, 14, 24, .94);
  color: var(--text);
  box-shadow: 0 18px 52px rgba(0,0,0,.36), 0 0 30px rgba(72,230,163,.1);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1280px) {
  .brain-layout { grid-template-columns: 235px minmax(0, 1fr); }
  .detail-panel {
    position: fixed;
    inset: auto 12px 12px 12px;
    z-index: 20;
    max-height: 78vh;
    min-height: 0;
    overflow: auto;
    transform: translateY(calc(100% + 24px));
    transition: transform .22s ease;
  }
  .detail-panel.open { transform: translateY(0); }
  .detail-empty { min-height: 240px; }
}

@media (max-width: 920px) {
  .brain-shell { width: min(100%, calc(100% - 16px)); padding-top: 8px; }
  .app-header,
  .search-dock { border-radius: 18px; }
  .search-dock {
    top: 6px;
    grid-template-columns: 1fr;
  }
  .quick-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .brain-layout { grid-template-columns: 1fr; }
  .filters-panel {
    position: static;
    max-height: none;
    border-radius: 18px;
  }
  .results-panel { border-radius: 18px; padding: 12px; }
  .cards { grid-template-columns: 1fr; }
  .results-head {
    align-items: start;
    flex-direction: column;
  }
  .meta { text-align: left; }
}

@media (max-width: 620px) {
  .app-header {
    align-items: start;
    flex-direction: column;
  }
  .header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  input[type="search"] {
    min-height: 52px;
    font-size: 16px;
  }
  .quick-stats strong { font-size: 22px; }
  .card-top {
    align-items: start;
    flex-direction: column;
  }
  .mini { min-height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .001ms !important;
  }
}

/* Dense cyber dashboard pass */
body::before { background-size: 28px 28px; mask-image: linear-gradient(to bottom, rgba(0,0,0,.78), transparent 84%); }

.brain-shell {
  width: min(1600px, calc(100% - 18px));
  padding: 9px 0 24px;
}

.app-header {
  min-height: 56px;
  border-radius: 16px;
  padding: 9px 11px;
  box-shadow: 0 18px 48px rgba(0,0,0,.34);
}

.brand { gap: 9px; }
.brand-mark { width: 34px; height: 34px; border-radius: 11px; }
.brand strong { font-size: 15px; }
.brand small { font-size: 12px; }
.header-actions { gap: 6px; }
.header-actions a, .mini, .chip {
  min-height: 32px;
  border-radius: 10px;
  padding: 7px 9px;
}

.search-dock {
  top: 8px;
  grid-template-columns: minmax(0, 1fr) minmax(360px, .42fr);
  gap: 8px;
  margin-top: 8px;
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 18px 48px rgba(0,0,0,.34);
}

label, .eyebrow, .panel-title span { margin-bottom: 5px; font-size: 10px; }
input[type="search"] { min-height: 44px; border-radius: 12px; padding: 0 13px; font-size: 16px; }
select { min-height: 36px; border-radius: 10px; padding: 0 9px; margin-bottom: 8px; }
.quick-stats { gap: 6px; }
.quick-stats div { min-height: 44px; border-radius: 12px; padding: 7px 8px; }
.quick-stats span { font-size: 10px; }
.quick-stats strong { font-size: 21px; }

.brain-layout {
  grid-template-columns: 230px minmax(0, 1fr) 360px;
  gap: 8px;
  margin-top: 8px;
}

.filters-panel,
.detail-panel {
  top: 92px;
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 18px 48px rgba(0,0,0,.34);
}

.filters-panel { max-height: calc(100vh - 108px); }
.panel-title, .tags-head, .results-head, .card-top, .detail-top, .detail-actions { gap: 8px; }
.tag-cloud { gap: 5px; }
.chip { min-height: 28px; border-radius: 999px; padding: 5px 8px; font-size: 11px; }

.results-panel {
  min-height: 620px;
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 18px 48px rgba(0,0,0,.34);
}

.results-head { margin-bottom: 8px; }
.results-head h1 { font-size: clamp(22px, 3vw, 32px); }
.meta { font-size: 12px; }
.cards { gap: 8px; }

.kb-card {
  min-height: 142px;
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 18px 48px rgba(0,0,0,.26);
}

.kb-title { font-size: 16px; }
.badges { margin-top: 6px; }
.tags { margin-top: 8px; }
.badge, .tag { padding: 4px 7px; font-size: 11px; }
.excerpt { margin-top: 8px; font-size: 13px; }
.detail-panel { min-height: calc(100vh - 108px); }
.detail-content { gap: 9px; }
.detail-top h2 { font-size: 19px; }
.detail-section { border-radius: 12px; padding: 9px; }
.detail-section p, .detail-section li { font-size: 13px; }
.command { gap: 6px; margin-top: 6px; padding: 8px; border-radius: 11px; }
.command code { font-size: 12px; }
.skeleton { min-height: 142px; border-radius: 14px; }

.app-header,
.search-dock,
.filters-panel,
.results-panel,
.detail-panel,
.kb-card {
  position: relative;
  overflow: hidden;
}

.app-header::before,
.search-dock::before,
.filters-panel::before,
.results-panel::before,
.detail-panel::before,
.kb-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background: linear-gradient(120deg, rgba(66,217,255,.14), transparent 24%, transparent 74%, rgba(72,230,163,.1));
  opacity: .5;
}

@media (max-width: 1280px) {
  .brain-layout { grid-template-columns: 220px minmax(0, 1fr); }
  .detail-panel { inset: auto 8px 8px 8px; }
}

@media (max-width: 920px) {
  .brain-shell { width: min(100%, calc(100% - 12px)); padding-top: 6px; }
  .app-header, .search-dock, .filters-panel, .results-panel { border-radius: 14px; }
  .search-dock { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .quick-stats strong { font-size: 20px; }
  input[type="search"] { min-height: 42px; font-size: 15px; }
}
