:root {
  --bg: #0b0f14;
  --bg-soft: #121821;
  --bg-card: #161d27;
  --border: #243040;
  --text: #e6edf5;
  --muted: #8b98a9;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, 0.14);
  --danger: #ff6b6b;
  --ok: #3ddc97;
  --warn: #ffbe5c;
  --radius: 14px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  overscroll-behavior-y: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px;
  background: rgba(11, 15, 20, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.topbar-title span {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 11px;
  min-width: 40px;
  height: 40px;
  font-size: 17px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:active {
  transform: scale(0.96);
}

.icon-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06121f;
  font-weight: 700;
}

.icon-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
}

.msg {
  max-width: 92%;
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--border);
  background: var(--bg-soft);
}

.msg.user {
  align-self: flex-end;
  background: var(--accent-soft);
  border-color: rgba(76, 141, 255, 0.35);
}

.msg.assistant {
  align-self: flex-start;
}

.msg.reasoning {
  align-self: flex-start;
  color: var(--muted);
  font-style: italic;
  background: transparent;
  border-style: dashed;
}

.msg.tool {
  align-self: stretch;
  max-width: 100%;
  background: var(--bg-card);
  font-size: 13px;
}

.msg.tool .tool-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  margin-bottom: 4px;
}

.msg.tool pre {
  margin: 4px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
  font-size: 12px;
  max-height: 220px;
  overflow: auto;
}

.msg.system {
  align-self: center;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12.5px;
  padding: 2px 0;
}

.msg .images {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.msg .images img {
  max-width: 140px;
  max-height: 180px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.todo-card {
  align-self: stretch;
  max-width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13.5px;
}

.todo-card li {
  margin: 2px 0;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn.primary-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #06121f;
}

.btn.danger-btn {
  background: rgba(255, 107, 107, 0.15);
  border-color: rgba(255, 107, 107, 0.4);
  color: var(--danger);
}

.btn.ghost {
  background: transparent;
}

.approval-card,
.question-card {
  align-self: stretch;
  max-width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.question-card {
  border-color: var(--accent);
}

.card-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.option {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--bg-soft);
  font-size: 14px;
}

.option input {
  margin-top: 3px;
}

.option .desc {
  color: var(--muted);
  font-size: 12px;
}

.composer {
  border-top: 1px solid var(--border);
  background: rgba(11, 15, 20, 0.96);
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 10px);
}

.composer-row {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  min-height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
}

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

.attachment {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-soft);
}

.attachment img {
  display: block;
  width: 56px;
  height: 56px;
  object-fit: cover;
}

.attachment button {
  position: absolute;
  top: 2px;
  right: 2px;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}

.banner {
  padding: 8px 12px;
  font-size: 13px;
  background: rgba(255, 190, 92, 0.14);
  border-bottom: 1px solid rgba(255, 190, 92, 0.35);
  color: var(--warn);
}

.banner.error {
  background: rgba(255, 107, 107, 0.14);
  border-color: rgba(255, 107, 107, 0.4);
  color: var(--danger);
}

.drawer {
  position: absolute;
  inset: 0;
  background: rgba(6, 9, 13, 0.72);
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 12px;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.session-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-item {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}

.session-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.session-item .row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}

.session-item .name {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.dot.running {
  background: var(--ok);
  box-shadow: 0 0 8px rgba(61, 220, 151, 0.7);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 9, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 16px;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 420px;
  padding: 16px;
  max-height: 86dvh;
  overflow: auto;
}

.modal-title {
  font-weight: 700;
  margin-bottom: 10px;
}

.modal-body label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 4px;
}

.modal-body input,
.modal-body select,
.modal-body textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  padding: 10px;
  font-size: 15px;
  font-family: inherit;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}

.endpoint-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 6px 0 4px;
}

.endpoint-row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: var(--bg-soft);
}

.endpoint-label {
  font-size: 13px;
  font-weight: 600;
}

.endpoint-url {
  font-size: 12px;
  word-break: break-all;
}

.endpoint-warn {
  font-size: 11px;
  color: var(--warn, #f5a623);
  margin-top: 4px;
}

.endpoint-row .btn {
  flex: 0 0 auto;
}

.endpoint-row .btn:disabled {
  opacity: 0.5;
}

.hidden {
  display: none !important;
}

.cursor::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s steps(2) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}
