/* Photo Wow — mobile-first UI. No build step (ADR-004). */
:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #17202a;
  --muted: #6b7480;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #dc2626;
  --border: #e3e6ea;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --card: #1a2028;
    --text: #eef1f4;
    --muted: #98a2ad;
    --border: #2a323c;
  }
}

/* Phase 6.2 curated album themes (app.albums.presentation picks the
   theme_key from the cover photo's own signals; the actual colors here
   are fixed/curated, never derived from the photo itself, so contrast
   is a design-time guarantee -- see that module's docstring). Applied
   via data-theme on the hero/album container. --hero-gradient-* are
   dark enough that --hero-text (white) clears WCAG AA for large text
   (>=3:1) regardless of the underlying cover photo's own brightness. */
:root {
  --hero-gradient-start: #1f2937;
  --hero-gradient-end: #111827;
  --hero-text: #ffffff;
}
[data-theme="nordic"] {
  --accent: #5b7a99;
  --accent-dark: #46617d;
  --hero-gradient-start: #3a4a5c;
  --hero-gradient-end: #1c242d;
}
[data-theme="sea"] {
  --accent: #1a7fb0;
  --accent-dark: #146089;
  --hero-gradient-start: #0d3b52;
  --hero-gradient-end: #0a2233;
}
[data-theme="forest"] {
  --accent: #3f8452;
  --accent-dark: #2f6a40;
  --hero-gradient-start: #1f4429;
  --hero-gradient-end: #12281a;
}
[data-theme="sunset"] {
  --accent: #d9713c;
  --accent-dark: #b8551f;
  --hero-gradient-start: #7a2e3a;
  --hero-gradient-end: #3d1a24;
}
[data-theme="night"] {
  --accent: #6366f1;
  --accent-dark: #4c4fd6;
  --hero-gradient-start: #1e1b3a;
  --hero-gradient-end: #0d0b1c;
}
[data-theme="neutral"] {
  --hero-gradient-start: #3a3f47;
  --hero-gradient-end: #1c1f24;
}

