:root {
  color-scheme: light;
  --bg: #f5f6f2;
  --sidebar: #202820;
  --sidebar-soft: #2c362d;
  --surface: #ffffff;
  --surface-soft: #eef3eb;
  --bubble: #ffffff;
  --bubble-user: #2d6a4f;
  --text: #1f241f;
  --muted: #667064;
  --line: #d8dfd3;
  --accent: #2d6a4f;
  --accent-dark: #204f3d;
  --accent-soft: #e3f1e9;
  --danger: #9b3428;
  --shadow: 0 16px 42px rgba(30, 38, 30, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

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

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

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin: 0;
}

code {
  border-radius: 5px;
  background: rgba(45, 106, 79, 0.1);
  color: var(--accent-dark);
  padding: 1px 5px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 0.92em;
}

.chat-app {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow: auto;
  background: var(--sidebar);
  color: #fff;
  padding: 12px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #ddf2e6;
  color: var(--accent-dark);
  font-weight: 900;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.1;
}

.brand p,
.sidebar-note {
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
  line-height: 1.4;
}

.new-chat-button,
.primary,
.secondary,
.send-button,
.ghost-button,
.copy-button,
.remove-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 750;
}

.new-chat-button {
  width: 100%;
  background: #fff;
  color: var(--sidebar);
}

.primary {
  background: var(--accent);
  color: #fff;
  padding: 9px 13px;
}

.primary:hover,
.send-button:hover {
  background: var(--accent-dark);
}

.secondary,
.copy-button {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
  padding: 9px 12px;
}

.send-button {
  background: var(--accent);
  color: #fff;
  padding: 9px 14px;
}

.ghost-button {
  width: 100%;
  border-color: rgba(255, 255, 255, 0.18);
  background: transparent;
  color: #fff;
  padding: 8px 11px;
}

.sidebar-title {
  margin-bottom: 8px;
  color: rgba(255, 255, 255, 0.54);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.history-list,
.sidebar-section,
.llm-box {
  display: grid;
  gap: 8px;
}

.llm-box:not([open]) {
  display: block;
}

.history-item {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: transparent;
  color: #fff;
  padding: 10px;
  text-align: left;
}

.history-item.is-active,
.history-item:hover {
  background: var(--sidebar-soft);
}

.history-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item span {
  display: block;
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.52);
  font-size: 12px;
}

.sidebar-field {
  display: grid;
  gap: 5px;
}

.sidebar-field span {
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  font-weight: 750;
}

.sidebar-field input,
.sidebar-field select {
  min-height: 36px;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  outline: none;
  padding: 7px 9px;
}

.sidebar-field option {
  color: var(--text);
}

.chat-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  height: 100vh;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 246, 242, 0.92);
  backdrop-filter: blur(12px);
  padding: 14px 18px;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-header h2 {
  font-size: 24px;
  line-height: 1.15;
}

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

.message {
  display: grid;
  gap: 7px;
  max-width: min(940px, 94%);
}

.message.assistant {
  align-self: flex-start;
}

.message.user {
  align-self: flex-end;
  max-width: min(760px, 86%);
}

.message-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.bubble {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--bubble);
  padding: 14px;
  line-height: 1.48;
  box-shadow: 0 6px 22px rgba(31, 36, 31, 0.05);
}

.message.assistant .bubble {
  border-top-left-radius: 6px;
}

.message.user .bubble {
  border-color: var(--bubble-user);
  border-top-right-radius: 6px;
  background: var(--bubble-user);
  color: #fff;
}

.agent-card {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.welcome-card,
.brief-card,
.generate-card,
.followup-card {
  max-width: 760px;
}

.chat-step {
  width: max-content;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 850;
}

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

.card-title h3 {
  font-size: 18px;
}

.card-title p,
.hint,
.empty,
.microcopy {
  color: var(--muted);
  line-height: 1.45;
}

.hint {
  border-radius: 8px;
  background: var(--accent-soft);
  padding: 10px;
}

.hint strong {
  color: var(--accent-dark);
}

.form-grid,
.profile-fields,
.link-grid {
  display: grid;
  gap: 10px;
}

.profile-fields {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.link-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.field {
  display: grid;
  gap: 6px;
}

.field span,
.select-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.field small {
  color: var(--muted);
  line-height: 1.35;
}

input[type="text"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input[type="text"],
select {
  min-height: 40px;
  padding: 8px 10px;
}

textarea {
  min-height: 120px;
  resize: vertical;
  padding: 10px;
  line-height: 1.45;
}

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

.row-actions,
.card-actions,
.composer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.profile-list,
.links-list,
.outputs-list {
  display: grid;
  gap: 10px;
}

.profile-list {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.profile-card,
.link-card,
.output-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fbfdf9;
  padding: 12px;
}

.profile-card {
  display: grid;
  gap: 10px;
  align-items: start;
}

.source-card-head,
.link-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.profile-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 850;
}

.remove-button {
  width: 34px;
  height: 34px;
  border-color: var(--line);
  background: #fff;
  color: var(--danger);
  font-size: 18px;
  font-weight: 900;
}

.switch-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 750;
}

.link-url {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.link-number {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 850;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  padding: 14px;
  text-align: center;
}

.output-card {
  display: grid;
  gap: 8px;
}

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

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

.output-card textarea {
  min-height: 150px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

.composer {
  display: grid;
  gap: 10px;
  margin: 0 18px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  padding: 12px;
  box-shadow: var(--shadow);
}

.composer textarea {
  min-height: 78px;
  border-radius: 14px;
}

.inline-details {
  display: grid;
  gap: 9px;
}

.inline-details summary {
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 850;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 36px));
  border-radius: 8px;
  background: #172018;
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .chat-main {
    height: auto;
    min-height: 100vh;
  }

  .agent-card {
    min-width: 0;
  }
}

@media (max-width: 760px) {
  .chat-header,
  .card-title {
    align-items: stretch;
    flex-direction: column;
  }

  .thread {
    padding: 14px;
  }

  .composer {
    margin: 0 14px 14px;
  }

  .profile-card,
  .profile-fields,
  .link-grid {
    grid-template-columns: 1fr;
  }
}
