:root {
  --bg: #0f1117;
  --bg2: #171a23;
  --bg3: #1e222e;
  --border: #2a2f3d;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #6d8bff;
  --accent2: #8f6dff;
  --green: #34d399;
  --danger: #f87171;
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 15px; }
a { color: var(--accent); }

/* ---------- AUTH ---------- */
.auth-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px 28px;
}
.brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 6px; }
.brand .logo { width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); display: grid; place-items: center; font-size: 20px; }
.brand h1 { font-size: 20px; font-weight: 700; }
.auth-sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.tabs { display: flex; background: var(--bg3); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.tabs button { flex: 1; background: none; border: none; color: var(--muted); padding: 9px; border-radius: 7px; font-weight: 600; }
.tabs button.active { background: var(--accent); color: #fff; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  padding: 11px 13px; border-radius: 9px; outline: none;
}
.field input:focus { border-color: var(--accent); }
.btn-primary {
  width: 100%; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff;
  border: none; padding: 12px; border-radius: 9px; font-weight: 700; font-size: 15px; margin-top: 6px;
}
.btn-primary:disabled { opacity: .6; cursor: default; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; background: #fff; color: #1f2430; text-decoration: none;
  padding: 13px; border-radius: 10px; font-weight: 600; font-size: 15px; margin-top: 8px;
  transition: filter .15s;
}
.google-btn:hover { filter: brightness(0.95); }
.divider { display: flex; align-items: center; gap: 10px; margin: 16px 0 12px; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; text-align: center; }
.hint { color: var(--muted); font-size: 12px; margin-top: 14px; text-align: center; }

/* ---------- APP LAYOUT ---------- */
.app { display: none; height: 100%; }
.app.show { display: flex; }
.sidebar {
  width: 270px; background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sb-head { padding: 16px; border-bottom: 1px solid var(--border); }
.sb-head .brand { justify-content: flex-start; margin: 0 0 12px; }
.sb-head .brand h1 { font-size: 16px; }
.new-chat {
  width: 100%; background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  padding: 10px; border-radius: 9px; font-weight: 600; display: flex; align-items: center; gap: 8px; justify-content: center;
}
.new-chat:hover { border-color: var(--accent); }
.conv-list { flex: 1; overflow-y: auto; padding: 8px; }
.conv {
  padding: 10px 12px; border-radius: 9px; cursor: pointer; display: flex; align-items: center;
  gap: 8px; color: var(--muted); font-size: 14px; margin-bottom: 2px;
}
.conv:hover { background: var(--bg3); color: var(--text); }
.conv.active { background: var(--bg3); color: var(--text); }
.conv .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .del { opacity: 0; background: none; border: none; color: var(--muted); font-size: 16px; padding: 2px 4px; }
.conv:hover .del { opacity: 1; }
.conv .del:hover { color: var(--danger); }
.sb-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; font-size: 13px; }
.sb-foot .who { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-foot button { background: none; border: none; color: var(--muted); font-size: 13px; }
.sb-foot button:hover { color: var(--text); }

/* ---------- MAIN ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { padding: 12px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.hamburger { display: none; background: none; border: none; color: var(--text); font-size: 22px; }
.model-select { position: relative; }
.model-btn {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 9px 14px;
  border-radius: 9px; display: flex; align-items: center; gap: 8px; max-width: 320px;
}
.model-btn:hover { border-color: var(--accent); }
.model-btn .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.badge { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 5px; }
.badge.free { background: rgba(52,211,153,.15); color: var(--green); }
.badge.auto { background: rgba(143,109,255,.18); color: var(--accent2); }
.dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; width: 380px; max-width: 86vw; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.5);
  z-index: 50; display: none; overflow: hidden;
}
.dropdown.show { display: block; }
.dd-search { padding: 10px; border-bottom: 1px solid var(--border); }
.dd-search input { width: 100%; background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 9px 11px; border-radius: 8px; outline: none; }
.dd-filter { display: flex; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.dd-filter button { font-size: 12px; background: var(--bg3); border: 1px solid var(--border); color: var(--muted); padding: 5px 10px; border-radius: 20px; }
.dd-filter button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.dd-list { max-height: 360px; overflow-y: auto; }
.dd-item { padding: 10px 14px; cursor: pointer; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid rgba(42,47,61,.5); }
.dd-item:hover { background: var(--bg3); }
.dd-item .nm { flex: 1; font-size: 14px; }
.dd-item .pr { font-size: 11px; color: var(--muted); }

/* ---------- MESSAGES ---------- */
.messages { flex: 1; overflow-y: auto; padding: 24px 0; }
.welcome { max-width: 680px; margin: 8vh auto; text-align: center; padding: 0 20px; }
.welcome .big { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); display: grid; place-items: center; font-size: 32px; }
.welcome h2 { font-size: 24px; margin-bottom: 8px; }
.welcome p { color: var(--muted); }
.msg { max-width: 760px; margin: 0 auto 22px; padding: 0 20px; display: flex; gap: 14px; }
.msg .av { width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; display: grid; place-items: center; font-size: 15px; font-weight: 700; }
.msg.user .av { background: var(--bg3); }
.msg.assistant .av { background: linear-gradient(135deg, var(--accent), var(--accent2)); }
.msg .body { flex: 1; min-width: 0; overflow-wrap: break-word; }
.msg .who { font-weight: 700; font-size: 13px; margin-bottom: 3px; }
.msg .who .mdl { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
.msg .content { }
.msg .content p { margin: 0 0 10px; }
.msg .content p:last-child { margin-bottom: 0; }
.msg .content pre { background: #0b0d13; border: 1px solid var(--border); border-radius: 10px; padding: 14px; overflow-x: auto; margin: 10px 0; }
.msg .content code { font-family: 'SF Mono', Menlo, Consolas, monospace; font-size: 13px; }
.msg .content :not(pre) > code { background: var(--bg3); padding: 2px 6px; border-radius: 5px; }
.msg .content ul, .msg .content ol { margin: 0 0 10px 22px; }
.msg .content h1,.msg .content h2,.msg .content h3 { margin: 14px 0 8px; }
.msg .content table { border-collapse: collapse; margin: 10px 0; }
.msg .content th, .msg .content td { border: 1px solid var(--border); padding: 6px 10px; }
.cursor::after { content: '▋'; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- COMPOSER ---------- */
.composer { padding: 14px 20px 20px; border-top: 1px solid var(--border); }
.composer-inner { max-width: 760px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end;
  background: var(--bg3); border: 1px solid var(--border); border-radius: 14px; padding: 8px 8px 8px 16px; }
.composer-inner:focus-within { border-color: var(--accent); }
.composer textarea { flex: 1; background: none; border: none; color: var(--text); resize: none; outline: none; max-height: 200px; padding: 6px 0; }
.send-btn { width: 38px; height: 38px; border-radius: 10px; border: none; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; font-size: 18px; display: grid; place-items: center; }
.send-btn:disabled { opacity: .4; cursor: default; }
.composer .foot { max-width: 760px; margin: 8px auto 0; text-align: center; color: var(--muted); font-size: 11px; }

/* ---------- MODAL (admin) ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-bg.show { display: flex; }
.modal { background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-width: 460px; padding: 24px; max-height: 86vh; overflow-y: auto; }
.modal h3 { margin-bottom: 16px; }
.modal .code-box { display: flex; gap: 8px; margin-bottom: 8px; }
.modal .code-box input { flex: 1; background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 10px; border-radius: 8px; letter-spacing: 1px; font-weight: 700; }
.modal .code-box button { background: var(--accent); border: none; color: #fff; padding: 0 16px; border-radius: 8px; font-weight: 600; }
.user-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.modal .close { background: var(--bg3); border: 1px solid var(--border); color: var(--text); width: 100%; padding: 10px; border-radius: 9px; margin-top: 16px; }

@media (max-width: 760px) {
  .sidebar { position: fixed; z-index: 60; height: 100%; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: block; }
  .dropdown { width: 92vw; }
}
