/**
 * 与 application/index/view/common/header.html 配套：顶栏、下拉、登录/注册弹窗。
 * 在需引入 common/header 的页面中 link 本文件，并加载 /static/js/auth-modal.js。
 */
:root {
  --brand-50: #fff6f1;
  --brand-100: #ffe9dd;
  --brand-400: #ffab80;
  --brand-500: #ff8a5b;
  --brand-600: #e56d3f;
  --ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
  --text: #111827;
  --text-muted: #6b7280;
  --border: rgba(17, 24, 39, 0.08);
  --topbar-height: 80px;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  width: 100%;
  max-width: 100vw;
  overflow-x: clip;
  backdrop-filter: blur(18px);
  background: rgba(255, 255, 255, 0.72);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  font-family: "Inter", "Noto Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar-inner {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  text-decoration: none;
  color: var(--text);
  flex-shrink: 1;
}

.brand-logo {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.brand-title {
  font-weight: 700;
  font-size: 18px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--brand-600);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.topbar-menu-btn:hover {
  background: var(--brand-50);
  border-color: rgba(255, 138, 91, 0.35);
}

.topbar-menu-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(255, 138, 91, 0.2);
}

.topbar-menu-btn__bars {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 20px;
}

.topbar-menu-btn__bars span {
  display: block;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  transition: transform 0.25s var(--ease-spring), opacity 0.2s, width 0.25s;
}

.topbar.is-nav-open .topbar-menu-btn__bars span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.topbar.is-nav-open .topbar-menu-btn__bars span:nth-child(2) {
  opacity: 0;
  width: 0;
}

.topbar.is-nav-open .topbar-menu-btn__bars span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.topbar-nav-backdrop {
  display: none;
}

.topbar .nav {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  min-width: 0;
}

.topbar .nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: color 0.25s;
}

.topbar .nav a:hover {
  color: var(--text);
}

.topbar .nav a.is-active {
  color: var(--brand-600);
  font-weight: 700;
  position: relative;
}

.topbar .nav a.is-active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -6px;
  height: 2px;
  border-radius: 999px;
  background: var(--brand-500);
}

.topbar-right {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.user-menu {
  position: relative;
  display: inline-block;
}

.user-menu::after {
  content: "";
  position: absolute;
  top: 100%;
  right: 0;
  width: 224px;
  height: 14px;
  z-index: 59;
}

.user-menu > .avatar-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  background: none;
  outline: none;
  transition: box-shadow 0.3s;
}

.user-menu:hover > .avatar-btn,
.user-menu:focus-within > .avatar-btn {
  box-shadow: 0 0 0 2px rgba(255, 138, 91, 0.4);
}

.user-menu > .avatar-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  display: block;
}

#user-dropdown {
  position: absolute;
  z-index: 60;
  top: calc(100% + 12px);
  right: 0;
  left: auto;
  margin: 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 224px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(18px);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.08);
  opacity: 0;
  transform: translateY(-8px) scale(0.96);
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.2s var(--ease-spring), transform 0.2s var(--ease-spring), visibility 0.2s;
}

.user-menu:hover #user-dropdown,
.user-menu:focus-within #user-dropdown {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  visibility: visible;
}

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

.topbar .auth-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  border-radius: 25vw;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, border-color 0.2s, filter 0.2s;
  white-space: nowrap;
}

.topbar .auth-btn-ghost {
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid var(--border);
}

.topbar .auth-btn-ghost:hover {
  color: var(--text);
  border-color: rgba(255, 138, 91, 0.35);
  background: var(--brand-50);
}

.topbar .auth-btn-primary {
  color: #fff;
  border: 0;
  background: linear-gradient(135deg, var(--brand-400), var(--brand-600));
  box-shadow: 0 4px 14px rgba(255, 138, 91, 0.35);
}

.topbar .auth-btn-primary:hover {
  box-shadow: 0 6px 18px rgba(255, 138, 91, 0.45);
  filter: brightness(1.03);
}

.topbar .user-auth .auth-btn {
  font: inherit;
  cursor: pointer;
}

.topbar .user-auth .auth-btn-ghost {
  border: 1px solid var(--border);
}

.auth-modal {
  padding: 0;
  border: none;
  border-radius: 18px;
  max-width: 420px;
  width: calc(100vw - 32px);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.18);
  font-family: "Inter", "Noto Sans SC", sans-serif;
}

.auth-modal::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(6px);
}

.auth-modal-panel {
  padding: 24px 24px 20px;
  position: relative;
}

.auth-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #9ca3af;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.auth-modal-close:hover {
  background: #f3f4f6;
  color: #374151;
}

