:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #262b36;
  --text: #e7eaf0;
  --muted: #8b93a3;
  --brand: #ff7a45;
  --brand-2: #ff9a6b;
  --ok: #35c46a;
  --warn: #ffb020;
  --bad: #ff5c5c;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { max-width: 100%; overflow-x: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 650; }
h1 { font-size: 22px; }
h2 { font-size: 16px; color: #cfd5e2; }
h3 { font-size: 14px; color: var(--muted); margin-top: 18px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.hidden { display: none !important; }

/* ---------- public ---------- */
body.center {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(255,122,69,.18), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(90,140,255,.12), transparent 55%),
    var(--bg);
}

.card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
}
.card.narrow { max-width: 360px; }

.code-input {
  width: 100%;
  margin: 14px 0;
  padding: 14px 16px;
  font-size: 18px;
  letter-spacing: 4px;
  text-align: center;
  text-transform: uppercase;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}
.code-input:focus { border-color: var(--brand); }
.code-input::placeholder { letter-spacing: 1px; color: #5b6273; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: .15s;
}
.btn:hover { border-color: #3a4152; text-decoration: none; }
.btn.primary {
  width: 100%;
  color: #1a0f08;
  font-weight: 700;
  background: linear-gradient(180deg, var(--brand-2), var(--brand));
  border: none;
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: #ffd9d9; border-color: #5a2a2a; background: #2a1616; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.alert {
  margin: 10px 0;
  padding: 10px 12px;
  font-size: 13px;
  color: #ffd6c9;
  background: rgba(255,92,92,.12);
  border: 1px solid rgba(255,92,92,.35);
  border-radius: 10px;
}
.alert.ok { color: #c8f5d8; background: rgba(53,196,106,.12); border-color: rgba(53,196,106,.35); }
.hint { margin-top: 14px; font-size: 12px; color: var(--muted); }

/* ---------- chat ---------- */
body.chat-body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
}
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(23,26,33,.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.chat-title { font-weight: 650; display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.chat-meta { display: flex; align-items: center; gap: 10px; min-width: 0; flex-wrap: wrap; }
.pill {
  padding: 4px 10px;
  font-size: 12px;
  color: var(--brand-2);
  background: rgba(255,122,69,.12);
  border: 1px solid rgba(255,122,69,.3);
  border-radius: 999px;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.msg { max-width: 86%; display: flex; flex-direction: column; gap: 6px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot { align-self: flex-start; }
.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .bubble { background: linear-gradient(180deg, var(--brand-2), var(--brand)); color: #1a0f08; }
.msg.bot .bubble { background: var(--panel-2); border: 1px solid var(--line); }
.msg .media img { max-width: 100%; border-radius: 12px; display: block; }
.msg .media a { font-size: 13px; }

.kbd { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.kbd-row { display: flex; flex-wrap: wrap; gap: 6px; }
.kbd button {
  flex: 1 1 auto;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  background: #20242e;
  border: 1px solid #2f3542;
  border-radius: 10px;
  cursor: pointer;
}
.kbd button:hover { border-color: var(--brand); }
.kbd a {
  flex: 1 1 auto;
  padding: 8px 12px;
  font-size: 13px;
  text-align: center;
  border: 1px dashed #3a4152;
  border-radius: 10px;
}

.chat-input {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.chat-input textarea {
  flex: 1;
  max-height: 120px;
  padding: 11px 14px;
  font: inherit;
  color: var(--text);
  resize: none;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}
.chat-input textarea:focus { border-color: var(--brand); }
.chat-input .btn.primary { width: auto; padding: 0 20px; }

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8,10,14,.78);
  backdrop-filter: blur(4px);
  z-index: 20;
}
.overlay-box {
  max-width: 380px;
  padding: 26px 22px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.typing { color: var(--muted); font-size: 13px; padding-left: 4px; }

/* ---------- admin ---------- */
body.admin { background: var(--bg); }
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topnav .brand { font-weight: 700; letter-spacing: .3px; }
.topnav .links { display: flex; align-items: center; gap: 16px; font-size: 14px; }
.topnav .links a { color: var(--muted); }
.topnav .links a.on, .topnav .links a:hover { color: var(--text); }
.inline { display: inline; }
.linklike {
  padding: 0; font: inherit; color: var(--muted);
  background: none; border: none; cursor: pointer;
}
.linklike:hover { color: var(--text); text-decoration: underline; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 22px; }
.grid.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat {
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }

.panel {
  margin-top: 18px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; }
.tbl tr.dim td { opacity: .62; }
.tbl tr.bad td { color: #ffb3b3; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.badge.ok { color: #bff5d1; border-color: rgba(53,196,106,.4); }
.badge.warn { color: #ffe0aa; border-color: rgba(255,176,32,.4); }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px 18px; margin: 10px 0; }
.kv > div { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.kv span { color: var(--muted); font-size: 13px; }
.kv b { font-weight: 600; font-size: 13px; text-align: right; word-break: break-all; }

.form-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.form-row label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.form-row label.grow { flex: 1 1 200px; }
.form-row input, .form-row select {
  padding: 9px 11px;
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  min-width: 90px;
}
.form-row input:focus, .form-row select:focus { border-color: var(--brand); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }

.conv { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.conv-row { padding: 8px 12px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.conv-row.user { border-color: rgba(255,122,69,.35); }
.conv-role { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.conv-text { font-size: 13px; white-space: pre-wrap; word-break: break-word; }

code {
  padding: 1px 5px;
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
}

@media (max-width: 640px) {
  .wrap { padding: 14px; }
  .topnav { flex-direction: column; align-items: flex-start; gap: 8px; padding: 10px 14px; }
  .tbl { font-size: 12px; }
  .kv { grid-template-columns: 1fr; }
}
