:root {
  --bg: #090a0d;
  --panel: #121419;
  --ink: #f3f4f6;
  --muted: #9da3af;
  --line: #252c37;
  --line-soft: #1c2330;
  --accent: #ffffff;
  --accent-ink: #0f1012;
  --danger: #ff7676;
  --ok: #9ce3bc;
  --shadow: 0 24px 44px rgba(0, 0, 0, 0.45);
  --radius-lg: 22px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  color: var(--ink);
  background: radial-gradient(circle at top left, #161921 0%, #090a0d 46%);
  font-family: "Manrope", sans-serif;
}

body {
  position: relative;
  overflow-x: hidden;
}

.bg-blur {
  position: fixed;
  width: 560px;
  height: 560px;
  border-radius: 50%;
  filter: blur(90px);
  z-index: 0;
  pointer-events: none;
}

.bg-blur-a {
  top: -230px;
  left: -180px;
  background: rgba(255, 255, 255, 0.1);
}

.bg-blur-b {
  right: -220px;
  bottom: -280px;
  background: rgba(255, 255, 255, 0.07);
}

.app,
.login-shell {
  position: relative;
  z-index: 1;
}

.app {
  width: min(1400px, 94vw);
  margin: 24px auto 34px;
}

.topbar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

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

.brand-logo-wrap {
  width: 260px;
  min-width: 260px;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid rgba(149, 160, 181, 0.2);
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.08), transparent 56%),
    rgba(12, 16, 24, 0.72);
}

.brand-copy {
  min-width: 0;
}

.brand-logo {
  width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 800;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
}

h1 {
  margin-top: 4px;
  font-size: clamp(1.45rem, 2.2vw, 2.25rem);
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
  min-height: calc(100vh - 126px);
}

.panel {
  background: linear-gradient(160deg, rgba(19, 22, 28, 0.97), rgba(14, 17, 23, 0.97));
  border: 1px solid rgba(121, 134, 157, 0.16);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.34);
}

.panel-head h2,
.panel-head h3 {
  font-size: 1.04rem;
}

