/* ========================================
   手機增強樣式 - 確保在所有手機上完美顯示
   ======================================== */

/* ========== 防止橫向滾動 ========== */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

/* ========== 觸控優化 ========== */
a, button, .btn, .link, .nav-link {
  -webkit-tap-highlight-color: rgba(74, 144, 226, 0.2);
  touch-action: manipulation;
}

/* ========== 圖片響應式 ========== */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ========== 漢堡選單按鈕 - 桌面版完全隱藏 (最高權重) ========== */
@media (min-width: 992px) {
  body .navbar .navbar-toggler,
  body .navbar-toggler,
  .navbar-toggler {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
  }
  
  body .navbar .navbar-toggler-text,
  .navbar-toggler-text {
    display: none !important;
  }
}

/* ========== 導航欄手機優化 ========== */
@media (max-width: 991px) {
  /* 漢堡選單按鈕顯示 */
  .navbar-toggler {
    display: flex !important;
    align-items: center;
    border: 1px solid rgba(0,0,0,.1);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
  }
  
  /* 漢堡選單文字樣式 */
  .navbar-toggler-text {
    font-size: 14px;
    font-weight: 500;
    color: #333;
    margin-left: 8px;
    display: inline-block;
  }
  
  .navbar-toggler:hover {
    background-color: rgba(74, 144, 226, 0.1);
  }
  
  .navbar-toggler:hover .navbar-toggler-text {
    color: #4A90E2;
  }
  
  .navbar-collapse {
    background: white;
    padding: 1rem;
    margin-top: 1rem;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  }
  
  .navbar-nav {
    align-items: stretch;
  }
  
  .nav-item {
    margin: 0.25rem 0;
  }
  
  .nav-link {
    padding: 0.75rem 1rem !important;
    border-radius: 8px;
  }
  
  .nav-link:hover {
    background: rgba(74, 144, 226, 0.1);
  }
  
  .dropdown-menu {
    border: none;
    box-shadow: none;
    background: transparent;
    padding: 0;
  }
  
  .dropdown-item {
    padding: 0.5rem 1.5rem;
    border-radius: 8px;
    margin: 0.25rem 0;
  }
  
  .nav-link-ai {
    text-align: center;
    display: block;
  }
}

/* ========== 表格手機優化 ========== */
@media (max-width: 768px) {
  .table-responsive {
    border: 1px solid var(--border-color, #E0E0E0);
    border-radius: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .table {
    min-width: 600px;
    font-size: 0.875rem;
  }
  
  .table thead th {
    position: sticky;
    top: 0;
    background: var(--bg-light, #F8F9FA);
    z-index: 10;
  }
}

/* ========== 網格系統手機優化 ========== */
@media (max-width: 768px) {
  .row {
    margin-left: -10px;
    margin-right: -10px;
  }
  
  [class*="col-"] {
    padding-left: 10px;
    padding-right: 10px;
  }
  
  .col-md-3, .col-md-4, .col-md-6 {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

/* ========== 卡片手機優化 ========== */
@media (max-width: 768px) {
  .card {
    margin-bottom: 1.5rem;
  }
  
  .card img {
    height: auto;
    min-height: 200px;
    max-height: 250px;
  }
  
  .card-body {
    padding: 1rem;
  }
}

/* ========== 按鈕手機優化 ========== */
@media (max-width: 576px) {
  .btn {
    width: 100%;
    margin: 0.5rem 0;
  }
  
  .btn-group {
    display: flex;
    flex-direction: column;
  }
  
  .btn-group .btn {
    border-radius: 25px !important;
    margin: 0.25rem 0;
  }
}

/* ========== 文字手機優化 ========== */
@media (max-width: 576px) {
  body {
    font-size: 0.9375rem;
    line-height: 1.5;
  }
  
  h1, .title {
    font-size: 1.5rem !important;
  }
  
  h2, .title2 {
    font-size: 1.25rem !important;
    display: block !important;
    width: 100% !important;
  }
  
  h3, .title3 {
    font-size: 1.125rem !important;
    display: block !important;
    width: 100% !important;
  }
  
  /* 保留有 text-center 類別的標題居中對齊 */
  .text-center.title2,
  .text-center.title3,
  .title2.text-center,
  .title3.text-center {
    text-align: center !important;
  }
  
  p {
    font-size: 0.9375rem;
  }
}

/* ========== 間距手機優化 ========== */
@media (max-width: 768px) {
  .container {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  
  .section, .activity, .member, .professor {
    padding: 1rem 0;
  }
  
  /* 減少首個區塊的上邊距，避免導航欄和內容之間空白過多 */
  .newest:first-of-type,
  .about:first-of-type,
  .research:first-of-type,
  .reward:first-of-type {
    padding-top: 0.5rem !important;
  }
  
  .mt-5, .my-5 { margin-top: 2rem !important; }
  .mb-5, .my-5 { margin-bottom: 2rem !important; }
}

/* ========== 輪播手機優化 ========== */
@media (max-width: 768px) {
  .carousel {
    border-radius: 0 0 12px 12px;
  }
  
  .carousel-control-prev,
  .carousel-control-next {
    width: 10%;
  }
  
  .carousel-indicators {
    bottom: 10px;
  }
  
  .carousel-indicators li {
    width: 8px;
    height: 8px;
    margin: 0 4px;
  }
  
  .carousel-indicators li.active {
    width: 24px;
  }
}

/* ========== 頁腳手機優化 ========== */
@media (max-width: 576px) {
  footer {
    padding: 1.5rem 0;
    font-size: 0.875rem;
  }
  
  footer p {
    margin: 0.5rem 0;
  }
}

/* ========== 表單手機優化 ========== */
@media (max-width: 768px) {
  input, textarea, select {
    font-size: 16px !important; /* 防止 iOS 自動縮放 */
  }
  
  .form-control {
    padding: 0.75rem;
  }
}

/* ========== 模態框手機優化 ========== */
@media (max-width: 576px) {
  .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100% - 1rem);
  }
  
  .modal-content {
    border-radius: 12px;
  }
}

/* ========== 導航固定優化 ========== */
@media (max-width: 768px) {
  .fixed-top {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 9999 !important;
    background-color: #fff !important; /* 確保背景白色不透明 */
  }
  
  body {
    padding-top: 120px !important; /* 再次增加空間，確保 Banner 不會被遮住 */
  }
}

/* ========== 手勢支援 ========== */
@media (hover: none) and (pointer: coarse) {
  /* 觸控設備 */
  .card:hover {
    transform: none; /* 移除懸停效果 */
  }
  
  .card:active {
    transform: scale(0.98);
  }
  
  .btn:hover::before {
    display: none;
  }
  
  .btn:active {
    transform: scale(0.95);
  }
}

/* ========== iOS 安全區域 ========== */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }
  
  .fixed-top {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }
  
  footer {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

/* ========== 橫向模式優化 ========== */
@media (max-width: 768px) and (orientation: landscape) {
  .navbar-brand img {
    height: 55px;
  }
  
  body {
    padding-top: 60px;
  }
  
  .section, .activity, .member {
    padding: 1.5rem 0;
  }
}

/* ========== 效能優化 ========== */
@media (max-width: 768px) {
  /* 移除全域 transform，避免破壞 fixed 定位 */
  .card, .btn, .nav-link {
    will-change: transform;
  }
}

/* ========== 可訪問性增強 ========== */
@media (max-width: 768px) {
  /* 增加觸控目標大小 */
  a, button, .btn, .link {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  
  /* 增加對比度 */
  .text-secondary {
    color: #495057 !important;
  }
}

