/* ============================================================
   Nested Photo Gallery — plain CSS (no Tailwind/build step)
   ============================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --blue: #3b82f6;
  --blue-600: #2563eb;
  --green: #22c55e;
  --green-600: #16a34a;
  --red: #ef4444;
  --red-600: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--gray-800);
  background: var(--gray-50);
  min-height: 100vh;
  line-height: 1.5;
}

/* ---------- Layout helpers ---------- */
.page {
  min-height: 100vh;
  background: linear-gradient(to bottom right, #eff6ff, #e0e7ff);
}
.container {
  max-width: 1152px;
  margin: 0 auto;
  padding: 24px;
}
.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

/* ---------- Cards ---------- */
.card {
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 24px;
}
.card + .card {
  margin-top: 24px;
}

/* ---------- Headings & text ---------- */
h1 { font-size: 1.875rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1.25rem; font-weight: 700; }
.muted { color: var(--gray-500); font-size: 0.875rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.stack > * + * { margin-top: 16px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  color: #fff;
  background: var(--blue);
  transition: background-color 0.15s ease;
}
.btn:hover { background: var(--blue-600); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-green { background: var(--green); }
.btn-green:hover { background: var(--green-600); }
.btn-red { background: var(--red-600); }
.btn-red:hover { background: #b91c1c; }
.btn-gray { background: var(--gray-500); }
.btn-gray:hover { background: #4b5563; }
.btn-light { background: var(--gray-200); color: var(--gray-700); }
.btn-light:hover { background: var(--gray-300); }
.btn-block { width: 100%; }
.btn-icon {
  padding: 8px;
  background: transparent;
  color: var(--gray-700);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.btn-icon:hover { background: var(--gray-100); }
/* Colour variants on icon buttons (override .btn-icon's transparent bg). */
.btn-icon.btn-light { background: var(--gray-200); color: var(--gray-700); }
.btn-icon.btn-light:hover { background: var(--gray-300); }
.btn-icon.btn-red { background: var(--red-600); color: #fff; }
.btn-icon.btn-red:hover { background: #b91c1c; }
/* Share button while the project is publicly shared: green tint. */
.btn-icon.btn-light.is-shared { background: var(--green); color: #fff; }
.btn-icon.btn-light.is-shared:hover { background: var(--green-600); }
/* Copy-link button feedback after copying. */
.btn.copied { background: var(--green); color: #fff; }
.btn svg, .btn-icon svg { width: 20px; height: 20px; }
/* "Move markers" toggle: a switch in front of a 4-way move-arrows icon. */
.move-toggle { display: inline-flex; align-items: center; gap: 8px; }
.move-toggle .switch {
  position: relative;
  width: 34px;
  height: 18px;
  border-radius: 9px;
  background: var(--gray-300);
  transition: background 0.15s ease;
  flex: 0 0 auto;
}
.move-toggle .switch .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease;
}
.move-toggle[aria-pressed="true"] .switch { background: var(--green); }
.move-toggle[aria-pressed="true"] .switch .knob { transform: translateX(16px); }
.move-toggle[aria-pressed="true"] { color: var(--green-600); }
/* Disabled buttons (e.g. Create Project before a valid name is entered). */
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------- Forms ---------- */
label { display: block; font-size: 0.875rem; font-weight: 500; color: var(--gray-700); margin-bottom: 8px; }
input[type="text"],
input[type="password"],
input[type="file"],
textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font: inherit;
  outline: none;
}
input:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}
.form-inline { display: flex; gap: 12px; flex-wrap: wrap; }
.form-inline input { flex: 1; min-width: 200px; }

/* ---------- Alerts ---------- */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
}
.alert-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
}

/* ---------- Login ---------- */
.login-card { width: 100%; max-width: 420px; }
.login-card .subtitle { text-align: center; color: var(--gray-500); margin-bottom: 24px; }
.login-card h1 { text-align: center; margin-bottom: 8px; }
.login-footer {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--gray-200);
  text-align: center;
  font-size: 0.875rem;
  color: var(--gray-500);
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }

/* ---------- Projects grid ---------- */
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}
@media (min-width: 768px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.project-card { background: #fff; border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; transition: box-shadow 0.15s ease; }
.project-card:hover { box-shadow: var(--shadow-lg); }
.project-card .inner { padding: 24px; }
.project-card h3 { margin-bottom: 8px; }
.card-actions { display: flex; gap: 8px; margin-top: 16px; }
.card-actions .btn { flex: 1; }
.card-actions .btn-icon, .card-actions .btn-light, .card-actions .btn-red { flex: 0 0 auto; }
.empty-state { grid-column: 1 / -1; text-align: center; padding: 48px 0; background: #fff; border-radius: 12px; box-shadow: var(--shadow); color: var(--gray-500); }

/* ---------- Admin accounts ---------- */
.account-row {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.account-row + .account-row { margin-top: 12px; }
.account-row:hover { background: var(--gray-50); }
.chip {
  background: var(--gray-100);
  padding: 4px 8px;
  border-radius: 6px;
}
.link-btn {
  background: none;
  border: none;
  color: var(--blue-600);
  cursor: pointer;
  font: inherit;
  font-size: 0.875rem;
  padding: 0;
  text-decoration: none;
}
.link-btn:hover { text-decoration: underline; }
.inline-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

/* ---------- List (outline) view ---------- */
.list-toolbar { position: relative; margin-bottom: 16px; }
.list-toolbar .search-ic {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  color: var(--gray-500);
  pointer-events: none;
}
.list-toolbar input { padding-left: 40px; }

.photo-list { display: flex; flex-direction: column; }
.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px calc(8px + var(--indent, 0px));
  border-bottom: 1px solid var(--gray-200);
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--gray-50); }
.level-badge {
  flex: 0 0 auto;
  min-width: 34px;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-700);
  background: var(--gray-100);
  border-radius: 6px;
  padding: 3px 6px;
}
.level-badge.loose { color: var(--gray-500); }
.list-thumb {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--gray-100);
}
/* The description doubles as an inline editor: looks like text until hovered/focused. */
.list-desc { flex: 1; min-width: 0; border-color: transparent; background: transparent; }
.list-desc:hover { border-color: var(--gray-300); }
.list-desc:focus { background: #fff; border-color: var(--blue); }
.list-desc::placeholder { color: var(--gray-300); }
.list-save { flex: 0 0 auto; padding: 6px 12px; }
.save-state { flex: 0 0 auto; width: 20px; text-align: center; font-weight: 700; }
.save-state.saving { color: var(--gray-500); }
.save-state.saved { color: var(--green-600); }
.save-state.error { color: var(--red-600); }
.open-btn { flex: 0 0 auto; }

/* On narrow screens the row wraps and the description drops onto its own
   full-width line, so it stays readable instead of being squeezed thin. */
@media (max-width: 640px) {
  .list-row { flex-wrap: wrap; }
  .list-row .save-state { margin-left: auto; }
  .list-desc {
    order: 1;
    flex-basis: 100%;
    border-color: var(--gray-300);
    background: #fff;
  }
}

/* ============================================================
   Photo viewer
   ============================================================ */
.viewer { min-height: 100vh; background: var(--gray-50); }
.top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 30;
}
.top-bar .spacer { width: 56px; flex: 0 0 auto; }
.top-bar .description {
  flex: 1;
  padding: 0 8px;
  font-size: 0.9rem;
  color: var(--gray-700);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.corner-btn {
  position: fixed;
  top: 0;
  z-index: 40;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: none;
  cursor: pointer;
  color: var(--gray-700);
  text-decoration: none;
}
.corner-btn:hover { background: var(--gray-100); }
.corner-btn.left { left: 0; padding: 0 16px; border-right: 1px solid var(--gray-200); }
.corner-btn.right { right: 0; width: 56px; border-left: 1px solid var(--gray-200); }
.corner-btn svg { width: 24px; height: 24px; }

.image-stage {
  position: fixed;
  top: 56px; left: 0; right: 0; bottom: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111827;
  user-select: none;
  touch-action: none;
}
.image-stage .pan-layer {
  position: relative;
  transform-origin: 0 0;
}
.image-stage img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100vw;
  max-height: calc(100vh - 56px);
  pointer-events: none;
}
.marker-hitlayer { position: absolute; inset: 0; }
.marker-hitlayer.adding { cursor: crosshair; }

.marker {
  position: absolute;
  transform: translate(-50%, -50%);
  box-shadow: var(--shadow);
  /* Locked by default: a tap navigates / opens its modal. Becomes a grab handle
     only in move-mode (see .viewer.move-mode below). */
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.marker.circle { border-radius: 50%; }
.marker.square { border-radius: 6px; }
.marker.has-target { background: linear-gradient(to bottom right, #10b981, #059669); }
.marker.no-target { background: linear-gradient(to bottom right, #fb923c, #f59e0b); }
.marker:hover { transform: translate(-50%, -50%) scale(1.1); box-shadow: var(--shadow-lg); }
.marker.dragging { transition: none; cursor: grabbing; transform: translate(-50%, -50%) scale(1.25); background: var(--blue); box-shadow: 0 0 0 4px rgba(147, 197, 253, 0.7); }
/* "Move markers" mode turns every marker into a drag handle. */
.viewer.move-mode .marker { cursor: grab; }
.viewer.move-mode .marker.dragging { cursor: grabbing; }
.marker .glow { position: absolute; inset: 0; background: #fff; opacity: 0.3; pointer-events: none; }
.marker .glow.circle { border-radius: 50%; }
.marker .glow.square { border-radius: 6px; }
.marker .ring { position: absolute; inset: 15%; border: 3px solid #fff; opacity: 0.5; pointer-events: none; }
/* On the large marker, 15% is a big absolute gap; pull the ring back so it
   sits roughly as far in as the medium marker's ring. */
.marker.size-200 .ring { inset: 7.5%; }
.marker .ring.circle { border-radius: 50%; }
.marker .ring.square { border-radius: 4px; }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 512px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header { padding: 16px; border-bottom: 1px solid var(--gray-200); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 16px; }
.modal-footer { padding: 16px; border-top: 1px solid var(--gray-200); display: flex; gap: 12px; justify-content: flex-end; }
[hidden] { display: none !important; }

/* ---------- Delete confirmation modal ---------- */
.dc-modal { max-width: 460px; }
.dc-warning { color: var(--gray-700); margin-bottom: 14px; }
.dc-instruction { margin-bottom: 10px; }
.dc-phrase {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--gray-100);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  word-break: break-word;
}
.dc-input {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--gray-300);
  border-radius: 8px;
  font-size: 1rem;
}
.dc-input:focus { outline: none; border-color: var(--red-600); }
.dc-match { color: var(--green-600); margin-top: 10px; font-size: 0.9rem; }
.dc-error { color: var(--red-600); margin-top: 10px; font-size: 0.9rem; }

/* ---------- Flash messages ---------- */
.flash-stack {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 480px);
}
.flash {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.95rem;
  color: #fff;
  box-shadow: var(--shadow);
}
.flash-success { background: var(--green); }
.flash-error { background: var(--red-600); }

/* ---------- Marker customization choices ---------- */
.choice-group { display: flex; gap: 12px; }
.choice {
  flex: 1;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px;
  border: 2px solid var(--gray-300);
  border-radius: 8px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.choice input { position: absolute; opacity: 0; width: 0; height: 0; }
.choice:has(input:checked) { border-color: var(--blue); background: #eff6ff; }
.swatch { background: linear-gradient(to bottom right, var(--blue), var(--blue-600)); border: 2px solid #fff; box-shadow: var(--shadow); }
.swatch.circle { border-radius: 50%; }
.swatch.square { border-radius: 6px; }

/* ---------- Spinner ---------- */
.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--blue);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
