/* Phira 多人服务器 · 静态管理面板样式（深色主题，无外部依赖） */

:root {
  color-scheme: dark;
  --bg: #0d1014;
  --bg-soft: #11151b;
  --surface: #171c24;
  --surface-2: #1d232d;
  --surface-3: #252d39;
  --border: #2a323e;
  --border-strong: #3a4555;
  --text: #e7ebf2;
  --text-dim: #9ba6b6;
  --text-faint: #6f7a8a;
  --accent: #5b8ff9;
  --accent-strong: #7aa5fb;
  --accent-soft: rgba(91, 143, 249, 0.14);
  --success: #43c98d;
  --success-soft: rgba(67, 201, 141, 0.14);
  --warning: #e7a94b;
  --warning-soft: rgba(231, 169, 75, 0.13);
  --danger: #ef6b6b;
  --danger-soft: rgba(239, 107, 107, 0.14);
  --info: #59b8d8;
  --info-soft: rgba(89, 184, 216, 0.14);
  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.4);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, "Courier New", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  background-color: var(--bg);
  background-image: radial-gradient(1100px 560px at 50% -12%, rgba(91, 143, 249, 0.12), transparent 62%);
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  line-height: 1.35;
}

p {
  margin: 0;
}

a {
  color: var(--accent-strong);
}

a:hover {
  color: #a6c4fd;
}

/* ---------- 顶部栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 16px;
  padding: 11px 20px;
  background: rgba(13, 16, 20, 0.88);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(150deg, #7aa5fb, #4f7fe8);
  color: #0b1220;
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  flex: 0 0 auto;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.brand-text strong {
  font-size: 14.5px;
  font-weight: 600;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}

.nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.nav-btn {
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.nav-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-btn.is-active {
  color: var(--text);
  background: var(--accent-soft);
  border-color: rgba(91, 143, 249, 0.38);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}

.api-chip {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11.5px;
}

.api-chip.is-missing {
  color: var(--warning);
  border-color: rgba(231, 169, 75, 0.35);
  background: var(--warning-soft);
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 10px 3px 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-soft);
  max-width: 220px;
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 600;
  flex: 0 0 auto;
}

.user-name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 页面与卡片 ---------- */

.page {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 24px 20px 72px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

#app-view,
#admin-app-view {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.auth-wrap {
  display: flex;
  justify-content: center;
  padding: 5vh 0 0;
}

.auth-card {
  width: 100%;
  max-width: 440px;
}

.card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}

.card-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.card-head .muted {
  margin-top: 3px;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  min-width: 0;
}

.muted {
  color: var(--text-dim);
  font-size: 13px;
}

.hint {
  color: var(--text-faint);
  font-size: 12.5px;
  line-height: 1.6;
}

.mono {
  font-family: var(--mono);
  font-size: 13px;
}

/* ---------- 工具栏 ---------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sync-status {
  font-size: 12.5px;
  color: var(--text-faint);
}

.sync-status.is-error {
  color: var(--danger);
}

/* ---------- 按钮 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: #46536a;
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0a1020;
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.btn-danger {
  background: var(--danger-soft);
  border-color: rgba(239, 107, 107, 0.45);
  color: #ffa8a8;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 107, 107, 0.24);
  border-color: rgba(239, 107, 107, 0.7);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.btn-block {
  width: 100%;
}

.btn.is-busy {
  cursor: progress;
  opacity: 0.8;
}

.btn.is-busy::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: 0 0 auto;
}

/* ---------- 表单 ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > span,
.field > label {
  font-size: 13px;
  color: var(--text-dim);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-faint);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input.is-invalid,
.textarea.is-invalid {
  border-color: var(--danger);
}

.textarea {
  min-height: 130px;
  resize: vertical;
  line-height: 1.6;
}

.select {
  cursor: pointer;
}

.select-sm {
  width: auto;
  padding: 6px 10px;
  font-size: 13px;
}

.field-error {
  margin: 0;
  font-size: 12.5px;
  color: #ff9a9a;
}

.form-error {
  margin: 0;
  padding: 8px 11px;
  border: 1px solid rgba(239, 107, 107, 0.3);
  border-radius: 8px;
  background: var(--danger-soft);
  color: #ffb4b4;
  font-size: 13px;
}

.notice {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 12px 14px;
  border: 1px solid rgba(231, 169, 75, 0.35);
  border-radius: var(--radius);
  background: var(--warning-soft);
  color: #f2cd93;
  font-size: 13.5px;
}

.notice .btn {
  align-self: flex-start;
}

.inline-form {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.inline-form .field {
  flex: 1 1 240px;
}

.control-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.control-row .field {
  flex: 1 1 210px;
}

.control-row > .btn {
  flex: 0 0 auto;
}

/* ---------- 标签 ---------- */

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.5;
  white-space: nowrap;
}

