/* ============================================
   KK Match — Mobile Responsive Stylesheet
   移动端自适应样式 — 零外部依赖
   ============================================ */

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --mobile-tap-size: 44px;
}

/* ============================================
   全局兜底：表单控件字体与可读性
   ============================================ */
.form-input,
input[type="text"],
input[type="date"],
input[type="time"],
input[type="email"],
input[type="number"],
select,
textarea {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif !important;
  font-size: 15px;
  color: #1f2937; /* gray-800 */
  background-color: #fff;
}

.form-input::placeholder,
input::placeholder {
  color: #9ca3af; /* gray-400 */
  font-family: inherit;
}

/* select 跨浏览器统一外观 */
select.form-input,
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath fill-rule='evenodd' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z' clip-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 36px !important;
}

/* ============================================
   BREAKPOINT: Tablet / Small Desktop (≤1024px)
   ============================================ */
@media (max-width: 1024px) {
  .max-w-6xl, .max-w-7xl {
    max-width: 100% !important;
    padding-left: 16px !important;
    padding-right: 16px !important;
  }
  
  main.max-w-6xl {
    padding: 32px 16px !important;
  }
}

/* ============================================
   BREAKPOINT: Mobile (≤768px)
   ============================================ */
@media (max-width: 768px) {
  /* ========== Base ========== */
  html {
    font-size: 15px;
    -webkit-tap-highlight-color: transparent;
  }
  
  body {
    padding-bottom: calc(60px + var(--safe-bottom));
    overflow-x: hidden;
  }
  
  /* ========== Header / Navigation ========== */
  header {
    position: sticky;
    top: 0;
    z-index: 60;
    padding: 0 !important;
  }
  
  header .max-w-6xl {
    padding: 8px 12px !important;
  }
  
  header .flex.items-center.justify-between {
    flex-wrap: nowrap;
    gap: 8px;
  }
  
  /* Stats - hide on mobile */
  header .hidden.md\\:flex {
    display: none !important;
  }
  
  /* Language selector - compact */
  #langSelectorWrapper button {
    padding: 6px 10px !important;
    font-size: 12px !important;
  }
  
  /* Logo section */
  header .w-12.h-12 {
    width: 36px !important;
    height: 36px !important;
  }
  header .w-12.h-12 svg {
    width: 20px !important;
    height: 20px !important;
  }
  header h1 {
    font-size: 18px !important;
  }
  header p {
    display: none;
  }
  
  /* ========== Hero Section ========== */
  #heroSection {
    margin-bottom: 40px !important;
    padding-top: 24px !important;
  }
  
  .hero-blob {
    display: none !important;
  }
  
  #heroSection h2 {
    font-size: 28px !important;
    line-height: 1.3 !important;
    margin-bottom: 16px !important;
  }
  
  #heroSection p {
    font-size: 14px !important;
    margin-bottom: 24px !important;
    max-width: 100% !important;
    padding: 0 8px !important;
  }
  
  /* ========== Feature Cards ========== */
  #featuresSection {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    margin-bottom: 32px !important;
  }
  
  .feature-icon {
    width: 44px !important;
    height: 44px !important;
    border-radius: 12px !important;
  }
  
  /* ========== Quick Match Section ========== */
  #quickMatchSection {
    border-radius: 20px !important;
    padding: 20px !important;
  }
  
  #quickMatchSection .grid.md\\:grid-cols-2 {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
  
  #quickMatchSection .grid.grid-cols-2 {
    grid-template-columns: 1fr 1fr !important;
  }

  /* ★ 表单内日期三列下拉（年/月/日）在移动端仍保持 3 列，不被全局规则压成单列 */
  #quickMatchSection .grid.grid-cols-3,
  #userAForm .grid.grid-cols-3,
  #profileForm .grid.grid-cols-3 {
    grid-template-columns: repeat(3, 1fr) !important;
  }
  
  /* User A&B panels */
  #quickMatchSection .bg-gradient-to-br {
    padding: 16px !important;
  }
  
  /* Form inputs - larger tap targets */
  .form-input,
  input[type="text"],
  input[type="date"],
  input[type="time"],
  select {
    font-size: 16px !important;  /* prevent iOS zoom */
    padding: 12px 16px !important;
    min-height: var(--mobile-tap-size);
  }
  
  /* Radio buttons */
  .peer-checked + div {
    padding: 12px !important;
  }
  
  /* Gender selection */
  label.flex-1 div {
    padding: 12px !important;
    min-height: var(--mobile-tap-size);
    font-size: 14px !important;
  }
  
  /* ========== Match Result ========== */
  #matchResultSection .rounded-2xl {
    padding: 16px !important;
  }
  
  /* Score cards grid */
  .grid.grid-cols-2.md\\:grid-cols-4 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  
  /* KK summary */
  .grid.md\\:grid-cols-2.gap-6 {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  
  /* Radar chart */
  .radar-container {
    width: 200px !important;
    height: 200px !important;
  }
  
  /* Stage cards */
  .grid.grid-cols-2.md\\:grid-cols-4.gap-4 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  
  /* Trajectory cards */
  .grid.md\\:grid-cols-2.gap-4.mt-4 {
    grid-template-columns: 1fr !important;
  }
  
  /* ========== Buttons - Larger Touch Targets ========== */
  .btn-primary,
  button[onclick] {
    min-height: var(--mobile-tap-size);
    padding: 12px 24px !important;
    font-size: 15px !important;
  }
  
  .btn-primary.px-10.py-4 {
    padding: 14px 28px !important;
    font-size: 16px !important;
  }
  
  /* ========== User B List ========== */
  #userBList {
    max-height: 240px !important;
  }
  
  #userBList > div {
    padding: 12px !important;
    min-height: var(--mobile-tap-size);
  }
  
  /* ========== Timeline ========== */
  .timeline-line {
    left: 6px !important;
  }
  
  /* ========== Modal ========== */
  .modal-overlay {
    padding: 12px !important;
    align-items: flex-end !important;
  }
  
  .modal-content {
    max-height: 85vh !important;
    width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    margin-bottom: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  
  /* ========== Feedback ========== */
  .feedback-container {
    padding: 16px !important;
  }
  
  .rating-stars {
    font-size: 28px !important;
  }
  
  /* ========== Mobile Bottom Navigation Bar ========== */
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    z-index: 50;
    box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.06);
  }
  
  .mobile-bottom-nav .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: #94a3b8;
    font-size: 10px;
    font-weight: 500;
    transition: color 0.2s;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
  }
  
  .mobile-bottom-nav .nav-item svg {
    width: 22px;
    height: 22px;
    transition: transform 0.2s;
  }
  
  .mobile-bottom-nav .nav-item.active {
    color: #6366f1;
  }
  
  .mobile-bottom-nav .nav-item.active svg {
    transform: scale(1.1);
  }
  
  .mobile-bottom-nav .nav-item:active {
    transform: scale(0.95);
    transition: transform 0.1s;
  }
  
  /* ========== Floating CTA (smaller screens) ========== */
  .mobile-floating-cta {
    display: flex;
    position: fixed;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 45;
    transition: transform 0.3s, opacity 0.3s;
  }
  
  .mobile-floating-cta.hidden {
    transform: translateX(-50%) translateY(20px);
    opacity: 0;
    pointer-events: none;
  }
  
  /* ========== Hamburger Menu ========== */
  .mobile-hamburger {
    display: block;
    width: var(--mobile-tap-size);
    height: var(--mobile-tap-size);
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
    position: relative;
    z-index: 70;
    -webkit-tap-highlight-color: transparent;
  }
  
  .mobile-hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: #475569;
    border-radius: 2px;
    transition: all 0.3s ease;
    position: absolute;
    left: 11px;
  }
  
  .mobile-hamburger span:nth-child(1) { top: 14px; }
  .mobile-hamburger span:nth-child(2) { top: 21px; }
  .mobile-hamburger span:nth-child(3) { top: 28px; }
  
  .mobile-hamburger.open span:nth-child(1) {
    top: 21px;
    transform: rotate(45deg);
  }
  .mobile-hamburger.open span:nth-child(2) {
    opacity: 0;
    transform: translateX(-10px);
  }
  .mobile-hamburger.open span:nth-child(3) {
    top: 21px;
    transform: rotate(-45deg);
  }
  
  /* Mobile side drawer */
  .mobile-drawer {
    position: fixed;
    top: 0;
    right: -100%;
    width: min(300px, 85vw);
    height: 100vh;
    height: 100dvh;
    background: white;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.1);
    z-index: 65;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 20px;
    padding-top: calc(20px + env(safe-area-inset-top, 0px));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .mobile-drawer.open {
    right: 0;
  }
  
  .mobile-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 64;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
  }
  
  .mobile-drawer-backdrop.open {
    opacity: 1;
    visibility: visible;
  }
  
  .mobile-drawer .drawer-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 12px;
    color: #475569;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    min-height: var(--mobile-tap-size);
  }
  
  .mobile-drawer .drawer-item:hover,
  .mobile-drawer .drawer-item:active {
    background: #f1f5f9;
    color: #6366f1;
  }
  
  .mobile-drawer .drawer-item svg {
    width: 20px;
    height: 20px;
  }
  
  /* ========== Charts ========== */
  canvas {
    max-width: 100% !important;
    height: auto !important;
  }
  
  /* ========== Typography ========== */
  .text-5xl, .text-6xl {
    font-size: 28px !important;
  }
  .text-4xl {
    font-size: 22px !important;
  }
  .text-3xl {
    font-size: 20px !important;
  }
  .text-2xl {
    font-size: 18px !important;
  }
  
  /* ========== Spacing ========== */
  .mb-20 { margin-bottom: 32px !important; }
  .mb-16 { margin-bottom: 24px !important; }
  .mb-12 { margin-bottom: 20px !important; }
  .mb-10 { margin-bottom: 16px !important; }
  .mb-8  { margin-bottom: 16px !important; }
  .py-12 { padding-top: 24px !important; padding-bottom: 24px !important; }
  .px-8  { padding-left: 16px !important; padding-right: 16px !important; }
  .px-10 { padding-left: 20px !important; padding-right: 20px !important; }
  .p-10  { padding: 20px !important; }
  
  /* ========== Scroll Optimization ========== */
  * {
    -webkit-overflow-scrolling: touch;
  }
  
  /* ========== Active State ========== */
  button:active,
  a:active,
  .card-hover:active,
  .nav-item:active {
    opacity: 0.8;
  }
  
  /* ========== Animation Performance ========== */
  .animate-fade-in,
  .animate-fade-left,
  .animate-fade-right,
  .animate-scale {
    animation-duration: 0.4s !important;
  }
  
  /* ========== Desktop-only (hide on mobile) ========== */
  .desktop-only {
    display: none !important;
  }
  
  /* ========== Visible scroll hint ========== */
  .scroll-hint {
    display: none;
  }
}

