/* ============================================================================
 * Offset Server · 管理控制台样式
 * 同源外置样式表（通过 <link href="/admin/admin.css"> 加载）。
 * 严格符合后端 CSP：default-src 'self'; frame-ancestors 'none';
 *   object-src 'none'; base-uri 'none'
 * 即：无外部字体/CSS/JS，无内联 <style>，仅使用系统字体栈。
 * ==========================================================================*/

/* ---- 设计令牌 ---------------------------------------------------------- */
:root {
  /* 背景与表面 */
  --bg:        #0b0f17;
  --bg-soft:   #0f141f;
  --surface:   #151b27;
  --surface-2: #1b2230;
  --surface-3: #232c3d;
  --line:      #2a3444;
  --line-soft: #1f2734;

  /* 文本 */
  --fg:        #e8eef6;
  --fg-soft:   #aeb9c7;
  --muted:     #7d8aa0;

  /* 主题强调色 */
  --accent:     #4f8cff;
  --accent-600: #3a78f0;
  --accent-700: #2f63cf;
  --accent-soft: rgba(79, 140, 255, .14);

  /* 语义色 */
  --ok:    #3fcf6b;
  --ok-bg: rgba(63, 207, 107, .12);
  --warn:  #e3b341;
  --err:   #ff6b6b;
  --err-bg: rgba(255, 107, 107, .12);

  /* 形状与节奏 */
  --radius:    10px;
  --radius-sm: 7px;
  --radius-lg: 16px;
  --shadow:    0 12px 32px rgba(0, 0, 0, .42);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .28);
  --ring:      0 0 0 3px var(--accent-soft);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* ---- 基础重置 ---------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font: 14px/1.6 var(--sans);
  color: var(--fg);
  background: var(--bg);
  background-image:
    radial-gradient(1100px 620px at 88% -8%, rgba(79, 140, 255, .12), transparent 60%),
    radial-gradient(900px 540px at 0% 100%, rgba(63, 207, 107, .06), transparent 55%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

::selection { background: var(--accent-soft); }

/* 仅供屏幕阅读器（视觉隐藏） */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

/* 自定义滚动条（同源，无外部依赖） */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #324056; background-clip: content-box; }

/* ---- 通用焦点可见性（无障碍） ------------------------------------------ */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ============================================================================
 * 按钮
 * ==========================================================================*/
button,
.btn {
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--fg);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  line-height: 1.2;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, transform .06s ease, box-shadow .15s ease, color .15s ease;
}
button:hover,
.btn:hover { background: var(--surface-3); border-color: #3a4760; }
button:active,
.btn:active { transform: translateY(1px); }
button:focus-visible,
.btn:focus-visible { outline: none; box-shadow: var(--ring); border-color: var(--accent); }

button.primary {
  background: var(--accent-600);
  border-color: var(--accent-600);
  color: #fff;
}
button.primary:hover { background: var(--accent); border-color: var(--accent); }
button.primary:focus-visible { box-shadow: 0 0 0 3px rgba(79, 140, 255, .35); }

button.ghost { background: transparent; }
button.ghost:hover { background: var(--surface-2); }

button.danger { color: var(--err); }
button.danger:hover { background: rgba(255, 107, 107, .1); border-color: var(--err); }

button.small { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }

button:disabled,
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
button:disabled:hover { background: var(--surface-2); border-color: var(--line); }

/* 按钮内联加载指示 */
.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  border-radius: 50%;
  display: none;
  animation: spin .7s linear infinite;
}
button.loading .spinner { display: inline-block; }
button.loading .label { opacity: .85; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================================
 * 表单控件
 * ==========================================================================*/
label {
  display: block;
  color: var(--fg-soft);
  font-size: 12.5px;
  font-weight: 550;
  margin: 0 0 6px;
}

input[type="text"],
input[type="password"],
input:not([type]) {
  font: inherit;
  width: 100%;
  color: var(--fg);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input::placeholder { color: #5d6b80; }
input:hover { border-color: #3a4760; }
input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
input:read-only {
  background: var(--surface);
  color: var(--fg-soft);
  cursor: not-allowed;
  border-style: dashed;
}

.field { display: flex; flex-direction: column; }
.field + .field { margin-top: 14px; }

/* 行内验证提示 */
.hint {
  color: var(--muted);
  font-size: 12px;
  margin: 6px 0 0;
  min-height: 16px;
  transition: color .15s ease;
}
.hint.err { color: var(--err); }
.hint.ok  { color: var(--ok); }

/* ============================================================================
 * 居中卡片布局（登录 / 修改密码）
 * ==========================================================================*/
.center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 380px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 30px 28px 26px;
  box-shadow: var(--shadow);
  animation: card-in .35s cubic-bezier(.2, .7, .3, 1) both;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(10px) scale(.99); }
  to   { opacity: 1; transform: none; }
}

/* 品牌标识 */
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 20px;
}
.brand-mark {
  width: 38px; height: 38px;
  flex: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-700) 100%);
  color: #fff;
  font-weight: 800;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(79, 140, 255, .4);
  letter-spacing: -1px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text .name { font-size: 15px; font-weight: 700; }
