/* app.css - 管理画面・共通スタイル（素朴だがスマホでも崩れないこと） */

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Hiragino Sans", Meiryo, sans-serif;
  background: #f4f5f7;
  color: #222;
  line-height: 1.6;
}

.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
}

.page-header h1 {
  font-size: 1.25rem;
  margin: 0;
}

.card {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 1.05rem;
  margin-top: 0;
}

label {
  display: block;
  font-weight: bold;
  margin-top: 12px;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

input[type="text"],
input[type="password"],
input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #bbb;
  border-radius: 6px;
  font-size: 1rem;
}

.expire-fieldset {
  border: 1px solid #ddd;
  border-radius: 6px;
  margin-top: 12px;
  padding: 10px 12px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: normal;
  margin: 6px 0;
}

.expire-days-input {
  width: 80px;
  display: inline-block;
}

.btn {
  display: inline-block;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  margin-top: 12px;
}

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

.btn-secondary {
  background: #e5e7eb;
  color: #222;
}

.btn-danger {
  background: #dc2626;
  color: #fff;
}

.inline-form {
  margin: 0;
}

.alert {
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 16px;
}

.alert-error {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
}

.alert-error ul {
  margin: 0;
  padding-left: 20px;
}

.alert-success {
  background: #dcfce7;
  border: 1px solid #86efac;
  color: #166534;
}

.share-url-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.share-url-input {
  flex: 1;
  min-width: 160px;
  font-size: 0.85rem;
}

.btn-copy {
  margin-top: 0;
  white-space: nowrap;
}

.table-scroll {
  overflow-x: auto;
}

.event-table {
  width: 100%;
  border-collapse: collapse;
}

.event-table th,
.event-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid #eee;
  vertical-align: middle;
  font-size: 0.9rem;
}

.event-table th {
  background: #f9fafb;
  font-weight: bold;
}

.login-card {
  max-width: 360px;
  margin: 48px auto;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.8rem;
  margin-top: 0;
}

/* ---- ファイル管理: アップロードエリア ---- */

.upload-area {
  border: 2px dashed #9ca3af;
  border-radius: 8px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  color: #555;
  transition: background 0.15s, border-color 0.15s;
}

.upload-area:hover,
.upload-area.dragover {
  background: #eff6ff;
  border-color: #2563eb;
}

.upload-area p {
  margin: 4px 0;
}

.upload-area-hint {
  font-size: 0.8rem;
  color: #888;
}

.upload-progress {
  margin-top: 16px;
}

.progress-bar {
  width: 100%;
  height: 10px;
  background: #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0;
  background: #2563eb;
  transition: width 0.2s;
}

#progress-label {
  font-size: 0.85rem;
  color: #555;
  margin: 6px 0;
}

.upload-result-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}

.upload-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid #eee;
  font-size: 0.85rem;
}

.upload-result-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-result-status {
  white-space: nowrap;
  color: #888;
}

.upload-result-success .upload-result-status {
  color: #166534;
}

.upload-result-fail .upload-result-status {
  color: #991b1b;
}

.upload-retry-btn {
  white-space: nowrap;
}

/* ---- ファイル管理: ファイル一覧グリッド ---- */

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.file-grid-empty {
  margin-top: 16px;
  color: #888;
}

.file-card {
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #fafafa;
}

.file-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  overflow: hidden;
  background: #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: center;
}

.file-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.file-thumb-video {
  color: #6b7280;
  font-size: 0.85rem;
  font-weight: bold;
}

.file-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.75rem;
}

.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: bold;
}

.file-size {
  color: #888;
}

/* ---- 閲覧側: パスコード入力画面 ---- */

.passcode-page {
  max-width: 360px;
  margin: 48px auto;
  padding: 16px;
}

.passcode-card {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 20px;
  text-align: center;
}

.passcode-card h1 {
  font-size: 1.1rem;
  margin-top: 0;
}

.passcode-card input[type="text"] {
  text-align: center;
  letter-spacing: 0.2em;
  font-size: 1.3rem;
}

/* ---- 閲覧側: ギャラリー ---- */

.gallery-page {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px;
}

.gallery-header {
  padding: 8px 4px 16px;
  text-align: center;
}

.gallery-header h1 {
  font-size: 1.2rem;
  margin: 0 0 4px;
  word-break: break-word;
}

.gallery-count {
  color: #666;
  font-size: 0.85rem;
  margin: 0 0 12px;
}

.btn-zip {
  display: inline-block;
}

.btn-zip-disabled {
  display: inline-block;
  background: #e5e7eb;
  color: #999;
  cursor: not-allowed;
  margin-top: 12px;
}

.gallery-zip-hint {
  font-size: 0.8rem;
  color: #888;
  margin: 8px auto 0;
  max-width: 480px;
}

.gallery-empty {
  text-align: center;
  color: #888;
  padding: 40px 0;
}

/* タップ領域を確保しつつ画面幅で自動的に2〜3列になるグリッド */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 6px;
}

@media (min-width: 480px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
  }
}

.grid-item {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
}

.grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.grid-item-placeholder,
.grid-item-broken {
  background: #d1d5db;
}

.grid-item-placeholder::after,
.grid-item-broken::after {
  content: "";
}

.grid-play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid-play-icon::before {
  content: "";
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 12px 0 12px 20px;
  border-color: transparent transparent transparent rgba(255, 255, 255, 0.9);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.gallery-sentinel {
  height: 1px;
}

/* ---- 閲覧側: 全画面ビューア ---- */

.viewer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  touch-action: pan-y pinch-zoom;
}

body.viewer-open {
  overflow: hidden;
}

.viewer-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1001;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.viewer-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 0;
}

.viewer-stage img,
.viewer-stage video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  touch-action: none;
  transition: transform 0.1s ease-out;
}

.viewer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  gap: 12px;
}

.viewer-counter {
  color: #eee;
  font-size: 0.85rem;
}

.viewer-save-btn {
  margin-top: 0;
}

/* スマホ幅ではテーブルをカード状に積み替える */
@media (max-width: 640px) {
  .event-table thead {
    display: none;
  }
  .event-table, .event-table tbody, .event-table tr, .event-table td {
    display: block;
    width: 100%;
  }
  .event-table tr {
    border: 1px solid #eee;
    border-radius: 6px;
    margin-bottom: 10px;
    padding: 6px 10px;
  }
  .event-table td {
    border-bottom: none;
    padding: 6px 0;
  }
  .event-table td::before {
    content: attr(data-label);
    display: block;
    font-weight: bold;
    font-size: 0.75rem;
    color: #666;
  }
}
