:root {
  --bg: #111114;
  --panel: #19191d;
  --panel-2: #202026;
  --line: #31313a;
  --text: #f3f1ed;
  --muted: #a7a198;
  --accent: #b72d38;
  --accent-2: #e0b65a;
  --blue: #4a9ccf;
  --green: #49a86c;
  --danger: #d04c4c;
  --radius: 8px;
  --sidebar: 268px;
  --font: "Segoe UI", "Aptos", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.45;
}

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

.login-page {
  display: grid;
  place-items: center;
  padding: 16px;
  overflow-x: hidden;
  background: #111114;
}

.login-shell {
  width: 100%;
  max-width: 420px;
  min-width: 0;
}

.login-panel,
.wide-panel,
.list-panel,
.editor-panel,
.metric-panel,
.simulator-controls,
.conversation-panel,
.prompt-panel,
.deploy-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.login-panel {
  width: 100%;
  min-width: 0;
  padding: 32px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: block;
  flex: 0 0 42px;
  border: 1px solid rgba(183, 45, 56, 0.65);
  border-radius: 8px;
  background: #050506;
  object-fit: cover;
}

.login-brand-mark {
  width: 68px;
  height: 68px;
  margin-bottom: 14px;
}

.login-panel h1,
.topbar h1,
.panel-heading h2,
.deploy-panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.login-panel p,
.topbar p,
.muted {
  color: var(--muted);
}

.login-form,
.form-grid,
.deploy-panel {
  display: grid;
  gap: 14px;
  min-width: 0;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #101014;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(224, 182, 90, 0.15);
}

input[readonly] {
  color: var(--muted);
  background: #17171b;
  cursor: not-allowed;
}

.form-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  background: #151519;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.sidebar-brand span,
.sidebar-footer span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.sidebar-nav {
  flex: 1;
  display: grid;
  align-content: start;
  gap: 4px;
  padding: 12px;
}

.nav-item {
  text-align: left;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 11px 12px;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background: #25191c;
  color: var(--text);
}

.nav-item.active {
  border-left: 3px solid var(--accent);
}

.sidebar-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-top: 1px solid var(--line);
}

.main-content {
  margin-left: var(--sidebar);
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 17, 20, 0.96);
}

