/* ================================================
   style.css — Photo Cloud App モバイルファースト CSS
   ================================================ */

/* ---------- リセット & ベース ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-primary:      #6366f1;
  --color-primary-dark: #4f46e5;
  --color-primary-light:#eef2ff;
  --color-success:      #22c55e;
  --color-danger:       #ef4444;
  --color-warning:      #f59e0b;
  --color-bg:           #f8fafc;
  --color-surface:      #ffffff;
  --color-border:       #e2e8f0;
  --color-text:         #1e293b;
  --color-text-muted:   #64748b;
  --radius:             10px;
  --radius-lg:          16px;
  --shadow:             0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:          0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg:          0 8px 24px rgba(0,0,0,.1);
  --nav-height:         56px;
  --font-sans:          'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- ナビゲーション ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 0.75rem;
  box-shadow: var(--shadow);
}

.nav__menu-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.3rem;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
  border-radius: var(--radius);
  -webkit-tap-highlight-color: transparent;
}

.nav__brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--color-primary);
  white-space: nowrap;
  flex: 1;
}

.nav__links {
  display: flex;
  gap: 0.25rem;
  flex: 1;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.nav__link {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.nav__link:hover,
.nav__link.active {
  background: var(--color-primary-light);
  color: var(--color-primary);
  text-decoration: none;
}

.nav__logout {
  margin-left: auto;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--color-text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
  font-family: inherit;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.nav__logout:hover {
  background: #fee2e2;
  color: var(--color-danger);
}

.nav__back-link {
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--color-text-muted);
  text-decoration: none;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

.nav__back-link:hover {
  background: var(--color-bg);
  color: var(--color-primary);
  text-decoration: none;
}

/* ---------- ドロワーメニュー ---------- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.drawer-overlay.open {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 270px;
  max-width: 80vw;
  background: var(--color-surface);
  z-index: 300;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  visibility: hidden;
}

.drawer.open {
  transform: translateX(0);
  visibility: visible;
}

.drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

.drawer__title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-primary);
}

.drawer__close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.4rem;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  border-radius: var(--radius);
  -webkit-tap-highlight-color: transparent;
}

.drawer__nav {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 0;
  flex: 1;
}

.drawer__link {
  padding: 1rem 1.5rem;
  font-size: 0.95rem;
  color: var(--color-text);
  text-decoration: none;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  border: none;
  background: none;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
}

.drawer__link:hover,
.drawer__link.active {
  background: var(--color-primary-light);
  color: var(--color-primary);
  text-decoration: none;
}

.drawer__link--danger:hover {
  background: #fee2e2;
  color: var(--color-danger);
}

.drawer__footer {
  border-top: 1px solid var(--color-border);
  padding: 0.5rem 0;
}

/* ---------- ページレイアウト ---------- */
.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.75rem;
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
}

.page__title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

/* ---------- 写真グリッド（3列） ---------- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.photo-grid__item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 4px;
  background: var(--color-border);
  cursor: pointer;
}

.photo-grid__item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s;
}

.photo-grid__item:hover img {
  transform: scale(1.05);
}

.photo-grid__item--selected::after {
  content: '✓';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  background: var(--color-primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
}

/* ---------- カード ---------- */
.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

/* ---------- フォーム ---------- */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--color-text);
}

.form-control {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  border: none;
  min-height: 44px;
  min-width: 44px;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--color-primary);
  color: #fff;
}

.btn--primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

.btn--danger {
  background: #fee2e2;
  color: var(--color-danger);
}

.btn--danger:hover:not(:disabled) {
  background: #fecaca;
}

.btn--ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--color-bg);
}

.btn--block {
  width: 100%;
}

.btn--sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  min-height: 36px;
}

