* { box-sizing: border-box; }
:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --muted: #9aa3b2;
  --accent: #6d5efc;
  --accent2: #8b7dff;
}
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
.error { color: #ff6b6b; margin-top: 0.75rem; font-size: 0.9rem; min-height: 1rem; }
.link { background: none; border: none; color: var(--muted); cursor: pointer; text-decoration: underline; font-size: 0.85rem; }
.link:hover { color: var(--text); }

/* Auth */
.auth { height: 100%; display: grid; place-items: center; }
.auth-card { width: 360px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 2rem; }
.auth-card h1 { margin: 0 0 0.25rem; }
.sub { color: var(--muted); margin: 0 0 1.25rem; font-size: 0.9rem; }
.tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.tab { flex: 1; padding: 0.55rem; background: var(--panel2); border: 1px solid var(--border); color: var(--muted); border-radius: 8px; cursor: pointer; }
.tab.active { color: var(--text); border-color: var(--accent); }
#auth-form { display: flex; flex-direction: column; gap: 0.6rem; }
input, textarea {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 0.65rem 0.8rem; font: inherit;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
button { font: inherit; }
#auth-submit, .new-btn, #send {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 0.65rem 1rem; cursor: pointer; font-weight: 600;
}
#auth-submit:hover, .new-btn:hover, #send:hover { background: var(--accent2); }
#send:disabled { opacity: 0.6; cursor: default; }

/* App layout */
.app { height: 100%; display: grid; grid-template-columns: 240px 1fr; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 1rem; min-height: 0; }
.brand { font-weight: 700; font-size: 1.1rem; margin-bottom: 1rem; }
.new-btn { width: 100%; margin-bottom: 1rem; }
.project-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.35rem; }
.project { display: flex; align-items: center; gap: 0.25rem; padding: 0.55rem 0.6rem; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.project:hover { background: var(--panel2); }
.project.active { background: var(--panel2); color: var(--text); }
.project-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-del { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 0 0.2rem; opacity: 0; }
.project:hover .project-del { opacity: 0.7; }
.project-del:hover { opacity: 1; color: #ff6b6b; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 0.75rem; margin-top: 0.5rem; display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.email { font-size: 0.8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gh-status { font-size: 0.8rem; color: var(--muted); padding: 0.5rem 0 0.25rem; }
.gh-status strong { color: var(--text); }

.main { display: grid; grid-template-columns: 1fr 1fr; height: 100%; min-height: 0; }
.chat { display: flex; flex-direction: column; border-right: 1px solid var(--border); min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.msg { padding: 0.65rem 0.8rem; border-radius: 10px; max-width: 90%; white-space: pre-wrap; font-size: 0.92rem; line-height: 1.4; word-wrap: break-word; }
.msg.user { background: var(--accent); color: #fff; align-self: flex-end; }
.msg.assistant { background: var(--panel2); border: 1px solid var(--border); align-self: flex-start; }
.chat-form { display: flex; gap: 0.5rem; padding: 1rem; border-top: 1px solid var(--border); align-items: stretch; }
.chat-form textarea { flex: 1; resize: none; }
.chat-actions { display: flex; flex-direction: column; gap: 0.4rem; justify-content: flex-end; }
.toggle { font-size: 0.78rem; color: var(--muted); display: flex; align-items: center; gap: 0.35rem; white-space: nowrap; cursor: pointer; }
.toggle input { accent-color: var(--accent); }
.chooser { display: flex; flex-direction: column; gap: 0.4rem; align-items: stretch; }
.chooser-head { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.1rem; }
.model-opt { text-align: left; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.7rem; cursor: pointer; color: var(--text); }
.model-opt:hover { border-color: var(--accent); }
.model-opt.recommended { border-color: var(--accent); }
.model-opt-name { font-weight: 600; font-size: 0.88rem; }
.model-opt-meta { font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; }

.preview { display: flex; flex-direction: column; min-height: 0; }
.preview-bar { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 1rem; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; }
.preview-bar .meta { margin-left: 1rem; margin-right: auto; color: var(--accent2); font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#preview-frame { flex: 1; width: 100%; border: none; background: #fff; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
}
