:root {
  --bg: #0d0f12;
  --bg-soft: #14171c;
  --bg-elev: #1a1e24;
  --bg-hover: #21262e;
  --line: #2a3038;
  --text: #ececf1;
  --text-dim: #9aa3b2;
  --text-faint: #6b7482;
  --accent: #10a37f;
  --accent-soft: rgba(16, 163, 127, 0.14);
  --danger: #f2555a;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  transition: background .15s ease, border-color .15s ease, opacity .15s ease;
}
button:hover { background: var(--bg-hover); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06231c;
  font-weight: 600;
}
button.primary:hover { background: #14b78e; }
button.ghost { background: transparent; }
button.danger { border-color: rgba(242,85,90,.5); color: var(--danger); }

input, textarea, select {
  font-family: inherit;
  font-size: 14px;
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 13px;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--text-dim); margin: 14px 0 6px; }

/* ------------------------------- auth pages ------------------------------ */

.auth-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 18px;
  background:
    radial-gradient(900px 480px at 20% -10%, rgba(16,163,127,.14), transparent 60%),
    radial-gradient(700px 420px at 90% 110%, rgba(88,101,242,.12), transparent 60%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: rgba(20,23,28,.92);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 30px 26px 24px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.brand-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  background: linear-gradient(140deg, #10a37f, #0b6b56);
  display: grid; place-items: center;
  font-weight: 700; color: #06231c; font-size: 15px;
}
.brand-name { font-size: 16px; font-weight: 650; letter-spacing: .2px; }
.auth-title { font-size: 21px; font-weight: 650; margin: 14px 0 4px; }
.auth-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 6px; }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 4px;
  margin: 18px 0 6px;
}
.tabs button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 13.5px;
}
.tabs button.active { background: var(--bg-elev); color: var(--text); }

.hint { font-size: 12px; color: var(--text-faint); margin-top: 10px; line-height: 1.6; }
.error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.link-btn { background: none; border: none; color: var(--text-dim); font-size: 12.5px; padding: 0; }

/* --------------------------------- shell -------------------------------- */

.shell { display: flex; height: 100%; }

.sidebar {
  width: 264px;
  flex: 0 0 264px;
  background: #0a0c0f;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  gap: 10px;
}
.sidebar .brand { padding: 4px 4px 10px; }

.side-btn {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid var(--line);
  padding: 10px 12px;
  border-radius: 11px;
  color: var(--text);
  font-size: 14px;
}
.side-btn:hover { background: var(--bg-hover); }

.side-label {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 8px 6px 2px;
}

.side-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.side-item {
  padding: 9px 10px;
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.side-item:hover { background: var(--bg-hover); color: var(--text); }
.side-item.active { background: var(--bg-elev); color: var(--text); }

.side-foot { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(140deg,#5865f2,#10a37f);
  display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #0b0d10;
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 54px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: rgba(13,15,18,.86);
  backdrop-filter: blur(8px);
}
.topbar .model-select { width: auto; min-width: 220px; padding: 7px 10px; font-size: 13.5px; }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 34px; height: 34px; padding: 0;
  display: grid; place-items: center;
  border-radius: 9px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-dim);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.chat-scroll { flex: 1; overflow-y: auto; }
.chat-inner { max-width: 780px; margin: 0 auto; padding: 26px 20px 8px; }

.welcome { text-align: center; padding: 12vh 10px 0; }
.welcome h1 { font-size: 26px; font-weight: 650; margin: 0 0 10px; }
.welcome p { color: var(--text-dim); font-size: 14px; margin: 0 auto; max-width: 460px; line-height: 1.7; }

.msg { display: flex; gap: 12px; padding: 15px 0; border-bottom: 1px solid rgba(42,48,56,.5); }
.msg:last-child { border-bottom: none; }
.msg .who {
  width: 28px; height: 28px; flex: 0 0 28px; border-radius: 7px;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
}
.msg.user .who { background: #2b3038; color: var(--text-dim); }
.msg.bot .who { background: var(--accent-soft); color: var(--accent); }
.msg .body { flex: 1; min-width: 0; font-size: 15px; line-height: 1.75; white-space: pre-wrap; word-break: break-word; }
.msg .body code { background: var(--bg-elev); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.msg .body pre {
  background: #0a0c0f; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; overflow-x: auto; font-size: 13px; line-height: 1.6; margin: 10px 0;
}
.msg .body pre code { background: none; padding: 0; }
.cursor { display: inline-block; width: 7px; height: 15px; background: var(--accent); vertical-align: -2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.composer-wrap { padding: 10px 20px 20px; }
.composer {
  max-width: 780px; margin: 0 auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 10px 8px;
}
.composer textarea {
  border: none; background: transparent; resize: none; max-height: 200px;
  padding: 8px 8px 4px; font-size: 15px; line-height: 1.6;
}
.composer-bar { display: flex; align-items: center; gap: 8px; padding: 4px 4px 0; }
.composer-bar .spacer { flex: 1; }
.composer-hint { font-size: 11.5px; color: var(--text-faint); }

/* --------------------------------- admin -------------------------------- */

.admin-wrap { max-width: 1080px; margin: 0 auto; padding: 26px 20px 60px; }
.admin-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.admin-head h1 { font-size: 20px; margin: 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 22px; }
.card {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 13px; padding: 14px 16px;
}
.card .k { font-size: 12px; color: var(--text-faint); }
.card .v { font-size: 22px; font-weight: 650; margin-top: 6px; }

.panel { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 20px; }
.panel h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.inline-form { display: grid; grid-template-columns: 120px 120px 1fr 1fr auto; gap: 10px; align-items: end; }
.inline-form label { margin: 0 0 5px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--text-faint); font-weight: 500; font-size: 12px; letter-spacing: .03em; }
code.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg-elev); padding: 2px 6px; border-radius: 6px; font-size: 12.5px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; border: 1px solid var(--line); color: var(--text-dim); }
.pill.ok { color: var(--accent); border-color: rgba(16,163,127,.4); background: var(--accent-soft); }
.pill.warn { color: #e3b341; border-color: rgba(227,179,65,.35); }
.pill.dead { color: var(--danger); border-color: rgba(242,85,90,.35); }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .inline-form { grid-template-columns: 1fr 1fr; }
}
