/* ChatGPT-style UI */
:root {
  --bg: #212121;
  --sidebar: #171717;
  --surface: #303030;
  --surface-hover: #3a3a3a;
  --border: #ffffff14;
  --text: #ececec;
  --text-muted: #b4b4b4;
  --accent: #ffffff;
  --accent-btn: #ffffff;
  --accent-btn-text: #000;
  --user-bg: #303030;
  --assistant-bg: transparent;
  --radius: 24px;
  --font: Söhne, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: #7ab7ff; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Login ── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100dvh; background: var(--bg); }
.login-card { width: min(400px, 92vw); padding: 2rem; background: var(--sidebar); border: 1px solid var(--border); border-radius: 16px; }
.login-logo { width: 48px; height: 48px; border-radius: 50%; background: var(--surface); display: flex; align-items: center; justify-content: center; font-size: 1.4rem; margin-bottom: 1rem; }
.login-card h1 { font-size: 1.5rem; margin-bottom: .25rem; font-weight: 600; }
.login-sub { color: var(--text-muted); font-size: .9rem; margin-bottom: 1.5rem; }
.login-card label { display: block; font-size: .85rem; color: var(--text-muted); margin-bottom: .35rem; margin-top: .75rem; }
.login-card input { width: 100%; padding: .75rem 1rem; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); color: var(--text); font-size: .95rem; outline: none; }
.login-card input:focus { border-color: #666; }
.btn-primary { width: 100%; margin-top: 1.25rem; padding: .75rem; border: none; border-radius: 12px; background: #fff; color: #000; font-size: 1rem; font-weight: 600; cursor: pointer; }
.btn-primary:hover { opacity: .9; }
.login-hint { margin-top: 1.25rem; font-size: .8rem; color: var(--text-muted); text-align: center; line-height: 1.6; }
.alert { padding: .75rem 1rem; border-radius: 12px; font-size: .875rem; margin-bottom: .5rem; }
.alert.error { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.35); color: #fca5a5; }

/* ── Layout ── */
.app { display: flex; height: 100dvh; }
.sidebar { width: 260px; background: var(--sidebar); display: flex; flex-direction: column; flex-shrink: 0; transition: transform .25s cubic-bezier(.4,0,.2,1); }
.sidebar-top { padding: .6rem; }
.btn-new { width: 100%; display: flex; align-items: center; gap: .6rem; padding: .6rem .75rem; border: 1px solid var(--border); border-radius: 12px; background: transparent; color: var(--text); font-size: .875rem; cursor: pointer; transition: background .15s; }
.btn-new:hover { background: var(--surface); }
.chat-list { flex: 1; overflow-y: auto; padding: 0 .5rem; }
.chat-item { display: block; width: 100%; text-align: left; padding: .55rem .75rem; margin-bottom: 2px; border: none; border-radius: 10px; background: transparent; color: var(--text-muted); font-size: .875rem; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background .15s, color .15s; }
.chat-item:hover { background: var(--surface); color: var(--text); }
.chat-item.active { background: var(--surface); color: var(--text); }
.sidebar-bottom { padding: .75rem; border-top: 1px solid var(--border); }
.user-email { font-size: .75rem; color: var(--text-muted); padding: 0 .5rem .5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-logout { display: block; text-align: center; padding: .5rem; font-size: .85rem; color: var(--text-muted); border-radius: 10px; transition: background .15s; }
.btn-logout:hover { background: var(--surface); text-decoration: none; color: var(--text); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.topbar { display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem; min-height: 52px; }
.btn-menu { display: none; background: none; border: none; color: var(--text); cursor: pointer; padding: .35rem; border-radius: 8px; }
.btn-menu:hover { background: var(--surface); }
.model-select { padding: .45rem .75rem; border: none; border-radius: 10px; background: transparent; color: var(--text); font-size: .9375rem; font-weight: 500; outline: none; cursor: pointer; }
.model-select:hover { background: var(--surface); }

.messages { flex: 1; overflow-y: auto; scroll-behavior: smooth; }

.welcome { display: flex; align-items: center; justify-content: center; height: 100%; min-height: 200px; animation: fadeIn .4s ease; }
.welcome h2 { font-size: 1.75rem; font-weight: 500; color: var(--text); letter-spacing: -.02em; }

/* ── Messages ── */
.msg-row { animation: msgEnter .35s cubic-bezier(.4,0,.2,1) both; }
.msg-row.user { background: transparent; }
.msg-row.assistant { background: transparent; }

@keyframes msgEnter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.msg-inner {
  max-width: 768px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  display: flex;
  gap: 1rem;
  line-height: 1.7;
  font-size: 1rem;
}

.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface);
  color: var(--text);
}
.msg-avatar svg { width: 18px; height: 18px; }
.msg-row.user .msg-avatar { background: #5436da; color: #fff; }
.msg-row.assistant .msg-avatar { background: #10a37f; color: #fff; }

.msg-body { flex: 1; min-width: 0; word-break: break-word; }
.msg-text { animation: textReveal .2s ease; }
@keyframes textReveal { from { opacity: .6; } to { opacity: 1; } }

.msg-attachment { margin: .5rem 0; border-radius: 12px; overflow: hidden; max-width: 320px; border: 1px solid var(--border); }
.msg-attachment img, .msg-attachment video { display: block; width: 100%; max-height: 280px; object-fit: cover; background: #000; }

.msg-body pre.code-block {
  background: #0d0d0d;
  padding: 1rem;
  border-radius: 12px;
  overflow-x: auto;
  margin: .75rem 0;
  font-size: .875rem;
  line-height: 1.5;
  border: 1px solid var(--border);
}
.msg-body code.inline-code {
  background: #0d0d0d;
  padding: .15rem .4rem;
  border-radius: 6px;
  font-size: .875em;
  border: 1px solid var(--border);
}
.msg-error { color: #fca5a5; font-size: .9375rem; padding: .5rem 0; }

/* Typing indicator (GPT-style 3 dots) */
.typing-indicator {
  display: flex; gap: 5px; align-items: center; padding: .25rem 0; height: 24px;
}
.typing-indicator span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -.16s; }
@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(.6); opacity: .4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Streaming cursor */
.stream-cursor {
  display: inline-block;
  width: 2px; height: 1.1em;
  background: var(--text);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursorPulse .9s step-end infinite;
}
@keyframes cursorPulse { 50% { opacity: 0; } }

.msg-row.msg-done .msg-text { animation: none; }

/* ── Composer (GPT-style pill) ── */
.composer-wrap {
  padding: .5rem 1rem 1.25rem;
  background: linear-gradient(180deg, transparent, var(--bg) 30%);
}

.attachment-preview {
  max-width: 768px;
  margin: 0 auto .5rem;
  display: none;
  flex-wrap: wrap;
  gap: .5rem;
}
.attachment-preview.visible { display: flex; }

.att-chip {
  position: relative;
  width: 72px; height: 72px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
}
.att-chip img, .att-chip video { width: 100%; height: 100%; object-fit: cover; }
.att-chip span {
  position: absolute; bottom: 0; left: 0; right: 0;
  font-size: .6rem; padding: 2px 4px;
  background: rgba(0,0,0,.7); color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.att-chip button {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px;
  border: none; border-radius: 50%;
  background: rgba(0,0,0,.65); color: #fff;
  cursor: pointer; font-size: 14px; line-height: 1;
}

.composer {
  max-width: 768px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: .25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: .45rem .45rem .45rem .35rem;
  box-shadow: 0 0 0 1px rgba(255,255,255,.03);
  transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within {
  border-color: #ffffff26;
  box-shadow: 0 0 0 1px rgba(255,255,255,.06);
}

.btn-attach {
  width: 36px; height: 36px;
  border: none; border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s, color .15s, transform .15s;
}
.btn-attach:hover { background: var(--surface-hover); color: var(--text); transform: scale(1.05); }

.composer textarea {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 200px;
  line-height: 1.5;
  padding: .5rem .25rem;
  min-height: 24px;
}

.btn-send, .btn-stop {
  width: 36px; height: 36px;
  border: none; border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, opacity .15s, background .15s;
}
.btn-send {
  background: #424242;
  color: #888;
}
.btn-send.ready {
  background: var(--accent-btn);
  color: var(--accent-btn-text);
}
.btn-send.ready:hover { transform: scale(1.06); }
.btn-send:disabled { cursor: not-allowed; opacity: .5; }
.btn-stop {
  background: #fff;
  color: #000;
  font-size: .75rem;
}
.btn-stop:hover { transform: scale(1.06); }
.hidden { display: none !important; }

.footer-note {
  text-align: center;
  font-size: .75rem;
  color: #666;
  margin-top: .625rem;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 100;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: translateX(0); }
  .btn-menu { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
