:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-soft: #f1f4ef;
  --text: #151716;
  --muted: #6e756f;
  --line: #d9ded6;
  --accent: #1f7a5f;
  --accent-dark: #145944;
  --danger: #b3261e;
  --shadow: 0 18px 48px rgba(21, 23, 22, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
textarea,
input {
  font: inherit;
}

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

.sidebar {
  border-right: 1px solid var(--line);
  background: #ecefeb;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--text);
  color: #fff;
  border-radius: 8px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-title {
  font-weight: 760;
}

.brand-subtitle,
.side-label,
.eyebrow,
.meta,
.empty-copy p {
  color: var(--muted);
}

.brand-subtitle,
.side-label,
.eyebrow {
  font-size: 12px;
}

.side-label,
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.new-chat {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  min-height: 42px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  padding: 0 14px;
  font-weight: 650;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
}

.history-item {
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  min-height: 40px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item:hover,
.history-item.active {
  background: rgba(31, 122, 95, 0.11);
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
}

.topbar {
  height: 84px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
}

.health-badge {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  min-height: 34px;
  padding: 7px 12px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.health-badge.ready {
  color: var(--accent-dark);
  border-color: rgba(31, 122, 95, 0.35);
}

.health-badge.warn {
  color: var(--danger);
}

.empty-state,
.messages {
  overflow-y: auto;
  padding: 32px max(28px, calc((100vw - 1040px) / 2));
}

.empty-state {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
}

.empty-copy {
  max-width: 760px;
}

.empty-copy h2 {
  font-size: clamp(32px, 6vw, 64px);
  line-height: 0.98;
  letter-spacing: 0;
}

.empty-copy p {
  margin-top: 18px;
  font-size: 18px;
  line-height: 1.55;
  max-width: 680px;
}

.model-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.model-strip span {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
}

.messages {
  display: none;
  flex-direction: column;
  gap: 22px;
}

.messages.has-content {
  display: flex;
}

.message {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 14px;
  max-width: 920px;
  width: 100%;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 760;
  background: var(--panel-soft);
}

.message.assistant .avatar {
  background: var(--text);
  color: #fff;
}

.bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 8px 24px rgba(21, 23, 22, 0.05);
  line-height: 1.58;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user .bubble {
  background: #f9faf8;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  font-size: 12px;
}

.status-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(31, 122, 95, 0.22);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.composer {
  margin: 0 max(18px, calc((100vw - 1040px) / 2)) 22px;
  padding: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 10px;
}

.composer textarea {
  border: 0;
  outline: 0;
  resize: none;
  min-height: 44px;
  max-height: 220px;
  padding: 11px 8px;
  background: transparent;
  color: var(--text);
  line-height: 1.5;
}

.composer button {
  border: 0;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.composer button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.composer svg {
  width: 21px;
  height: 21px;
  fill: currentColor;
}

.token-dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  width: min(420px, calc(100vw - 32px));
}

.token-dialog::backdrop {
  background: rgba(21, 23, 22, 0.42);
}

.token-dialog form {
  padding: 22px;
  display: grid;
  gap: 14px;
}

.token-dialog input {
  height: 42px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 12px;
}

.token-dialog button {
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  cursor: pointer;
}

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

  .sidebar {
    display: none;
  }

  .topbar {
    height: auto;
    padding: 16px;
  }

  .empty-state,
  .messages {
    padding: 24px 16px;
  }

  .composer {
    margin: 0 10px 12px;
  }
}

/* ----- file attachments ----- */
.composer {
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: end;
}

.composer button.attach {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.composer button.attach:hover {
  color: var(--accent-dark);
  border-color: rgba(31, 122, 95, 0.35);
  background: rgba(31, 122, 95, 0.06);
}

.composer button.attach svg {
  width: 20px;
  height: 20px;
  fill: none;
}

.composer.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31, 122, 95, 0.25), var(--shadow);
}

.attachments {
  margin: 0 max(18px, calc((100vw - 1040px) / 2)) 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  padding: 6px 8px 6px 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(21, 23, 22, 0.05);
}

.attachment-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-size {
  color: var(--muted);
  font-size: 12px;
  flex-shrink: 0;
}

.attachment-remove {
  border: 0;
  background: var(--panel-soft);
  color: var(--muted);
  width: 20px;
  height: 20px;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1;
  font-size: 15px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.attachment-remove:hover {
  background: rgba(179, 38, 30, 0.12);
  color: var(--danger);
}

/* attached-file chips shown inside a sent user message */
.message-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.message-file {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
}

.message-file::before {
  content: "\1F4CE";
  margin-right: 6px;
}

@media (max-width: 820px) {
  .attachments {
    margin: 0 10px 8px;
  }
}

/* ----- history rows with delete ----- */
.history-row {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: 8px;
  padding-right: 4px;
}

.history-row:hover,
.history-row.active {
  background: rgba(31, 122, 95, 0.11);
}

.history-item {
  flex: 1 1 auto;
  min-width: 0;
}

/* row now owns the hover/active background */
.history-item:hover,
.history-item.active {
  background: transparent;
}

.history-delete {
  flex-shrink: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.history-row:hover .history-delete,
.history-row.active .history-delete {
  opacity: 1;
}

.history-delete:hover {
  background: rgba(179, 38, 30, 0.12);
  color: var(--danger);
}

/* on touch devices there is no hover — always show the control */
@media (hover: none) {
  .history-delete {
    opacity: 1;
  }
}

/* ----- attachment loading state ----- */
.attachment.loading {
  opacity: 0.7;
}

.attachment.loading .attachment-size {
  color: var(--accent-dark);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}
