/**
 * PreKOSDAQ Mobile Responsive Styles
 * 모바일 반응형 디자인
 */

/* ===== 기본 모바일 최적화 ===== */
html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* 터치 영역 최적화 */
a, button, input, select, textarea {
  touch-action: manipulation;
}

/* ===== 태블릿 (768px ~ 1024px) ===== */
@media (max-width: 1024px) {
  .container {
    padding: 0 16px;
  }

  main {
    padding: 30px 16px;
  }

  /* 네비게이션 */
  nav.navbar .nav-menu a {
    padding: 8px 20px;
    font-size: 14px;
  }

  /* 그리드 3열 -> 2열 */
  .intro-page > div > div[style*="grid-template-columns: repeat(3"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ===== 모바일 (768px 이하) ===== */
@media (max-width: 768px) {
  /* PC 전용 메뉴 숨기기 */
  .desktop-only {
    display: none !important;
  }

  /* 모바일 전용 메뉴 표시 */
  li.mobile-only {
    display: list-item !important;
  }

  .mobile-only {
    display: block !important;
  }

  /* 네비게이션 바 */
  nav.navbar .container {
    height: 56px;
    padding: 0 12px;
  }

  nav.navbar .logo {
    font-size: 18px;
  }

  nav.navbar .nav-menu {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: auto;
    background: #fff;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    margin: 0;
    padding: 16px 20px;
    gap: 0;
    overflow-y: auto;
    z-index: 99;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
  }

  nav.navbar .nav-menu.active {
    display: flex;
  }

  nav.navbar .nav-menu li {
    width: 100%;
    border-bottom: 1px solid #eee;
  }

  nav.navbar .nav-menu a {
    padding: 16px 0;
    font-size: 16px;
    border-bottom: none;
  }

  nav.navbar .nav-menu a.active {
    background: transparent;
    color: var(--primary);
    border-radius: 0;
    padding: 16px 0;
  }

  nav.navbar .nav-actions {
    gap: 8px;
  }

  nav.navbar .btn-myinfo,
  nav.navbar .btn-logout {
    padding: 6px 10px;
    font-size: 12px;
  }

  /* 햄버거 메뉴 버튼 */
  .mobile-menu-btn {
    display: flex !important;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
  }

  .mobile-menu-btn span {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--text);
    transition: all 0.3s;
  }

  .mobile-menu-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
  }

  .mobile-menu-btn.active span:nth-child(2) {
    opacity: 0;
  }

  .mobile-menu-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
  }

  /* 메인 콘텐츠 */
  main {
    padding: 20px 12px;
  }

  .container {
    padding: 0 12px;
  }

  /* 페이지 헤더 */
  .page-header h1 {
    font-size: 22px;
  }

  .page-header p {
    font-size: 13px;
  }

  /* 게시판 테이블 */
  .board-table {
    font-size: 13px;
  }

  .board-table th,
  .board-table td {
    padding: 10px 8px;
  }

  .board-table .col-num,
  .board-table .col-views,
  .board-table .col-date {
    display: none;
  }

  /* 버튼 */
  .btn-write,
  .btn-primary,
  .btn-submit {
    padding: 12px 16px;
    font-size: 14px;
    width: 100%;
  }

  /* 폼 요소 */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  select,
  textarea {
    font-size: 16px !important; /* iOS 줌 방지 */
    padding: 12px;
  }

  /* 푸터 */
  .site-footer {
    padding: 16px 12px;
    font-size: 12px;
  }
}

/* ===== 소형 모바일 (480px 이하) ===== */
@media (max-width: 480px) {
  nav.navbar .container {
    height: 50px;
  }

  nav.navbar .logo {
    font-size: 16px;
  }

  main {
    padding: 16px 10px;
  }

  .page-header h1 {
    font-size: 20px;
  }

  /* 카드 그리드 1열 */
  .card-grid,
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* 플렉스 아이템 세로 정렬 */
  .board-header,
  [style*="display: flex"][style*="justify-content: space-between"] {
    flex-direction: column;
    gap: 12px;
    align-items: stretch !important;
  }

  /* 버튼 풀 너비 */
  .btn-write,
  .btn-primary,
  .btn-submit,
  button[type="submit"] {
    width: 100%;
  }
}

