:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #263248;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: radial-gradient(circle at top right, #172554 0%, var(--bg) 52%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }
.hint { color: var(--muted); font-size: 0.82rem; }
.center { text-align: center; }

.toast {
  position: fixed; top: 18px; right: 18px; z-index: 9999;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 12px 16px; border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,0.45);
  max-width: 360px; font-size: 0.92rem;
}
.toast.ok { border-color: var(--accent); color: #d1fae5; }
.toast.err { border-color: var(--danger); color: #fee2e2; }

/* Auth Gate */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-card {
  width: 100%; max-width: 430px; background: rgba(17, 24, 39, 0.92);
  border: 1px solid var(--border); border-radius: 16px; padding: 28px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.brand-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.brand-head h1 { font-size: 1.28rem; }
.brand-logo {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3b82f6, #06b6d4); font-weight: 800; font-size: 1.3rem; color: #fff;
}
.brand-logo.sm { width: 32px; height: 32px; font-size: 1rem; border-radius: 8px; }

.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; }
.auth-tab {
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
  padding: 9px; border-radius: 8px; cursor: pointer; font-weight: 600;
}
.auth-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.form-stack { display: flex; flex-direction: column; gap: 12px; }
.form-stack label { display: flex; flex-direction: column; gap: 6px; font-size: 0.88rem; }
input[type="text"], input[type="password"], input[type="time"], input[type="number"] {
  background: #0f172a; border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: 8px; font-size: 0.95rem; outline: none;
}
input:focus { border-color: var(--primary); }
.inline-check { flex-direction: row !important; align-items: center; gap: 8px !important; cursor: pointer; }
.sep { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

.captcha-box { display: flex; flex-direction: column; gap: 6px; font-size: 0.86rem; }
.captcha-row { display: flex; gap: 10px; align-items: center; }
.captcha-img { cursor: pointer; border-radius: 8px; overflow: hidden; flex-shrink: 0; border: 1px solid var(--border); line-height: 0; }
.captcha-row input { flex: 1; min-width: 0; }

/* Buttons & Badges */
.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 9px 15px;
  cursor: pointer; font-weight: 600; font-size: 0.9rem; color: #fff; transition: 0.15s;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.sm { padding: 6px 11px; font-size: 0.82rem; }
.btn.full { width: 100%; }
.btn-primary { background: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-warn { background: #d97706; }
.btn-warn:hover:not(:disabled) { background: #b45309; }
.btn-danger { background: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-ghost { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { border-color: #475569; }

.pill, .badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.78rem;
  background: var(--surface-2); border: 1px solid var(--border); color: #cbd5e1;
}
.pill.ok { background: rgba(16,185,129,0.15); border-color: rgba(16,185,129,0.4); color: #6ee7b7; }
.pill.warn { background: rgba(245,158,11,0.15); border-color: rgba(245,158,11,0.4); color: #fcd34d; }
.pill.danger { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.4); color: #fca5a5; }

.alert { padding: 10px 12px; border-radius: 8px; font-size: 0.86rem; margin-bottom: 12px; }
.alert-danger { background: rgba(239,68,68,0.14); border: 1px solid rgba(239,68,68,0.4); color: #fecaca; }
.alert-info { background: rgba(59,130,246,0.14); border: 1px solid rgba(59,130,246,0.35); color: #bfdbfe; }

/* App Layout */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; background: rgba(17, 24, 39, 0.88); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100; backdrop-filter: blur(8px);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.brand-title { font-weight: 700; font-size: 1rem; }
.nav-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.nav-btn {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 7px 13px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 0.88rem;
}
.nav-btn.active { background: var(--surface-2); color: #fff; border-color: var(--border); }

.container { max-width: 1120px; margin: 20px auto; padding: 0 16px 40px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.card {
  background: rgba(17, 24, 39, 0.9); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.card h2 { font-size: 1.05rem; }

.progress-track { width: 100%; height: 10px; background: #0f172a; border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #3b82f6, #38bdf8); transition: width 0.2s; }
.progress-fill.accent { background: linear-gradient(90deg, #10b981, #34d399); }

.upload-controls { display: flex; flex-direction: column; gap: 10px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 0.82rem; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Chat */
.chat-card { display: flex; flex-direction: column; height: 74vh; min-height: 460px; }
.chat-messages {
  flex: 1; overflow-y: auto; padding: 12px; background: #0b1222; border-radius: 10px;
  border: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px;
}
.msg-item { display: flex; flex-direction: column; gap: 4px; max-width: 82%; }
.msg-item.self { align-self: flex-end; align-items: flex-end; }
.msg-meta { font-size: 0.76rem; color: var(--muted); }
.msg-bubble {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 12px; white-space: pre-wrap; word-break: break-word; font-size: 0.92rem;
}
.msg-item.self .msg-bubble { background: #1d4ed8; border-color: #2563eb; }
.msg-img { max-width: 260px; max-height: 240px; border-radius: 8px; margin-top: 4px; cursor: pointer; display: block; }
.chat-input-bar { display: flex; gap: 8px; margin-top: 12px; align-items: center; }
.chat-input-bar input[type="text"] { flex: 1; }
.file-btn { display: inline-flex; align-items: center; }

/* Invite & Metrics */
.invite-display {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #0f172a; border: 1px dashed #3b82f6; border-radius: 10px;
  padding: 14px 16px; margin: 14px 0 8px;
}
.invite-display code { font-size: 1.25rem; letter-spacing: 2px; color: #38bdf8; font-weight: 700; }
.big-metric { font-size: 1.45rem; font-weight: 800; margin: 6px 0 10px; color: #34d399; }

.kv-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 14px; }
.kv-list > div { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid rgba(38,50,72,0.6); font-size: 0.9rem; }
.mc-btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 8px; }
.danger-fold { margin-top: 14px; padding: 10px; border-radius: 8px; background: rgba(239,68,68,0.08); border: 1px solid rgba(239,68,68,0.28); font-size: 0.86rem; }
.danger-fold summary { cursor: pointer; color: #fca5a5; font-weight: 600; }