.auth-modal-title {
  margin: 0 0 16px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.auth-form-msg {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.auth-form-msg[hidden] {
  display: none !important;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-label {
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin-top: 4px;
}

.auth-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-input:focus {
  outline: none;
  border-color: rgba(255, 138, 91, 0.55);
  box-shadow: 0 0 0 3px rgba(255, 138, 91, 0.2);
}

.auth-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.auth-submit {
  margin-top: 8px;
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--brand-400), var(--brand-600));
  box-shadow: 0 6px 18px rgba(255, 138, 91, 0.35);
  transition: filter 0.2s, box-shadow 0.2s;
}

.auth-submit:hover {
  filter: brightness(1.03);
}

.auth-submit:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.auth-modal-footer {
  margin: 16px 0 0;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.auth-text-btn {
  display: inline;
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--brand-600);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.auth-text-btn:hover {
  color: var(--brand-500);
}

.auth-captcha-row .input-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.auth-captcha-row .form-control.auth-input {
  flex: 1 1 140px;
  min-width: 0;
}

.auth-captcha-row .btn-captcha {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 10px;
  border: 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--brand-500);
  color: #fff;
  text-decoration: none;
}

.auth-captcha-row img[onclick] {
  border-radius: 8px;
  cursor: pointer;
  vertical-align: middle;
}

.auth-login-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 18px;
  border-radius: 12px;
  padding: 4px;
  background: rgba(17, 24, 39, 0.06);
}

.auth-login-tab {
  flex: 1;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  background: transparent;
  transition: background 0.2s, color 0.2s;
}

.auth-login-tab.is-active {
  color: var(--brand-600);
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.dropdown-head {
  padding: 8px 10px;
  border-bottom: 1px solid #f0f2f5;
  margin-bottom: 6px;
}

.dropdown-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.dropdown-mail {
  margin: 2px 0 0;
  font-size: 12px;
  color: #6b7280;
}

.dropdown-link {
  display: block;
  text-decoration: none;
  font-size: 14px;
  color: #374151;
  padding: 8px 10px;
  border-radius: 10px;
  transition: background 0.2s, color 0.2s;
}

.dropdown-link:hover {
  background: var(--brand-50);
  color: var(--brand-600);
}

.dropdown-link.danger {
  color: #dc2626;
  margin-top: 4px;
}

.dropdown-link.danger:hover {
  background: #fef2f2;
}

.footer {
  margin-top: 40px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.65);
}

.footer-inner {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
  font-size: 14px;
}

.footer-inner p {
  margin: 0;
}

body.topbar-nav-open {
  overflow: hidden;
}

@media (max-width: 991px) {
  :root {
    --topbar-height: 64px;
  }

  .container {
    padding: 0 16px;
  }

  .topbar .container.topbar-inner,
  .topbar .topbar-inner {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .topbar-inner {
    height: var(--topbar-height);
    gap: 6px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, max-content) 44px;
    grid-template-areas: "brand actions menu";
    align-items: center;
  }

  .topbar .brand {
    grid-area: brand;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
  }

  .topbar-right {
    grid-area: actions;
    min-width: 0;
    max-width: 100%;
    gap: 8px;
  }

  .topbar .user-auth {
    min-width: 0;
    gap: 6px;
  }

  .topbar-menu-btn {
    grid-area: menu;
    display: inline-flex;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
  }

  .brand-title {
    font-size: 14px;
  }

  .topbar .auth-btn {
    padding: 6px 10px;
    font-size: 12px;
  }

  .topbar-nav-backdrop {
    display: block;
    position: fixed;
    inset: var(--topbar-height) 0 0 0;
    z-index: 48;
    background: rgba(15, 23, 42, 0.38);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s, visibility 0.25s;
  }

  .topbar.is-nav-open .topbar-nav-backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .topbar-nav-backdrop[hidden] {
    display: block;
  }

  .topbar .nav {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    z-index: 49;
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 2px;
    max-height: calc(100dvh - var(--topbar-height));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px 16px 18px;
    background: rgba(255, 255, 255, 0.98);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.1);
    transform: translateY(-12px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.28s var(--ease-spring), opacity 0.22s, visibility 0.22s;
  }

  .topbar.is-nav-open .nav {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .topbar .nav a {
    padding: 13px 12px;
    font-size: 15px;
    border-radius: 10px;
  }

  .topbar .nav a:hover {
    background: var(--brand-50);
  }

  .topbar .nav a.is-active::after {
    left: 0;
    right: auto;
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 22px;
    border-radius: 0 999px 999px 0;
  }

  .user-menu > .avatar-btn {
    width: 36px;
    height: 36px;
  }
}

@media (max-width: 420px) {
  .topbar .user-auth .auth-btn-primary {
    display: none;
  }

  .topbar .user-auth .auth-btn-ghost {
    padding: 7px 12px;
    font-size: 13px;
  }
}

@media (max-width: 360px) {
  .topbar .brand-title {
    display: none;
  }
}
