:root {
  --bg: #212121;
  --sidebar: #171717;
  --elev: #2f2f2f;
  --line: rgba(255, 255, 255, 0.08);
  --text: #ececec;
  --muted: #9b9b9b;
  --accent: #10a37f;
  --accent-2: #1acd9a;
  --danger: #ef4444;
  --user: #2f2f2f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

[hidden] { display: none !important; }

button, input, textarea { font: inherit; color: inherit; }

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(800px 400px at 50% -10%, rgba(16, 163, 127, 0.18), transparent 50%),
    var(--sidebar);
}

.login-card {
  width: min(400px, calc(100% - 32px));
  text-align: center;
}

.logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 18px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #04150f;
  font-weight: 800;
  font-size: 22px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
  font-weight: 650;
}

.login-desc {
  margin: 0 0 28px;
  color: var(--muted);
}

#login-form {
  display: grid;
  gap: 10px;
}

#login-form input,
#login-form button {
  height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line);
}

#login-form input {
  background: var(--elev);
  padding: 0 14px;
  outline: none;
}

#login-form input:focus {
  border-color: rgba(16, 163, 127, 0.7);
}

#login-form button {
  background: var(--text);
  color: #111;
  font-weight: 650;
  cursor: pointer;
  border: 0;
}

#login-form button:hover { opacity: 0.92; }

.error { color: var(--danger); margin: 12px 0 0; }

.app {
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 12px;
}

.new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.new-chat:hover { background: rgba(255,255,255,0.05); }

.conv-list {
  overflow-y: auto;
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 4px;
  flex: 1;
}

.conv-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: transparent;
  border: 0;
  text-align: left;
  cursor: pointer;
  color: #d9d9d9;
  font-size: 14px;
}

.conv-item span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.conv-item:hover,
.conv-item.active { background: var(--elev); }

.conv-item .del {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.sidebar-foot {
  flex-shrink: 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 12px;
}

.user-chip b {
  display: block;
  font-size: 13px;
}

.user-chip em {
  display: block;
  font-style: normal;
  color: var(--muted);
  font-size: 12px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--elev);
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.avatar.tiny { width: 34px; height: 34px; }

.msg.assistant .avatar {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #04150f;
}

.main {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-weight: 600;
}

.icon-btn {
  display: none;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.messages {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 24px 0 8px;
}

.msg {
  padding: 10px 0;
}

.msg-inner {
  width: min(760px, calc(100% - 40px));
  margin: 0 auto;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.msg.user .msg-inner { flex-direction: row-reverse; }

.msg-body {
  min-width: 0;
  line-height: 1.75;
  font-size: 15.5px;
}

.msg.user .msg-body {
  background: var(--user);
  border-radius: 22px;
  padding: 10px 16px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.assistant .msg-body {
  padding-top: 4px;
  word-break: break-word;
}

.msg.assistant .msg-body p,
.msg.assistant .msg-body ul,
.msg.assistant .msg-body ol { margin: 0 0 10px; }

.msg.assistant .msg-body p:last-child { margin-bottom: 0; }

.msg.assistant .msg-body a { color: #7dd3c0; }

.msg.assistant .msg-body pre {
  overflow: auto;
  padding: 12px;
  background: #0f0f0f;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.msg.assistant .msg-body code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px;
}

.tool-chip {
  width: min(760px, calc(100% - 40px));
  margin: 0 auto 8px;
  color: var(--accent-2);
  font-size: 12px;
}

.empty {
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--text);
}

.empty .logo {
  margin-bottom: 16px;
}

.empty h2 {
  margin: 0 0 8px;
  font-size: 28px;
  font-weight: 600;
}

.empty p {
  margin: 0;
  color: var(--muted);
}

.composer {
  flex-shrink: 0;
  padding: 8px 16px 18px;
}

.composer-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 8px;
  padding: 10px 10px 10px 16px;
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.2), 0 18px 50px rgba(0,0,0,0.18);
}

.composer-shell:focus-within {
  border-color: rgba(255,255,255,0.18);
}

.composer textarea {
  resize: none;
  min-height: 28px;
  max-height: 180px;
  border: 0;
  outline: none;
  background: transparent;
  padding: 10px 0;
  line-height: 1.5;
}

#send {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: #111;
  display: grid;
  place-items: center;
  cursor: pointer;
}

#send:hover { opacity: 0.9; }

.credit {
  width: min(760px, 100%);
  margin: 8px auto 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.ghost-btn {
  width: 100%;
  margin-top: 8px;
  height: 36px;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
  color: var(--muted);
}

.ghost-btn:hover { background: rgba(255,255,255,0.05); color: var(--text); }

.create-user {
  display: grid;
  gap: 8px;
  margin: 0 12px 8px;
}

.create-user input,
.create-user button {
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--elev);
  padding: 0 12px;
  font-size: 16px;
}

.create-user button {
  background: #fff;
  color: #111;
  font-weight: 650;
  cursor: pointer;
}

.admin-app {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--bg);
}

.admin-scroll {
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 24px;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--accent-2);
  cursor: pointer;
  padding: 0 4px 0 0;
  font-size: 14px;
}

.admin-h {
  margin: 16px 16px 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.user-list {
  padding: 0 8px;
}

.admin-body {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
}

.admin-convs,
.admin-thread {
  min-height: 0;
  padding: 8px 12px 16px;
}

@media (min-width: 801px) {
  .admin-body {
    grid-template-columns: 340px minmax(0, 1fr);
    min-height: 50vh;
  }
  .admin-convs { border-right: 1px solid var(--line); }
}

.admin-item {
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 8px;
  background: transparent;
}

.admin-item:hover,
.admin-item.active { background: var(--elev); }

.admin-item b { display: block; margin-bottom: 4px; }
.admin-item span, .empty-hint { color: var(--muted); font-size: 13px; }

.admin-msg {
  padding: 10px 12px;
  border-radius: 12px;
  margin: 0 0 10px;
  background: var(--elev);
}

.admin-msg.user { background: #2a3a33; }

@media (max-width: 800px) {
  .admin-body { grid-template-columns: 1fr; }
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(260px, 86vw);
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 8;
  }
  .sidebar.open { transform: none; }
  .sidebar-mask {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 7;
  }
  .icon-btn { display: grid; }
}