.topbar-actions,
.button-row,
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.save-state {
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.save-state.dirty {
  color: var(--accent-2);
}

.prompt-cache-status {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.section {
  display: none;
  padding: 24px;
}

.section.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-panel {
  padding: 16px;
}

.draft-summary {
  margin-top: 16px;
}

.draft-active-status {
  padding: 4px 8px;
  border: 1px solid rgba(224, 182, 90, 0.45);
  border-radius: 6px;
  background: #252119;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 700;
}

.draft-active-status.aligned {
  border-color: rgba(73, 168, 108, 0.45);
  background: #17221b;
  color: #8fd7a8;
}

.metric-panel span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.metric-panel strong {
  display: block;
  margin-top: 8px;
  font-size: 20px;
}

.wide-panel,
.list-panel,
.editor-panel,
.simulator-controls,
.conversation-panel,
.prompt-panel {
  padding: 16px;
}

.split-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 16px;
}

.simulator-layout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.ticket-list,
.version-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.ticket-row,
.version-row {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  padding: 10px;
  text-align: left;
  cursor: pointer;
}

.ticket-row.active,
.version-row.active {
  border-color: var(--accent-2);
}

.ticket-row small,
.version-row small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.product-layout {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.product-catalog-panel,
.product-editor-panel {
  min-width: 0;
}

.product-catalog-panel {
  position: sticky;
  top: 16px;
}

.product-list {
  display: grid;
  gap: 6px;
  margin-top: 14px;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
}

.product-row {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.product-row:hover {
  border-color: #4a4a55;
}

.product-row.active {
  border-color: var(--accent-2);
  background: #242125;
}

.product-row-main {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.product-row-main strong,
.product-row-main small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-row-main small {
  color: var(--muted);
  font-size: 12px;
}

.product-link-count {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.product-editor-panel {
  padding: 0;
  overflow: hidden;
}

.product-editor-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.product-editor-header h2,
.product-editor-header p,
.product-section-heading h3,
.product-section-heading p {
  margin: 0;
}

.product-editor-header h2 {
  margin-top: 3px;
  font-size: 20px;
}

.product-editor-header p,
.product-section-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.product-eyebrow {
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.product-editor-section {
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.product-editor-section:last-child {
  border-bottom: 0;
}

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

.product-section-heading h3 {
  font-size: 14px;
}

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

.pricing-mode-control {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 14px;
}

.pricing-mode-option {
  min-height: 72px;
  display: block;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #151519;
  cursor: pointer;
}

.pricing-mode-option:hover {
  border-color: #4a4a55;
}

.pricing-mode-option.active {
  border-color: var(--accent-2);
  background: #252119;
}

.pricing-mode-option:focus-within {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(224, 182, 90, 0.15);
}

.pricing-mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.pricing-mode-option span {
  display: grid;
  gap: 3px;
}

.pricing-mode-option strong {
  color: var(--text);
  font-size: 13px;
}

.pricing-mode-option small,
label small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.price-preview {
  display: grid;
  justify-items: end;
  gap: 2px;
  text-align: right;
}

.price-preview span {
  color: var(--muted);
  font-size: 11px;
}

.price-preview strong {
  color: var(--accent-2);
  font-size: 13px;
}

.input-affix {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #101014;
  overflow: hidden;
}

.input-affix:focus-within {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(224, 182, 90, 0.15);
}

.input-affix > span {
  padding-left: 12px;
  color: var(--muted);
}

.input-affix input {
  border: 0;
  box-shadow: none;
}

.input-affix-suffix {
  grid-template-columns: minmax(0, 1fr) auto;
}

.input-affix-suffix > span {
  padding: 0 12px 0 0;
}

.pricing-empty-state {
  grid-column: 1 / -1;
  margin: 0;
  padding: 12px;
  border-left: 3px solid var(--green);
  background: #17221b;
  color: var(--muted);
  font-size: 13px;
}

.product-ticket-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.product-ticket-link {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  padding: 7px 10px;
  cursor: pointer;
}

.product-ticket-link:hover {
  border-color: var(--accent-2);
}

.span-two {
  grid-column: 1 / -1;
}

.editor-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.scope-link-fieldset {
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.scope-link-fieldset legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.scope-link-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.scope-link-option {
  min-width: 0;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  cursor: pointer;
}

.scope-link-option:has(input:checked) {
  border-color: var(--accent-2);
  background: #252119;
}

.scope-link-option input {
  width: 16px;
  height: 16px;
  margin-top: 2px;
}

.scope-link-option span {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.scope-link-option small {
  color: var(--muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

.status-dot.enabled {
  background: var(--green);
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}

.stage-toolbar h3 {
  margin: 0;
  font-size: 15px;
}

.stage-list {
  display: grid;
  gap: 12px;
}

.stage-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

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

.stage-title-button {
  min-width: 0;
  display: grid;
  gap: 2px;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.stage-title-button strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-title-button span {
  color: var(--muted);
  font-size: 12px;
}

.stage-control-group {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.icon-button {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #202228;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 18px;
  line-height: 1;
}

.icon-button:hover:not(:disabled) {
  border-color: var(--accent-2);
  background: #292c33;
}

.icon-button:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.icon-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.stage-body {
  display: grid;
  gap: 10px;
}

.stage-card.collapsed .stage-body {
  display: none;
}

.stage-card.collapsed {
  padding-top: 10px;
  padding-bottom: 10px;
}

.text-editor textarea {
  min-height: 220px;
}

.instruction-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.instruction-scope-picker {
  width: min(430px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
}

.instruction-scope-settings {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(220px, 1.5fr) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.instruction-scope-settings.global {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.instruction-scope-settings.global > div {
  display: grid;
  gap: 2px;
}

.instruction-scope-settings.global span {
  color: var(--muted);
  font-size: 12px;
}

.scope-usage-summary {
  min-height: 42px;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

.scope-usage-summary span {
  color: var(--muted);
  font-size: 11px;
}

.scope-usage-summary strong {
  color: var(--text);
}

.scope-linked-flows {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.instruction-scope-actions {
  flex-wrap: nowrap;
}

.scope-status {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.scope-status.enabled {
  border-color: rgba(73, 168, 108, 0.45);
  color: #8fd7a8;
}

.instruction-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
}

.instruction-block-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.instruction-row {
  display: grid;
  gap: 3px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.instruction-row.active {
  border-color: var(--accent-2);
}

.instruction-row small {
  color: var(--muted);
}

.instruction-block-editor {
  display: grid;
  gap: 14px;
}

.large-editor {
  min-height: 460px;
}

.variable-palette {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.variable-palette > span {
  color: var(--muted);
  font-size: 12px;
}

.variable-palette select {
  width: auto;
  min-width: 150px;
}

.variable-button {
  border: 1px solid #426174;
  border-radius: 6px;
  background: #17252d;
  color: #b9dff2;
  padding: 7px 9px;
  cursor: pointer;
}

.instruction-support-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.settings-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.toggle-row input {
  width: 16px;
  height: 16px;
}

.change-list,
.validation-output {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.change-item,
.validation-issue,
.validation-summary,
.deploy-readiness,
.empty-state {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--muted);
}

.validation-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.validation-summary.valid {
  border-left: 3px solid var(--green);
}

.validation-summary.invalid,
.validation-issue.error {
  border-left: 3px solid var(--danger);
}

.validation-issue.warning {
  border-left: 3px solid var(--accent-2);
}

.validation-issue {
  display: grid;
  gap: 3px;
}

.validation-issue strong {
  color: var(--text);
}

.deploy-readiness {
  margin: 4px 0;
}

.conversation-thread {
  min-height: 360px;
  max-height: 520px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
}

.detected-ticket {
  display: grid;
  gap: 5px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--blue);
  border-radius: 6px;
  background: var(--panel-2);
}

.detected-ticket span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.detected-ticket small {
  color: var(--muted);
  font-size: 12px;
}

.detected-ticket strong {
  color: var(--text);
  font-size: 14px;
}

.message {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: var(--panel-2);
}

.message.user {
  border-left: 3px solid var(--blue);
}

.message.assistant {
  border-left: 3px solid var(--green);
}

.message strong {
  display: block;
  margin-bottom: 4px;
}

.prompt-preview,
.code-output {
  margin: 12px 0 0;
  min-height: 160px;
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0d0d10;
  color: #d8d2c8;
  padding: 12px;
  white-space: pre-wrap;
}

.primary-action,
.secondary-action,
.ghost-action,
.danger-action {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 9px 12px;
  color: var(--text);
  cursor: pointer;
}

.primary-action {
  background: var(--accent);
}

.secondary-action {
  background: #23262c;
  border-color: var(--line);
}

.ghost-action {
  background: transparent;
  border-color: var(--line);
}

.danger-action {
  background: transparent;
  border-color: rgba(208, 76, 76, 0.6);
  color: #f0b3b3;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #22252b;
  color: var(--text);
  opacity: 0;
  transform: translateY(10px);
  transition: 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1080px) {
  .sidebar {
    position: static;
    width: auto;
    height: auto;
  }

  .main-content {
    margin-left: 0;
  }

  .product-catalog-panel {
    position: static;
  }

  .product-list {
    max-height: none;
  }

  .metric-grid,
  .simulator-layout,
  .split-layout,
  .product-layout,
  .instruction-layout,
  .instruction-support-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .instruction-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .instruction-scope-settings {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .instruction-scope-actions {
    justify-content: flex-end;
  }

  .variable-palette {
    justify-content: flex-start;
  }

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

  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }
}

@media (max-width: 640px) {
  .login-page {
    padding: 12px;
  }

  .login-panel {
    padding: 24px;
  }

  .section {
    padding: 14px;
  }

  .product-form-grid,
  .scope-link-list,
  .settings-form {
    grid-template-columns: 1fr;
  }

  .span-two {
    grid-column: auto;
  }

  .pricing-mode-control {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .product-section-heading,
  .product-editor-header {
    align-items: stretch;
    flex-direction: column;
  }

  .price-preview {
    justify-items: start;
    text-align: left;
  }

  .instruction-scope-picker,
  .instruction-scope-settings,
  .instruction-scope-settings.global {
    grid-template-columns: 1fr;
  }

  .instruction-scope-actions {
    justify-content: stretch;
  }

  .instruction-scope-actions button {
    flex: 1;
  }
}