.panel-head p {
  margin: 5px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.sidebar {
  position: sticky;
  top: 14px;
  height: calc(100vh - 126px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  overflow: hidden;
}

.nav-menu {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  align-content: start;
  overflow: auto;
  padding-right: 2px;
}

.nav-item {
  width: 100%;
  border: 1px solid rgba(124, 138, 162, 0.24);
  border-radius: 12px;
  background: #131821;
  color: var(--ink);
  padding: 10px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-family: inherit;
}

.nav-item.is-active {
  border-color: #dce4f2;
  background: linear-gradient(140deg, #1a202c, #151922);
}

.nav-icon {
  width: 26px;
  height: 26px;
  border: 1px solid rgba(127, 141, 165, 0.38);
  border-radius: 8px;
  background: #171e2a;
  color: #dce4f3;
  display: grid;
  place-items: center;
  flex: 0 0 26px;
}

.nav-icon svg {
  width: 14px;
  height: 14px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-item.is-active .nav-icon {
  border-color: rgba(228, 236, 249, 0.75);
  background: #202938;
}

.nav-title {
  display: block;
  font-size: 0.9rem;
  line-height: 1.2;
  font-weight: 700;
}

.nav-item.nav-stage {
  display: flex;
}

.nav-item.nav-config {
  margin-top: 8px;
  border-top-width: 2px;
}

.sidebar-footer {
  border-top: 1px solid #2b3240;
  padding-top: 12px;
  display: grid;
  gap: 10px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #161d29;
  border: 1px solid #394254;
  font-weight: 800;
  font-size: 0.88rem;
  color: #f4f6fb;
}

.sidebar-user-name {
  font-size: 0.9rem;
  line-height: 1.2;
}

.sidebar-version {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-refresh,
.sidebar-logout {
  width: 100%;
}

.work-area {
  min-width: 0;
  height: calc(100vh - 126px);
  min-height: 0;
}

.mode-view {
  display: none;
}

.mode-view.is-active {
  display: block;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.config-panel {
  height: 100%;
  min-height: 0;
  overflow: auto;
}

.prompt-preview {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0f1319;
  padding: 12px;
  white-space: pre-wrap;
  font-size: 0.83rem;
  line-height: 1.45;
}

.chat-panel {
  height: 100%;
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 10px;
}

.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.chat-header h2 {
  margin-top: 4px;
  font-size: clamp(1.2rem, 1.8vw, 1.55rem);
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#stage-description {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.prompt-btn {
  white-space: nowrap;
}

.artifact-live {
  border: 1px solid rgba(130, 144, 168, 0.28);
  border-radius: 14px;
  padding: 10px;
  background: linear-gradient(160deg, rgba(17, 24, 35, 0.95), rgba(13, 19, 29, 0.95));
}

.artifact-live-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.artifact-live-head strong {
  font-size: 0.88rem;
}

.artifact-live-meta {
  color: var(--muted);
  font-size: 0.76rem;
}

.artifact-live-body {
  margin-top: 8px;
  display: grid;
  gap: 8px;
}

.chat-zone {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid rgba(118, 132, 157, 0.24);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(17, 23, 34, 0.96), rgba(10, 15, 24, 0.96)),
    radial-gradient(circle at 14% 0%, rgba(255, 255, 255, 0.08), transparent 45%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    inset 0 -80px 120px rgba(4, 8, 16, 0.45);
  overflow: hidden;
}

.chat-zone-head {
  padding: 10px 12px;
  border-bottom: 1px solid #293141;
  font-size: 0.76rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #c4ccda;
  font-weight: 800;
}

.chat-log {
  padding: 12px;
  min-height: 0;
  max-height: none;
  min-width: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  align-content: flex-start;
  gap: 10px;
}

.bubble {
  display: inline-block;
  width: fit-content;
  max-width: 92%;
  align-self: flex-start;
  height: auto;
  flex: 0 0 auto;
  white-space: pre-wrap;
  word-break: break-word;
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 0.86rem;
  line-height: 1.35;
}

.bubble.user {
  margin-left: auto;
  max-width: min(78%, 760px);
  border: 1px solid rgba(129, 143, 171, 0.44);
  background: #1b2331;
}

.bubble.assistant {
  margin-right: auto;
  width: fit-content;
  max-width: 92%;
  border: 1px solid rgba(102, 115, 138, 0.38);
  background: #141a24;
}

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

.attachment-chip {
  border: 1px solid #3f4757;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.77rem;
  background: #151b25;
}

.chat-composer {
  border: 1px solid rgba(118, 132, 157, 0.26);
  border-radius: 14px;
  background: #0f1319;
  padding: 8px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.clip-btn,
.ghost-btn,
.primary-btn {
  border-radius: 12px;
  border: none;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.88rem;
  cursor: pointer;
}

.clip-btn {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(120, 134, 157, 0.34);
  background: #181d26;
  color: var(--ink);
  font-size: 1.15rem;
}

.composer-input {
  width: 100%;
  min-width: 0;
  resize: none;
  border: 1px solid rgba(118, 132, 157, 0.3);
  border-radius: 10px;
  background: #10141a;
  color: var(--ink);
  padding: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  min-height: 44px;
  max-height: 130px;
}

.composer-input:focus {
  border-color: #f5f5f5;
  outline: 1px solid rgba(245, 245, 245, 0.25);
}

.ghost-btn {
  background: #181d26;
  border: 1px solid rgba(120, 134, 157, 0.3);
  color: var(--ink);
  padding: 10px 12px;
}

.primary-btn {
  background: linear-gradient(135deg, #ffffff, #d8dce4);
  color: #111318;
  padding: 10px 14px;
}

.config-note {
  margin: 12px 0 0;
  font-size: 0.86rem;
  color: var(--muted);
}

.config-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.config-actions .ghost-btn,
.config-actions .primary-btn {
  padding: 9px 12px;
}

.flow-overview {
  margin-top: 12px;
  border: 1px solid rgba(118, 132, 157, 0.24);
  border-radius: 14px;
  background: #0f1319;
  padding: 12px;
}

.flow-head h4 {
  margin: 0;
  font-size: 0.95rem;
  font-family: "Space Grotesk", sans-serif;
}

.flow-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.flow-track {
  margin-top: 10px;
  display: flex;
  align-items: stretch;
  gap: 0;
  overflow-x: auto;
  padding-bottom: 4px;
}

.flow-segment {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.flow-node {
  width: 220px;
  border: 1px solid rgba(118, 132, 157, 0.28);
  border-radius: 12px;
  background: #111723;
  padding: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.flow-node.is-decision {
  border-style: dashed;
  background: linear-gradient(140deg, #1a212d, #151a24);
}

.flow-stage {
  display: inline-flex;
  align-items: center;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid rgba(142, 157, 183, 0.3);
  background: #1a2230;
  color: #d5deef;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 800;
}

.flow-stage-control {
  background: #262029;
  border-color: rgba(188, 161, 191, 0.35);
  color: #f1deff;
}

.flow-node strong {
  display: block;
  margin-top: 8px;
  font-size: 0.9rem;
}

.flow-node p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.flow-arrow {
  color: #8f9cb5;
  font-size: 1.2rem;
  line-height: 1;
}

.config-list {
  margin-top: 12px;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.config-item {
  border: 1px solid rgba(118, 132, 157, 0.24);
  border-radius: 12px;
  background: #0f1319;
  padding: 10px;
  overflow: hidden;
}

.config-item strong {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.config-item-meta {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.config-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.config-item-head strong {
  margin: 0;
}

.config-remove-btn {
  background: #20151a;
  border: 1px solid rgba(193, 128, 140, 0.4);
  color: #ffd9df;
  border-radius: 10px;
  padding: 6px 10px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
}

.config-grid {
  margin-top: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.config-field {
  display: grid;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}

.config-field input,
.config-field select,
.config-field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(118, 132, 157, 0.3);
  border-radius: 10px;
  background: #10141a;
  color: var(--ink);
  padding: 9px 10px;
  font-family: inherit;
  font-size: 0.85rem;
}

.config-field textarea {
  min-height: 90px;
  resize: vertical;
}

#save-config-btn {
  margin-top: 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  background: rgba(6, 8, 12, 0.68);
  backdrop-filter: blur(3px);
  padding: 20px;
}

.modal-card {
  width: min(760px, 94vw);
  max-height: 84vh;
  overflow: auto;
  border: 1px solid rgba(118, 132, 157, 0.26);
  border-radius: 20px;
  background: linear-gradient(160deg, rgba(18, 21, 28, 0.99), rgba(13, 16, 22, 0.99));
  box-shadow: var(--shadow);
  padding: 16px;
}

.stage-modal-card {
  width: min(980px, 95vw);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-copy {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.stage-modal-body {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.stage-widget {
  border: 1px solid rgba(118, 132, 157, 0.24);
  border-radius: 12px;
  background: #0f1319;
  padding: 12px;
}

.stage-widget-artifact {
  border-color: rgba(168, 193, 228, 0.35);
  background: linear-gradient(150deg, #121a27, #101622);
}

.stage-widget h4 {
  margin: 0;
  font-size: 0.9rem;
}

.stage-text {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.86rem;
}

.stage-kpi-grid {
  margin-top: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.stage-kpi-item {
  border: 1px solid rgba(118, 132, 157, 0.24);
  border-radius: 10px;
  background: #111723;
  padding: 8px 10px;
  display: grid;
  gap: 4px;
}

.stage-kpi-label {
  font-size: 0.74rem;
  color: var(--muted);
}

.stage-list {
  margin: 8px 0 0;
  padding-left: 18px;
  display: grid;
  gap: 5px;
  color: #d8dee8;
  font-size: 0.86rem;
}

.stage-empty {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.stage-table-wrap {
  margin-top: 8px;
  overflow: auto;
}

.stage-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 460px;
}

.stage-table th,
.stage-table td {
  border: 1px solid rgba(118, 132, 157, 0.24);
  padding: 7px 8px;
  text-align: left;
  font-size: 0.82rem;
  vertical-align: top;
}

.stage-table th {
  background: #161f2d;
  font-weight: 800;
}

.stage-markdown {
  margin: 8px 0 0;
  border: 1px solid rgba(118, 132, 157, 0.24);
  border-radius: 10px;
  background: #0f1319;
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Manrope", sans-serif;
  font-size: 0.84rem;
  line-height: 1.45;
  color: #dde4f0;
}

body.modal-open {
  overflow: hidden;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(440px, 95vw);
  border-radius: 24px;
  border: 1px solid rgba(118, 132, 157, 0.25);
  background: rgba(18, 20, 25, 0.95);
  padding: 24px;
  box-shadow: var(--shadow);
}

.login-hero {
  width: 100%;
  min-height: 116px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  border: 1px solid #303748;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.16), transparent 58%),
    linear-gradient(160deg, rgba(21, 24, 31, 0.98), rgba(12, 14, 18, 0.98));
  padding: 14px;
  margin-bottom: 14px;
}

.login-hero-logo {
  width: min(340px, 100%);
  height: 68px;
  object-fit: contain;
}

.login-kicker {
  margin-top: 2px;
}

.login-card h2 {
  margin: 6px 0 8px;
}

.login-copy {
  margin: 0 0 14px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label {
  display: grid;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 700;
}

.login-forgot {
  justify-self: end;
  color: #c8d4ea;
  font-size: 0.78rem;
  text-decoration: none;
  border-bottom: 1px dashed rgba(200, 212, 234, 0.45);
  padding-bottom: 2px;
}

.login-forgot:hover,
.login-forgot:focus-visible {
  color: #eef4ff;
  border-bottom-color: rgba(238, 244, 255, 0.75);
}

.login-form input {
  width: 100%;
  border: 1px solid rgba(118, 132, 157, 0.3);
  border-radius: 10px;
  padding: 10px;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9rem;
  background: #10141a;
}

.login-form input:focus {
  border-color: #f5f5f5;
  outline: 1px solid rgba(245, 245, 245, 0.25);
}

.login-hint {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.login-error {
  min-height: 1.2em;
  margin: 0;
  color: var(--danger);
  font-size: 0.82rem;
}

@media (max-width: 1220px) {
  .workspace {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .sidebar {
    position: static;
    height: auto;
    overflow: visible;
    grid-template-rows: auto;
  }

  .work-area {
    height: auto;
  }

  .mode-view.is-active,
  .chat-panel {
    height: auto;
  }
}

@media (max-width: 980px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .brand-logo-wrap {
    width: min(250px, 78vw);
    min-width: 0;
  }

  .chat-composer {
    grid-template-columns: 44px 1fr;
  }

  .chat-composer .primary-btn {
    grid-column: 1 / -1;
  }

  .chat-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .chat-header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .flow-node {
    width: 196px;
  }
}
