:root {
  color-scheme: light dark;
  --brand: #0b6e6e;
  --brand-strong: #085656;
  --brand-soft: #e2f1ef;
  --accent: #f5a524;
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-2: #eef0ec;
  --text: #17201f;
  --muted: #5d6967;
  --line: #dde1dc;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --on-brand: #ffffff;
  --shadow: 0 18px 50px rgb(20 40 38 / 12%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #3fb5ad;
    --brand-strong: #63cbc3;
    --brand-soft: #173331;
    --bg: #101514;
    --surface: #181f1e;
    --surface-2: #212a28;
    --text: #e9eeec;
    --muted: #9eaaa7;
    --line: #2d3735;
    --danger: #ff9d94;
    --danger-soft: #3a1d1a;
    --on-brand: #06211f;
    --shadow: 0 18px 50px rgb(0 0 0 / 40%);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
}

h1, h2, p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
a { color: var(--brand-strong); }
small { color: var(--muted); font-size: 12.5px; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Welcome */
.welcome {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.welcome-card {
  width: min(100%, 420px);
  display: grid;
  gap: 16px;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.welcome-logo { border-radius: 14px; }
.welcome-card h1 { font-size: 24px; line-height: 1.2; letter-spacing: -.01em; }
.lede { margin-top: -8px; color: var(--muted); }

.field { display: grid; gap: 5px; }
.field > span { font-size: 13px; font-weight: 600; }

.field input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.field input:focus { border-color: var(--brand); outline: 1px solid var(--brand); }

.model-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 9px 12px;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.model-row > span:first-child { display: grid; min-width: 0; }
.model-row strong { font-weight: 600; }
.link-text { color: var(--brand-strong); font-weight: 600; font-size: 13px; }

.primary {
  height: 44px;
  font-weight: 600;
  color: var(--on-brand);
  background: var(--brand);
  border: 0;
  border-radius: 8px;
}

.primary:hover:not(:disabled) { background: var(--brand-strong); }

.form-error {
  padding: 9px 12px;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: 8px;
  font-size: 13.5px;
}

.tenant-line { text-align: center; color: var(--muted); font-size: 12.5px; }

/* Chat layout */
.chat { height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar img { border-radius: 8px; flex: none; }
.topbar-title { display: grid; min-width: 0; margin-right: auto; line-height: 1.25; }
.topbar-title small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.model-pill, .ghost {
  height: 34px;
  padding: 0 11px;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.ghost { border-color: transparent; color: var(--muted); }
.ghost:hover:not(:disabled), .model-pill:hover:not(:disabled) { background: var(--surface-2); }
.model-pill { display: inline-flex; align-items: center; gap: 7px; }
.dot { width: 8px; height: 8px; background: var(--accent); border-radius: 50%; }

.log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 16px 12px;
  scrollbar-gutter: stable both-edges;
}

.log > * { max-width: 780px; margin-inline: auto; }

.empty { padding-top: min(12vh, 90px); text-align: center; }
.empty h2 { font-size: 26px; line-height: 1.2; letter-spacing: -.01em; }
.empty p { margin-top: 8px; color: var(--muted); }

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 26px;
  text-align: left;
}

.suggestions button {
  padding: 12px 14px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.suggestions button:hover { border-color: var(--brand); background: var(--brand-soft); }

/* Messages */
.message { margin-bottom: 18px; overflow-wrap: anywhere; }

.message.user {
  width: fit-content;
  max-width: min(82%, 640px);
  margin-left: auto;
  margin-right: max(0px, calc((100% - 780px) / 2));
  padding: 9px 14px;
  white-space: pre-wrap;
  color: var(--on-brand);
  background: var(--brand);
  border-radius: 14px 14px 4px 14px;
}

.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer p, .answer ul, .answer ol, .answer pre, .answer blockquote { margin: 0 0 10px; }
.answer h1, .answer h2, .answer h3, .answer h4 { margin: 16px 0 6px; font-size: 16px; line-height: 1.3; }
.answer ul, .answer ol { padding-left: 22px; }
.answer blockquote { padding-left: 12px; color: var(--muted); border-left: 3px solid var(--line); }
.answer code { padding: 1px 4px; font: 13px Consolas, ui-monospace, monospace; background: var(--surface-2); border-radius: 4px; }
.answer pre { padding: 12px; overflow-x: auto; background: var(--surface-2); border-radius: 8px; }
.answer pre code { padding: 0; background: none; }
.table-wrap { max-width: 100%; margin-bottom: 10px; overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.answer table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.answer th, .answer td { padding: 7px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.answer th { background: var(--surface-2); white-space: nowrap; }
.answer tr:last-child td { border-bottom: 0; }

.notice { margin-bottom: 14px; color: var(--muted); font-size: 13px; }
.notice.error { padding: 9px 12px; color: var(--danger); background: var(--danger-soft); border-radius: 8px; }

.thinking { display: flex; gap: 5px; height: 22px; align-items: center; margin-bottom: 14px; }
.thinking i { width: 7px; height: 7px; background: var(--brand); border-radius: 50%; animation: pulse 1.1s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* Tool activity */
.tool { margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.tool summary { display: flex; align-items: center; gap: 8px; width: fit-content; cursor: pointer; list-style: none; }
.tool summary::-webkit-details-marker { display: none; }
.status { width: 9px; height: 9px; flex: none; border-radius: 50%; background: var(--line); }
.tool[data-status="running"] .status { background: var(--accent); animation: pulse 1.1s infinite; }
.tool[data-status="done"] .status { background: var(--brand); }
.tool[data-status="error"] .status, .tool[data-status="declined"] .status { background: var(--danger); }
.tool pre {
  max-height: 220px;
  margin: 6px 0 4px 17px;
  padding: 9px;
  overflow: auto;
  white-space: pre-wrap;
  font: 12px Consolas, ui-monospace, monospace;
  background: var(--surface-2);
  border-radius: 6px;
}

/* Approval */
.approval {
  margin-bottom: 14px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 10px;
}

.approval h3 { margin: 0 0 2px; font-size: 14.5px; }
.approval p { color: var(--muted); font-size: 13px; }
.approval pre {
  max-height: 260px;
  margin: 10px 0;
  padding: 10px;
  overflow: auto;
  white-space: pre-wrap;
  font: 12.5px Consolas, ui-monospace, monospace;
  background: var(--surface-2);
  border-radius: 6px;
}
.approval-actions { display: flex; gap: 8px; }
.approval-actions .primary { height: 36px; padding: 0 16px; }
.approval-actions .ghost { height: 36px; border-color: var(--line); color: var(--text); }

/* Composer */
.composer { padding: 6px 16px 10px; }
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 780px;
  margin: 0 auto;
  padding: 8px 8px 8px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.composer-box:focus-within { border-color: var(--brand); }
.composer textarea {
  flex: 1;
  max-height: 180px;
  padding: 6px 0;
  resize: none;
  background: transparent;
  border: 0;
  outline: 0;
}
.send {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  color: var(--on-brand);
  background: var(--brand);
  border: 0;
  border-radius: 10px;
}
.send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.send.stop svg { fill: currentColor; stroke: none; }
.hint { margin-top: 5px; text-align: center; color: var(--muted); font-size: 11.5px; }

/* Model dialog */
.model-dialog {
  width: min(calc(100% - 32px), 480px);
  padding: 20px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.model-dialog::backdrop { background: rgb(10 20 18 / 45%); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { font-size: 18px; }
.icon-button { width: 32px; height: 32px; font-size: 21px; line-height: 1; background: none; border: 0; border-radius: 8px; }
.icon-button:hover { background: var(--surface-2); }
.dialog-note { margin: 2px 0 14px; color: var(--muted); font-size: 13px; }
.model-list { display: grid; gap: 8px; }
.model-option {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px 12px;
  width: 100%;
  padding: 11px 13px;
  text-align: left;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.model-option:hover { background: var(--surface-2); }
.model-option[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--brand); }
.model-option strong { font-weight: 600; }
.model-option .price { color: var(--muted); font-size: 12.5px; text-align: right; }
.badge { margin-left: 6px; padding: 1px 6px; color: var(--brand-strong); background: var(--brand-soft); border-radius: 5px; font-size: 11px; font-weight: 600; }
.model-option[aria-pressed="true"] .badge { background: var(--surface); }

@media (max-width: 560px) {
  .welcome-card { padding: 24px 20px; }
  .topbar { flex-wrap: wrap; padding: 8px 12px; gap: 6px; }
  .topbar-title { flex: 1 1 calc(100% - 44px); margin: 0; }
  .model-pill { margin-right: auto; }
  .suggestions { grid-template-columns: 1fr; }
  .empty { padding-top: 20px; }
  .log { padding-inline: 12px; }
  .composer { padding-inline: 12px; }
  .message.user { max-width: 90%; }
}

@media (prefers-reduced-motion: reduce) {
  .thinking i, .tool[data-status="running"] .status { animation: none; }
}
