:root {
  --bg: #f5f8fc;
  --bg-accent: #e8eef6;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-strong: #ffffff;
  --text: #163a63;
  --muted: #6c8198;
  --line: rgba(22, 58, 99, 0.14);
  --shadow: 0 18px 42px rgba(26, 61, 104, 0.08);
  --user: #1f5e9c;
  --assistant: #f3f7fb;
  --stripe: #79a9d4;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: 13px;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(121, 169, 212, 0.08), transparent 180px),
    linear-gradient(180deg, var(--bg), var(--bg-accent));
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px 14px 14px;
  display: grid;
  grid-template-columns: minmax(220px, 20%) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(121, 169, 212, 0.16), rgba(255, 255, 255, 0.88)),
    rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

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

.page-title {
  margin: 4px 0 0;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid rgba(31, 94, 156, 0.12);
  border-radius: 999px;
  color: var(--user);
  background: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  transition:
    transform 160ms ease,
    background-color 160ms ease,
    border-color 160ms ease;
}

.nav-link:hover {
  transform: translateY(-1px);
  border-color: rgba(31, 94, 156, 0.22);
  background: rgba(255, 255, 255, 0.94);
}

.nav-link.active {
  border-color: rgba(31, 94, 156, 0.28);
  background: rgba(31, 94, 156, 0.12);
}

.eyebrow,
.panel-label,
.message-role,
.composer-label,
.status {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.history-panel {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

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

.session-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  flex: 1;
  overflow-y: auto;
}

.main-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
}

.prompt-shell {
  height: 100vh;
  overflow: hidden;
  grid-template-columns: minmax(0, 1fr);
}

.editor-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
}

.editor-card {
  height: 100%;
  width: 100%;
  min-height: 0;
  padding: 20px 22px 22px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 18px;
  overflow: hidden;
}

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

