:root {
  --bg: #0f1220;
  --bg-2: #171b2e;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-strong: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.12);
  --text: #eef1f8;
  --muted: #9aa3bd;
  --primary: #6d8cff;
  --primary-strong: #4f6df5;
  --accent: #34d399;
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 18px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 15% -10%, #26304f 0%, transparent 55%),
    radial-gradient(900px 600px at 110% 20%, #2b2140 0%, transparent 50%),
    var(--bg);
  min-height: 100vh;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }

.view { display: none; position: fixed; inset: 0; }
.view--active { display: block; }

.view--fade { animation: viewIn 0.35s ease both; }
@keyframes viewIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

/* ================= 计算器 ================= */
#view-calculator {
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#view-calculator.view--active { display: flex; }

.calc {
  width: min(380px, 100%);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  padding: 20px;
}

.calc__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.calc__brand { font-size: 0.8rem; letter-spacing: 0.18em; color: var(--muted); text-transform: uppercase; }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 1.1rem;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--panel); color: var(--text); }

.calc__screen {
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  padding: 10px 8px 14px;
  gap: 6px;
  overflow: hidden;
}

.calc__expr {
  font-size: 1.1rem;
  color: var(--muted);
  word-break: break-all;
  text-align: right;
  min-height: 1.3em;
}

input.calc__expr {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  padding: 6px 0;
  line-height: 1.4;
  font-family: inherit;
  caret-color: var(--primary);
  cursor: text;
}

.calc__result {
  font-size: 2.6rem;
  font-weight: 300;
  letter-spacing: 0.01em;
  word-break: break-all;
  text-align: right;
  line-height: 1.1;
}

.calc__pad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.key {
  border: none;
  border-radius: 16px;
  padding: 16px 0;
  font-size: 1.35rem;
  color: var(--text);
  background: var(--panel);
  transition: transform 0.08s, background 0.15s;
}
.key:hover { background: var(--panel-strong); }
.key:active { transform: scale(0.94); }
.key--fn { color: var(--muted); background: rgba(255, 255, 255, 0.04); }
.key--op { background: rgba(109, 140, 255, 0.18); color: #b9c7ff; }
.key--eq { background: linear-gradient(180deg, var(--primary), var(--primary-strong)); color: #fff; }

.calc__hint {
  margin-top: 14px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0.75;
}
.calc__hint code {
  background: var(--panel);
  padding: 1px 6px;
  border-radius: 6px;
}

/* ================= 登录/注册 ================= */
#view-auth {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#view-auth.view--active { display: flex; }

.auth {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px;
  backdrop-filter: blur(18px);
}

.link-back {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0;
  font-size: 0.85rem;
  margin-bottom: 18px;
}
.link-back:hover { color: var(--text); }

.auth__title { margin: 0 0 4px; font-size: 1.6rem; }
.auth__sub { margin: 0 0 20px; color: var(--muted); font-size: 0.9rem; }

.tabs {
  display: flex;
  gap: 6px;
  background: rgba(0, 0, 0, 0.2);
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 18px;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 9px;
  border-radius: 9px;
  font-size: 0.95rem;
}
.tab--active { background: var(--panel-strong); color: var(--text); }

.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 0.82rem; color: var(--muted); }
.field input,
.sidebar__search input,
.chat__input input,
.modal input {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border 0.15s;
  width: 100%;
}
.field input:focus,
.sidebar__search input:focus,
.modal input:focus { border-color: var(--primary); }

.form__error {
  background: rgba(248, 113, 113, 0.14);
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: #ffc9c9;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  transition: all 0.15s;
}
.btn:hover { background: var(--panel-strong); }
.btn--primary {
  background: linear-gradient(180deg, var(--primary), var(--primary-strong));
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}
.btn--primary:hover { filter: brightness(1.08); }
.btn--danger { color: var(--danger); border-color: rgba(248, 113, 113, 0.35); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.auth__foot { margin: 18px 0 0; font-size: 0.78rem; color: var(--muted); text-align: center; }

/* ================= 应用主界面 ================= */
#view-app.view--active { display: block; }

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.22);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.sidebar__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  flex-shrink: 0;
  font-size: 0.95rem;
}

.sidebar__me { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.sidebar__me strong { font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  font-size: 0.68rem;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted);
  width: fit-content;
}
.badge--admin { background: rgba(251, 191, 36, 0.2); color: var(--warn); }
.badge--on { background: rgba(52, 211, 153, 0.2); color: var(--accent); }

