/* MAL v4.3 モバイル最適化・レスポンシブデザイン */

/* PWA用メタタグとビューポート */
@viewport {
  width: device-width;
  initial-scale: 1;
  user-scalable: yes;
}

/* ベースレスポンシブ設定 */
* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  line-height: 1.6;
  overflow-x: hidden;
}

/* モバイル用フォントサイズ最適化 */
@media (max-width: 768px) {
  html {
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 13px;
  }
}

/* コンテナのレスポンシブ対応 */
.container {
  width: 100%;
  padding-left: 1rem;
  padding-right: 1rem;
  margin-left: auto;
  margin-right: auto;
}

@media (min-width: 640px) {
  .container { max-width: 640px; padding-left: 1.5rem; padding-right: 1.5rem; }
}

@media (min-width: 768px) {
  .container { max-width: 768px; padding-left: 2rem; padding-right: 2rem; }
}

@media (min-width: 1024px) {
  .container { max-width: 1024px; }
}

@media (min-width: 1280px) {
  .container { max-width: 1280px; }
}

/* ヘッダー・ナビゲーションのモバイル対応 */
.mobile-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: white;
  border-bottom: 1px solid #e5e7eb;
  padding: 0.75rem 1rem;
}

.mobile-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mobile-menu-button {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #374151;
}

@media (max-width: 768px) {
  .mobile-menu-button {
    display: block;
  }
  
  .desktop-nav {
    display: none;
  }
}

/* モバイル用サイドメニュー */
.mobile-sidebar {
  position: fixed;
  top: 0;
  left: -100%;
  width: 280px;
  height: 100vh;
  background: white;
  z-index: 100;
  transition: left 0.3s ease;
  box-shadow: 2px 0 10px rgba(0,0,0,0.1);
  overflow-y: auto;
}

.mobile-sidebar.open {
  left: 0;
}

.mobile-sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 90;
  display: none;
}

.mobile-sidebar-overlay.show {
  display: block;
}

.mobile-sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mobile-sidebar-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #6b7280;
}

.mobile-sidebar-menu {
  padding: 1rem 0;
}

.mobile-sidebar-item {
  display: block;
  padding: 0.75rem 1rem;
  color: #374151;
  text-decoration: none;
  border-bottom: 1px solid #f3f4f6;
  transition: background-color 0.2s;
}

.mobile-sidebar-item:hover {
  background-color: #f9fafb;
}

.mobile-sidebar-item i {
  margin-right: 0.75rem;
  width: 20px;
}

/* 検索フォームのモバイル最適化 */
.search-container {
  padding: 1rem;
}

@media (max-width: 768px) {
  .search-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  
  .search-form .form-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .search-form .form-group {
    flex: 1;
    min-width: 0;
  }
}

@media (max-width: 480px) {
  .search-form .form-row {
    flex-direction: column;
  }
}

/* 検索結果のモバイル対応 */
.property-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

@media (max-width: 768px) {
  .property-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
}

.property-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.property-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

@media (max-width: 768px) {
  .property-card {
    border-radius: 6px;
  }
  
  .property-card:hover {
    transform: none;
  }
}

.property-card-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  background: #f3f4f6;
}

@media (max-width: 768px) {
  .property-card-image {
    height: 160px;
  }
}

.property-card-content {
  padding: 1rem;
}

@media (max-width: 768px) {
  .property-card-content {
    padding: 0.75rem;
  }
}

.property-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #1f2937;
  line-height: 1.4;
}

@media (max-width: 768px) {
  .property-title {
    font-size: 1rem;
  }
}

.property-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.5rem;
  margin: 0.75rem 0;
}

@media (max-width: 480px) {
  .property-details {
    grid-template-columns: 1fr 1fr;
  }
}

.property-detail {
  display: flex;
  flex-direction: column;
  text-align: center;
  padding: 0.5rem;
  background: #f9fafb;
  border-radius: 4px;
}

.property-detail-label {
  font-size: 0.75rem;
  color: #6b7280;
  margin-bottom: 0.25rem;
}

.property-detail-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: #1f2937;
}

/* ボタンのモバイル最適化 */
.btn {
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
}

@media (max-width: 768px) {
  .btn {
    padding: 0.875rem 1.25rem;
    font-size: 1rem;
    min-height: 44px; /* タッチターゲット最小サイズ */
  }
}

.btn-primary {
  background: #2563eb;
  color: white;
}

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-secondary {
  background: #6b7280;
  color: white;
}

.btn-secondary:hover {
  background: #4b5563;
}

.btn-outline {
  background: transparent;
  border: 2px solid #d1d5db;
  color: #374151;
}

.btn-outline:hover {
  border-color: #2563eb;
  color: #2563eb;
}

/* フローティングアクションボタン（モバイル用） */
.fab {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  width: 56px;
  height: 56px;
  background: #2563eb;
  border-radius: 50%;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
}

@media (max-width: 768px) {
  .fab {
    display: flex;
  }
}

.fab:hover {
  background: #1d4ed8;
  transform: scale(1.1);
}

/* モーダル・ダイアログのモバイル対応 */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-content {
  background: white;
  border-radius: 8px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

@media (max-width: 768px) {
  .modal {
    align-items: flex-end;
    padding: 0;
  }
  
  .modal-content {
    border-radius: 16px 16px 0 0;
    max-height: 80vh;
    width: 100%;
  }
}

.modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid #e5e7eb;
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
}

@media (max-width: 480px) {
  .modal-footer {
    flex-direction: column;
  }
}

/* タブレット対応 */
@media (min-width: 769px) and (max-width: 1024px) {
  .container {
    padding-left: 2rem;
    padding-right: 2rem;
  }
  
  .property-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* スクロールバーの最適化 */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* タッチデバイス用の最適化 */
@media (pointer: coarse) {
  .btn, .property-card, .mobile-sidebar-item {
    min-height: 44px;
  }
  
  input, select, textarea {
    font-size: 16px; /* iOS Safariのズーム防止 */
  }
}

/* PWAスタンドアロンモード用スタイル */
@media (display-mode: standalone) {
  .pwa-only {
    display: block !important;
  }
  
  .web-only {
    display: none !important;
  }
  
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ダークモード対応 */
@media (prefers-color-scheme: dark) {
  body {
    background: #1f2937;
    color: #f9fafb;
  }
  
  .property-card {
    background: #374151;
    color: #f9fafb;
  }
  
  .mobile-sidebar {
    background: #374151;
  }
  
  .mobile-header {
    background: #1f2937;
    border-bottom-color: #4b5563;
  }
}

/* アニメーション設定 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* 印刷用スタイル */
@media print {
  .mobile-sidebar, .fab, .modal {
    display: none !important;
  }
  
  .property-grid {
    grid-template-columns: 1fr !important;
  }
  
  .property-card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #e5e7eb;
  }
}

/* ローディング状態 */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e5e7eb;
  border-top: 3px solid #2563eb;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* エラー状態 */
.error-message {
  background: #fef2f2;
  color: #dc2626;
  padding: 1rem;
  border-radius: 6px;
  border: 1px solid #fecaca;
  margin: 1rem 0;
}

@media (prefers-color-scheme: dark) {
  .error-message {
    background: #7f1d1d;
    color: #fca5a5;
    border-color: #991b1b;
  }
}

/* 成功状態 */
.success-message {
  background: #f0fdf4;
  color: #16a34a;
  padding: 1rem;
  border-radius: 6px;
  border: 1px solid #bbf7d0;
  margin: 1rem 0;
}

@media (prefers-color-scheme: dark) {
  .success-message {
    background: #14532d;
    color: #86efac;
    border-color: #166534;
  }
}