.brand-text .tag { font-size: 11.5px; color: var(--muted); }

.card h1 { font-size: 20px; margin-bottom: 6px; }
.card .sub { color: var(--fg-soft); font-size: 13px; margin: 0 0 20px; }

.card .field + .field { margin-top: 16px; }
.card .actions { margin-top: 22px; display: flex; gap: 10px; }
.card .actions button { flex: 1; }

/* ============================================================================
 * 顶部应用栏 + 工具栏（控制台）
 * ==========================================================================*/
.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 22px;
  background: rgba(15, 20, 31, .82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.appbar .brand { margin-bottom: 0; }
.appbar .spacer { flex: 1; }
.appbar .user-actions { display: flex; gap: 8px; align-items: center; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line-soft);
}
.toolbar .group { display: flex; gap: 8px; align-items: flex-end; }
.toolbar .filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-left: auto;
}
.toolbar .filters .field { min-width: 168px; }
.toolbar .filters .field + .field { margin-top: 0; }

main { padding: 18px 22px 80px; }

/* 区块标题 + 计数 */
.section-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 4px 2px 12px;
}
.section-head h2 { font-size: 15px; }
.count-badge {
  font-size: 12px;
  color: var(--fg-soft);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 2px 9px;
  border-radius: 999px;
}

/* ============================================================================
 * 视图切换 / 子栏 / 创建项目表单
 * ==========================================================================*/
.view[hidden] { display: none; }

/* 创建项目内联表单（位于 toolbar 内） */
.create-project {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  width: 100%;
}
.create-project .field { min-width: 200px; }
.create-project .field + .field { margin-top: 0; }

/* 偏移/配置视图的上下文子栏 */
.subbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line-soft);
}
.subbar .spacer { flex: 1; }
.subbar .ctx {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(79, 140, 255, .3);
  padding: 4px 12px;
  border-radius: 999px;
}

/* 说明性提示条 */
.note {
  margin: 0 2px 14px;
  padding: 11px 14px;
  font-size: 12.5px;
  color: var(--fg-soft);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
}
.note strong { color: var(--fg); font-weight: 650; }
.note code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--accent);
}

/* 复选框列 */
.check-col { width: 38px; text-align: center; }
.check-col input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* 文本域（批量导入） */
textarea {
  font: 13px/1.5 var(--mono);
  width: 100%;
  color: var(--fg);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  resize: vertical;
  min-height: 120px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
textarea::placeholder { color: #5d6b80; }

/* 多行消息（导入结果） */
.msg { white-space: pre-line; }

/* ============================================================================
 * 配置加密视图
 * ==========================================================================*/
.config-key-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 18px;
}
.config-key-box > label {
  margin-bottom: 10px;
  color: var(--warn);
}

.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row input { flex: 1; }
.copy-row .copy-btn { flex: none; }

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}
.config-field {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.config-field .copy-row { margin-top: 10px; }
.enc-out {
  font-size: 12px;
  color: var(--ok);
  background: var(--bg-soft);
}
.enc-out::placeholder { color: #5d6b80; font-family: var(--sans); }

/* ============================================================================
 * 数据表格
 * ==========================================================================*/
.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
table { width: 100%; border-collapse: collapse; }

thead th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  background: var(--surface-2);
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
}
tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) { background: rgba(255, 255, 255, .015); }
tbody tr:hover { background: var(--accent-soft); }

