/* 网站响应式改造 CSS 框架 */

/* 1. 基础重置与变量 */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
  color: #222;
  background-color: #fff;
}

:root {
  --color-primary: #2176ff;
  --color-primary-dark: #1857b3;
  --color-text-main: #222;
  --color-text-muted: #666;
  --color-border: #e0e0e0;
  --color-bg-soft: #f7f8fa;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;

  --shadow-soft: 0 4px 12px rgba(0, 0, 0, 0.06);

  --space-2xs: 0.25rem;
  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;

  --container-max-width: 1200px;
}

/* 2. 断点体系 */
@media (max-width: 1200px) { }
@media (max-width: 992px) { }
@media (max-width: 768px) { }
@media (max-width: 576px) { }

/* 3. 排版基础 */
h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--space-md);
  font-weight: 600;
  color: var(--color-text-main);
}

p {
  margin: 0 0 var(--space-md);
  color: var(--color-text-main);
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

ul, ol {
  margin: 0 0 var(--space-md);
  padding-left: 1.5rem;
}

/* 4. 图片、视频、表格自适应 */
img, video {
  max-width: 100%;
  height: auto;
  display: block;
}

table {
  width: 100%;
  border-collapse: collapse;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

th, td {
  border: 1px solid var(--color-border);
  padding: 0.5rem;
}

/* 5. 布局容器 */
.container {
  width: 100%;
  max-width: var(--container-max-width);
  margin: 0 auto;
  padding-left: var(--space-md);
  padding-right: var(--space-md);
}

/* 6. Flex 工具类 */
.flex { display: flex; }
.flex-row { display: flex; flex-direction: row; }
.flex-column { display: flex; flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.items-center { align-items: center; }

.col { flex: 1 1 0; }
.col-2 { flex: 0 0 50%; }
.col-3 { flex: 0 0 33.3333%; }
.col-4 { flex: 0 0 25%; }

@media (max-width: 768px) {
  .col-2, .col-3, .col-4 {
    flex: 0 0 100%;
  }
}

/* 7. Grid 工具类 */
.grid {
  display: grid;
  gap: var(--space-md);
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
}

/* 8. 间距工具类 */
.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }

.mt-sm { margin-top: var(--space-sm) !important; }
.mt-md { margin-top: var(--space-md) !important; }
.mt-lg { margin-top: var(--space-lg) !important; }

.mb-sm { margin-bottom: var(--space-sm) !important; }
.mb-md { margin-bottom: var(--space-md) !important; }
.mb-lg { margin-bottom: var(--space-lg) !important; }

.p-sm { padding: var(--space-sm) !important; }
.p-md { padding: var(--space-md) !important; }
.p-lg { padding: var(--space-lg) !important; }

.px-md { padding-left: var(--space-md) !important; padding-right: var(--space-md) !important; }
.py-md { padding-top: var(--space-md) !important; padding-bottom: var(--space-md) !important; }

/* 9. 文本与显示工具类 */
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

.hidden { display: none !important; }
.d-block { display: block !important; }
.d-inline { display: inline !important; }
.d-flex { display: flex !important; }

@media (min-width: 769px) {
  .show-desktop { display: block !important; }
  .hide-desktop { display: none !important; }
}

@media (max-width: 768px) {
  .show-mobile { display: block !important; }
  .hide-mobile { display: none !important; }
}

/* 10. 响应式导航栏（含汉堡菜单） */
.header {
  border-bottom: 1px solid var(--color-border);
  background-color: #fff;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.logo {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-primary);
}

.nav {
  display: flex;
  gap: var(--space-md);
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav a {
  color: var(--color-text-main);
  padding: 0.25rem 0.5rem;
}

.menu-toggle {
  display: none;
  font-size: 1.5rem;
  cursor: pointer;
}

@media (max-width: 768px) {
  .header-inner {
    height: auto;
    padding-top: var(--space-sm);
    padding-bottom: var(--space-sm);
  }

  .nav {
    display: none;
    flex-direction: column;
    margin-top: var(--space-sm);
  }

  .nav.is-open {
    display: flex;
  }

  .menu-toggle {
    display: block;
    margin-left: 1rem;
  }

  /* Ensure proper spacing between user dropdown and menu toggle on mobile */
  .mobile-menu-container {
    display: flex;
    align-items: center;
  }

  /* Hide mobile nav buttons on desktop */
  @media (min-width: 769px) {
    .mobile-nav-buttons {
        display: none !important;
    }

    .mobile-user-dropdown {
        display: none !important;
    }
  }
}

/* 11. 按钮组件 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background-color: var(--color-primary);
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
}

.btn-outline {
  background-color: #fff;
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* 12. 卡片组件 */
.section {
  padding: var(--space-xl) 0;
}

.section-soft {
  background-color: var(--color-bg-soft);
}

.card {
  background-color: #fff;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  padding: var(--space-md);
  box-shadow: 0 2px 6px rgba(0,0,0,0.03);
}

.cards-grid {
  display: grid;
  gap: var(--space-md);
  grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 992px) {
  .cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .cards-grid {
    grid-template-columns: 1fr;
  }
}

/* 13. 全站移动端优化区 */
@media (max-width: 768px) {
  body {
    font-size: 0.95rem;
  }

  .container {
    padding-left: var(--space-sm);
    padding-right: var(--space-sm);
  }

  .two-column {
    flex-direction: column;
  }

  .hero-text {
    text-align: center;
  }

  .banner {
    height: auto;
    padding-top: var(--space-lg);
    padding-bottom: var(--space-lg);
  }

  /* Hide desktop login/register buttons on mobile, but keep user dropdown */
  #guest-menu {
    display: none !important;
  }

  /* Make sure user dropdown is visible on mobile */
  #user-info {
    display: flex !important;
  }



  /* Mobile user dropdown menu positioning fix */
  /* Position dropdown below the navbar on mobile */
  .user-dropdown {
    position: absolute;
    right: 1rem;
    top: 5.5rem; /* Adjusted to give more space for username */
    z-index: 10000; /* Ensure dropdown is on top */
  }

  /* Ensure full menu visibility on mobile */
  @media (max-width: 768px) {
    /* Make dropdown menu scrollable if content is long */
    .user-dropdown-menu {
      max-height: 80vh;
      overflow-y: auto;
      max-width: 90vw;
    }

    /* Hamburger menu container to prevent overflow */
    .nav-menu {
      max-height: calc(100vh - 8rem);
      overflow-y: auto;
    }
  }

  /* Improve dropdown appearance */
  .user-dropdown-menu {
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 1rem;
    min-width: 240px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.15);
  }

  /* Style dropdown items */
  .dropdown-item {
    color: #374151;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    transition: all 0.3s ease;
  }

  .dropdown-item:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
  }

  /* Ensure menu stays open when toggled */
  .user-dropdown-menu.active {
    display: block !important;
  }

  /* Improve filter buttons layout */
  .filter-bar {
    gap: 0.25rem !important;
    padding: 0.8rem !important;
    display: flex !important;
    flex-wrap: wrap;
    justify-content: center;
  }

  .filter-btn {
    flex: 1 1 45%; /* Two buttons per row on mobile */
    min-width: 100px;
    font-size: 0.85rem;
    padding: 0.6rem 0.8rem;
  }

  /* For very small screens */
  @media (max-width: 480px) {
    .filter-bar {
      gap: 0.3rem !important;
    }

    .filter-btn {
      flex: 1 1 48%; /* Two buttons per row on very small screens */
      min-width: 85px;
      font-size: 0.75rem;
      padding: 0.5rem 0.6rem;
    }

    /* Keep all buttons in rows on very small screens */
    .filter-btn:nth-child(1) {
      flex: 1 1 48%;
    }
  }

