/**
 * Mobile-Specific UI Components for Sunflower
 * モバイルデバイス専用のUIコンポーネント
 */

/* ========================================
   Base Mobile Styles
   ======================================== */

/* モバイルファーストのレスポンシブ基準 */
@media (max-width: 768px) {
  :root {
    --mobile-padding: 1rem;
    --mobile-margin: 0.5rem;
    --mobile-border-radius: 8px;
    --mobile-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --mobile-tap-target: 44px;
    --mobile-font-size: 14px;
    --mobile-line-height: 1.5;
  }
  
  body {
    font-size: var(--mobile-font-size);
    line-height: var(--mobile-line-height);
    padding: 0;
    margin: 0;
  }
}

/* ========================================
   Mobile Navigation Components
   ======================================== */

/* モバイル用ボトムナビゲーション */
.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  z-index: 1000;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.mobile-bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  text-decoration: none;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  min-width: var(--mobile-tap-target);
  min-height: var(--mobile-tap-target);
  border-radius: var(--mobile-border-radius);
}

.mobile-bottom-nav-item:hover,
.mobile-bottom-nav-item.active {
  color: var(--primary-color);
  background: rgba(var(--primary-color-rgb), 0.1);
}

.mobile-bottom-nav-item i {
  font-size: 1.2rem;
  margin-bottom: 4px;
}

.mobile-bottom-nav-item span {
  font-size: 0.75rem;
  font-weight: 500;
}

/* モバイル用ハンバーガーメニュー */
.mobile-hamburger {
  display: none;
  flex-direction: column;
  justify-content: space-around;
  width: 24px;
  height: 24px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  z-index: 1001;
}

.mobile-hamburger span {
  display: block;
  height: 3px;
  width: 100%;
  background: var(--text-primary);
  border-radius: 10px;
  transition: all 0.3s ease;
}

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

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

.mobile-hamburger.active span:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -6px);
}

/* モバイルメニューオーバーレイ */
.mobile-menu-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.mobile-menu-overlay.active {
  display: block;
  opacity: 1;
}

.mobile-menu {
  position: fixed;
  top: 0;
  right: -100%;
  width: 280px;
  height: 100vh;
  background: var(--bg-primary);
  z-index: 1000;
  transition: right 0.3s ease;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
  overflow-y: auto;
}

.mobile-menu.active {
  right: 0;
}

.mobile-menu-header {
  padding: 2rem 1rem 1rem;
  border-bottom: 1px solid var(--border-light);
  background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
  color: white;
}

.mobile-menu-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
}

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

.mobile-menu-item {
  display: flex;
  align-items: center;
  padding: 1rem;
  text-decoration: none;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-light);
  transition: all var(--transition-fast);
}

.mobile-menu-item:hover {
  background: var(--bg-muted);
  color: var(--primary-color);
}

.mobile-menu-item i {
  margin-right: 1rem;
  width: 20px;
  text-align: center;
}

/* ========================================
   Mobile Card Components
   ======================================== */

/* モバイル用カードレイアウト */
@media (max-width: 768px) {
  .mobile-card {
    background: var(--bg-primary);
    border-radius: var(--mobile-border-radius);
    box-shadow: var(--mobile-shadow);
    margin: var(--mobile-margin);
    overflow: hidden;
    transition: all var(--transition-fast);
  }
  
  .mobile-card:active {
    transform: scale(0.98);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  }
  
  .mobile-card-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-light);
    background: linear-gradient(135deg, rgba(var(--primary-color-rgb), 0.05), rgba(var(--primary-color-rgb), 0.02));
  }
  
  .mobile-card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
  }
  
  .mobile-card-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0.25rem 0 0 0;
  }
  
  .mobile-card-body {
    padding: 1rem;
  }
  
  .mobile-card-footer {
    padding: 0.75rem 1rem;
    background: var(--bg-muted);
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}

/* ========================================
   Mobile Form Components
   ======================================== */

