:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev2: #1c2230;
  --border: #2a3140;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #6e7bff;
  --accent-hover: #5865f2;
  --user-bubble: #22304a;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
#app { height: 100vh; }

button { font-family: inherit; cursor: pointer; }
input, textarea, select {
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  transition: background .15s;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent); background: transparent; }

/* ---------- Auth screen ---------- */
.auth-wrap {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
}
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card p { color: var(--text-dim); margin: 0 0 20px; font-size: 14px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .btn { width: 100%; }
.logo { font-size: 26px; margin-bottom: 10px; }
.error-msg { color: var(--err); font-size: 14px; margin-top: 10px; min-height: 18px; }

/* ---------- Layout ---------- */
.layout { display: flex; height: 100vh; }
.sidebar {
  width: 260px;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-head {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}
.sidebar .newchat { margin: 12px; }
.chats { flex: 1; overflow-y: auto; padding: 0 8px; }
.chat-item {
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
}
.chat-item span { overflow: hidden; text-overflow: ellipsis; }
.chat-item:hover { background: var(--bg-elev2); color: var(--text); }
.chat-item.active { background: var(--bg-elev2); color: var(--text); }
.chat-item .del { opacity: 0; color: var(--text-dim); background: none; border: none; font-size: 16px; }
.chat-item:hover .del { opacity: 1; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 10px; display: flex; gap: 8px; }
.sidebar-foot .btn-ghost { flex: 1; text-align: center; }

/* ---------- Main / chat ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.topbar .repo { color: var(--text-dim); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hamburger { display: none; background: none; border: none; color: var(--text); font-size: 22px; }

.messages { flex: 1; overflow-y: auto; padding: 24px; }
.msg-empty { color: var(--text-dim); text-align: center; margin-top: 15vh; }
.msg-empty .big { font-size: 40px; margin-bottom: 12px; }

.msg { display: flex; gap: 12px; margin-bottom: 22px; max-width: 860px; margin-left: auto; margin-right: auto; }
.msg .avatar {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700;
}
.msg.user .avatar { background: var(--user-bubble); }
.msg.assistant .avatar { background: var(--accent); }
.msg .body { flex: 1; min-width: 0; }
.msg .role { font-weight: 600; font-size: 13px; margin-bottom: 4px; color: var(--text-dim); }
.msg .content { white-space: pre-wrap; word-wrap: break-word; }
.msg .content code { background: var(--bg-elev2); padding: 1px 5px; border-radius: 4px; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 20px; margin-left: 6px; }
.badge.ok { background: rgba(63,185,80,.15); color: var(--ok); }
.badge.err { background: rgba(248,81,73,.15); color: var(--err); }
.badge.run { background: rgba(210,153,34,.15); color: var(--warn); }
.pr-link { display: inline-block; margin-top: 8px; color: var(--accent); text-decoration: none; }
.pr-link:hover { text-decoration: underline; }
.thinking { color: var(--text-dim); font-style: italic; }
.dots::after { content: ''; animation: dots 1.4s steps(4, end) infinite; }
@keyframes dots { 0%{content:'';} 25%{content:'.';} 50%{content:'..';} 75%{content:'...';} }

/* ---------- Composer ---------- */
.composer { border-top: 1px solid var(--border); padding: 14px 20px 18px; }
.composer-inner { max-width: 860px; margin: 0 auto; }
.attach-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.attach-chip {
  background: var(--bg-elev2); border: 1px solid var(--border); border-radius: 20px;
  padding: 4px 10px; font-size: 13px; display: flex; align-items: center; gap: 6px;
}
.attach-chip button { background: none; border: none; color: var(--text-dim); font-size: 15px; }
.input-box {
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.input-box:focus-within { border-color: var(--accent); }
.input-box textarea {
  border: none; background: transparent; resize: none; padding: 6px 8px; max-height: 180px;
}
.composer-controls { display: flex; align-items: center; gap: 8px; }
.composer-controls select { width: auto; min-width: 150px; background: var(--bg-elev); }
.icon-btn {
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text-dim);
  width: 38px; height: 38px; border-radius: 8px; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.spacer { flex: 1; }
.send-btn { width: 38px; height: 38px; border-radius: 8px; border: none; background: var(--accent); color: #fff; font-size: 18px; }
.send-btn:disabled { opacity: .5; }

/* ---------- Modal (settings) ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; padding: 24px;
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal .sub { color: var(--text-dim); font-size: 13px; margin: 0 0 18px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--text-dim); }
.field .hint { font-size: 12px; color: var(--text-dim); margin-top: 5px; }
.checkbox { display: flex; align-items: center; gap: 8px; }
.checkbox input { width: auto; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elev2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 8px; z-index: 100; font-size: 14px;
}
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--err); }

@media (max-width: 720px) {
  .sidebar {
    position: fixed; z-index: 40; height: 100vh; left: -280px; transition: left .2s;
    box-shadow: 0 0 40px rgba(0,0,0,.5);
  }
  .sidebar.open { left: 0; }
  .hamburger { display: block; }
  .composer-controls select { min-width: 120px; }
}
