/* Photos — styles.
   Mobile-first: the grid, toolbar and detail view all reflow at 720px.
   Colours follow the OS light/dark preference. */

:root {
  --bg: #f6f6f7;
  --surface: #ffffff;
  --surface-2: #eeeef1;
  --text: #16161a;
  --text-dim: #6a6a75;
  --border: #dcdce2;
  --accent: #2f6df6;
  --accent-text: #ffffff;
  --danger: #c8372c;
  --shadow: 0 1px 2px rgba(16, 16, 24, 0.06), 0 8px 24px rgba(16, 16, 24, 0.08);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131316;
    --surface: #1d1d21;
    --surface-2: #26262c;
    --text: #f2f2f4;
    --text-dim: #9b9ba6;
    --border: #33333b;
    --accent: #5c8cff;
    --accent-text: #0d1020;
    --danger: #ff6b5e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.screen {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 16px 64px;
}

.boot, .fatal {
  max-width: 640px;
  margin: 48px auto;
  padding: 0 16px;
  color: var(--text-dim);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- Top bar --------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 0 16px;
}

.topbar-main { flex: 1 1 200px; min-width: 0; }

.app-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--text-dim);
  font-size: 0.875rem;
}

.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- Buttons --------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn:focus-visible,
.field-input:focus-visible,
.select:focus-visible,
.tile:focus-visible,
.collection-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn-danger { color: var(--danger); }

.btn-danger-solid {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-back { padding-inline: 10px; }
.icon { font-size: 1.05em; line-height: 1; }

.select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9375rem;
}

/* --- Toolbar --------------------------------------------------------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 16px;
}

.toolbar-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- Collections ----------------------------------------------------- */

.collection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
}

.collection-card {
  display: block;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}

.collection-card:hover { transform: translateY(-2px); }

.cover { aspect-ratio: 4 / 3; background: var(--surface-2); }

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

.cover-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 2rem;
  opacity: 0.35;
}

.collection-meta {
  display: block;
  padding: 10px 12px 12px;
}

.collection-name {
  display: block;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.collection-count {
  display: block;
  color: var(--text-dim);
  font-size: 0.8125rem;
}

/* --- Photo grid ------------------------------------------------------ */

.photo-groups { display: flex; flex-direction: column; gap: 24px; }

.day-heading {
  margin: 0 0 10px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

.tile {
  position: relative;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: var(--surface-2);
  aspect-ratio: 1;
  cursor: pointer;
  overflow: hidden;
}

.tile-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.16s ease;
}

.tile:hover .tile-img { transform: scale(1.04); }

.tile-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 14px 8px 6px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
  color: #fff;
  font-size: 0.75rem;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Empty states + footer ------------------------------------------- */

.empty {
  padding: 48px 24px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  color: var(--text-dim);
}

.empty-title {
  margin: 0 0 6px;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}

.empty .btn { margin-top: 12px; }

.footer {
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.8125rem;
}

/* --- Upload progress -------------------------------------------------- */

.upload-status {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 0.875rem;
}

.progress {
  flex: 1 1 160px;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s ease;
}

.upload-errors { color: var(--danger); }

/* --- Overlays --------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 8, 12, 0.7);
  backdrop-filter: blur(3px);
}

.modal {
  width: min(420px, 100%);
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-title { margin: 0 0 8px; font-size: 1.125rem; }
.modal-message { margin: 0 0 4px; color: var(--text-dim); font-size: 0.9375rem; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* --- Fields ----------------------------------------------------------- */

.field { margin-top: 14px; }

.field label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-dim);
}

.field-input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9375rem;
}

.field-textarea { resize: vertical; min-height: 84px; }

/* --- Photo detail ------------------------------------------------------ */

.overlay-detail {
  padding: 0;
  align-items: stretch;
  height: 100vh;
  /* dvh tracks the mobile URL bar. Without it the fixed overlay is sized to
     the *large* viewport and its bottom — the Save button — sits permanently
     underneath the browser chrome. */
  height: 100dvh;
}

.detail {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  /* On a phone the image and the form cannot both fit, so the whole column
     scrolls as one unit. The form used to be its own nested scroller inside a
     fixed overlay, which is close to undriveable with a thumb. */
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}

.detail-close {
  /* Fixed, not absolute: it must stay reachable while the column scrolls. */
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 2;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
}

.detail-stage {
  position: relative;
  flex: 0 0 auto;
  height: 55vh;
  height: 55dvh;
  min-height: 200px;
  display: grid;
  place-items: center;
  background: #0b0b0e;
}

.detail-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.nav-arrow {
  position: absolute;
  /* Pinned to the bottom of the image on phones: vertically centred, they
     collide with the fixed Close button once the column is scrolled. */
  bottom: 12px;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 0;
  border: none;
}

.nav-arrow::after {
  font-size: 1.5rem;
  line-height: 1;
}

.nav-prev { left: 12px; }
.nav-prev::after { content: "‹"; }
.nav-next { right: 12px; }
.nav-next::after { content: "›"; }

.detail-panel {
  flex: 0 0 auto;
  /* No max-height and no scroller of its own — .detail does the scrolling.
     The safe-area padding keeps Save clear of the iPhone home indicator. */
  padding: 12px 16px calc(28px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.detail-meta {
  margin: 14px 0 0;
  color: var(--text-dim);
  font-size: 0.8125rem;
  overflow-wrap: anywhere;
}

.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.detail-actions .btn { text-decoration: none; }

/* Desktop: side-by-side, with the image fixed and only the form scrolling. */
@media (min-width: 860px) {
  .detail {
    flex-direction: row;
    overflow: hidden;
  }
  .detail-stage {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
  }
  .detail-panel {
    flex: 0 0 360px;
    overflow-y: auto;
    border-top: none;
    border-left: 1px solid var(--border);
    padding: 44px 20px 24px;
  }
  .detail-close { position: absolute; }
  .nav-arrow {
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
  }
}

/* --- Camera ------------------------------------------------------------ */

.camera {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(900px, 100%);
  max-height: 100%;
}

.camera-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 240px;
  border-radius: var(--radius);
  background: #000;
  overflow: hidden;
}

.camera-video {
  width: 100%;
  max-height: 70vh;
  display: block;
  object-fit: contain;
}

.camera-status {
  position: absolute;
  margin: 0;
  padding: 0 24px;
  color: #fff;
  text-align: center;
}

.camera-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-shutter { padding: 12px 22px; font-size: 1rem; }

/* --- Drag and drop ------------------------------------------------------ */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: rgba(8, 8, 12, 0.55);
  pointer-events: none;
}

.drop-message {
  padding: 24px 32px;
  border: 2px dashed rgba(255, 255, 255, 0.8);
  border-radius: var(--radius);
  color: #fff;
  font-size: 1.125rem;
  font-weight: 600;
}

/* --- Toast -------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  transform: translateX(-50%);
  max-width: min(440px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: 10px;
  background: #1f1f28;
  color: #fff;
  font-size: 0.9375rem;
  box-shadow: var(--shadow);
}

.toast-error { background: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