.sidebar__search { position: relative; padding: 12px 16px 4px; }

.search-results {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 58px;
  background: #1a1f36;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 320px;
  overflow-y: auto;
  z-index: 30;
}

.search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.search-item:last-child { border-bottom: none; }
.search-item__info { flex: 1; min-width: 0; }
.search-item__info strong { display: block; font-size: 0.9rem; }
.search-item__info span { font-size: 0.75rem; color: var(--muted); }
.search-item .btn { padding: 7px 12px; font-size: 0.8rem; }

.sidebar__tabs {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}
.stab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 9px;
  border-radius: 10px;
  font-size: 0.88rem;
  position: relative;
}
.stab--active { background: var(--panel); color: var(--text); }
.stab .dot {
  position: absolute;
  top: 5px;
  right: 10px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

.sidebar__body { flex: 1; overflow-y: auto; padding: 0 10px 16px; min-height: 0; }
.panel { display: none; }
.panel--active { display: block; }

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.list-item:hover { background: var(--panel); }
.list-item--active { background: var(--panel-strong); }
.list-item__info { flex: 1; min-width: 0; }
.list-item__info strong { display: block; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item__info span { font-size: 0.76rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.list-item__meta { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.list-item__meta time { font-size: 0.68rem; color: var(--muted); }

.pill {
  background: var(--primary);
  color: #fff;
  font-size: 0.68rem;
  padding: 1px 7px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}

.empty-hint { padding: 24px 16px; text-align: center; color: var(--muted); font-size: 0.85rem; }

.section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  padding: 14px 12px 6px;
}

.req-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  margin: 8px 4px;
}
.req-card__head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.req-card__actions { display: flex; gap: 8px; }
.req-card__actions .btn { flex: 1; padding: 8px; font-size: 0.82rem; }

.admin-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 12px;
}
.admin-row:hover { background: var(--panel); }
.admin-row__info { flex: 1; min-width: 0; }
.admin-row__info strong { display: block; font-size: 0.9rem; }
.admin-row__info span { font-size: 0.74rem; color: var(--muted); }
.admin-row__actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.admin-row__actions .btn { padding: 6px 10px; font-size: 0.75rem; }

/* ================= 聊天窗口 ================= */
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

.chat__empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 12px;
}
.chat__empty-icon { font-size: 3rem; opacity: 0.6; }

.chat__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
}
.chat__head strong { font-size: 1rem; }
.chat__head span { font-size: 0.78rem; color: var(--muted); }

.chat__back {
  display: none;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.3rem;
  padding: 0 6px 0 0;
}
.chat__back:hover { color: var(--text); }

.chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.msg { max-width: 68%; display: flex; flex-direction: column; gap: 4px; }
.msg__bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg--in { align-self: flex-start; }
.msg--in .msg__bubble { background: var(--panel-strong); border-bottom-left-radius: 4px; }
.msg--out { align-self: flex-end; }
.msg--out .msg__bubble {
  background: linear-gradient(180deg, var(--primary), var(--primary-strong));
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg time { font-size: 0.68rem; color: var(--muted); }
.msg--out time { align-self: flex-end; }

.chat__form {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
}
.chat__input { flex: 1; }
.chat__form .btn--primary { padding: 12px 22px; }

/* ================= 弹窗 & Toast ================= */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}
.modal__card {
  width: min(420px, 100%);
  background: #1a1f36;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal__card h2 { margin: 0; font-size: 1.2rem; }
.modal__actions { display: flex; gap: 10px; }
.modal__actions .btn { flex: 1; }
.modal__status { margin: 0; font-size: 0.82rem; min-height: 1.2em; color: var(--muted); }
.modal__status.ok { color: var(--accent); }
.modal__status.err { color: var(--danger); }

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: #262c45;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  z-index: 200;
  animation: toastIn 0.25s ease both;
  max-width: 90vw;
  text-align: center;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ================= 响应式 ================= */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: absolute; inset: 0; z-index: 20; width: 100%; max-width: 100%; transition: transform 0.25s; }
  .app.show-chat .sidebar { transform: translateX(-100%); }
  .chat { position: absolute; inset: 0; z-index: 10; }
  .app.show-chat .chat { z-index: 30; }
  .chat__back { display: inline-block; }
  .app:not(.show-chat) .chat { z-index: 5; }
  .msg { max-width: 82%; }
}