/* ============================================
   BREAKPOINT: Large Desktop (≥1025px) 
   Hide mobile elements
   ============================================ */
@media (min-width: 1025px) {
  .mobile-bottom-nav,
  .mobile-hamburger,
  .mobile-drawer,
  .mobile-drawer-backdrop,
  .mobile-floating-cta,
  .mobile-only {
    display: none !important;
  }
}

/* ============================================
   ADMIN DASHBOARD — Dark Theme Mobile
   ============================================ */
@media (max-width: 768px) {
  /* Hide desktop sidebar */
  body {
    background: var(--bg-base, #0a0e17) !important;
  }

  /* Sidebar → hidden on mobile, accessible via hamburger */
  .sidebar,
  [class*="sidebar"],
  nav[style*="position: fixed"][style*="left"] {
    transform: translateX(-100%) !important;
    transition: transform 0.3s ease !important;
    z-index: 70 !important;
    width: min(260px, 80vw) !important;
  }

  .sidebar.open,
  [class*="sidebar"].open {
    transform: translateX(0) !important;
  }

  /* Main content full width */
  main,
  .main-content,
  [style*="margin-left"] {
    margin-left: 0 !important;
    width: 100% !important;
    padding: 16px !important;
  }

  /* Admin metric cards */
  .dashboard-metrics {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  .metric-card {
    padding: 14px !important;
    border-radius: 12px !important;
  }

  .metric-card .text-3xl {
    font-size: 22px !important;
  }

  /* Charts */
  .chart-container {
    min-height: 220px !important;
    margin-bottom: 16px !important;
  }

  .chart-container canvas {
    max-height: 220px !important;
  }

  /* Table horizontal scroll */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  table thead,
  table tbody {
    display: table;
    width: 100%;
    min-width: 600px;
  }

  /* Card grids */
  .grid.grid-cols-3,
  .grid.grid-cols-4 {
    grid-template-columns: 1fr !important;
  }

  /* ★ Modal 内的 3 列下拉（年/月/日、时/分）始终保持 3 列，不被压成 1 列堆叠 */
  .modal-content .grid.grid-cols-3 {
    grid-template-columns: repeat(3, 1fr) !important;
  }
  .modal-content .grid.grid-cols-2 {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Admin header */
  header .text-xl,
  header .text-2xl {
    font-size: 16px !important;
  }

  /* Module status indicators */
  .status-grid {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  /* Footer/Sidebar Toggle */
  .sidebar-toggle-btn {
    display: flex !important;
    position: fixed;
    bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed, #06b6d4);
    box-shadow: 0 4px 16px rgba(124, 58, 237, 0.4);
    z-index: 50;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    color: white;
    transition: transform 0.2s;
  }

  .sidebar-toggle-btn:active {
    transform: scale(0.92);
  }
}

/* ============================================
   BREAKPOINT: Small Mobile (≤480px)
   ============================================ */
@media (max-width: 480px) {
  html { font-size: 14px; }
  
  header .w-12.h-12 {
    width: 32px !important;
    height: 32px !important;
  }
  
  header h1 {
    font-size: 16px !important;
  }
  
  #heroSection h2 {
    font-size: 24px !important;
  }
  
  .glass-card.rounded-3xl {
    border-radius: 16px !important;
  }
}
