:root {
  color-scheme: dark;
  --bg: #050706;
  --panel: #0b1110;
  --panel-2: #111a18;
  --text: #f3fff9;
  --muted: #9db2aa;
  --line: rgba(145, 255, 220, 0.15);
  --line-strong: rgba(145, 255, 220, 0.34);
  --primary: #3df2a1;
  --primary-strong: #90ffd2;
  --primary-soft: rgba(61, 242, 161, 0.13);
  --cyan: #44c7ff;
  --cyan-soft: rgba(68, 199, 255, 0.12);
  --amber: #ffbd5a;
  --amber-soft: rgba(255, 189, 90, 0.14);
  --rose: #ff5c8a;
  --rose-soft: rgba(255, 92, 138, 0.13);
  --code: #020403;
  --shadow: 0 22px 68px rgba(0, 0, 0, 0.44), 0 0 32px rgba(61, 242, 161, 0.06);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 16% 0%, rgba(61, 242, 161, 0.18), transparent 28rem),
    radial-gradient(circle at 90% 8%, rgba(255, 189, 90, 0.12), transparent 24rem),
    linear-gradient(180deg, #050706 0%, #0b1110 48%, #050706 100%),
    var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

button,
textarea,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
textarea:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.rag-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 7, 6, 0.84);
  padding: 10px 18px;
  backdrop-filter: blur(16px);
}

.topbar-main {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.brand {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  box-shadow: 0 0 24px rgba(61, 242, 161, 0.2);
}

.brand-copy {
  display: grid;
  gap: 1px;
}

.brand-name {
  font-weight: 950;
}

.brand-tagline {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.top-actions,
.mobile-actions,
.button-group,
.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.mobile-actions,
.mobile-history-action {
  display: none;
}

.button-row {
  justify-content: space-between;
  margin-top: 16px;
}

.btn {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(11, 17, 16, 0.88);
  color: var(--text);
  padding: 0 13px;
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
}

.btn.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #00140d;
  box-shadow: 0 0 24px rgba(61, 242, 161, 0.24);
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn.icon {
  width: 38px;
  padding: 0;
}

.btn svg,
.history-action svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rag-body {
  display: grid;
  grid-template-columns: 278px minmax(0, 1fr);
  min-height: calc(100vh - 58px);
}

.history-rail {
  position: sticky;
  top: 58px;
  align-self: start;
  height: calc(100vh - 58px);
  overflow: auto;
  border-right: 1px solid var(--line);
  background: rgba(5, 7, 6, 0.64);
  padding: 14px;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  display: grid;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  padding: 11px;
}

.history-item:hover,
.history-item.active {
  border-color: var(--line-strong);
  background: var(--primary-soft);
}

.history-item.active {
  box-shadow: inset 3px 0 0 var(--primary);
}

.history-open {
  display: grid;
  min-width: 0;
  gap: 4px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
}

.history-title,
.history-subtitle,
.history-time {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-title {
  font-size: 13px;
  font-weight: 950;
}

.history-subtitle {
  color: var(--muted);
  font-size: 12px;
}

.history-time {
  color: var(--primary-strong);
  font-size: 11px;
  font-weight: 800;
}

.history-actions {
  display: flex;
  gap: 6px;
}

.history-action {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
}

.history-action.danger:hover {
  border-color: var(--rose);
  color: var(--rose);
}

.rag-main {
  min-width: 0;
}

.wizard-layout,
.output-layout {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.wizard-shell {
  display: grid;
  gap: 18px;
  width: min(940px, 100%);
  min-height: calc(100vh - 96px);
  align-content: center;
  margin: 0 auto;
  padding: 24px 0 72px;
}

.output-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 540px;
  gap: 18px;
  align-items: start;
}

.output-main {
  display: grid;
  gap: 18px;
}

.flow-steps {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.flow-step {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(11, 17, 16, 0.82);
  color: var(--muted);
  padding: 8px 11px;
  font-size: 12px;
  font-weight: 900;
}

.flow-step span {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 10px;
}

.flow-step.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--text);
}

.flow-step.done span {
  background: var(--primary);
  color: #00140d;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.028), rgba(255, 255, 255, 0)),
    rgba(11, 17, 16, 0.9);
  box-shadow: var(--shadow);
}

.section,
.hero-panel {
  padding: 18px;
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 18px;
  align-items: end;
  background:
    linear-gradient(135deg, rgba(61, 242, 161, 0.13), rgba(68, 199, 255, 0.08) 42%, rgba(255, 189, 90, 0.08)),
    rgba(11, 17, 16, 0.92);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1;
}

h2 {
  margin: 0;
  font-size: 18px;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.subtitle.compact {
  max-width: 740px;
  font-size: 13px;
}

.health-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(5, 7, 6, 0.58);
  padding: 14px;
}

.health-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.health-card strong {
  font-size: 34px;
  line-height: 1;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(5, 7, 6, 0.58);
  padding: 12px;
}

.stat strong {
  display: block;
  font-size: 24px;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.meter {
  overflow: hidden;
  height: 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.07);
}

.meter i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--cyan), var(--amber));
}