@media (max-width: 768px) {
  .mobile-form-group {
    margin-bottom: 1.5rem;
  }
  
  .mobile-form-label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    font-size: 0.875rem;
  }
  
  .mobile-form-input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-light);
    border-radius: var(--mobile-border-radius);
    font-size: 1rem;
    transition: all var(--transition-fast);
    -webkit-appearance: none;
    appearance: none;
  }
  
  .mobile-form-input:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-color-rgb), 0.1);
  }
  
  .mobile-form-textarea {
    resize: vertical;
    min-height: 100px;
  }
  
  .mobile-form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
  }
}

/* ========================================
   Mobile Button Components
   ======================================== */

@media (max-width: 768px) {
  .mobile-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--mobile-border-radius);
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: var(--mobile-tap-target);
    min-width: var(--mobile-tap-target);
    position: relative;
    overflow: hidden;
  }
  
  .mobile-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transition: width 0.6s, height 0.6s, top 0.6s, left 0.6s;
    transform: translate(-50%, -50%);
  }
  
  .mobile-btn:active::before {
    width: 300px;
    height: 300px;
    top: 50%;
    left: 50%;
  }
  
  .mobile-btn-primary {
    background: var(--primary-color);
    color: white;
  }
  
  .mobile-btn-primary:hover {
    background: var(--primary-dark);
  }
  
  .mobile-btn-secondary {
    background: var(--secondary-color);
    color: white;
  }
  
  .mobile-btn-outline {
    background: transparent;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
  }
  
  .mobile-btn-outline:hover {
    background: var(--primary-color);
    color: white;
  }
  
  .mobile-btn-full {
    width: 100%;
  }
  
  .mobile-btn-lg {
    padding: 1rem 2rem;
    font-size: 1.125rem;
  }
  
  .mobile-btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
  }
}

/* ========================================
   Mobile List Components
   ======================================== */

@media (max-width: 768px) {
  .mobile-list {
    background: var(--bg-primary);
    border-radius: var(--mobile-border-radius);
    box-shadow: var(--mobile-shadow);
    overflow: hidden;
  }
  
  .mobile-list-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-light);
    text-decoration: none;
    color: var(--text-primary);
    transition: all var(--transition-fast);
    min-height: var(--mobile-tap-target);
  }
  
  .mobile-list-item:last-child {
    border-bottom: none;
  }
  
  .mobile-list-item:active {
    background: var(--bg-muted);
  }
  
  .mobile-list-icon {
    margin-right: 1rem;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--primary-color-rgb), 0.1);
    border-radius: 50%;
    color: var(--primary-color);
  }
  
  .mobile-list-content {
    flex: 1;
  }
  
  .mobile-list-title {
    font-weight: 600;
    margin: 0 0 0.25rem 0;
    font-size: 1rem;
  }
  
  .mobile-list-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
  }
  
  .mobile-list-action {
    margin-left: 1rem;
    color: var(--text-muted);
  }
}

/* ========================================
   Mobile Video Components
   ======================================== */

@media (max-width: 768px) {
  .mobile-video-container {
    position: relative;
    width: 100%;
    margin: var(--mobile-margin) 0;
    border-radius: var(--mobile-border-radius);
    overflow: hidden;
    box-shadow: var(--mobile-shadow);
  }
  
  .mobile-video {
    width: 100%;
    height: auto;
    display: block;
  }
  
  .mobile-video-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    padding: 2rem 1rem 1rem;
    color: white;
  }
  
  .mobile-video-progress {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    margin-bottom: 1rem;
    overflow: hidden;
  }
  
  .mobile-video-progress-bar {
    height: 100%;
    background: var(--primary-color);
    border-radius: 2px;
    transition: width 0.2s ease;
  }
  
  .mobile-video-buttons {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  
  .mobile-video-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.25rem;
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-fast);
    min-width: var(--mobile-tap-target);
    min-height: var(--mobile-tap-target);
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .mobile-video-btn:active {
    background: rgba(255, 255, 255, 0.2);
  }
}

/* ========================================
   Mobile Dashboard Components
   ======================================== */

