: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;
  overflow-x: hidden;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

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: 220px minmax(0, 1fr);
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  transition: grid-template-columns 0.18s ease;
}

.chat-app.sidebar-collapsed {
  grid-template-columns: 56px minmax(0, 1fr);
}

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

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

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

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

.copy-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin-top: 6px;
  border-radius: 999px;
  background: #e7f6ed;
  color: var(--accent-dark);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.header-copy {
  margin-top: 8px;
}

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

.sidebar-toggle {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}

.sidebar-collapsed .sidebar {
  gap: 12px;
  overflow-y: hidden;
  padding: 12px 8px;
}

.sidebar-collapsed .sidebar-head {
  justify-content: center;
}

.sidebar-collapsed .brand,
.sidebar-collapsed .new-chat-button,
.sidebar-collapsed .sidebar-section {
  display: none;
}

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

.small-button {
  min-height: 32px;
  padding: 6px 9px;
  font-size: 12px;
}

.copy-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.primary.shortener-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
}

.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 {
  padding-top: 8px;
}

.settings-lock,
.llm-settings-fields {
  display: grid;
  gap: 8px;
}

.settings-lock[hidden],
.llm-settings-fields[hidden] {
  display: none;
}

.history-item {
  position: relative;
  display: block;
  width: 100%;
  max-height: 86px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: transparent;
  color: #fff;
  overflow: hidden;
  padding: 0;
  text-align: left;
}

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

.history-main {
  display: block;
  min-width: 0;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 10px 44px 10px 10px;
  text-align: left;
}

.history-delete {
  position: absolute;
  top: 9px;
  right: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-size: 20px;
  font-weight: 850;
  line-height: 28px;
  padding: 0;
}

.history-delete:hover {
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.history-item strong {
  display: -webkit-box;
  overflow: hidden;
  line-height: 1.2;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.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,
.sidebar-field textarea,
.sidebar-inline input {
  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 textarea {
  min-height: 150px;
  resize: vertical;
}

.sidebar-inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

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

.danger-ghost {
  border-color: rgba(255, 255, 255, 0.16);
  color: rgba(255, 255, 255, 0.82);
}

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

.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 {
  display: -webkit-box;
  max-width: 980px;
  overflow: hidden;
  font-size: 24px;
  line-height: 1.15;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.thread {
  display: grid;
  gap: 16px;
  align-content: start;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 18px 22px 28px;
}

.workspace-card {
  width: min(1080px, 100%);
  min-width: 0;
}

.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;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.78);
  padding: 16px;
  box-shadow: 0 10px 30px rgba(31, 36, 31, 0.04);
}

.input-card {
  gap: 16px;
}

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

.hint.is-warning {
  background: #fff5df;
  color: #6e4a00;
}

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

.input-grid {
  gap: 14px;
}

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

.link-grid {
  grid-template-columns: minmax(240px, 1.2fr) minmax(140px, 0.5fr) minmax(260px, 1fr);
  align-items: start;
}

.link-grid.has-date-field {
  grid-template-columns: minmax(220px, 1.15fr) minmax(120px, 0.45fr) minmax(170px, 0.55fr) minmax(240px, 0.9fr);
}

.link-grid .field {
  min-width: 0;
}

.link-grid input[type="text"],
.link-grid select {
  min-height: 48px;
}

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

.main-field {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  padding: 14px;
  box-shadow: 0 8px 28px rgba(31, 36, 31, 0.04);
}

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

.links-field textarea {
  min-height: 230px;
}

.count-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--accent-dark);
  padding: 7px 11px;
  font-size: 13px;
  font-weight: 850;
}

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(min(230px, 100%), 1fr));
}

.date-mode-panel {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdf9;
  padding: 12px;
}

.date-mode-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 12px;
}

.date-mode-head strong {
  color: var(--accent-dark);
  font-weight: 900;
}

.date-mode-head span {
  color: var(--muted);
  font-size: 13px;
}

.date-mode-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.date-mode-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 800;
}

.date-filter-field {
  max-width: 320px;
}

.option-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  align-items: start;
  gap: 12px;
}

.option-group {
  display: grid;
  gap: 8px;
  align-self: start;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdf9;
  padding: 10px;
}

.option-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.option-group-head strong {
  display: block;
  color: var(--text);
  font-size: 13px;
}

.option-group-head span {
  color: var(--muted);
  font-size: 11px;
}

.option-list {
  display: grid;
  gap: 7px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 3px;
}

.option-row {
  display: grid;
  grid-template-columns: minmax(90px, 0.9fr) minmax(120px, 1.1fr) 34px;
  gap: 6px;
  align-items: center;
}

.option-row input[type="text"] {
  min-width: 0;
  min-height: 34px;
  padding: 6px 8px;
  font-size: 13px;
}

.option-row .remove-button {
  width: 34px;
  height: 34px;
}

.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;
  text-decoration-color: rgba(45, 106, 79, 0.35);
  text-underline-offset: 2px;
}

.link-url:hover {
  color: var(--accent-dark);
}

.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-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.result-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

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

.compact-details {
  max-width: 360px;
}

.options-manager {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

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

.date-field {
  max-width: 180px;
}

.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,
  .option-row {
    grid-template-columns: 1fr;
  }

  .option-row .remove-button {
    width: 100%;
  }
}