.section-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

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

.source-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.toggle-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 14px;
}

.template-card,
.source-card,
.toggle-card {
  display: grid;
  gap: 5px;
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(5, 7, 6, 0.58);
  color: var(--text);
  padding: 12px;
  text-align: left;
}

.template-card:hover,
.source-card:hover,
.toggle-card:hover {
  border-color: var(--line-strong);
}

.template-card.active,
.source-card.active,
.toggle-card.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.template-card strong,
.source-card span,
.toggle-card strong {
  font-weight: 950;
}

.template-card span,
.source-card small,
.toggle-card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.upload-zone {
  display: grid;
  min-height: 150px;
  place-items: center;
  gap: 8px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(61, 242, 161, 0.1), rgba(68, 199, 255, 0.06)),
    rgba(5, 7, 6, 0.54);
  padding: 22px;
  color: var(--text);
  text-align: center;
  cursor: pointer;
}

.upload-zone.dragging {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.upload-zone input {
  display: none;
}

.upload-zone strong {
  font-size: 18px;
}

.upload-zone span {
  max-width: 620px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.paste-box {
  display: grid;
  grid-template-columns: minmax(180px, 0.36fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-top: 14px;
}

.document-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.doc-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.42fr);
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(5, 7, 6, 0.6);
  padding: 12px;
}

.doc-main {
  display: grid;
  min-width: 0;
  gap: 5px;
}

.doc-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 950;
}

.doc-main span,
.doc-main p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

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

.warn-text {
  color: var(--amber) !important;
}

.empty-card {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.btn.danger {
  border-color: var(--rose);
  background: var(--rose-soft);
  color: var(--rose);
}

.field {
  display: grid;
  gap: 8px;
}

.field + .field,
.field-row {
  margin-top: 14px;
}

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

.field-row.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
}

.label span,
.hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.textarea,
.input,
.select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(2, 4, 3, 0.8);
  color: var(--text);
  outline: none;
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.textarea:focus,
.input:focus,
.select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(61, 242, 161, 0.13);
}

.textarea {
  min-height: 160px;
  resize: vertical;
  padding: 13px;
  line-height: 1.55;
}

.textarea.small {
  min-height: 108px;
}

.input,
.select {
  min-height: 42px;
  padding: 0 12px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.bridge-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-color: rgba(68, 199, 255, 0.28);
  background:
    linear-gradient(135deg, var(--cyan-soft), rgba(61, 242, 161, 0.08) 45%, rgba(255, 189, 90, 0.07)),
    rgba(11, 17, 16, 0.92);
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(2, 4, 3, 0.76);
  color: var(--text);
  padding: 8px 11px;
  font-size: 13px;
  font-weight: 850;
}

.chip.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.preview-pane {
  position: sticky;
  top: 76px;
  display: grid;
  grid-template-rows: auto 1fr;
  height: calc(100vh - 94px);
  max-height: calc(100vh - 94px);
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 10px;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  padding: 3px;
}