@media (max-width: 768px) {
  .mobile-dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--mobile-margin);
    padding: var(--mobile-padding);
  }
  
  .mobile-metric-card {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: white;
    padding: 1.5rem;
    border-radius: var(--mobile-border-radius);
    text-align: center;
    box-shadow: var(--mobile-shadow);
  }
  
  .mobile-metric-value {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    display: block;
  }
  
  .mobile-metric-label {
    font-size: 0.875rem;
    opacity: 0.9;
  }
  
  .mobile-chart-container {
    background: var(--bg-primary);
    border-radius: var(--mobile-border-radius);
    padding: 1rem;
    box-shadow: var(--mobile-shadow);
    margin: var(--mobile-margin) 0;
  }
  
  .mobile-chart-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    text-align: center;
    color: var(--text-primary);
  }
}

/* ========================================
   Mobile Interaction Helpers
   ======================================== */

@media (max-width: 768px) {
  /* タッチ対応要素 */
  .touch-friendly {
    min-height: var(--mobile-tap-target);
    min-width: var(--mobile-tap-target);
    padding: 0.75rem;
  }
  
  /* スワイプ可能要素 */
  .swipeable {
    touch-action: pan-x;
    user-select: none;
    -webkit-user-select: none;
  }
  
  /* プルトゥリフレッシュ対応 */
  .pull-to-refresh-container {
    position: relative;
    overflow: hidden;
  }
  
  /* モバイル専用表示/非表示 */
  .mobile-only {
    display: block;
  }
  
  .desktop-only {
    display: none;
  }
  
  /* タッチ時のハイライト除去 */
  .no-highlight {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
  
  /* モバイル用の間隔調整 */
  .mobile-mt-0 { margin-top: 0; }
  .mobile-mt-1 { margin-top: var(--mobile-margin); }
  .mobile-mt-2 { margin-top: calc(var(--mobile-margin) * 2); }
  
  .mobile-mb-0 { margin-bottom: 0; }
  .mobile-mb-1 { margin-bottom: var(--mobile-margin); }
  .mobile-mb-2 { margin-bottom: calc(var(--mobile-margin) * 2); }
  
  .mobile-p-0 { padding: 0; }
  .mobile-p-1 { padding: var(--mobile-padding); }
  .mobile-p-2 { padding: calc(var(--mobile-padding) * 2); }
}

/* ========================================
   Desktop Override
   ======================================== */

@media (min-width: 769px) {
  .mobile-only {
    display: none;
  }
  
  .desktop-only {
    display: block;
  }
  
  .mobile-bottom-nav {
    display: none;
  }
  
  .mobile-hamburger {
    display: none;
  }
}

/* ========================================
   Animations for Mobile
   ======================================== */

@media (max-width: 768px) {
  @keyframes mobileSlideIn {
    from {
      transform: translateX(100%);
      opacity: 0;
    }
    to {
      transform: translateX(0);
      opacity: 1;
    }
  }
  
  @keyframes mobileSlideOut {
    from {
      transform: translateX(0);
      opacity: 1;
    }
    to {
      transform: translateX(-100%);
      opacity: 0;
    }
  }
  
  @keyframes mobileFadeIn {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  @keyframes mobileScaleIn {
    from {
      transform: scale(0.8);
      opacity: 0;
    }
    to {
      transform: scale(1);
      opacity: 1;
    }
  }
  
  .mobile-slide-in {
    animation: mobileSlideIn 0.3s ease-out;
  }
  
  .mobile-slide-out {
    animation: mobileSlideOut 0.3s ease-out;
  }
  
  .mobile-fade-in {
    animation: mobileFadeIn 0.4s ease-out;
  }
  
  .mobile-scale-in {
    animation: mobileScaleIn 0.3s ease-out;
  }
}

/* ========================================
   Dark Mode Support for Mobile
   ======================================== */

@media (max-width: 768px) and (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-muted: #404040;
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --text-muted: #808080;
    --border-light: #404040;
  }
  
  .mobile-card {
    background: var(--bg-secondary);
  }
  
  .mobile-form-input {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-light);
  }
  
  .mobile-list {
    background: var(--bg-secondary);
  }
  
  .mobile-menu {
    background: var(--bg-primary);
  }
}