/* ════════════════════════════════════════════
   HengFrame — Shared Base Styles
   所有页面共享：Reset, Navbar, Card, Button, Toast, Spinner
   ════════════════════════════════════════════ */

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ── Auth Gate ── */
#auth-gate {
  position: fixed; inset: 0; z-index: 9999;
  background: #fff;
  display: flex; align-items: center; justify-content: center;
}
#auth-gate .gate-spinner {
  width: 36px; height: 36px;
  border: 3px solid #e8e9eb;
  border-top-color: #1a1a1a;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Body ── */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: #f5f6f7;
  color: #1a1a1a;
  min-height: 100vh;
  line-height: 1.6;
  font-size: 14px;
}
#app-root { display: none; }

/* ── Top Navbar ── */
.navbar {
  position: sticky; top: 0; z-index: 100;
  background: #fff;
  border-bottom: 1px solid #e8e9eb;
  padding: 0 24px; height: 56px;
  display: flex; align-items: center; justify-content: space-between;
}
.nav-left { 
  display: flex; align-items: center; gap: 16px; 
  min-width: 0; 
  flex: 1 1 auto;
  overflow-x: auto;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}
.nav-left::-webkit-scrollbar { display: none; /* Chrome/Safari */ }
.nav-logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; letter-spacing: -0.3px; flex-shrink: 0; }
.nav-logo .logo-icon {
  width: 30px; height: 30px; border-radius: 8px;
  object-fit: cover; display: block;
}
.nav-links { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.nav-links a {
  padding: 7px 12px; border-radius: 999px;
  font-size: 13px; color: #555; cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.nav-links a:hover { background: #f0f1f2; color: #1a1a1a; }
.nav-links a.active { background: #f0f1f2; color: #1a1a1a; font-weight: 600; }
.nav-right { display: flex; align-items: center; gap: 12px; }
.nav-user-area { display: flex; align-items: center; gap: 10px; }

/* 积分徽章 */
.nav-points-badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 4px 12px; border-radius: 999px;
  background: #fffbeb; color: #92400e;
  border: 1px solid #fde68a;
  font-size: 12px; font-weight: 600;
}

/* 用户名下拉菜单容器 */
.nav-user-dropdown-wrap { position: relative; }

/* 用户名触发按钮 */
.nav-user-trigger {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  border: 1px solid #e0e0e0;
  background: #fff;
  cursor: pointer;
  font-size: 13px; color: #333;
  transition: all 0.15s;
}
.nav-user-trigger:hover { border-color: #bbb; background: #fafafa; }

/* 小头像 */
.nav-avatar-sm {
  width: 26px; height: 26px; border-radius: 50%;
  background: #e8e9eb; color: #666;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  flex-shrink: 0;
}

/* 用户名文字 */
.nav-username-text { font-weight: 500; }

/* 管理员徽章 */
.nav-admin-badge {
  background: #f59e0b; color: #fff;
  font-size: 10px; padding: 1px 5px; border-radius: 3px;
  margin-left: 2px;
}

/* 下拉箭头 */
.nav-dropdown-arrow {
  font-size: 10px; color: #999;
  transition: transform 0.15s;
}
.nav-user-dropdown.show ~ .nav-user-trigger .nav-dropdown-arrow,
.nav-user-trigger:has(+ .nav-user-dropdown.show) .nav-dropdown-arrow,
.nav-user-dropdown-wrap:has(.show) .nav-dropdown-arrow {
  transform: rotate(180deg);
}

/* 下拉菜单 */
.nav-user-dropdown {
  display: none;
  position: absolute; top: calc(100% + 6px); right: 0;
  background: #fff; border: 1px solid #e8e9eb; border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  min-width: 150px; z-index: 200; overflow: hidden;
}
.nav-user-dropdown.show { display: block; }

.dropdown-item {
  display: block; width: 100%; padding: 10px 16px;
  border: none; background: #fff; font-size: 13px; color: #333;
  text-align: left; cursor: pointer; transition: background 0.12s;
}
.dropdown-item:hover { background: #f5f6f7; }

/* 分隔线 */
.dropdown-divider {
  height: 1px; background: #e8e9eb; margin: 4px 0;
}

/* 危险操作（退出） */
.dropdown-item-danger { color: #dc2626; }
.dropdown-item-danger:hover { background: #fef2f2; }

/* ── Card ── */
.card {
  background: #fff; border: 1px solid #e8e9eb;
  border-radius: 12px; padding: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-title {
  font-size: 14px; font-weight: 700; color: #1a1a1a;
  display: flex; align-items: center; gap: 8px;
}
.card-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.badge-black { background: #1a1a1a; color: #fff; }
.badge-gray  { background: #f0f1f2; color: #666; }

/* ── Buttons ── */
.btn-generate {
  width: 100%; padding: 13px; border-radius: 10px;
  background: #1a1a1a; color: #fff; border: none;
  font-size: 14px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: opacity 0.15s; margin-top: 8px;
}
.btn-generate:hover:not(:disabled) { opacity: 0.85; }
.btn-generate:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-outline {
  padding: 7px 16px; border-radius: 8px;
  border: 1px solid #d0d1d3; background: #fff;
  font-size: 13px; color: #555;
  transition: all 0.15s; display: inline-flex; align-items: center; gap: 5px;
}
.btn-outline:hover { border-color: #999; color: #1a1a1a; }
.btn-outline:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-black {
  padding: 7px 16px; border-radius: 8px;
  background: #1a1a1a; color: #fff; border: none;
  font-size: 13px; font-weight: 500;
  transition: opacity 0.15s;
}
.btn-black:hover:not(:disabled) { opacity: 0.85; }
.btn-black:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Form Controls ── */
.input-field {
  width: 100%; padding: 10px 12px;
  border: 1px solid #e0e0e0; border-radius: 8px;
  background: #fff; font-size: 13px; color: #1a1a1a;
  outline: none; transition: border-color 0.15s;
  font-family: inherit;
}
.input-field:focus { border-color: #1a1a1a; }
.input-field:disabled { background: #f9fafb; color: #aaa; cursor: not-allowed; }
.input-field::placeholder { color: #bbb; }

.text-input {
  width: 100%; padding: 12px 14px;
  border: 1px solid #e0e0e0; border-radius: 8px;
  background: #fff; font-size: 13px; color: #1a1a1a;
  outline: none; resize: vertical; min-height: 100px;
  font-family: inherit; line-height: 1.6;
  transition: border-color 0.15s;
}
.text-input:focus { border-color: #1a1a1a; }
.text-input::placeholder { color: #bbb; }
.text-input:disabled { background: #f9fafb; color: #aaa; cursor: not-allowed; }

select.custom-select {
  width: 100%; padding: 10px 12px;
  border: 1px solid #e0e0e0; border-radius: 8px;
  background: #fafafa url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
  font-size: 13px; color: #1a1a1a;
  outline: none; appearance: none;
}
select.custom-select:focus { border-color: #1a1a1a; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: #444; margin-bottom: 5px; }
.form-group .required { color: #e03e3e; margin-left: 2px; }

/* ── Section / Step ── */
.section-title { font-size: 13px; font-weight: 700; color: #1a1a1a; margin-bottom: 10px; margin-top: 8px; }
.step-label { font-size: 13px; font-weight: 600; color: #1a1a1a; margin-bottom: 12px; }
.step-num { color: #999; margin-right: 4px; }

/* ── Result Tabs ── */
.result-tabs {
  display: flex; align-items: center; gap: 4px;
  border-bottom: 1px solid #e8e9eb;
  padding-bottom: 0; margin-bottom: 16px;
}
.result-tab {
  padding: 8px 16px; font-size: 13px; font-weight: 500;
  color: #888; border: none; background: none;
  position: relative; transition: color 0.15s;
}
.result-tab:hover { color: #333; }
.result-tab.active { color: #1a1a1a; font-weight: 600; }
.result-tab.active::after {
  content: ''; position: absolute; bottom: -1px; left: 16px; right: 16px;
  height: 2px; background: #1a1a1a; border-radius: 1px;
}

/* ── Toast ── */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  padding: 10px 24px; border-radius: 8px; font-size: 13px; font-weight: 500;
  z-index: 9999; animation: toastIn 0.25s ease; pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
.toast.err { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.toast.ok  { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ── Spinner ── */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.35); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
.spinner-dark { border-color: rgba(0,0,0,0.12); border-top-color: #333; }

/* ── Status Dots ── */
.status-dot {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600;
}
.status-gen { background: #fef3c7; color: #92400e; }
.status-ok  { background: #dcfce7; color: #166534; }
.status-err { background: #fee2e2; color: #991b1b; }

/* ── Empty / Loading ── */
.empty-state { text-align: center; padding: 32px 16px; color: #aaa; font-size: 13px; }
.loading-center { text-align: center; padding: 40px 0; color: #999; font-size: 13px; }

/* ── Footer ── */
.footer-note { text-align: center; padding: 16px 24px; color: #bbb; font-size: 12px; }

/* ── Disabled ── */
button:disabled, input:disabled, textarea:disabled, select:disabled {
  opacity: 0.5; cursor: not-allowed !important; pointer-events: auto;
}

/* ── Search Bar (shared) ── */
.search-bar {
  display: flex; gap: 10px; align-items: center;
  flex-wrap: wrap; margin-bottom: 14px;
}
.search-bar .search-input {
  flex: 1; min-width: 160px;
  padding: 8px 12px; border: 1px solid #ddd; border-radius: 8px;
  font-size: 13px; outline: none; transition: border 0.12s;
}
.search-bar .search-input:focus { border-color: #3b82f6; }
.search-bar .search-select {
  padding: 8px 12px; border: 1px solid #ddd; border-radius: 8px;
  font-size: 13px; outline: none; background: #fff;
  min-width: 100px; cursor: pointer; transition: border 0.12s;
}
.search-bar .search-select:focus { border-color: #3b82f6; }
.search-bar .btn-search {
  padding: 8px 18px; border-radius: 8px; border: none;
  background: #1a1a1a; color: #fff; font-size: 13px;
  font-weight: 500; cursor: pointer; transition: background 0.12s;
  white-space: nowrap;
}
.search-bar .btn-search:hover { background: #333; }

/* ── Pagination (shared) ── */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 6px; padding: 16px 0 4px;
}
.pagination .page-btn {
  min-width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid #ddd; background: #fff;
  font-size: 13px; color: #333; font-weight: 500;
  cursor: pointer; transition: all 0.12s;
  display: flex; align-items: center; justify-content: center;
  padding: 0 10px;
}
.pagination .page-btn:hover { background: #f5f5f5; border-color: #bbb; }
.pagination .page-btn.active {
  background: #1a1a1a; color: #fff; border-color: #1a1a1a;
}
.pagination .page-btn:disabled {
  color: #ccc; border-color: #eee; cursor: not-allowed;
  background: #fafafa;
}
.pagination .page-info {
  font-size: 12px; color: #999; margin: 0 8px; white-space: nowrap;
}

/* ── Confirm Modal (shared) ── */
.confirm-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center; z-index: 1001;
  animation: confirmFadeIn 0.18s ease;
}
.confirm-card {
  background: #fff; border-radius: 14px; width: 340px; max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15); overflow: hidden;
  animation: confirmScaleIn 0.18s ease;
}
.confirm-body {
  padding: 28px 24px 20px; text-align: center;
}
.confirm-icon {
  width: 44px; height: 44px; border-radius: 50%;
  background: #fef2f2; color: #dc2626; border: 2px solid #fecaca;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; margin-bottom: 14px;
}
.confirm-title {
  margin: 0 0 8px; font-size: 15px; color: #1a1a1a; font-weight: 700;
}
.confirm-msg {
  margin: 0; font-size: 13px; color: #666; line-height: 1.5;
}
.confirm-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 14px 20px; border-top: 1px solid #eee; background: #fafafa;
}
.btn-danger {
  padding: 8px 18px; border-radius: 8px; border: none;
  background: #dc2626; color: #fff; font-size: 13px;
  font-weight: 500; cursor: pointer; transition: background 0.12s;
}
.btn-danger:hover { background: #b91c1c; }
.confirm-footer .btn {
  padding: 8px 18px; border-radius: 8px; border: none;
  font-size: 13px; font-weight: 500; cursor: pointer; transition: all 0.12s;
}
.confirm-footer .btn-ghost {
  background: transparent; color: #666; border: 1px solid #ddd;
}
.confirm-footer .btn-ghost:hover { background: #f5f5f5; }

@keyframes confirmFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes confirmScaleIn { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ── Settings Form Modal ── */
.settings-form-card {
  background: #fff; border-radius: 14px; width: 360px; max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15); overflow: hidden;
  animation: confirmScaleIn 0.18s ease;
}
.settings-form-title {
  font-size: 16px; font-weight: 600; color: #1a1a1a;
  padding: 20px 24px 0; margin: 0;
}
.settings-form-body {
  padding: 16px 24px;
}
.settings-label {
  display: block; font-size: 13px; font-weight: 500; color: #555; margin-bottom: 6px;
}
.settings-input {
  width: 100%; padding: 9px 12px; border: 1px solid #ddd; border-radius: 8px;
  font-size: 14px; color: #333; outline: none; transition: border-color 0.15s;
}
.settings-input:focus { border-color: #1a1a1a; }
.settings-error {
  margin-top: 10px; font-size: 12px; color: #dc2626;
}

/* ── Image Preview Lightbox ── */
.img-preview-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 2000; animation: confirmFadeIn 0.18s ease;
}
.img-preview-container {
  position: relative; max-width: 90vw; max-height: 90vh;
  background: #fff; border-radius: 12px; overflow: hidden;
  box-shadow: 0 12px 48px rgba(0,0,0,0.25);
  animation: confirmScaleIn 0.18s ease;
}
.img-preview-container img {
  display: block; max-width: 90vw; max-height: 80vh;
  object-fit: contain; background: #f5f6f7;
}
.img-preview-close {
  position: absolute; top: 8px; right: 8px;
  width: 32px; height: 32px; border-radius: 50%;
  border: none; background: rgba(0,0,0,0.45); color: #fff;
  font-size: 18px; line-height: 32px; cursor: pointer;
  text-align: center; transition: background 0.12s;
}
.img-preview-close:hover { background: rgba(0,0,0,0.7); }
.img-preview-bar {
  padding: 10px 16px; display: flex; justify-content: space-between;
  align-items: center; background: #fff; border-top: 1px solid #eee;
}
.img-preview-label { font-size: 14px; color: #1a1a1a; font-weight: 600; }
.img-preview-dl {
  padding: 6px 14px; border-radius: 8px; border: 1px solid #ddd;
  background: #fff; font-size: 13px; color: #666; cursor: pointer;
  transition: all 0.12s;
}
.img-preview-dl:hover { border-color: #1a1a1a; color: #1a1a1a; }
.img-result img:hover { cursor: pointer; }

/* ── 移动端下拉页签切换器 ── */
.nav-mobile-title-wrap {
  display: none;
  position: relative;
  min-width: 0;
}
.nav-mobile-title {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px;
  border: 1px solid #ccc; background: #fff;
  cursor: pointer; font-size: 13px; font-weight: 600;
  color: #1a1a1a; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  position: relative; z-index: 201;
}
.nav-mobile-title:active { opacity: 0.7; background: #f5f6f7; }
.nav-mobile-title .nav-mobile-title-arrow {
  font-size: 11px;
  font-weight: 700;
  color: #666;
  margin-left: 2px;
  transition: transform 0.2s;
  display: inline-block;
}
.nav-mobile-title.open .nav-mobile-title-arrow {
  transform: rotate(180deg);
}

/* 移动端下拉面板 */
.nav-mobile-dropdown {
  display: none; flex-direction: column; gap: 2px;
  position: absolute; top: calc(100% + 8px); left: 0;
  min-width: 140px; background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  border: 1px solid #eef0f2;
  padding: 6px; z-index: 200;
}
.nav-mobile-title.open + .nav-mobile-dropdown {
  display: flex;
}
.nav-mobile-dropdown a {
  display: block; padding: 10px 14px;
  border-radius: 8px; font-size: 14px; color: #333;
  text-decoration: none; white-space: nowrap;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-mobile-dropdown a:hover,
.nav-mobile-dropdown a:active { background: #f5f6f7; }
.nav-mobile-dropdown a.active {
  background: #f0f1f2; font-weight: 600; color: #1a1a1a;
}

/* 下拉遮罩（点击空白处关闭，z-index 需低于 navbar 的 100） */
.nav-mobile-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 99;
}
.nav-mobile-backdrop.show { display: block; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .navbar { padding: 0 12px; height: 52px; }
  .nav-left { gap: 10px; }
  .nav-logo { font-size: 14px; }
  .nav-logo .logo-icon { width: 26px; height: 26px; }
  .nav-links { gap: 0; }
  .nav-links a { padding: 5px 8px; font-size: 12px; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ── Mobile (≤ 640px) — 下拉页签切换 ── */
@media (max-width: 640px) {
  .navbar {
    padding: 0 10px;
    height: 48px;
  }
  .nav-left {
    gap: 8px;
    min-width: 0;
    flex: 1 1 auto;
    overflow: visible; /* 关键：否则 overflow-x:auto 会导致 y 轴裁剪下拉面板 */
  }

  /* 隐藏桌面端链接，显示移动端下拉切换器 */
  .nav-links { display: none; }
  .nav-mobile-title-wrap {
    display: flex; align-items: center;
  }

  /* 右侧区域紧凑化 */
  .nav-right {
    gap: 6px;
    flex-shrink: 0;
  }
  .nav-user-area {
    gap: 6px;
  }

  /* 积分徽章缩小 */
  .nav-points-badge {
    padding: 2px 8px;
    font-size: 11px;
    white-space: nowrap;
  }

  /* 用户触发按钮：隐藏用户名文字，只保留头像+箭头 */
  .nav-user-trigger {
    padding: 2px 6px 2px 2px;
    gap: 4px;
  }
  .nav-username-text { display: none; }
  .nav-avatar-sm {
    width: 28px; height: 28px; font-size: 11px;
  }
  .nav-admin-badge { display: none; }
  .nav-dropdown-arrow { font-size: 9px; }
}

/* ── 极小屏 (< 380px) ── */
@media (max-width: 379px) {
  .navbar { padding: 0 8px; }
  .nav-points-badge { padding: 2px 6px; font-size: 10.5px; }
  .nav-mobile-title { font-size: 12px; padding: 4px 8px; }
}