.tag-ok {
  color: var(--success);
  background: var(--success-soft);
  border-color: rgba(67, 201, 141, 0.26);
}

.tag-warn {
  color: var(--warning);
  background: var(--warning-soft);
  border-color: rgba(231, 169, 75, 0.26);
}

.tag-danger {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: rgba(239, 107, 107, 0.26);
}

.tag-info {
  color: var(--info);
  background: var(--info-soft);
  border-color: rgba(89, 184, 216, 0.26);
}

.tag-muted {
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
}

.tag-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tag-inline {
  margin-left: 6px;
}

/* ---------- 表格 ---------- */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 14px;
}

.table-compact {
  min-width: 440px;
}

.table th,
.table td {
  padding: 9px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}

.table thead th {
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.table tr.is-selected td {
  background: var(--accent-soft);
}

.table tr.is-self td {
  background: rgba(91, 143, 249, 0.08);
}

.table td .tag-row {
  gap: 4px;
}

/* ---------- 房间展示 ---------- */

.room-summary {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.room-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.room-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.room-id {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px 18px;
}

.meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.meta-label {
  font-size: 12px;
  color: var(--text-faint);
}

.meta-value {
  font-size: 14px;
  word-break: break-word;
}

.control-groups {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.control-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

.hint-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding-left: 18px;
  color: var(--warning);
  font-size: 12.5px;
}

/* ---------- 状态卡片 ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.stat-label {
  font-size: 12.5px;
  color: var(--text-dim);
}

.stat-value {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-faint);
}

/* ---------- 空状态 / 加载 ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 28px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--text-dim);
  text-align: center;
  font-size: 13.5px;
}

.empty-title {
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 16px;
  color: var(--text-dim);
  font-size: 13.5px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: 0 0 auto;
}

/* ---------- 弹层 ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(2px);
}

.modal {
  width: min(470px, 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: pop 0.16s ease-out;
}

.modal-head {
  padding: 16px 18px 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 18px 16px;
}

.modal-text {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.65;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 18px 18px;
}

/* ---------- Toast ---------- */

.toast-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: 9px;
  background: var(--surface-2);
  box-shadow: var(--shadow);
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
  animation: slide-in 0.18s ease-out;
  pointer-events: auto;
}

.toast-success {
  border-left-color: var(--success);
}

.toast-error {
  border-left-color: var(--danger);
}

.toast-info {
  border-left-color: var(--info);
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* ---------- 日志 / 链接 ---------- */

.log-view {
  margin: 0;
  padding: 14px;
  max-height: 62vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0a0d11;
  color: #c8d2e0;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
}

.link-box {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
}

.link-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 260px;
  min-width: 0;
}

.link-main a {
  word-break: break-all;
  font-family: var(--mono);
  font-size: 13px;
}

/* ---------- 动画 ---------- */

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- 响应式 ---------- */

@media (max-width: 820px) {
  .topbar {
    padding: 10px 14px;
  }

  .nav {
    order: 3;
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-btn {
    flex: 0 0 auto;
  }

  .api-chip {
    max-width: 150px;
  }

  .page {
    padding: 16px 14px 56px;
  }

  .card-head,
  .card-body {
    padding: 14px;
  }

  .auth-wrap {
    padding: 8px 0 0;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-row .field,
  .inline-form .field {
    flex-basis: 100%;
  }

  .inline-form > .btn {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .topbar-actions {
    width: 100%;
    margin-left: 0;
    justify-content: flex-end;
  }

  .topbar-actions .api-chip {
    display: none;
  }

  .topbar-actions .user-chip {
    margin-left: auto;
  }
}

@media (max-width: 460px) {
  .brand-sub {
    display: none;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .user-chip {
    max-width: 160px;
  }

  .api-chip {
    max-width: 120px;
  }

  .modal-backdrop {
    padding: 12px;
  }
}
