:root {
  color-scheme: light;
  --bg: #f5f6f4;
  --panel: #ffffff;
  --text: #1b2523;
  --muted: #66736f;
  --line: #dce3df;
  --primary: #176b5d;
  --primary-dark: #0f5046;
  --accent: #a95728;
  --soft: #eef5f2;
  --danger: #b42318;
  --shadow: 0 16px 48px rgba(28, 43, 38, .08);
}

* {
  box-sizing: border-box;
}

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;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar,
.panel-head,
.button-row,
.source-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 20px;
}

.topbar h1,
.widget-header h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.1;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.workspace {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 18px;
  align-items: start;
}

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

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

.panel h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.panel p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.stack,
.source-form,
.embed-panel,
.chat-preview {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #26332f;
  font-size: 14px;
  font-weight: 700;
}

small {
  color: var(--muted);
  font-weight: 500;
  line-height: 1.35;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(23, 107, 93, .12);
}

select {
  min-height: 44px;
  appearance: auto;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--primary);
}

.range-value {
  color: var(--muted);
  font-size: 13px;
}

.primary,
.secondary,
.ghost-link,
.delete-button {
  border-radius: 8px;
  border: 1px solid transparent;
  min-height: 42px;
  padding: 10px 14px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.primary {
  background: var(--primary);
  color: #fff;
}

.primary:hover {
  background: var(--primary-dark);
}

.secondary,
.ghost-link {
  background: var(--soft);
  border-color: #cddbd5;
  color: var(--primary-dark);
}

.delete-button {
  min-height: 34px;
  padding: 7px 10px;
  background: #fff5f3;
  color: var(--danger);
  border-color: #ffd8d2;
}

.model-row {
  display: grid;
  grid-template-columns: 1fr 46px;
  gap: 8px;
}

.icon-action {
  min-width: 46px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.hidden {
  display: none;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--primary-dark);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
}

.source-grid {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 18px;
  margin-top: 18px;
}

.source-list-wrap {
  min-width: 0;
}

.source-list {
  display: grid;
  gap: 10px;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.source-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
}

.source-item h3 {
  margin: 0;
  font-size: 15px;
}

.source-item p {
  margin: 8px 0 0;
  font-size: 13px;
}

.empty-state {
  border: 1px dashed #c6d0cc;
  border-radius: 8px;
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.split {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(280px, 420px);
  gap: 18px;
}

.messages {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 320px;
  max-height: 440px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 12px;
}

.message {
  width: fit-content;
  max-width: min(82%, 720px);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.45;
  font-size: 14px;
  white-space: pre-wrap;
}

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

.message.assistant {
  justify-self: start;
  background: #edf2ef;
  color: var(--text);
}

.message.system {
  justify-self: center;
  background: transparent;
  color: var(--muted);
  text-align: center;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.embed-panel textarea {
  min-height: 118px;
  color: #22302c;
  background: #fbfcfb;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 40px));
  transform: translateY(120%);
  border-radius: 8px;
  background: #1b2523;
  color: #fff;
  padding: 12px 14px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, .18);
  transition: transform .2s ease;
}

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

.widget-body {
  min-height: 100vh;
  background: #fff;
}

.widget-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  min-height: 420px;
  background: #fff;
}

.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.widget-header h1 {
  font-size: 20px;
}

.online-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #2e9f6d;
  box-shadow: 0 0 0 5px rgba(46, 159, 109, .15);
}

.widget-messages {
  min-height: 0;
  max-height: none;
  border: 0;
  border-radius: 0;
  padding: 14px;
}

.widget-form {
  border-top: 1px solid var(--line);
  padding: 12px;
}

@media (max-width: 1080px) {
  .workspace,
  .source-grid,
  .split {
    grid-template-columns: 1fr;
  }

  .settings-panel {
    order: -1;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100% - 20px, 1440px);
    padding-top: 14px;
  }

  .topbar,
  .panel-head,
  .button-row {
    align-items: stretch;
    flex-direction: column;
  }

  .chat-form {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 92%;
  }
}
