:root {
  --bg-page: #f4f6fa;
  --bg-card: rgba(255, 255, 255, 0.82);
  --bg-card-solid: #ffffff;
  --bg-raised: rgba(15, 23, 42, 0.045);
  --text-primary: #111827;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --hairline: rgba(15, 23, 42, 0.09);
  --hairline-strong: rgba(15, 23, 42, 0.16);
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, 0.11);
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --shadow-card: 0 12px 32px -12px rgba(15, 23, 42, 0.12), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-focus: 0 0 0 3px rgba(0, 113, 227, 0.2);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --robot-body: #ffffff;
  --robot-ink: #1e293b;
  --robot-screen: #0f172a;
  --robot-eye: #38bdf8;
  --robot-accent: #e2e8f0;
}

html[data-theme="dark"] {
  --bg-page: #0b0e14;
  --bg-card: rgba(22, 27, 38, 0.82);
  --bg-card-solid: #161b26;
  --bg-raised: rgba(255, 255, 255, 0.06);
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --hairline: rgba(255, 255, 255, 0.09);
  --hairline-strong: rgba(255, 255, 255, 0.16);
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.15);
  --accent-contrast: #0b0e14;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --shadow-card: 0 16px 40px -14px rgba(0, 0, 0, 0.55);
  --robot-body: #1e293b;
  --robot-ink: #94a3b8;
  --robot-screen: #020617;
  --robot-eye: #38bdf8;
  --robot-accent: #334155;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg-page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.35;
  pointer-events: none;
  z-index: 0;
}
.bg-orb-1 { width: 420px; height: 420px; top: -120px; left: -100px; background: var(--accent); }
.bg-orb-2 { width: 380px; height: 380px; bottom: -120px; right: -80px; background: #818cf8; }

.surface {
  position: relative;
  z-index: 1;
  background: var(--bg-card);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.code-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--hairline-strong);
  background: var(--bg-card-solid);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.14s ease, background 0.16s ease, border-color 0.16s ease, opacity 0.16s ease;
}
.btn:hover { background: var(--bg-raised); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-contrast);
}
.btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: var(--hairline); }
.btn-danger-ghost { background: transparent; border-color: var(--danger-soft); color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-accent-soft { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn-xs { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }

.input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--hairline-strong);
  background: var(--bg-card-solid);
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: inherit;
  transition: box-shadow 0.16s ease, border-color 0.16s ease;
}
textarea.input { height: auto; padding: 9px 12px; resize: vertical; }
.input-sm { height: 34px; font-size: 13px; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--shadow-focus); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 500; color: var(--text-secondary); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap .input { padding-right: 54px; }
.pwd-toggle {
  position: absolute;
  right: 8px;
  height: 26px;
  padding: 0 8px;
  border: none;
  border-radius: 6px;
  background: var(--bg-raised);
  color: var(--text-secondary);
  font-size: 11.5px;
  cursor: pointer;
}

/* Login View */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 72px 18px 32px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 36px 28px 28px;
  position: relative;
}
.robot-buddy {
  position: absolute;
  top: -58px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}
.robot-bubble {
  margin-bottom: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--bg-card-solid);
  border: 1px solid var(--hairline-strong);
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}
.robot-head-svg { width: 88px; height: 56px; }
.robot-paws {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 96px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  transition: transform 0.22s ease;
}
.robot-paw {
  width: 24px;
  height: 16px;
  border-radius: 999px;
  background: var(--robot-body);
  border: 2.5px solid var(--robot-ink);
}
.login-card.is-cover-eyes .robot-paws { transform: translate(-50%, -22px); }

.login-head { text-align: center; margin-bottom: 22px; }
.login-title { margin: 10px 0 6px; font-size: 20px; font-weight: 700; }
.login-sub { margin: 0; font-size: 12px; color: var(--text-muted); word-break: break-all; }
.login-sub code { font-family: var(--font-mono); color: var(--text-secondary); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.form-error { min-height: 18px; font-size: 12.5px; color: var(--danger); }

/* Main Admin App */
.app-shell {
  max-width: 1360px;
  margin: 0 auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
}
.topbar {
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand-badge {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-contrast);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-family: var(--font-mono);
}
.brand-title { font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 11.5px; color: var(--text-muted); }
.admin-user-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--bg-raised);
  font-size: 13px;
  font-weight: 500;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; }