.segmented button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 900;
}

.segmented button.active {
  background: var(--primary);
  color: #00140d;
}

.preview-body {
  overflow: auto;
  padding: 18px;
}

.markdown {
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
}

.markdown h1,
.markdown h2,
.markdown h3 {
  line-height: 1.18;
}

.markdown h1 {
  margin: 0 0 18px;
  font-size: 26px;
}

.markdown h2 {
  margin: 24px 0 10px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
  font-size: 18px;
}

.markdown h3 {
  margin: 18px 0 8px;
  font-size: 16px;
}

.markdown p {
  margin: 8px 0;
}

.markdown ul {
  margin: 8px 0 12px 22px;
  padding: 0;
}

.markdown code {
  border-radius: 5px;
  background: rgba(61, 242, 161, 0.12);
  padding: 2px 5px;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
}

.markdown pre {
  overflow: auto;
  border-radius: var(--radius);
  background: var(--code);
  color: #fff9ec;
  padding: 14px;
}

.markdown table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}

.markdown th,
.markdown td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.markdown th {
  background: rgba(255, 255, 255, 0.05);
}

.editor {
  width: 100%;
  min-height: 68vh;
  border: 0;
  background: transparent;
  color: var(--text);
  outline: none;
  resize: none;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.7;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 60;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #00140d;
  color: var(--primary-strong);
  padding: 10px 14px;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 900;
}

@media (max-width: 1180px) {
  .output-shell {
    grid-template-columns: 1fr;
  }

  .preview-pane {
    position: static;
    height: auto;
    max-height: none;
  }
}

@media (max-width: 820px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 0;
    padding: 10px 14px;
  }

  .topbar-main {
    justify-content: space-between;
  }

  .mobile-actions {
    display: flex;
  }

  .top-actions {
    display: none;
    width: 100%;
    margin-top: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(2, 4, 3, 0.94);
    padding: 8px;
  }

  .topbar.menu-open .top-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .top-actions .btn {
    width: 100%;
  }

  .desktop-new {
    display: none;
  }

  .mobile-history-action {
    display: inline-flex;
  }

  .rag-body {
    display: block;
  }

  .history-rail {
    display: none;
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
  }

  .history-rail.history-open {
    display: block;
  }

  .history-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 3px;
  }

  .history-item {
    flex: 0 0 230px;
  }

  .wizard-layout,
  .output-layout {
    padding: 12px;
  }

  .wizard-shell {
    min-height: auto;
    align-content: start;
    padding: 14px 0 44px;
  }

  .flow-steps {
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .flow-step {
    flex: 0 0 auto;
  }

  .hero-panel,
  .template-grid,
  .source-grid,
  .toggle-grid,
  .stat-grid,
  .paste-box,
  .doc-card,
  .field-row,
  .field-row.four {
    grid-template-columns: 1fr;
  }

  .doc-controls {
    grid-template-columns: 1fr;
  }

  .section-head,
  .bridge-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .button-row,
  .button-group {
    align-items: stretch;
    width: 100%;
  }

  .button-group .btn,
  .button-row .btn {
    flex: 1;
  }

  h1 {
    font-size: 34px;
  }
}

@media (max-width: 430px) {
  .flow-steps {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    overflow: visible;
  }

  .flow-step {
    display: grid;
    justify-items: center;
    gap: 3px;
    min-width: 0;
    padding: 7px 4px;
    text-align: center;
    font-size: 10px;
  }

  .flow-step span {
    width: 22px;
    height: 22px;
  }

  .preview-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media print {
  body {
    background: #fff;
    color: #000;
  }

  .topbar,
  .history-rail,
  .output-main {
    display: none !important;
  }

  .rag-body,
  .output-shell,
  .preview-pane {
    display: block;
    height: auto;
    max-height: none;
  }

  .preview-pane {
    border: 0;
    box-shadow: none;
  }
}