/* ---------- アラート ---------- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.alert--error {
  background: #fee2e2;
  color: #991b1b;
}

.alert--success {
  background: #dcfce7;
  color: #166534;
}

.alert--info {
  background: #dbeafe;
  color: #1e40af;
}

.alert--warning {
  background: #fef3c7;
  color: #92400e;
}

.alert.hidden {
  display: none;
}

/* ---------- ログイン画面 ---------- */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  background: linear-gradient(160deg, #eef2ff 0%, #faf5ff 50%, #f0fdf4 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 2.5rem 1.5rem;
  box-shadow: var(--shadow-lg);
}

.login-card__logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-card__logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
}

.login-card__logo p {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 0.35rem;
}

/* ---------- プログレスバー ---------- */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 0.35rem;
  text-align: center;
}

/* ---------- ローディング ---------- */
.loading {
  text-align: center;
  padding: 2rem;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 0.75rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- 空状態 ---------- */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--color-text-muted);
}

.empty-state__icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.empty-state__title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.5rem;
}

.empty-state__desc {
  font-size: 0.85rem;
}

/* ---------- フルスクリーン画像ビューア ---------- */
.viewer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.viewer.hidden { display: none; }

.viewer__img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.viewer__close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  min-width: 44px;
  min-height: 44px;
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer__actions {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.75rem;
}

/* ---------- アップロードエリア ---------- */
.upload-area {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: 2rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.upload-area:hover,
.upload-area--active {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.upload-area__icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.upload-area__text {
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

/* ---------- ツールバー ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.toolbar--secondary {
  margin-bottom: 1rem;
}

.toolbar__select {
  flex: 1;
  min-width: 0;
  max-width: 180px;
}

/* ---------- ソート切り替えボタン ---------- */
.sort-toggle {
  white-space: nowrap;
  font-size: 0.8rem;
  font-weight: 500;
}

/* ---------- フィルタータブ ---------- */
.filter-tabs {
  display: flex;
  gap: 0.35rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.filter-tab {
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.filter-tab:hover {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.filter-tab.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

/* ---------- モーダル ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 1.75rem 1.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.modal__title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

/* ---------- アルバムリスト ---------- */
.album-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* ---------- 動画オーバーレイアイコン ---------- */
.video-overlay-icon {
  position: absolute;
  bottom: 6px;
  left: 6px;
  width: 28px;
  height: 28px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  pointer-events: none;
}

.video-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  background: #374151;
  color: #9ca3af;
}

/* ---------- ユーティリティ ---------- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

/* ---------- レスポンシブ (375px以上でモバイルファースト) ---------- */
@media (min-width: 375px) {
  .login-card {
    padding: 2.5rem 2rem;
  }
}

@media (min-width: 768px) {
  .page {
    padding: 1.5rem 2rem 3rem;
  }

  .photo-grid {
    gap: 6px;
  }

  .photo-grid__item {
    border-radius: var(--radius);
  }

  .nav {
    padding: 0.5rem 1.5rem;
    gap: 1rem;
    flex-wrap: nowrap;
  }

  .nav__brand {
    font-size: 1.05rem;
  }

  .nav__link {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    min-height: 44px;
  }

  .nav__logout {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    min-height: 44px;
  }

  .toolbar__select {
    max-width: 200px;
  }
}

@media (min-width: 1024px) {
  .photo-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }
}

/* ---------- 選択モード ---------- */
.selection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  background: var(--color-primary-light);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.selection-bar__actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

#selectionCount {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-primary);
  white-space: nowrap;
}

/* 選択モード時のグリッドアイテム */
.photo-grid--select-mode .photo-grid__item {
  cursor: pointer;
}

.photo-grid__item.selected::after {
  content: '✓';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  background: var(--color-primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  z-index: 2;
}

.photo-grid--select-mode .photo-grid__item::before {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: 2px solid rgba(255,255,255,0.8);
  border-radius: 50%;
  z-index: 1;
}

.photo-grid__item.selected {
  outline: 3px solid var(--color-primary);
  outline-offset: -3px;
}
