:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", sans-serif;
  --bg: #070a12;
  --panel: #0e1422;
  --panel-2: #151d2e;
  --line: rgba(255, 255, 255, 0.09);
  --muted: #8e9bb1;
  --text: #f4f7fb;
  --accent: #5aa8ff;
  --accent-2: #8d72ff;
  --danger: #ff6b78;
  --success: #3ddc97;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 10% -10%, rgba(90, 168, 255, 0.20), transparent 36rem),
    radial-gradient(circle at 100% 15%, rgba(141, 114, 255, 0.15), transparent 32rem),
    var(--bg);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
}

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar h1, .pair-card h2, .chat-header h2 {
  margin: 3px 0 0;
  letter-spacing: -0.03em;
}

.topbar h1 { font-size: clamp(22px, 4vw, 30px); }

.eyebrow, .project-label {
  margin: 0;
  color: #8ebeff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
}

.badge-offline { color: var(--muted); }
.badge-warn { color: #ffc66b; }
.badge-online { color: var(--success); border-color: rgba(61, 220, 151, 0.3); }

.pair-wrap {
  min-height: calc(100vh - 110px);
  display: grid;
  place-items: center;
}

.card, .workspace {
  background: rgba(14, 20, 34, 0.88);
  border: 1px solid var(--line);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(22px);
}

.pair-card {
  width: min(460px, 100%);
  padding: 34px;
  border-radius: 28px;
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  margin-bottom: 24px;
  border-radius: 17px;
  font-size: 24px;
  font-weight: 800;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
}

.muted { color: var(--muted); line-height: 1.65; }
.stack { display: grid; gap: 10px; margin-top: 24px; }
label { color: #cbd5e5; font-size: 13px; font-weight: 650; }

input, textarea {
  width: 100%;
  color: var(--text);
  background: #090e19;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
}

input { min-height: 48px; padding: 0 14px; }
textarea { resize: none; padding: 13px 14px; line-height: 1.45; }
input:focus, textarea:focus { border-color: rgba(90, 168, 255, 0.65); }

.primary, .send-button {
  border: 0;
  color: #fff;
  background: linear-gradient(135deg, #318df5, #7257f5);
  box-shadow: 0 10px 30px rgba(49, 141, 245, 0.22);
}

.primary { min-height: 46px; border-radius: 13px; font-weight: 750; }
.wide { width: 100%; }

.quiet, .icon-button, .tool-button, .cancel-button, .load-more {
  color: #c9d3e3;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 11px;
}

.quiet { padding: 8px 11px; }
.notice { margin-top: 22px; padding: 16px; border: 1px solid rgba(90, 168, 255, 0.25); border-radius: 16px; background: rgba(90, 168, 255, 0.07); }
.notice p { margin: 8px 0 14px; color: var(--muted); line-height: 1.5; }
.install-tip { margin-top: 20px; color: var(--muted); font-size: 13px; }
.install-tip p { line-height: 1.55; }
.error { min-height: 1.2em; color: #ff8a95; font-size: 13px; }

.workspace {
  height: calc(100vh - 102px);
  min-height: 610px;
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  overflow: hidden;
  border-radius: 25px;
}

.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: rgba(7, 10, 18, 0.48);
}

.project-card {
  display: grid;
  gap: 5px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--panel);
}

.project-card strong { font-size: 17px; }
.project-card > span:last-child { color: var(--muted); font-size: 12px; }

.conversation-list {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow-y: auto;
}

.conversation-item {
  min-width: 0;
  display: grid;
  gap: 5px;
  padding: 12px;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 13px;
}

.conversation-item:hover { background: rgba(255, 255, 255, 0.04); }
.conversation-item.active { background: rgba(90, 168, 255, 0.12); border-color: rgba(90, 168, 255, 0.28); }
.conversation-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item span, .conversation-empty { color: var(--muted); font-size: 11px; }

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

.chat-panel { min-width: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; }
.chat-header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.chat-header h2 { max-width: 70vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 20px; }
.icon-button { width: 38px; height: 38px; font-size: 20px; }

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 24px clamp(16px, 5vw, 58px);
  scroll-behavior: smooth;
}

.empty-state { height: 100%; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); }
.empty-state > span { font-size: 44px; color: #7894c3; }
.empty-state strong { margin-top: 12px; color: #dbe5f5; }
.empty-state p { max-width: 440px; line-height: 1.55; }

.message {
  position: relative;
  width: min(760px, 90%);
  margin: 0 0 17px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 17px;
}

.message-user { margin-left: auto; background: linear-gradient(145deg, rgba(45, 125, 220, 0.20), rgba(101, 75, 220, 0.16)); border-bottom-right-radius: 6px; }
.message-assistant { margin-right: auto; background: rgba(255, 255, 255, 0.035); border-bottom-left-radius: 6px; }
.message-meta { margin-bottom: 8px; color: var(--muted); font-size: 11px; }
.message-body { line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-status { margin-top: 9px; color: var(--muted); font-size: 11px; }
.status-processing, .status-queued { color: #ffc66b; }
.status-failed { color: var(--danger); }
.status-completed { color: var(--success); }

.message-files { display: grid; gap: 5px; margin-top: 10px; }
.message-files a { color: #8fc4ff; font-size: 12px; text-decoration: none; }
.cancel-button { margin-top: 9px; padding: 5px 9px; font-size: 11px; }

.load-more {
  justify-self: center;
  margin: 5px 0;
  padding: 7px 12px;
  font-size: 12px;
}

.composer {
  margin: 0 18px 18px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #090e19;
}

.composer.disabled { opacity: 0.5; }
.composer textarea { min-height: 46px; max-height: 180px; padding: 9px 8px; border: 0; background: transparent; }
.composer-actions { display: flex; align-items: center; gap: 8px; }
.tool-button { min-height: 35px; display: inline-flex; align-items: center; gap: 5px; padding: 0 10px; font-size: 12px; }
.tool-button.recording { color: #fff; background: rgba(255, 107, 120, 0.24); border-color: rgba(255, 107, 120, 0.45); }
.compose-hint { flex: 1; color: var(--muted); text-align: right; font-size: 11px; }
.send-button { min-height: 37px; padding: 0 18px; border-radius: 11px; font-weight: 700; }
.composer .error { margin: 7px 4px 0; }

.attachment-tray { display: flex; flex-wrap: wrap; gap: 7px; padding: 3px 3px 8px; }
.attachment-chip { max-width: 100%; display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 9px; background: var(--panel-2); color: #cbd6e8; font-size: 11px; }
.attachment-chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip button { color: var(--muted); background: transparent; border: 0; }

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

@media (max-width: 760px) {
  .app-shell { padding-left: 10px; padding-right: 10px; }
  .topbar { min-height: 58px; padding: 0 4px; }
  .topbar .eyebrow { display: none; }
  .workspace { height: calc(100vh - 78px); min-height: 560px; grid-template-columns: 118px minmax(0, 1fr); border-radius: 18px; }
  .sidebar { gap: 9px; padding: 10px 8px; }
  .project-card { padding: 10px 8px; }
  .project-card strong { font-size: 13px; }
  .project-card > span:last-child, .project-label { font-size: 9px; }
  .sidebar > .primary { min-height: 38px; font-size: 11px; }
  .conversation-item { padding: 9px 7px; }
  .conversation-item strong { font-size: 12px; }
  .conversation-item span { font-size: 9px; }
  .sidebar-footer { display: grid; }
  .sidebar-footer > span { display: none; }
  .chat-header { min-height: 58px; padding: 10px 12px; }
  .chat-header h2 { font-size: 15px; }
  .messages { padding: 14px 10px; }
  .message { width: 94%; padding: 11px 12px; font-size: 14px; }
  .composer { margin: 0 8px max(8px, env(safe-area-inset-bottom)); }
  .tool-button { padding: 0 8px; }
  .tool-button span:last-child { display: none; }
  .send-button { padding: 0 13px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