.hero {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  margin: 12px 0 20px;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: linear-gradient(180deg, var(--hero-gradient-start), var(--hero-gradient-end));
  color: var(--hero-text);
}
.hero-cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.hero-overlay {
  position: relative;
  z-index: 1;
  padding: 20px 16px 16px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.55) 70%);
}
.hero-title { font-size: 1.5rem; font-weight: 700; margin: 0 0 4px; color: var(--hero-text); }
.hero-subtitle { font-size: 0.95rem; margin: 0; color: var(--hero-text); opacity: 0.92; }
* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
.container { max-width: 640px; margin: 0 auto; padding: 16px; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; max-width: 640px; margin: 0 auto;
}
.brand { font-size: 1.35rem; font-weight: 700; margin: 0; }
h1 { font-size: 1.4rem; margin: 0 0 4px; }
.section-title { font-size: 1.05rem; color: var(--muted); margin: 24px 0 8px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
  display: flex; flex-direction: column; gap: 12px;
}
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }
input[type="text"], input[type="password"] {
  font-size: 1rem; padding: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.btn {
  font-size: 1rem; padding: 12px 18px; border-radius: 10px; border: none;
  cursor: pointer; background: var(--card); color: var(--text);
  border: 1px solid var(--border); text-decoration: none; text-align: center;
  display: inline-block; min-height: 44px; box-sizing: border-box;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 0.85rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.6; }
.row { display: flex; gap: 10px; }

.login-wrap {
  min-height: 100dvh; display: flex; flex-direction: column;
  justify-content: center; align-items: center; padding: 24px; gap: 20px;
}
.login-form { width: 100%; max-width: 360px; }

.album-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.album-card {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; text-decoration: none; color: var(--text);
}
.album-title { font-weight: 600; font-size: 1.05rem; }
.album-meta { color: var(--muted); font-size: 0.85rem; }
.album-head { margin: 12px 0; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

.stats { flex-direction: row; flex-wrap: wrap; gap: 16px; }
.stats p { margin: 0; }
.empty { color: var(--muted); text-align: center; margin: 32px 0; }
.error { color: var(--danger); margin: 0; font-size: 0.9rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 4px 0 0; }
.danger-zone { margin-top: 48px; }

/* Upload panel */
.upload-panel { margin: 16px 0; }
.upload-picker { text-align: center; cursor: pointer; }
.upload-queue {
  list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 8px;
}
.upload-item {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  font-size: 0.85rem;
}
.upload-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-status { color: var(--muted); white-space: nowrap; }
.upload-item.upload-error .upload-status { color: var(--danger); }
.upload-item.upload-duplicate .upload-status { color: var(--accent); }
.progress-track {
  width: 100%; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden;
}
.progress-fill { height: 100%; background: var(--accent); transition: width 0.2s ease; }

/* Photo grid */
.photo-grid {
  list-style: none; padding: 0; margin: 16px 0; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px;
}
.photo-tile { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.photo-thumb {
  aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--card);
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-placeholder { font-size: 0.7rem; color: var(--muted); text-align: center; padding: 4px; }
.photo-name {
  font-size: 0.75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.photo-status { font-size: 0.7rem; color: var(--muted); }
.photo-tile.photo-failed .photo-status { color: var(--danger); }

/* Gallery toolbar: filters + sort */
.gallery-toolbar { display: flex; flex-direction: column; gap: 8px; margin: 16px 0 4px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; }
.sort-row { align-items: center; flex-wrap: wrap; }
.sort-label { flex-direction: row; align-items: center; gap: 6px; font-size: 0.85rem; }
.sort-label select {
  font-size: 0.9rem; padding: 6px 8px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
}
.chip {
  font-size: 0.82rem; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  cursor: pointer; min-height: 44px;
}
/* font-weight, not just color, marks the active chip -- color alone is
   not a valid state indicator (WCAG 1.4.1). */
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.small.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Photo tile selection */
.photo-thumb-btn { border: none; background: none; padding: 0; margin: 0; width: 100%; cursor: pointer; }
.photo-thumb-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.photo-tile.photo-selected .photo-thumb { outline: 3px solid var(--accent); outline-offset: -3px; }
.select-badge {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem;
}
.photo-thumb { position: relative; }
.ai-badge {
  position: absolute; bottom: 6px; left: 6px; padding: 2px 6px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.65); color: #fff; font-size: 0.72rem; line-height: 1.4;
}

/* AI similarity-group override UI */
.ai-groups { display: flex; flex-direction: column; gap: 16px; margin: 12px 0; padding: 0; list-style: none; }
.ai-group-photos { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.ai-group-photo {
  position: relative; width: 84px; height: 84px; min-width: 44px; min-height: 44px;
  padding: 0; border: 2px solid var(--border); border-radius: 10px; overflow: hidden;
  background: none; cursor: pointer;
}
.ai-group-photo:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ai-group-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ai-group-photo-chosen { border-color: var(--accent); }
.ai-group-badge {
  position: absolute; bottom: 2px; left: 2px; right: 2px; padding: 2px 4px; border-radius: 6px;
  background: var(--accent); color: #fff; font-size: 0.65rem; text-align: center; line-height: 1.3;
}
.ai-group-badge-ai { background: rgba(0, 0, 0, 0.65); bottom: auto; top: 2px; }

.ai-badge-edited { background: rgba(37, 99, 235, 0.85); }

/* AI edit result cards */
.ai-edit-cards {
  list-style: none; padding: 0; margin: 12px 0; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px;
}
.ai-edit-card { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ai-edit-card-body { display: flex; flex-direction: column; gap: 6px; }
.ai-edit-thumb {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border); background: var(--card); padding: 0; cursor: pointer;
}
.ai-edit-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ai-edit-flag {
  position: absolute; top: 6px; left: 6px; right: 6px; padding: 2px 6px; border-radius: 6px;
  background: rgba(0, 0, 0, 0.65); color: #fff; font-size: 0.68rem; text-align: center;
}
.ai-edit-flag-bad { background: rgba(220, 38, 38, 0.85); }
.ai-edit-card-error { color: var(--danger); font-size: 0.85rem; margin: 0; }
.ai-edit-card .row { flex-wrap: wrap; gap: 6px; }
.ai-edit-card .btn.small { flex: 1 1 auto; min-width: 0; }

/* Before/after comparison viewer */
.compare-modal { gap: 12px; }
.compare-frame {
  position: relative; width: 100%; aspect-ratio: 4 / 3; border-radius: 10px;
  overflow: hidden; background: #000;
}
.compare-frame::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: var(--pos); width: 2px;
  margin-left: -1px; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5); pointer-events: none;
}
.compare-before, .compare-after {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block;
}
.compare-after { clip-path: inset(0 calc(100% - var(--pos)) 0 0); }
.compare-label {
  position: absolute; top: 8px; padding: 2px 8px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 0.7rem;
}
.compare-label-before { left: 8px; }
.compare-label-after { right: 8px; }
.compare-slider { width: 100%; }

.gallery-more { margin: 12px 0 24px; }
.load-sentinel { height: 1px; }

/* Bottom action bar */
.action-bar {
  position: sticky; bottom: 0; left: 0; right: 0; margin: 16px -16px 0;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--border);
}
.action-bar-inner { display: flex; gap: 8px; max-width: 640px; margin: 0 auto; flex-wrap: wrap; }
.action-bar-inner .btn { flex: 1 1 auto; min-width: 100px; }

/* Modal (download menu) */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
}
.modal {
  width: 100%; max-width: 480px; margin: 0; border-radius: 16px 16px 0 0;
  max-height: 85dvh; overflow-y: auto;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) {
  .modal { border-radius: var(--radius); }
}
.download-menu h2 { margin: 0; font-size: 1.15rem; }
.download-options { display: flex; flex-direction: column; gap: 8px; }
.download-option { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.download-option .hint { margin: 0; }
.archive-progress p, .archive-ready p, .archive-failed p { margin: 0 0 8px; }

/* Fullscreen viewer */
.viewer-backdrop {
  position: fixed; inset: 0; background: #000; z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.viewer {
  width: 100%; height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; position: relative;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.viewer-image-wrap { flex: 1 1 auto; width: 100%; display: flex; align-items: center; justify-content: center; min-height: 0; touch-action: pan-y; }
.viewer-image { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-placeholder { color: #ccc; }
.viewer-close {
  position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; z-index: 2;
  color: #fff; border-color: rgba(255,255,255,0.3); background: rgba(0,0,0,0.4);
  min-width: 44px; min-height: 44px;
}
.viewer-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  color: #fff; border-color: rgba(255,255,255,0.3); background: rgba(0,0,0,0.4);
  font-size: 1.5rem; min-width: 44px; min-height: 44px;
}
.viewer-prev { left: 8px; }
.viewer-next { right: 8px; }
.viewer-nav:disabled { opacity: 0.25; }
.viewer-bar { display: flex; gap: 8px; padding: 10px; flex-wrap: wrap; justify-content: center; }
.viewer-bar .btn { color: #fff; border-color: rgba(255,255,255,0.3); background: rgba(0,0,0,0.4); }
.viewer-meta { color: #ccc; font-size: 0.8rem; padding-bottom: 10px; text-align: center; }

/* Private album sharing (Phase 5.5) */
.share-modal h2 { margin: 0; font-size: 1.15rem; }
.share-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.share-row { gap: 6px; }
.share-row-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.share-row-actions { flex-wrap: wrap; }
.share-permissions { border: 1px solid var(--border); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.share-permissions legend { padding: 0 4px; color: var(--muted); font-size: 0.85rem; }
.share-permission-row { flex-direction: row; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--text); }
.share-reveal { background: var(--bg); }
.share-link-value { font-size: 0.85rem; word-break: break-all; color: var(--accent); }

/* Guest pages */
.guest-shell { min-height: 100dvh; }
.guest-entry-form { width: 100%; max-width: 360px; }
.guest-topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; }
.guest-ai-badge { background: rgba(37, 99, 235, 0.85); }
.guest-filter-explanation { margin: 0 0 12px; line-height: 1.45; }
.guest-best-reason {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}
.guest-best-reason strong { color: var(--text); }
.viewer-recommendation { margin: 6px 0 0; line-height: 1.4; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
