:root {
  color-scheme: light;
  --bg: #eef1f4;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --line: #d9dee5;
  --accent: #006d77;
  --accent-dark: #00535b;
  --soft: #f7f9fb;
  --selected: #e7f2f3;
  --code: #101828;
  --warn: #8a4b00;
  --ui-zoom: 0.8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
textarea,
select {
  font: inherit;
}

.appShell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  width: calc(100vw / var(--ui-zoom));
  height: calc(100vh / var(--ui-zoom));
  overflow: hidden;
  transform: scale(var(--ui-zoom));
  transform-origin: top left;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 14px;
  min-height: 0;
  height: calc(100vh / var(--ui-zoom));
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  padding: 16px;
}

.brand,
.sidebarHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.sidebarHeader {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
}

.mainPane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  height: calc(100vh / var(--ui-zoom));
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

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

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

.controls,
.composerActions {
  display: flex;
  align-items: center;
  gap: 10px;
}

select,
button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
}

.primaryAction {
  width: 100%;
}

.brand button,
.sidebarHeader button {
  min-height: 32px;
  border-color: var(--line);
  background: #fff;
  color: var(--muted);
  padding: 0 10px;
}

.threads {
  display: grid;
  align-content: start;
  gap: 6px;
  overflow: auto;
  min-height: 0;
}

.threadButton {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 58px;
  max-height: 68px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  padding: 10px;
  text-align: left;
  overflow: hidden;
}

.threadButton:hover {
  background: var(--soft);
}

.threadButton.active {
  background: var(--selected);
}

.threadTitle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 650;
}

.threadMeta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 26px;
}

.message {
  max-width: 920px;
  margin: 0 auto 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--panel);
  padding: 13px 15px;
  white-space: pre-wrap;
  line-height: 1.5;
}

.message.user {
  background: #eaf5f6;
  border-color: #c9e4e7;
}

.message.system {
  color: var(--muted);
  font-size: 14px;
}

.message.error {
  border-color: #efb7a8;
  color: #8f2412;
}

.message.log {
  display: none;
  color: var(--warn);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.composer {
  display: grid;
  gap: 10px;
  padding: 12px 22px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 74px;
  max-height: 160px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--text);
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachments.isEmpty {
  display: none;
}

.attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  padding: 6px 8px;
  color: var(--muted);
  font-size: 13px;
}

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

.attachment button,
.attachButton {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  padding: 0 10px;
  cursor: pointer;
}

.attachButton {
  display: inline-flex;
  align-items: center;
}

.attachButton input {
  display: none;
}

input {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
}

textarea:focus,
select:focus,
button:focus {
  outline: 3px solid rgba(0, 109, 119, 0.2);
  outline-offset: 1px;
}

#cwd {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

@media (max-width: 700px) {
  .appShell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .threads {
    max-height: 220px;
  }

  .topbar,
  .composerActions {
    align-items: stretch;
    flex-direction: column;
  }

  .controls {
    width: 100%;
  }

  select,
  button {
    width: 100%;
  }
}

.loginBody {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: var(--bg);
}

.loginShell {
  width: min(420px, calc(100vw - 32px));
}

.loginPanel {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 24px;
  box-shadow: 0 16px 40px rgba(16, 24, 40, 0.08);
}

.loginPanel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

#loginError {
  min-height: 18px;
  color: #8f2412;
  font-size: 13px;
}