.editor-title {
  margin: 4px 0 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.editor-status {
  flex: 0 0 auto;
  margin-top: 2px;
}

.editor-status.is-error {
  color: #a54f36;
}

.editor-status.is-success {
  color: #2f7754;
}

.prompt-form {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.prompt-textarea {
  min-height: 0;
  height: 100%;
  max-height: 100%;
  resize: vertical;
  line-height: 1.55;
  font-family: "SFMono-Regular", "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
}

.editor-actions {
  display: flex;
  justify-content: flex-end;
}

.session-item {
  width: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(31, 94, 156, 0.05);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.session-item.active {
  border-color: rgba(31, 94, 156, 0.18);
  background: rgba(31, 94, 156, 0.1);
}

.session-item-body {
  min-width: 0;
}

.session-item-title,
.session-item-id {
  display: block;
}

.session-item-title {
  font-size: 0.85rem;
}

.session-item-id {
  margin-top: 2px;
  font-size: 0.7rem;
  color: var(--muted);
  display: none;
}

.session-item.active .session-item-id {
  display: block;
}

.session-item-delete {
  flex: 0 0 auto;
  width: 18px;
  line-height: 1;
  text-align: center;
  color: var(--muted);
  opacity: 0.6;
}

.session-item:hover .session-item-delete {
  opacity: 1;
}

.session-id,
.message-text {
  margin: 0;
  line-height: 1.6;
}

.message-text {
  white-space: pre-wrap;
}

.message-text ul {
  margin: 0;
  padding-left: 18px;
}

.message-text li + li {
  margin-top: 4px;
}

.product-carousel {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
}

.product-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid rgba(22, 58, 99, 0.16);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 18px rgba(22, 58, 99, 0.06);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
}

.product-image-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 120px;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid rgba(22, 58, 99, 0.08);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}

.product-image {
  display: block;
  width: 84px;
  height: 84px;
  min-width: 84px;
  min-height: 84px;
  max-width: 84px;
  max-height: 84px;
  object-fit: cover;
  object-position: center;
}

.product-brand,
.product-name,
.product-price {
  margin: 0;
}

.product-brand {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.product-name {
  margin-top: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
  min-height: 2.8em;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.product-price {
  margin-top: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--user);
}

.message-meta {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.message-stats,
.message-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.meta-item {
  font-size: 0.7rem;
  color: var(--muted);
}

.meta-button {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--user);
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
}

.meta-button:hover {
  background: rgba(31, 94, 156, 0.08);
}

.meta-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.secondary-button,
.primary-button {
  height: fit-content;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition:
    transform 160ms ease,
    opacity 160ms ease,
    background-color 160ms ease;
}

.secondary-button {
  padding: 9px 12px;
  color: var(--user);
  background: rgba(31, 94, 156, 0.08);
}

.primary-button {
  align-self: flex-end;
  padding: 10px 16px;
  color: #fff;
  background: #1f5e9c;
}

.secondary-button:hover,
.primary-button:hover {
  transform: translateY(-1px);
}

.secondary-button:disabled,
.primary-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.chat-layout {
  backdrop-filter: blur(18px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.messages {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.message {
  max-width: min(680px, 100%);
  padding: 13px 15px;
  border-radius: 15px;
  border: 1px solid var(--line);
  animation: reveal 220ms ease;
}

.message.user {
  align-self: flex-end;
  background: var(--user);
  color: #fff;
}

.message.user .message-role {
  color: rgba(255, 255, 255, 0.72);
}

.message.assistant {
  align-self: flex-start;
  width: 100%;
  max-width: 100%;
  background: var(--assistant);
}

.composer {
  position: sticky;
  bottom: 0;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.composer-row {
  margin-top: 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: end;
}

textarea {
  width: 100%;
  min-height: 52px;
  max-height: 170px;
  resize: none;
  padding: 13px 15px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 15px;
  outline: none;
}

textarea:focus {
  border-color: rgba(31, 94, 156, 0.36);
}

.text-input {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}

.text-input:focus {
  border-color: rgba(31, 94, 156, 0.36);
}

.compact-input {
  width: min(260px, 100%);
}

.analysis-shell {
  max-width: 1280px;
  grid-template-columns: minmax(260px, 28%) minmax(0, 1fr);
}

.analysis-sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.analysis-panel,
.analysis-main {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.analysis-panel {
  padding: 12px;
}

.analysis-main {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.analysis-form {
  margin-top: 12px;
  display: grid;
  gap: 9px;
}

.analysis-results {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
}

.analysis-session-result {
  width: 100%;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(31, 94, 156, 0.05);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.analysis-session-result:hover {
  border-color: rgba(31, 94, 156, 0.18);
  background: rgba(31, 94, 156, 0.09);
}

.session-result-message,
.session-result-meta {
  display: block;
}

.session-result-message {
  line-height: 1.35;
}

.session-result-meta {
  margin-top: 5px;
  font-size: 0.72rem;
  color: var(--muted);
}

.analysis-content {
  height: 100%;
  min-height: 0;
  padding: 16px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 12px;
  overflow: hidden;
}

.analysis-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.analysis-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.analysis-empty {
  padding: 28px;
}

.analysis-empty h2 {
  margin: 0;
  font-size: 1.1rem;
}

.analysis-empty p,
.analysis-empty-inline,
.analysis-muted,
.analysis-text {
  margin: 0;
  line-height: 1.6;
}

.analysis-muted,
.analysis-empty-inline {
  color: var(--muted);
}

.turn-list {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  gap: 10px;
  padding-right: 4px;
}

.turn-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(243, 247, 251, 0.78);
  overflow: hidden;
}

.turn-card.needs-attention {
  border-color: rgba(165, 79, 54, 0.34);
}

.turn-header {
  width: 100%;
  padding: 12px 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  text-align: left;
  cursor: pointer;
}

.turn-title {
  min-width: 0;
  font-weight: 600;
  line-height: 1.4;
}

.turn-meta,
.section-meta {
  flex: 0 0 auto;
  font-size: 0.72rem;
  color: var(--muted);
}

.turn-body {
  padding: 0 12px 12px;
  display: grid;
  gap: 8px;
}

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

.analysis-section {
  border: 1px solid rgba(22, 58, 99, 0.11);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
}

.analysis-section summary {
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 600;
}

.analysis-item {
  padding: 0 12px 12px;
}

.analysis-item h4 {
  margin: 4px 0 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.analysis-error {
  margin: 0 12px 12px;
  color: #a54f36;
  line-height: 1.5;
}

.json-snippet,
.raw-json-viewer {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SFMono-Regular", "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.76rem;
  line-height: 1.55;
  color: #244966;
}

.json-snippet {
  max-height: 260px;
  overflow: auto;
  padding: 10px;
  border-radius: 10px;
  background: rgba(22, 58, 99, 0.05);
}

.raw-json-panel {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.raw-json-panel summary {
  cursor: pointer;
  font-weight: 600;
}

.raw-json-viewer {
  max-height: 240px;
  margin-top: 10px;
  overflow: auto;
  padding: 12px;
  border-radius: 12px;
  background: rgba(22, 58, 99, 0.05);
}

.analysis-products.product-carousel {
  margin-top: 0;
}

.status {
  margin-top: 10px;
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

  .analysis-shell {
    grid-template-columns: 1fr;
  }

  .topbar,
  .editor-header,
  .analysis-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .history-panel {
    min-width: 0;
    max-height: 180px;
  }

  .analysis-results {
    max-height: 220px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 14px 12px 12px;
  }

  .topbar {
    padding: 14px 16px;
  }

  .page-title {
    font-size: 1.18rem;
  }

  .chat-layout {
    width: 100%;
  }

  .messages,
  .composer {
    padding-left: 18px;
    padding-right: 18px;
  }

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

  .product-carousel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .composer-row {
    grid-template-columns: 1fr;
  }

  .primary-button {
    width: 100%;
  }

  .editor-actions {
    justify-content: stretch;
  }

  .turn-header,
  .analysis-section summary {
    flex-direction: column;
  }

  .analysis-actions,
  .compact-input {
    width: 100%;
  }
}