td.mono, th.mono { font-family: var(--mono); font-size: 12.5px; }
td.value { font-family: var(--mono); color: var(--accent); }
.actions-cell { white-space: nowrap; text-align: right; }
.actions-cell button { margin-left: 7px; }

/* 空状态 / 加载状态 */
.empty {
  display: none;
  color: var(--muted);
  text-align: center;
  padding: 56px 24px;
}
.empty .empty-mark {
  font-size: 30px;
  display: block;
  margin-bottom: 10px;
  opacity: .55;
}
.empty .empty-title { color: var(--fg-soft); font-size: 14px; font-weight: 600; }
.empty .empty-sub { font-size: 12.5px; margin-top: 4px; }

.loading-row td {
  text-align: center;
  color: var(--muted);
  padding: 40px 24px;
}
.loading-row .spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border-color: var(--surface-3);
  border-top-color: var(--accent);
  vertical-align: middle;
  margin-right: 8px;
}

/* ============================================================================
 * 静态消息条（卡片内行内反馈，aria-live）
 * ==========================================================================*/
.msg {
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: none;
  border: 1px solid transparent;
}
.msg.show { display: block; }
.msg.err { background: var(--err-bg); color: var(--err); border-color: rgba(255, 107, 107, .4); }
.msg.ok  { background: var(--ok-bg);  color: var(--ok);  border-color: rgba(63, 207, 107, .4); }

/* ============================================================================
 * Toast 通知（非阻塞，aria-live 由 JS 写入）
 * ==========================================================================*/
.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 36px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in .26s cubic-bezier(.2, .7, .3, 1) both;
}
.toast.leaving { animation: toast-out .22s ease forwards; }
.toast.ok   { border-left-color: var(--ok); }
.toast.err  { border-left-color: var(--err); }
.toast.info { border-left-color: var(--accent); }
.toast .toast-icon { font-weight: 700; line-height: 1.5; }
.toast.ok .toast-icon  { color: var(--ok); }
.toast.err .toast-icon { color: var(--err); }
.toast.info .toast-icon{ color: var(--accent); }
.toast .toast-body { flex: 1; color: var(--fg); }
.toast .toast-close {
  border: none; background: transparent; color: var(--muted);
  padding: 0 2px; font-size: 16px; line-height: 1;
}
.toast .toast-close:hover { background: transparent; color: var(--fg); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(16px); }
}

/* ============================================================================
 * 模态弹层（新增 / 编辑）
 * ==========================================================================*/
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 12, .62);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
.overlay.show { display: flex; animation: overlay-in .18s ease both; }
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }

.dialog {
  width: 100%;
  max-width: 440px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  animation: dialog-in .24s cubic-bezier(.2, .7, .3, 1) both;
}
@keyframes dialog-in {
  from { opacity: 0; transform: translateY(12px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.dialog h2 { font-size: 17px; margin-bottom: 6px; }
.dialog .dialog-hint { color: var(--muted); font-size: 12.5px; margin: 0 0 18px; }
.dialog .actions { margin-top: 22px; display: flex; gap: 10px; justify-content: flex-end; }
.dialog .actions button { min-width: 92px; }

/* ============================================================================
 * 响应式（窄屏）
 * ==========================================================================*/
@media (max-width: 720px) {
  .appbar { padding: 10px 14px; }
  .appbar .brand-text .tag { display: none; }
  .toolbar { padding: 14px; }
  .toolbar .filters { margin-left: 0; width: 100%; }
  .toolbar .filters .field { flex: 1; min-width: 120px; }
  main { padding: 14px 14px 70px; }

  /* 表格转为卡片式堆叠 */
  .table-wrap { border: none; background: transparent; box-shadow: none; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tbody tr {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 12px;
    padding: 6px 4px;
  }
  tbody tr:hover { background: var(--surface); }
  tbody td {
    border: none;
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 7px 14px;
    text-align: right;
  }
  tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-family: var(--sans);
    text-align: left;
  }
  .actions-cell { justify-content: flex-end; }
  .actions-cell button { margin-left: 7px; }
  .actions-cell::before { content: ""; }

  .toast-region { left: 14px; right: 14px; bottom: 14px; max-width: none; }
}

@media (max-width: 420px) {
  .card { padding: 24px 20px; }
}

/* 尊重减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
