:root {
  --bg: #0c0e10;
  --bg-elev: #14171a;
  --sidebar: #0a0c0e;
  --line: #23282d;
  --text: #e8ecef;
  --muted: #8b949e;
  --faint: #5b656e;
  --accent: #7ee0c8;
  --accent-dim: #1a3a34;
  --accent-text: #04221c;
  --user-bg: #1b2127;
  --danger: #f0a0a0;
  --warn: #e6c07b;
  --card: #121518;
  --shadow: 0 16px 48px rgba(0,0,0,.45);
  --radius: 16px;
  --sans: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  overflow: hidden;
}
body { -webkit-font-smoothing: antialiased; }
#app {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}
input, textarea, select { color-scheme: dark; }
input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  caret-color: var(--text);
  transition: background-color 9999s ease-out;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- auth / pricing shells ---------- */
.gate {
  min-height: 100%;
  height: 100%;
  overflow: auto;
  display: grid;
  grid-template-columns: minmax(280px, 42%) 1fr;
}
.gate-brand {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(126,224,200,.16), transparent 50%),
    radial-gradient(ellipse at 80% 90%, rgba(126,224,200,.06), transparent 45%),
    var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 56px 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.mark { display: flex; align-items: center; gap: 12px; }
.mark img { width: 36px; height: 36px; }
.mark .word { font-weight: 700; letter-spacing: .06em; font-size: 17px; }
.gate-brand h1 { font-size: 40px; line-height: 1.15; font-weight: 600; margin: 48px 0 16px; letter-spacing: -0.03em; }
.gate-brand p { color: var(--muted); font-size: 16px; line-height: 1.55; max-width: 360px; }
.gate-form {
  display: flex; align-items: center; justify-content: center;
  padding: 48px 24px;
}
.panel {
  width: 100%; max-width: 400px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 6px; font-size: 22px; font-weight: 600; }
.panel .sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }
input[type=text], input[type=password], #auth-form input, #u, #p {
  display: block;
  width: 100%;
  max-width: 100%;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; margin-bottom: 14px; outline: none;
  color: var(--text);
  font: inherit;
  min-height: 44px;
}
input:focus, textarea:focus { border-color: var(--accent); }
.btn {
  border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--user-bg); filter: none; }
.btn.wide { width: 100%; }
.tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tabs button { flex: 1; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0 0 10px; }
.note { color: var(--muted); font-size: 12px; margin-top: 16px; line-height: 1.45; }

