:root {
  color-scheme: light;
  --bg: #f6f8fa;
  --panel: #ffffff;
  --panel-muted: #f3f5f8;
  --panel-hover: #fafbfc;
  --text: #1f2328;
  --text-secondary: #57606a;
  --muted: #8c959f;
  --line: #d0d7de;
  --line-light: #eaeef2;
  --primary: #0969da;
  --primary-hover: #0856b3;
  --primary-light: #e8f2ff;
  --success: #1a7f37;
  --success-hover: #15662c;
  --success-light: #e6f6eb;
  --warning: #d97706;
  --danger: #cf222e;
  --danger-hover: #a40e26;
  --danger-light: #ffebe9;
  --shadow-sm: 0 1px 3px rgba(31, 35, 40, 0.08), 0 1px 2px rgba(31, 35, 40, 0.06);
  --shadow: 0 8px 24px rgba(31, 35, 40, 0.08), 0 2px 8px rgba(31, 35, 40, 0.04);
  --shadow-lg: 0 16px 48px rgba(31, 35, 40, 0.16);
  --radius: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
}

button, input, select, textarea {
  font: inherit;
}

/* 顶部导航栏 */
.top-navbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line-light);
  padding: 0 24px;
}

.nav-container {
  max-width: 1100px;
  height: 64px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.2px;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #0969da, #218bff);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(9, 105, 218, 0.35);
}

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

.nav-tabs {
  display: flex;
  background: var(--panel-muted);
  padding: 3px;
  border-radius: 8px;
}

.nav-tab-btn {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  transition: all 150ms ease;
}

.nav-tab-btn.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 6px;
  background: var(--panel-muted);
  border: 1px solid var(--line-light);
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}

/* 主内容容器 */
.page-shell {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

/* 按钮通用 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
  padding: 7px 16px;
  cursor: pointer;
  transition: all 160ms ease;
  white-space: nowrap;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #ffffff;
  color: var(--text);
  border-color: var(--line);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--panel-muted);
  border-color: #b1b9c2;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--panel-muted);
  color: var(--text);
}

.btn-success {
  background: var(--success);
  color: #ffffff;
}
.btn-success:hover:not(:disabled) {
  background: var(--success-hover);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
}
.btn-danger-ghost:hover:not(:disabled) {
  background: var(--danger-light);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-lg {
  padding: 10px 20px;
  font-size: 15px;
  border-radius: 8px;
}

/* 视图面板容器 */
.view-panel {
  display: none;
}
.view-panel.active {
  display: block;
}

/* 未登录引导条 */
.guest-banner {
  background: linear-gradient(90deg, #eaf2ff 0%, #f0f7ff 100%);
  border: 1px solid #c8e1ff;
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.guest-banner-text h3 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 700;
  color: #0550ae;
}

.guest-banner-text p {
  margin: 0;
  font-size: 13px;
  color: #24292f;
}

/* 快捷生成器卡片 */
.generator-card {
  max-width: 520px;
  margin: 0 auto;
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 32px 30px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line-light);
}

.generator-card .app-header {
  text-align: center;
  margin-bottom: 26px;
}

.generator-card .app-header h1 {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 26px;
  font-weight: 750;
}

.generator-card .app-header p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 14px;
}

.form-stack {
  display: grid;
  gap: 12px;
}

.field-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.input-text {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  outline: 0;
  transition: all 160ms ease;
}

.input-text:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.15);
}

.hint {
  margin: -4px 0 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.code-display-box {
  position: relative;
  overflow: hidden;
  margin-top: 20px;
  padding: 18px 16px 20px;
  border-radius: var(--radius);
  background: var(--panel-muted);
  text-align: center;
  border: 1px solid var(--line-light);
}

.code-display-box .code-val {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 32px;
  font-weight: 750;
  color: var(--text);
  letter-spacing: 2px;
  display: block;
}

.code-display-box .code-timer {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.code-display-box .code-timer.urgent {
  color: var(--danger);
  animation: pulse-urgent 1s infinite alternate;
}

@keyframes pulse-urgent {
  0% { opacity: 0.7; }
  100% { opacity: 1; }
}

.progress-track {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: rgba(9, 105, 218, 0.08);
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--primary);
  transition: width 240ms linear;
}

.code-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 14px;
}

.qr-panel {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line-light);
  text-align: center;
}

.qr-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

#qr-canvas {
  display: block;
  margin: 0 auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: #ffffff;
}

/* ========================================================
   我的密钥管理工作台 (Vault Dashboard)
   ======================================================== */
.vault-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.vault-title-group h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -0.2px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.vault-title-group p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.vault-count-badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.vault-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.search-box {
  position: relative;
  width: 240px;
}

.search-box input {
  padding-left: 32px;
  height: 38px;
  font-size: 13px;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.global-timer-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--panel);
  border: 1px solid var(--line-light);
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  box-shadow: var(--shadow-sm);
}

.timer-indicator-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: blink 1.5s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