/* ===== 인트로 페이지 모바일 ===== */
@media (max-width: 768px) {
  /* 히어로 섹션 */
  .intro-page > div:first-child {
    padding: 40px 20px !important;
    border-radius: 12px !important;
  }

  .intro-page > div:first-child h1 {
    font-size: 28px !important;
  }

  .intro-page > div:first-child p {
    font-size: 14px !important;
  }

  /* 서비스 카드 그리드 */
  .intro-page [style*="grid-template-columns: repeat(3"] {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* 서비스 카드 */
  .intro-page [style*="border-radius: 12px"][style*="padding: 30px"] {
    padding: 20px !important;
  }

  .intro-page [style*="width: 70px"][style*="height: 70px"] {
    width: 50px !important;
    height: 50px !important;
    font-size: 20px !important;
  }

  .intro-page [style*="font-size: 20px"][style*="margin: 0 0 15px"] {
    font-size: 18px !important;
  }

  /* 이용 절차 */
  .intro-page [style*="display: flex"][style*="justify-content: space-between"] {
    flex-direction: column !important;
    gap: 20px !important;
  }

  .intro-page [style*="width: 50px"][style*="height: 50px"][style*="border-radius: 50%"] {
    width: 40px !important;
    height: 40px !important;
    font-size: 16px !important;
  }

  /* 전략 소개 섹션 */
  .intro-page [style*="grid-template-columns: repeat(2"] {
    grid-template-columns: 1fr !important;
  }
}

/* ===== 로그인/회원가입 페이지 모바일 ===== */
@media (max-width: 768px) {
  .auth-container,
  .login-container,
  .signup-container {
    padding: 20px 16px !important;
    margin: 20px auto !important;
    max-width: 100% !important;
  }

  .auth-container h1,
  .login-container h1,
  .signup-container h1 {
    font-size: 24px !important;
  }

  .form-group {
    margin-bottom: 16px;
  }

  .form-group label {
    font-size: 14px;
    margin-bottom: 6px;
  }
}

/* ===== 대시보드 모바일 ===== */
@media (max-width: 768px) {
  .dashboard-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }

  .stat-card {
    padding: 16px !important;
  }

  .stat-card .value {
    font-size: 20px !important;
  }

  .stat-card .label {
    font-size: 12px !important;
  }
}

@media (max-width: 480px) {
  .dashboard-stats {
    grid-template-columns: 1fr !important;
  }
}

/* ===== 계좌/종목 관리 페이지 모바일 ===== */
@media (max-width: 768px) {
  .account-info,
  .stock-list {
    padding: 16px !important;
  }

  .stock-item {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
    padding: 12px !important;
  }

  .stock-item .actions {
    width: 100%;
    display: flex;
    gap: 8px;
  }

  .stock-item .actions button {
    flex: 1;
  }
}

/* ===== 모달 모바일 ===== */
@media (max-width: 768px) {
  .modal-content,
  .modal-box,
  [class*="modal"] > div {
    width: 95% !important;
    max-width: none !important;
    margin: 10px !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
  }
}

/* ===== 테이블 모바일 최적화 ===== */
@media (max-width: 768px) {
  .responsive-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* 카드형 테이블 변환 */
  .board-table tbody tr {
    display: flex;
    flex-direction: column;
    border: 1px solid #eee;
    border-radius: 8px;
    margin-bottom: 12px;
    padding: 12px;
  }

  .board-table tbody td {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border: none;
    border-bottom: 1px solid #f5f5f5;
  }

  .board-table tbody td:last-child {
    border-bottom: none;
  }

  .board-table tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-light);
    font-size: 12px;
  }

  .board-table thead {
    display: none;
  }
}

/* ===== PWA 스탠드얼론 모드 ===== */
@media (display-mode: standalone) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  nav.navbar {
    padding-top: env(safe-area-inset-top);
  }
}

/* iOS 노치 대응 */
@supports (padding-top: env(safe-area-inset-top)) {
  body.pwa-standalone {
    padding-top: env(safe-area-inset-top);
  }

  body.pwa-standalone nav.navbar {
    padding-top: env(safe-area-inset-top);
  }

  body.pwa-standalone .site-footer {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

/* ===== 터치 피드백 ===== */
@media (hover: none) {
  a:active,
  button:active,
  .btn:active {
    opacity: 0.7;
    transform: scale(0.98);
  }

  /* 호버 효과 제거 (터치 디바이스) */
  a:hover,
  button:hover {
    opacity: 1;
  }
}

/* ===== 스크롤바 숨기기 (모바일) ===== */
@media (max-width: 768px) {
  ::-webkit-scrollbar {
    width: 0;
    height: 0;
  }
}

/* ===== 이미지 반응형 ===== */
img {
  max-width: 100%;
  height: auto;
}

/* ===== 비디오 반응형 ===== */
video,
iframe {
  max-width: 100%;
}

/* ===== 폰트 사이즈 조정 ===== */
@media (max-width: 480px) {
  html {
    font-size: 14px;
  }
}

/* ===== 하단 고정 버튼 (모바일) ===== */
.mobile-bottom-btn {
  display: none;
}

@media (max-width: 768px) {
  .mobile-bottom-btn {
    display: block;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    background: #fff;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 90;
  }

  .mobile-bottom-btn button {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
  }

  /* 하단 버튼 있을 때 콘텐츠 패딩 */
  body.has-bottom-btn main {
    padding-bottom: 80px;
  }
}

/* ===== 풀다운 새로고침 스타일 ===== */
.pull-to-refresh {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--bg-light);
  justify-content: center;
  align-items: center;
  z-index: 1000;
  transform: translateY(-100%);
  transition: transform 0.3s;
}

.pull-to-refresh.active {
  display: flex;
  transform: translateY(0);
}

.pull-to-refresh .spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #ddd;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===== 모바일에서 좌측 서브메뉴 숨기기 ===== */
@media (max-width: 768px) {
  /* 국내주식/해외주식/벤처투자 페이지의 좌측 서브메뉴 숨김 */
  .venture-sidebar,
  .sidebar-menu {
    display: none !important;
  }

  /* 서브메뉴 없을 때 컨텐츠 전체 너비로 */
  .venture-layout {
    display: block !important;
  }

  .venture-content {
    width: 100% !important;
    max-width: 100% !important;
  }
}