.workspace {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.sidebar {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 18px;
}
.nav-item {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover { background: var(--bg-raised); color: var(--text-primary); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-code { font-family: var(--font-mono); font-size: 11px; opacity: 0.78; }

.panel { display: none; flex-direction: column; gap: 14px; }
.panel.is-active { display: flex; }

/* Studio */
.studio-head {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.studio-head-left, .studio-head-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.muted-meta { font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); }
.seg-control {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--bg-raised);
  border: 1px solid var(--hairline);
}
.seg-btn {
  height: 28px;
  padding: 0 14px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}
.seg-btn.is-active { background: var(--bg-card-solid); color: var(--text-primary); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); }

.studio-grid {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
.post-list-col {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 180px);
}
.post-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
}
.post-list-item {
  width: 100%;
  text-align: left;
  padding: 10px 11px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.post-list-item:hover { background: var(--bg-raised); }
.post-list-item.is-active { background: var(--accent-soft); border-color: rgba(0, 113, 227, 0.25); }
.post-list-title { font-size: 13px; font-weight: 600; line-height: 1.35; }
.post-list-meta { font-size: 11.5px; color: var(--text-muted); font-family: var(--font-mono); }

.studio-editor-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 14px;
  align-items: start;
}
.editor-canvas {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 540px;
}
.editor-title-input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 22px;
  font-weight: 700;
  outline: none;
  padding: 4px 0;
  border-bottom: 1px solid var(--hairline);
}
.md-toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.md-textarea {
  width: 100%;
  flex: 1;
  min-height: 410px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.7;
  resize: vertical;
  outline: none;
}
.md-preview {
  min-height: 410px;
  padding: 6px 2px;
  font-size: 14.5px;
  line-height: 1.8;
}
.md-preview h2 { margin: 20px 0 10px; font-size: 18px; }
.md-preview pre {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--bg-raised);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.md-preview code { font-family: var(--font-mono); padding: 1px 5px; border-radius: 5px; background: var(--bg-raised); font-size: 0.9em; }
.md-preview pre code { padding: 0; background: transparent; }
.md-preview blockquote {
  margin: 12px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--accent);
  background: var(--bg-raised);
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
}
.md-preview img { max-width: 100%; border-radius: 10px; }

.inspector-col {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-raised);
  font-size: 13px;
  cursor: pointer;
}
.inspector-footer { padding-top: 10px; border-top: 1px solid var(--hairline); }

/* Settings & Invites */
.settings-shell { padding: 18px 20px; display: flex; flex-direction: column; gap: 18px; }
.settings-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--hairline);
}
.subtab-bar { display: flex; gap: 6px; flex-wrap: wrap; }
.subtab-btn {
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}
.subtab-btn.is-active { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }

.site-pane { display: flex; flex-direction: column; gap: 16px; }
.card-block {
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--hairline);
  background: var(--bg-raised);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card-block h3 { margin: 0; font-size: 14.5px; }
.card-block-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-desc { margin: -4px 0 2px; font-size: 12px; color: var(--text-muted); }

.setting-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}
.setting-row label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.inline-control { display: flex; align-items: center; gap: 8px; }
.inline-wrap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.avatar-preview {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--hairline-strong);
  flex-shrink: 0;
}

.stack-list { display: flex; flex-direction: column; gap: 8px; }
.extra-row {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.contact-grid-head, .contact-edit-row {
  display: grid;
  grid-template-columns: 100px 130px 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}
.contact-grid-head { font-size: 11.5px; color: var(--text-muted); padding: 0 2px; }

.invite-card {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--hairline);
  background: var(--bg-card-solid);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.invite-top, .invite-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.invite-code { font-family: var(--font-mono); font-size: 13.5px; font-weight: 700; letter-spacing: 0.04em; }
.invite-meta { font-size: 12px; color: var(--text-muted); }

.kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--hairline);
  flex-wrap: wrap;
}
.kv-row:last-child { border-bottom: none; }
.kv-row span { color: var(--text-secondary); }
.kv-row code { font-family: var(--font-mono); font-size: 12.5px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 16px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--text-primary);
  color: var(--bg-card-solid);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  z-index: 999;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1080px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { position: static; flex-direction: row; overflow-x: auto; }
  .nav-item { width: auto; white-space: nowrap; gap: 8px; }
  .studio-grid { grid-template-columns: 1fr; }
  .studio-editor-wrap { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .setting-row { grid-template-columns: 1fr; gap: 6px; }
  .contact-grid-head { display: none; }
  .contact-edit-row { grid-template-columns: 1fr; }
}
