:root {
  color-scheme: dark;
  --bg: #0f1220;
  --panel: #171d31;
  --line: #2a3154;
  --text: #e8ecff;
  --muted: #9fb2ff;
  --accent: #4a8bff;
  --danger: #ff7f9f;
  --user: #22345f;
  --assistant: #1a243f;
  --system: #3a2040;
}

* {
  box-sizing: border-box;
}

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

body {
  overscroll-behavior: none;
}

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  border-bottom: 1px solid var(--line);
  background: #12182b;
}

.topbar-title {
  flex: 1;
  min-width: 0;
}

.title {
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.icon-btn,
button {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  font-size: 15px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  background: #1a1f36;
  border: 1px solid var(--line);
}

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

button.danger {
  color: var(--danger);
  border-color: #5a3040;
}

button:disabled,
button.is-loading {
  opacity: 0.65;
  pointer-events: none;
}

button.is-loading {
  cursor: wait;
}

.main {
  flex: 1;
  min-height: 0;
  overflow: auto;
  position: relative;
}

.screen-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: min(320px, 50vh);
  padding: 40px 20px;
  color: var(--muted);
  text-align: center;
}

.screen-loader p {
  margin: 0;
  font-size: 14px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

.project-card.is-loading {
  opacity: 0.75;
  pointer-events: none;
  border-color: var(--accent);
}

.project-card.is-loading .meta {
  color: var(--accent);
}

.panel {
  padding: 16px;
}

.auth-panel {
  max-width: 420px;
  margin: 0 auto;
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0;
  font-size: 13px;
  color: var(--muted);
}

input,
textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #11162a;
  color: var(--text);
  padding: 12px;
  font: inherit;
}

textarea {
  resize: vertical;
  min-height: 44px;
  max-height: 160px;
}

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

.muted.small {
  font-size: 13px;
  margin-bottom: 12px;
}

.error {
  color: var(--danger);
  font-size: 14px;
}

.hidden {
  display: none !important;
}

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

.projects-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.project-card {
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.project-card h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.project-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.project-card .meta {
  margin-top: 8px;
  font-size: 12px;
  color: #7d8ec8;
}

.streaming-badge {
  color: #6ee7a8;
  font-weight: 600;
}

.project-card.missing {
  opacity: 0.55;
}

.chat-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  line-height: 1.45;
}

.msg.user {
  align-self: flex-end;
  background: var(--user);
}

.msg.assistant {
  align-self: flex-start;
  background: var(--assistant);
  border: 1px solid var(--line);
}

.msg.system {
  align-self: center;
  background: var(--system);
  color: #ffc7d4;
  font-size: 13px;
}

.composer {
  border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: #12182b;
}

.agent-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.picker-wrap {
  position: relative;
}

.picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #1a1f36;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  line-height: 1.2;
}

.picker-icon {
  color: var(--muted);
  font-size: 14px;
}

.picker-chevron {
  color: var(--muted);
  font-size: 11px;
}

.picker-menu {
  position: absolute;
  left: 0;
  bottom: calc(100% + 6px);
  z-index: 20;
  min-width: 180px;
  max-width: min(280px, 90vw);
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #171d31;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  padding: 6px;
}

.picker-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 14px;
}

.picker-item:hover:not(:disabled) {
  background: #222a46;
}

.picker-item.active {
  background: #243058;
}

.picker-item:disabled {
  opacity: 0.45;
}

.picker-item .item-icon {
  width: 18px;
  color: var(--muted);
  text-align: center;
}

.picker-item .item-label {
  flex: 1;
}

.picker-item .item-check {
  color: var(--accent);
  font-size: 12px;
}

.picker-item .item-hint {
  font-size: 11px;
  color: var(--muted);
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  padding: 8px;
  width: min(320px, 92vw);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

dialog button {
  width: 100%;
  margin: 4px 0;
  background: #1a1f36;
  border: 1px solid var(--line);
}

.typing {
  color: var(--muted);
  font-size: 13px;
  padding: 0 4px;
}