/* Fix logo text color for better visibility */
.logo {
    color: white !important;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

  /* Ensure menu toggle is visible */
  .menu-toggle {
    display: block !important;
  }

  /* 移动端粘性导航栏 - 上下滚动时保持可见 */
  .navbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 1000 !important;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.3);
    backdrop-filter: blur(10px);
  }

  /* 导航菜单容器 */
  @media (max-width: 768px) {
    /* 确保菜单打开时不被遮挡 */
    .nav-menu-container {
        position: relative;
        z-index: 999;
    }

    /* 改进汉堡菜单样式，使其在滚动时也可用 */
    .header-inner {
        position: sticky;
        top: 0;
        z-index: 1000;
    }

    /* 确保全屏菜单在打开时覆盖全屏并可滚动 */
    .nav.is-open {
        display: flex;
        position: fixed;
        top: 80px;
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
        background: linear-gradient(135deg, rgba(102, 126, 234, 0.95) 0%, rgba(118, 75, 162, 0.95) 100%);
        border-radius: 16px;
        padding: 1.5rem;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
        backdrop-filter: blur(15px);
        max-height: calc(100vh - 100px);
        overflow-y: auto;
    }
}

  /* User info in hamburger menu */
  .nav-menu-user-info {
    border-top: 1px solid var(--color-border);
    padding: var(--space-md) 0;
    margin-top: var(--space-md);
  }

  #username-display-mobile {
    color: var(--color-text-main) !important;
    font-weight: 600;
  }

  /* Ensure user info is hidden on desktop and visible on mobile when menu is active */
  @media (min-width: 769px) {
    .nav-menu-user-info {
      display: none !important;
    }
  }

  @media (max-width: 768px) {
    /* Show user info in mobile hamburger menu */
    .nav-menu.active .nav-menu-user-info {
      display: block !important;
      margin: 1rem 0;
      padding: 0.5rem 1rem;
      border-top: 1px solid rgba(255, 255, 255, 0.1);
      border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

        /* 鸽子信息管理部分 - 移动端修复 */
        /* 按钮容器布局修复 */
        .section-header {
        flex-direction: column !important;
        gap: 1rem !important;
        align-items: stretch !important;
    }

    .section-header div {
        width: 100% !important;
        flex-wrap: wrap !important;
        justify-content: space-between !important;
    }

    .section-header .btn {
        flex: 1 1 calc(32% - 0.33rem) !important;
        padding: 0.6rem !important;
        font-size: 0.85rem !important;
    }

        /* 确保按钮可见 */
        #all-pigeons-btn, #my-pigeons-btn, #add-pigeon-btn {
        display: inline-block !important;
        opacity: 1 !important;
    }
  }

  /* 小屏幕移动端进一步优化 */
  @media (max-width: 480px) {
        .section-header div {
        justify-content: center !important;
        gap: 0.5rem !important;
    }

    .section-header .btn {
        flex: 1 1 calc(48% - 0.25rem) !important;
    }
  }
}