/* ---------- app shell ---------- */
.app {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  min-height: 0;
}
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.side-top { flex: none; padding: 16px 14px 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.side-top .mark .word { font-size: 15px; }
.icon-btn {
  background: transparent; border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 8px 10px; font-size: 13px; font-weight: 500;
}
.icon-btn:hover { background: var(--user-bg); }
.conv-list { flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; padding: 6px 8px 12px; }
.conv {
  display: block; width: 100%; text-align: left;
  background: transparent; border: 0; color: var(--text);
  padding: 10px 10px; border-radius: 10px; margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13.5px;
}
.conv:hover, .conv.active { background: var(--user-bg); }
.conv .when { display: block; color: var(--faint); font-size: 11px; margin-top: 2px; }
.side-bottom { flex: none; border-top: 1px solid var(--line); padding: 12px 14px 14px; background: var(--sidebar); }
.meter-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.meter { height: 6px; background: #1c2228; border-radius: 99px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.meter.warn > span { background: var(--warn); }
.meter.full > span { background: var(--danger); }
.user-row { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; gap: 8px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent-dim);
  color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 700;
  flex: none;
}
.user-meta { min-width: 0; flex: 1; }
.user-meta .name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta .plan { font-size: 11px; color: var(--muted); }
.linkish { background: none; border: 0; color: var(--muted); font-size: 12px; padding: 0; }
.linkish:hover { color: var(--accent); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; overflow: hidden; }
.topbar {
  flex: none;
  height: 56px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; gap: 12px;
}
.topbar h1 { font-size: 15px; font-weight: 600; margin: 0; }
.top-actions { display: flex; align-items: center; gap: 8px; }
select.backend {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 10px; font-size: 13px;
}
.thread { flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; }
.thread-inner { max-width: 820px; margin: 0 auto; padding: 28px 24px 12px; }
.msg { display: flex; gap: 14px; margin: 0 0 26px; align-items: flex-start; }
.bubble { min-width: 0; flex: 1; }
.who { font-size: 12px; font-weight: 600; margin: 0 0 6px; letter-spacing: .02em; }
.who span { font-weight: 400; color: var(--faint); margin-left: 8px; }
.body { font-size: 15.5px; line-height: 1.65; white-space: pre-wrap; word-wrap: break-word; }
.body p { margin: 0 0 10px; }
.body p:last-child { margin-bottom: 0; }
.body code {
  font-family: var(--mono); font-size: 13px;
  background: #1a1f24; border: 1px solid var(--line);
  border-radius: 6px; padding: 1px 5px;
}
.body pre {
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  background: #0a0c0e; border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 16px; overflow: auto;
  margin: 10px 0;
}
.body pre code { background: none; border: 0; padding: 0; }
.msg.user .bubble { background: var(--user-bg); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.composer-wrap { flex: none; padding: 8px 24px 22px; background: var(--bg); }
.composer {
  max-width: 820px; margin: 0 auto;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 18px; padding: 10px 10px 10px 16px;
  display: flex; align-items: flex-end; gap: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.composer textarea {
  flex: 1; border: 0; background: transparent; resize: none; outline: none;
  max-height: 180px; min-height: 44px; padding: 10px 0; line-height: 1.45;
}
.send {
  width: 40px; height: 40px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font-weight: 700;
}
.send:disabled { opacity: .4; }
.hint { max-width: 820px; margin: 8px auto 0; color: var(--faint); font-size: 11px; text-align: center; }

.empty { text-align: center; padding: 12vh 16px 24px; }
.empty img { width: 56px; height: 56px; margin-bottom: 16px; opacity: .9; }
.empty h2 { margin: 0 0 8px; font-weight: 600; letter-spacing: -0.02em; }
.empty p { color: var(--muted); margin: 0 auto 22px; max-width: 420px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  background: var(--bg-elev); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 8px 12px; font-size: 13px;
}
.chip:hover { border-color: var(--accent); }

.limit-card {
  background: linear-gradient(180deg, #1a1710, #141210);
  border: 1px solid #3a3324; border-radius: 14px; padding: 16px 18px;
  margin: 8px 0 20px;
}
.limit-card h3 { margin: 0 0 6px; font-size: 16px; }
.limit-card p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }

/* pricing */
.page { flex: 1 1 auto; min-height: 0; overflow: auto; }
.page-inner { max-width: 1040px; margin: 0 auto; padding: 36px 24px 64px; }
.page-inner h1 { font-size: 32px; letter-spacing: -0.03em; margin: 0 0 8px; }
.lead { color: var(--muted); margin: 0 0 16px; }
.banner {
  background: #1a1710; border: 1px solid #3a3324; color: var(--warn);
  border-radius: 12px; padding: 12px 14px; font-size: 13.5px; margin: 0 0 28px; line-height: 1.5;
}
.tiers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.tier {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 22px;
  display: flex; flex-direction: column; min-height: 340px;
}
.tier.featured { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tier h3 { margin: 0; font-size: 18px; }
.price { font-size: 36px; font-weight: 700; margin: 12px 0 0; letter-spacing: -0.03em; }
.price span { font-size: 14px; color: var(--muted); font-weight: 500; }
.tier .blurb { color: var(--muted); font-size: 14px; margin: 10px 0 16px; }
.tier ul { margin: 0 0 20px; padding: 0 0 0 18px; color: var(--text); font-size: 14px; line-height: 1.7; flex: 1; }
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: grid; place-items: center; padding: 20px; z-index: 20;
}
.modal {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 16px;
  padding: 24px; max-width: 460px; width: 100%;
}
.admin-box {
  margin-top: 36px; border: 1px dashed #3a3324; border-radius: 14px; padding: 16px 18px;
  background: #141210;
}
.admin-box h3 { margin: 0 0 6px; font-size: 14px; color: var(--warn); }
.admin-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.admin-row input, .admin-row select { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.typing::after { content: "▍"; animation: blink 1s step-end infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.hidden { display: none !important; }

@media (max-width: 860px) {
  .gate { grid-template-columns: 1fr; }
  .gate-brand { display: none; }
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.open { display: flex; position: fixed; inset: 0 auto 0 0; width: 80%; max-width: 300px; z-index: 10; height: 100dvh; min-height: 0; }
  .tiers { grid-template-columns: 1fr; }
}

.or-row {
  display: flex; align-items: center; gap: 12px;
  margin: 18px 0 14px; color: var(--muted); font-size: 12px; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase;
}
.or-row::before, .or-row::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}
.google-slot { min-height: 40px; display: flex; justify-content: center; }
.google-slot > div { width: 100%; }
.btn.google {
  background: #fff; color: #1f1f1f; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-weight: 600;
}
.btn.google:hover { filter: none; background: #f3f3f3; }
.btn.google:disabled { opacity: .7; cursor: not-allowed; background: #ececec; }
.btn.google .g-icon {
  width: 18px; height: 18px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--sans); font-weight: 700; font-size: 13px;
  background: #fff; color: #4285f4; border: 1px solid #dadce0;
}
#google-note code { font-family: var(--mono); font-size: 11px; }
