:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #f5f7fb;
  color: #18202f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow-x: hidden;
}

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

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

.sidebar {
  min-width: 0;
  border-right: 1px solid #d8dee9;
  background: #ffffff;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.brand {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  min-width: 0;
}

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

#connectionStatus {
  font-size: 13px;
  color: #5d6678;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: #3c4659;
}

.auth-panel {
  display: grid;
  gap: 10px;
}

#userLabel {
  min-height: 20px;
  font-size: 13px;
  color: #3c4659;
  overflow-wrap: anywhere;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #c9d1df;
  border-radius: 6px;
  padding: 10px 12px;
  background: #ffffff;
  color: #18202f;
}

textarea {
  resize: vertical;
  min-height: 84px;
}

button {
  border: 1px solid #1d4f91;
  border-radius: 6px;
  background: #1d4f91;
  color: #ffffff;
  padding: 10px 14px;
  cursor: pointer;
}

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

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.button-row button:last-child {
  border-color: #b8c1d1;
  background: #ffffff;
  color: #263247;
}

.thread-info {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: #5d6678;
}

.thread-info code {
  overflow-wrap: anywhere;
  color: #263247;
}

.chat-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  overflow: hidden;
}

.messages {
  padding: 24px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.message {
  width: min(760px, 100%);
  max-width: 100%;
  min-width: 0;
  border: 1px solid #d8dee9;
  border-radius: 8px;
  padding: 12px 14px;
  background: #ffffff;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.message.user {
  align-self: flex-end;
  background: #e7f0fb;
  border-color: #bfd4ef;
}

.message.system {
  background: #fff8e8;
  border-color: #ead7a8;
  color: #594511;
}

.message .meta {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: #6a7384;
}

.message-body {
  white-space: pre-wrap;
}

.markdown {
  white-space: normal;
}

.markdown > :first-child {
  margin-top: 0;
}

.markdown > :last-child {
  margin-bottom: 0;
}

.markdown p,
.markdown ul,
.markdown ol,
.markdown blockquote,
.markdown pre {
  margin: 0 0 10px;
}

.markdown h3,
.markdown h4,
.markdown h5 {
  margin: 14px 0 8px;
  font-size: 15px;
  line-height: 1.25;
}

.markdown ul,
.markdown ol {
  padding-left: 20px;
}

.markdown li + li {
  margin-top: 4px;
}

.markdown blockquote {
  border-left: 3px solid #c9d1df;
  padding-left: 10px;
  color: #4b5568;
}

.markdown code,
.message-body code {
  border-radius: 4px;
  background: #eef2f7;
  padding: 1px 4px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.markdown pre {
  max-width: 100%;
  overflow: auto;
  border: 1px solid #d8dee9;
  border-radius: 6px;
  background: #111827;
  color: #edf2f7;
  padding: 10px;
  white-space: pre;
  -webkit-overflow-scrolling: touch;
}

.markdown pre code {
  display: block;
  min-width: max-content;
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 12px;
}

.markdown a {
  color: #1d4f91;
  overflow-wrap: anywhere;
}

.tool-event {
  width: min(760px, 100%);
  max-width: 100%;
  min-width: 0;
  border: 1px solid #cbd7e6;
  border-radius: 8px;
  background: #f8fafc;
  padding: 10px 12px;
  color: #263247;
  overflow-wrap: anywhere;
}

.tool-event.failed {
  border-color: #e0a8a8;
  background: #fff5f5;
}

.tool-event-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.tool-event-title {
  font-size: 12px;
  font-weight: 700;
  color: #42526a;
  text-transform: uppercase;
}

.tool-event-status {
  flex: 0 0 auto;
  border: 1px solid #c9d1df;
  border-radius: 999px;
  padding: 2px 7px;
  background: #ffffff;
  color: #5d6678;
  font-size: 11px;
}

.tool-event-name {
  margin-top: 6px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  color: #18202f;
  overflow-wrap: anywhere;
}

.tool-event-body {
  margin: 8px 0 0;
  max-height: 180px;
  overflow: auto;
  border: 1px solid #d8dee9;
  border-radius: 6px;
  background: #ffffff;
  color: #263247;
  padding: 8px;
  white-space: pre;
  font-size: 12px;
  -webkit-overflow-scrolling: touch;
}

.composer {
  border-top: 1px solid #d8dee9;
  background: #ffffff;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.approval-panel {
  display: grid;
  gap: 10px;
  padding: 0 16px 12px;
  background: #ffffff;
  min-width: 0;
}

.approval-panel:empty {
  display: none;
}

.approval-card {
  border: 1px solid #d5b45c;
  border-radius: 8px;
  background: #fff8e4;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.approval-title {
  font-weight: 650;
  color: #43350f;
}

.approval-body {
  margin: 0;
  padding: 10px;
  border-radius: 6px;
  background: #ffffff;
  border: 1px solid #ead7a8;
  color: #263247;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 160px;
  overflow: auto;
}

.approval-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.approval-actions button:nth-child(3),
.approval-actions button:nth-child(4) {
  border-color: #b8c1d1;
  background: #ffffff;
  color: #263247;
}

@media (max-width: 760px) {
  html,
  body {
    min-height: 100%;
    overflow-x: hidden;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100svh;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid #d8dee9;
    padding: 10px 10px 12px;
    gap: 8px;
    max-height: none;
    overflow: visible;
  }

  .brand {
    align-items: center;
  }

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

  label,
  #connectionStatus,
  #userLabel,
  .thread-info {
    font-size: 12px;
  }

  input,
  select,
  textarea,
  button {
    max-width: 100%;
    padding: 8px 9px;
  }

  button {
    min-height: 38px;
  }

  .button-row {
    gap: 8px;
  }

  .chat-panel {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 65svh;
    overflow: visible;
  }

  .messages {
    flex: 1 1 auto;
    min-height: 46svh;
    padding: 10px;
    overflow: visible;
    gap: 10px;
  }

  .message,
  .tool-event {
    width: 100%;
    max-width: calc(100vw - 20px);
    font-size: 14px;
    padding: 10px;
  }

  .markdown pre,
  .tool-event-body,
  .approval-body {
    max-width: 100%;
    overflow-x: auto;
  }

  .markdown h3,
  .markdown h4,
  .markdown h5 {
    font-size: 14px;
  }

  .tool-event-body {
    max-height: 140px;
  }

  .approval-panel {
    position: sticky;
    bottom: 0;
    z-index: 5;
    padding: 8px 10px;
    border-top: 1px solid #ead7a8;
    box-shadow: 0 -8px 18px rgba(24, 32, 47, 0.08);
  }

  .approval-actions {
    grid-template-columns: 1fr 1fr;
  }

  .approval-actions button {
    font-size: 12px;
  }

  .approval-body {
    max-height: 130px;
    font-size: 12px;
  }

  .composer {
    grid-template-columns: 1fr;
    position: sticky;
    bottom: 0;
    z-index: 4;
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .composer textarea {
    min-height: 76px;
    max-height: 28svh;
  }
}