/* 密钥卡片列表网格 */
.secrets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.secret-card {
  background: var(--panel);
  border: 1px solid var(--line-light);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
  position: relative;
  overflow: hidden;
}

.secret-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: #c0c8d0;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.account-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 750;
  font-size: 16px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  border: 1px solid rgba(9, 105, 218, 0.15);
}

.account-info {
  min-width: 0;
}

.account-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-issuer {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 2px 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-menu-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: grid;
  place-items: center;
}
.card-menu-btn:hover {
  background: var(--panel-muted);
  color: var(--text);
}

/* 验证码主体展示 */
.card-code-area {
  background: var(--panel-muted);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: center;
  cursor: pointer;
  position: relative;
  border: 1px solid var(--line-light);
  transition: all 160ms ease;
  user-select: none;
}

.card-code-area:hover {
  background: #edf2f8;
  border-color: #b5c7db;
}

.card-code-area:active {
  transform: scale(0.99);
}

.card-code-digits {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 30px;
  font-weight: 750;
  letter-spacing: 3px;
  color: var(--text);
  line-height: 1.2;
}

.card-timer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
}

.card-timer-meta .seconds-left {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.card-timer-meta.urgent .seconds-left {
  color: var(--danger);
  font-weight: 700;
}

.card-code-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(9, 105, 218, 0.1);
  border-radius: 0 0 var(--radius) var(--radius);
}

.card-code-progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 240ms linear;
}

.card-code-progress-fill.urgent {
  background: var(--danger);
}

/* 卡片操作条 */
.card-bottom-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line-light);
}

.card-action-group {
  display: flex;
  gap: 6px;
}

/* 空状态卡片 */
.empty-vault-state {
  text-align: center;
  padding: 60px 20px;
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg);
}

.empty-vault-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-size: 28px;
}

.empty-vault-state h3 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 700;
}

.empty-vault-state p {
  margin: 0 auto 20px;
  max-width: 400px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
}

/* ========================================================
   模态框 (Modal)
   ======================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-dialog {
  background: var(--panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(100%, 460px);
  overflow: hidden;
  transform: translateY(12px) scale(0.98);
  transition: transform 180ms ease;
  border: 1px solid var(--line-light);
}

.modal-overlay.active .modal-dialog {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line-light);
}

.modal-header h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 750;
  color: var(--text);
}

.modal-close-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
}

.modal-close-btn:hover {
  background: var(--panel-muted);
  color: var(--text);
}

.modal-body {
  padding: 22px 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px;
  background: var(--panel-muted);
  border-top: 1px solid var(--line-light);
}

/* 模态框内的 Tab */
.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--line-light);
  margin: -22px -24px 20px;
  background: #fafbfc;
}

.modal-tab-btn {
  flex: 1;
  padding: 12px 16px;
  background: transparent;
  border: 0;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 140ms ease;
}

.modal-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: #ffffff;
}

/* 密码切换查看小图标 */
.password-input-wrap {
  position: relative;
}

.password-input-wrap input {
  padding-right: 40px;
}

.toggle-pwd-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
}

/* 实时预览 TOTP 小卡片（添加密钥时） */
.preview-box {
  background: var(--panel-muted);
  border: 1px solid var(--line-light);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 12px;
  display: none;
}
.preview-box.show {
  display: block;
}

.preview-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.preview-digits {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

/* 全局 Toast 通知 */
.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: #1f2328;
  color: #ffffff;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-10px);
  transition: all 200ms cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  background: #1a7f37;
}

.toast.error {
  background: #cf222e;
}

/* OAuth 第三方登录区域 */
.oauth-divider {
  margin-top: 16px;
  padding-top: 14px;
}

.divider-line {
  position: relative;
  text-align: center;
  margin-bottom: 14px;
}

.divider-line::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  right: 0;
  height: 1px;
  background: var(--line-light);
}

.divider-line span {
  position: relative;
  background: var(--panel);
  padding: 0 12px;
  color: var(--muted);
  font-size: 12px;
}

.user-avatar-img {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  object-fit: cover;
  display: block;
}

/* 底部 Footer */
.footer {
  margin-top: auto;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 20px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line-light);
  background: #ffffff;
}

.footer a {
  color: var(--text-secondary);
  text-decoration: none;
}

.footer a:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* 响应式调整 */
@media (max-width: 640px) {
  .top-navbar {
    padding: 0 16px;
  }
  .nav-container {
    height: 56px;
  }
  .brand-link span {
    font-size: 16px;
  }
  .page-shell {
    padding: 16px 14px 36px;
  }
  .vault-header {
    flex-direction: column;
    align-items: stretch;
  }
  .vault-actions {
    flex-wrap: wrap;
  }
  .search-box {
    width: 100%;
  }
  .secrets-grid {
    grid-template-columns: 1fr;
  }
  .guest-banner {
    flex-direction: column;
    align-items: flex-start;
  }
}
