:root {
  color-scheme: light;
  --bg: #f6f7f5;
  --surface: #ffffff;
  --line: #d7dcd4;
  --text: #1d2522;
  --muted: #66736d;
  --accent: #007b73;
  --accent-dark: #005f59;
  --warning: #b46a00;
  --danger: #a83232;
  --bot: #eef6f5;
  --user: #fff4df;
  --shadow: 0 1px 2px rgba(18, 28, 24, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

.auth-body {
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.auth-card p {
  margin: 0 0 16px;
  color: var(--muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-message {
  min-height: 20px;
  margin-top: 12px;
  color: var(--danger);
}

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

button {
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

button.secondary {
  background: #fff;
  color: var(--accent-dark);
}

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

textarea {
  resize: vertical;
  line-height: 1.4;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 123, 115, 0.14);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 16px;
  min-height: 100vh;
  padding: 16px;
  align-items: start;
}

.chat-pane,
.side-pane {
  min-width: 0;
}

.chat-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  height: calc(100vh - 32px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
}

.topbar h1,
.panel h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions,
.button-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-chip {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.topbar-actions select {
  min-width: 132px;
}

.messages {
  overflow: auto;
  min-height: 180px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 760px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  white-space: pre-wrap;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.message a {
  color: var(--accent-dark);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message strong {
  font-weight: 700;
}

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

.message.bot {
  align-self: flex-start;
  background: var(--bot);
}

.message.bot:has(.product-block) {
  width: min(100%, 900px);
}

.product-block {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 18px;
  align-items: start;
}

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

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

.product-block + .product-block,
.message-paragraph + .product-block,
.product-block + .message-paragraph {
  margin-top: 14px;
}

.product-thumb-link {
  display: block;
  justify-self: end;
}

.product-thumb {
  width: 150px;
  height: 150px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  object-fit: contain;
}

.message-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.message-image {
  width: 100%;
  max-width: 220px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  object-fit: contain;
}

.message.meta {
  align-self: center;
  max-width: 100%;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 92px;
  gap: 10px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: #fbfcfb;
}

.composer textarea {
  min-height: 54px;
}

.image-upload {
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 84px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.image-upload input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.image-preview {
  padding: 0 10px 10px;
  color: var(--muted);
  font-size: 13px;
  background: #fbfcfb;
}

.feedback-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.feedback-bar button {
  background: var(--danger);
  border-color: var(--danger);
}

.side-pane {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

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

.metrics div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  min-width: 0;
}

.metrics dt {
  color: var(--muted);
  font-size: 12px;
}

.metrics dd {
  margin: 4px 0 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.rules-editor {
  min-height: 260px;
  font-family:
    "JetBrains Mono",
    ui-monospace,
    SFMono-Regular,
    Menlo,
    monospace;
  font-size: 13px;
}

.rules-editor[readonly] {
  background: #fbfcfb;
  color: var(--muted);
}

.search-results {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}

.feedback-results,
.users-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow: auto;
}

.feedback-actions,
.user-item button {
  margin-top: 8px;
}

.storage-panel p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.35;
}

.feedback-item,
.user-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.feedback-item strong,
.user-item strong {
  display: block;
  margin-bottom: 4px;
}

.feedback-item span,
.user-item span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.search-result {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  line-height: 1.35;
}

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

.search-result span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.warn {
  color: var(--warning);
}

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

  .chat-pane {
    height: auto;
  }

  .messages {
    max-height: 34vh;
  }

  .message.bot:has(.product-block) {
    width: auto;
  }

  .product-block {
    grid-template-columns: 1fr;
  }

  .product-thumb-link {
    justify-self: start;
  }

  .product-thumb {
    width: 116px;
    height: 116px;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 8px;
  }

  .topbar,
  .feedback-bar,
  .composer,
  .panel-header {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .feedback-bar,
  .composer {
    display: flex;
    flex-direction: column;
  }

  .metrics {
    grid-template-columns: 1fr;
  }
}
