:root { color-scheme: light dark; }
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Yu Gothic", Meiryo, sans-serif;
  background: #f5f5f5;
  color: #222;
}

/* ===== ログイン画面 ===== */
.login-wrap {
  max-width: 360px;
  margin: 12vh auto;
  padding: 24px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .08);
}
.login-wrap h1 { font-size: 1.25rem; margin: 0 0 8px; }
.lead { color: #666; font-size: .9rem; margin: 0 0 16px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: #444; }
.login-form input { padding: 10px; font-size: 1rem; border: 1px solid #ccc; border-radius: 8px; }
.login-form button {
  padding: 12px; font-size: 1rem; border: 0; border-radius: 8px;
  background: #2b6cb0; color: #fff; cursor: pointer;
}
.login-form button:hover { background: #2559a0; }
.error {
  color: #c53030; background: #fff5f5; border: 1px solid #feb2b2;
  padding: 8px 10px; border-radius: 8px; font-size: .85rem; margin: 0 0 4px;
}

/* ===== 写真一覧画面 ===== */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: #fff; border-bottom: 1px solid #e2e2e2;
  position: sticky; top: 0; z-index: 10; font-size: .9rem;
}
.topbar .logout { font-size: .85rem; color: #2b6cb0; text-decoration: none; }
.topbar .logout:hover { text-decoration: underline; }

.photos-main { padding: 16px; max-width: 1200px; margin: 0 auto; }
.guide {
  font-size: .9rem; color: #555; line-height: 1.7;
  background: #fffbea; border: 1px solid #f6e05e;
  padding: 12px 14px; border-radius: 8px; margin: 0 0 4px;
}
.empty { color: #777; text-align: center; padding: 40px; }

/*
  写真の並び（グリッド）
  左から右へ行単位で並べる（1,2,3 が上段に左から並ぶ）。
  縦横比は保ったまま（正方形に切り抜かない）なので、顔が端でも切れない（仕様書 §4(B)）。
*/
.masonry {
  display: grid;
  grid-template-columns: repeat(2, 1fr);   /* スマホ縦：2列 */
  gap: 10px;
  align-items: start;    /* 縦横比が違っても各写真は上揃え */
  margin-top: 16px;
}
@media (min-width: 768px)  { .masonry { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1200px) { .masonry { grid-template-columns: repeat(4, 1fr); } }

.tile {
  margin: 0;
  position: relative;
}
.tile img {
  width: 100%;
  height: auto;          /* 縦横比を保つ */
  display: block;
  border-radius: 8px;
  background: #ddd;      /* 読み込み中の背景 */
  cursor: zoom-in;
}

/* 選択された写真は枠と少し暗くして分かるように */
.tile.selected img {
  outline: 3px solid #2b6cb0;
  outline-offset: -3px;
}
.tile.selected::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: 8px;
  background: rgba(43, 108, 176, .18);
  pointer-events: none;
}

/* 各写真の「選択」ボタン（右上） */
.select-btn {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 10px; border: 0; border-radius: 999px;
  background: rgba(255, 255, 255, .92); color: #2b6cb0;
  font-size: .8rem; font-weight: 600; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}
.select-btn .check {
  display: inline-grid; place-items: center;
  width: 16px; height: 16px; border-radius: 50%;
  border: 1.5px solid currentColor; font-size: .7rem; line-height: 1;
  color: transparent;
}
.tile.selected .select-btn { background: #2b6cb0; color: #fff; }
.tile.selected .select-btn .check { border-color: #fff; color: #fff; }

/* ===== 管理：登録済み写真の一覧＋削除 ===== */
.photos-manage { margin-top: 26px; }
.pm-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
}
.pm-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ap-check {
  position: absolute; top: 6px; left: 6px; z-index: 2;
  background: rgba(255, 255, 255, .9); border-radius: 6px;
  padding: 3px 4px; display: flex; box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
.ap-check input { width: 20px; height: 20px; cursor: pointer; margin: 0; }
.admin-photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px; margin-top: 12px;
}
.ap-tile { position: relative; margin: 0; }
.ap-tile img {
  width: 100%; height: 140px; object-fit: cover;
  border-radius: 8px; background: #ddd; display: block;
}
.ap-del {
  position: absolute; top: 6px; right: 6px;
  width: 30px; height: 30px; border: 0; border-radius: 50%;
  background: rgba(200, 30, 30, .88); color: #fff;
  font-size: 1.1rem; line-height: 1; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
.ap-del:hover { background: rgba(170, 20, 20, 1); }

/* ===== 下部の送信バー ===== */
.submitbar {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: #fff;
  border-top: 1px solid #e2e2e2; box-shadow: 0 -2px 10px rgba(0, 0, 0, .06);
}
.submitbar .count { font-size: .95rem; }
.submitbar .count strong { font-size: 1.1rem; color: #2b6cb0; }
.submitbar .hint { font-size: .78rem; color: #777; flex: 1 1 auto; }
.submitbar .submit {
  padding: 12px 18px; border: 0; border-radius: 8px;
  background: #2b6cb0; color: #fff; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.submitbar .submit:hover { background: #2559a0; }
.guide .note { color: #b7791f; }

/* ===== 拡大表示（ライトボックス） ===== */
.lightbox {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, .85);
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 82vw; max-height: 66vh;
  object-fit: contain; border-radius: 6px; background: #333;
}
.lb-close {
  position: absolute; top: 14px; right: 16px;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .18); color: #fff; font-size: 1.7rem;
  line-height: 1; cursor: pointer; z-index: 3;
}
.lb-close:hover { background: rgba(255, 255, 255, .3); }

/* 前へ／次へ の矢印（左右・大きめ・タップしやすく） */
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 68px; height: 68px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .22); color: #fff;
  font-size: 2.6rem; line-height: 1; cursor: pointer; z-index: 3;
  display: flex; align-items: center; justify-content: center;
  padding-bottom: 4px; /* ‹ › の視覚的な中央合わせ */
  -webkit-tap-highlight-color: transparent;
}
.lb-nav:hover { background: rgba(255, 255, 255, .38); }
.lb-nav:active { background: rgba(255, 255, 255, .5); }
.lb-prev { left: 14px; }
.lb-next { right: 14px; }
.lb-nav[hidden] { display: none; }
@media (max-width: 480px) {
  .lb-nav { width: 60px; height: 60px; font-size: 2.3rem; }
  .lb-prev { left: 8px; }
  .lb-next { right: 8px; }
  .lightbox img { max-width: 88vw; }
}

/* 「写っています」ボタンは画面下部に離して配置（誤タップ防止） */
.lb-actions {
  position: absolute; left: 0; right: 0; bottom: 26px;
  display: flex; justify-content: center; z-index: 3;
}
.lb-toggle {
  padding: 16px 26px; border: 2px solid #fff; border-radius: 999px;
  background: rgba(0, 0, 0, .45); color: #fff; font-size: 1.05rem; font-weight: 700;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.lb-toggle.on { background: #2b6cb0; border-color: #2b6cb0; }

/* ===== 送信確認ダイアログ ===== */
.dialog-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(0, 0, 0, .5);
}
.dialog-overlay[hidden] { display: none; }
.dialog {
  background: #fff; border-radius: 12px; padding: 22px;
  max-width: 360px; width: 100%; box-shadow: 0 8px 30px rgba(0, 0, 0, .3);
}
.dialog p { margin: 0 0 18px; font-size: .95rem; line-height: 1.6; }
.dialog-buttons { display: flex; gap: 10px; justify-content: flex-end; }
.dialog-buttons button {
  padding: 10px 16px; border-radius: 8px; font-size: .95rem; cursor: pointer;
}
.dialog-buttons .cancel { border: 1px solid #ccc; background: #fff; color: #444; }
.dialog-buttons .ok { border: 0; background: #2b6cb0; color: #fff; font-weight: 600; }
.dialog-buttons .ok:disabled { opacity: .6; cursor: default; }

/* ===== 送信完了画面 ===== */
.done-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.done-card {
  background: #fff; border-radius: 14px; padding: 34px 28px; text-align: center;
  max-width: 420px; width: 100%; box-shadow: 0 2px 14px rgba(0, 0, 0, .08);
}
.done-icon {
  width: 64px; height: 64px; margin: 0 auto 16px;
  display: grid; place-items: center; border-radius: 50%;
  background: #2f855a; color: #fff; font-size: 2rem;
}
.done-card h1 { font-size: 1.3rem; margin: 0 0 10px; }
.done-lead { font-size: 1rem; margin: 0 0 6px; }
.done-sub { color: #666; font-size: .88rem; margin: 0 0 22px; line-height: 1.6; }
.done-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.btn-secondary {
  display: inline-block; padding: 10px 16px; border-radius: 8px;
  border: 1px solid #2b6cb0; color: #2b6cb0; text-decoration: none; font-size: .9rem;
}
.btn-secondary:hover { background: #eef4fb; }

/* ===== 管理画面（ステップ3） ===== */
.topbar .back { font-size: .85rem; color: #2b6cb0; text-decoration: none; }
.topbar .back:hover { text-decoration: underline; }

.admin-main { padding: 16px; max-width: 1000px; margin: 0 auto; }

/* 上部サマリー */
.summary { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.summary-card {
  flex: 1 1 120px; background: #fff; border: 1px solid #e2e2e2; border-radius: 10px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 2px;
}
.summary-card .num { font-size: 1.5rem; font-weight: 700; color: #222; line-height: 1.2; }
.summary-card .cap { font-size: .78rem; color: #777; }
.summary-card.warn .num { color: #b7791f; }
.summary-card.alert { border-color: #feb2b2; background: #fff5f5; }
.summary-card.alert .num { color: #c53030; }

/* 一覧テーブル */
.admin-table {
  width: 100%; border-collapse: collapse; background: #fff;
  border: 1px solid #e2e2e2; border-radius: 10px; overflow: hidden; font-size: .9rem;
}
.admin-table th, .admin-table td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid #eee;
}
.admin-table thead th {
  background: #fafafa; font-size: .78rem; color: #666; font-weight: 600;
}
.admin-table tbody tr:last-child td { border-bottom: 0; }
.admin-table tbody tr:hover { background: #f7fafc; }
.admin-table .name { font-weight: 600; }
.admin-table .num-col { text-align: right; white-space: nowrap; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: .85em; }
.muted { color: #bbb; }
.row-link { color: #2b6cb0; text-decoration: none; font-weight: 600; }
.row-link:hover { text-decoration: underline; }
.pending-dot { color: #c53030; font-size: .78rem; font-weight: 700; margin-left: 4px; }

/* 状態バッジ */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: .76rem; font-weight: 600; white-space: nowrap;
}
.badge.small { font-size: .72rem; padding: 2px 8px; }
.badge.gray  { background: #edf2f7; color: #4a5568; }
.badge.blue  { background: #ebf4ff; color: #2b6cb0; }
.badge.green { background: #f0fff4; color: #2f855a; }
.badge.red   { background: #fff5f5; color: #c53030; }

/* 詳細ヘッダー */
.detail-head { margin-bottom: 14px; }
.detail-head h1 { font-size: 1.3rem; margin: 0 0 6px; }
.detail-meta { color: #666; font-size: .85rem; margin: 0 0 10px; }

/* 申告写真グリッド */
.report-grid {
  display: grid; gap: 14px; margin-top: 16px;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
.report-tile {
  margin: 0; background: #fff; border: 1px solid #e2e2e2; border-radius: 10px;
  overflow: hidden; display: flex; flex-direction: column;
}
.report-tile img { width: 100%; height: auto; display: block; background: #ddd; }
.report-tile.handled { opacity: .7; }
.report-tile.handled img { filter: grayscale(.4); }
.report-tile figcaption {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px;
}
.report-tile .fname { color: #666; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.handle-btn {
  margin: 0 10px 10px; padding: 9px; border: 0; border-radius: 8px;
  background: #2f855a; color: #fff; font-size: .88rem; font-weight: 600; cursor: pointer;
}
.handle-btn:hover { background: #276749; }
.handle-btn.undo { background: #fff; color: #718096; border: 1px solid #cbd5e0; }
.handle-btn.undo:hover { background: #f7fafc; }

/* ===== 管理ナビ（ステップ4） ===== */
.admin-nav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.admin-nav a { font-size: .85rem; color: #4a5568; text-decoration: none; }
.admin-nav a:hover { text-decoration: underline; }
.admin-nav a.current { color: #2b6cb0; font-weight: 700; }
.page-title { font-size: 1.3rem; margin: 4px 0 10px; }

/* アップロード画面 */
.dropzone {
  border: 2px dashed #cbd5e0; border-radius: 12px; background: #fff;
  padding: 32px 20px; text-align: center; transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: #2b6cb0; background: #eef4fb; }
.dz-main { font-size: 1rem; font-weight: 600; margin: 0 0 4px; }
.dz-sub { color: #999; font-size: .82rem; margin: 6px 0; }
.dz-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.dz-btn {
  display: inline-block; padding: 10px 18px; border-radius: 8px; cursor: pointer;
  background: #2b6cb0; color: #fff; font-size: .9rem; font-weight: 600;
}
.dz-btn:hover { background: #2559a0; }
.dz-btn.secondary { background: #fff; color: #2b6cb0; border: 1px solid #2b6cb0; }
.dz-btn.secondary:hover { background: #eef4fb; }
.dz-selected { margin: 14px 0 0; font-size: .9rem; color: #2b6cb0; font-weight: 600; min-height: 1.2em; }
.upload-submit {
  margin-top: 16px; padding: 12px 20px; border: 0; border-radius: 8px;
  background: #2f855a; color: #fff; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.upload-submit:hover { background: #276749; }
.upload-submit:disabled { background: #a0aec0; cursor: default; }
.upload-result {
  background: #f0fff4; border: 1px solid #9ae6b4; border-radius: 10px;
  padding: 12px 14px; margin-bottom: 16px; font-size: .9rem;
}
.upload-result .skip-head { color: #b7791f; margin: 8px 0 4px; }
.skip-list { margin: 0; padding-left: 20px; color: #a0522d; font-size: .84rem; }

/* パネル（設定・アカウント） */
.panel {
  background: #fff; border: 1px solid #e2e2e2; border-radius: 12px;
  padding: 18px; margin-bottom: 18px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-actions { display: flex; gap: 14px; align-items: center; }
.panel-title { font-size: 1.05rem; margin: 0 0 10px; }
.panel-head .panel-title { margin: 0; }
.settings-form {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-top: 6px;
}
.settings-form label { display: flex; flex-direction: column; gap: 5px; font-size: .8rem; color: #555; }
.settings-form input {
  padding: 9px 10px; border: 1px solid #ccc; border-radius: 8px; font-size: .95rem; min-width: 180px;
}
.settings-form button {
  padding: 10px 18px; border: 0; border-radius: 8px;
  background: #2b6cb0; color: #fff; font-size: .92rem; font-weight: 600; cursor: pointer;
}
.settings-form button:hover { background: #2559a0; }

/* アカウント一覧の編集セル */
.th-note { font-weight: 400; color: #aaa; font-size: .72rem; }
.cell-input {
  width: 100%; padding: 6px 8px; border: 1px solid #ddd; border-radius: 6px; font-size: .88rem;
}
.row-actions { display: flex; gap: 6px; white-space: nowrap; }
.mini-btn {
  padding: 6px 12px; border: 0; border-radius: 6px; font-size: .82rem; font-weight: 600;
  cursor: pointer; background: #2b6cb0; color: #fff;
}
.mini-btn:hover { background: #2559a0; }
.mini-btn.danger { background: #fff; color: #c53030; border: 1px solid #feb2b2; }
.mini-btn.danger:hover { background: #fff5f5; }

/* リマインド画面 */
.note-guide { background: #fffbea; border-color: #f6e05e; }
.mail-body {
  width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 8px;
  font-size: .92rem; line-height: 1.7; color: #333; background: #fafafa; resize: vertical;
  font-family: inherit;
}
.reminder-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

@media print {
  .topbar, .settings-form, .panel-head button, .row-actions, .error { display: none !important; }
  .panel { border: 0; padding: 0; }
  body { background: #fff; }
}
