/* ─────────────────────────────────────────────
   Design tokens
   ───────────────────────────────────────────── */
:root {
  --bg: #f4f2ed;
  --bg-2: #eceae3;
  --bg-3: #e3e0d8;
  --text: #1c1a16;
  --text-2: #5a5750;
  --text-3: #9a9690;
  --border: #d8d4cb;
  --accent: #7a6a50;
  --accent-light: #c4b49a;
  --danger: #8b3a3a;
  --danger-bg: #f5ebeb;
  --success-bg: #eaf0e8;
  --success: #3a6b3a;

  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-body: "Jost", system-ui, sans-serif;

  --gap: 4px;
  --radius: 2px;
  --header-h: 56px;

  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg: #131210;
  --bg-2: #1c1a17;
  --bg-3: #252320;
  --text: #e8e4dc;
  --text-2: #a09c94;
  --text-3: #6a6660;
  --border: #2e2c28;
  --accent: #b09870;
  --accent-light: #6a5a40;
  --danger: #b06060;
  --danger-bg: #2a1a1a;
  --success-bg: #1a2a1a;
  --success: #70a070;
}

/* ─────────────────────────────────────────────
   Reset & base
   ───────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 300;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition:
    background var(--transition),
    color var(--transition);
}

a {
  color: inherit;
  text-decoration: none;
}
img {
  display: block;
  max-width: 100%;
}
button {
  cursor: pointer;
  font-family: var(--font-body);
}
textarea,
input,
select {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 300;
}

/* ─────────────────────────────────────────────
   Header
   ───────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.site-title {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  gap: 0;
}

.site-title-main {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0.02em;
  color: var(--text);
}

.site-title-sub {
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-3);
}

.theme-toggle {
  background: none;
  border: none;
  color: var(--text-2);
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    color var(--transition),
    background var(--transition);
}

.theme-toggle:hover {
  color: var(--text);
  background: var(--bg-2);
}

[data-theme="light"] .icon-moon {
  display: block;
}
[data-theme="light"] .icon-sun {
  display: none;
}
[data-theme="dark"] .icon-moon {
  display: none;
}
[data-theme="dark"] .icon-sun {
  display: block;
}

/* ─────────────────────────────────────────────
   Tag bar
   ───────────────────────────────────────────── */
.tag-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 90;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.tag-bar-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 24px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.tag-bar-inner::-webkit-scrollbar {
  display: none;
}

@media (max-width: 600px) {
  .tag-bar-inner {
    flex-wrap: nowrap;
    padding: 8px 16px;
  }
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.03em;
  color: var(--text-2);
  white-space: nowrap;
  transition:
    border-color var(--transition),
    color var(--transition),
    background var(--transition);
}

.tag-pill:hover {
  border-color: var(--accent);
  color: var(--text);
}

.tag-pill.active {
  border-color: var(--text);
  color: var(--text);
  background: var(--bg-2);
}

.tag-count {
  font-size: 10px;
  color: var(--text-3);
}

/* ─────────────────────────────────────────────
   Main & footer
   ───────────────────────────────────────────── */
.site-main {
  flex: 1;
}

.site-footer {
  padding: 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  border-top: 1px solid var(--border);
  margin-top: 48px;
}

/* ─────────────────────────────────────────────
   Masonry gallery
   ───────────────────────────────────────────── */
.gallery-grid {
  columns: 4 240px;
  column-gap: var(--gap);
  padding: var(--gap);
}

@media (max-width: 480px) {
  .gallery-grid {
    columns: 2;
  }
}

.photo-card {
  display: block;
  break-inside: avoid;
  margin-bottom: var(--gap);
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--bg-2);
}

.photo-card-inner {
  position: relative;
  overflow: hidden;
}

.photo-card img {
  width: 100%;
  height: auto;
  display: block;
  transition:
    transform 0.4s ease,
    opacity 0.3s ease;
  opacity: 0;
}

.photo-card img.loaded {
  opacity: 1;
}

/* Progressive load via JS — also handle no-JS */
.photo-card img[loading] {
  opacity: 1;
}

.photo-card:hover img {
  transform: scale(1.025);
}

.photo-card-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px 12px 10px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
  opacity: 0;
  transform: translateY(4px);
  transition:
    opacity 0.3s ease,
    transform 0.3s ease;
  pointer-events: none;
}

.photo-card:hover .photo-card-caption,
.photo-card:focus-within .photo-card-caption {
  opacity: 1;
  transform: translateY(0);
}

.photo-card-title {
  display: block;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 300;
  font-style: italic;
  color: #fff;
  line-height: 1.2;
}

.photo-card-tags {
  display: flex;
  gap: 10px;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.65);
  margin-top: 3px;
}

.empty-state {
  padding: 64px 24px;
  text-align: center;
  color: var(--text-3);
  font-style: italic;
  font-family: var(--font-display);
  font-size: 18px;
}

.load-more-trigger {
  height: 1px;
}

/* ─────────────────────────────────────────────
   Photo detail
   ───────────────────────────────────────────── */
.photo-detail {
  display: grid;
  grid-template-columns: 1fr 320px;
  min-height: calc(100vh - var(--header-h));
  gap: 0;
}

@media (max-width: 860px) {
  .photo-detail {
    grid-template-columns: 1fr;
  }
}

.photo-detail-image {
  background: var(--bg-2);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  min-height: 400px;
}

.photo-full-link {
  display: block;
  cursor: zoom-in;
}

.photo-detail-image img {
  max-width: 100%;
  max-height: calc(100vh - var(--header-h) - 48px);
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.15);
}

.photo-detail-info {
  padding: 40px 32px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

@media (max-width: 860px) {
  .photo-detail-info {
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 24px 20px;
  }
}

.photo-detail-title {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 400;
  font-style: italic;
  line-height: 1.2;
  color: var(--text);
}

.photo-detail-date {
  font-size: 13px;
  color: var(--text-3);
  letter-spacing: 0.04em;
}

.photo-detail-desc {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.7;
}

.photo-detail-location {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-3);
}

/* EXIF grid */
.exif-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  padding: 16px;
  background: var(--bg-2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.exif-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.exif-label {
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
}

.exif-value {
  font-size: 13px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.photo-detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin-top: auto;
  transition: color var(--transition);
}

.back-link:hover {
  color: var(--text);
}

/* ─────────────────────────────────────────────
   Buttons
   ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
  transition:
    background var(--transition),
    color var(--transition),
    border-color var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.btn-primary:hover {
  background: var(--text-2);
  border-color: var(--text-2);
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--bg-2);
  color: var(--text);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--border);
  font-size: 12px;
  padding: 5px 12px;
}

.btn-danger:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
}

.btn-large {
  padding: 12px 28px;
  font-size: 14px;
}

/* ─────────────────────────────────────────────
   Auth
   ───────────────────────────────────────────── */
.auth-wrapper {
  min-height: calc(100vh - var(--header-h));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.auth-form {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 400;
  font-style: italic;
  color: var(--text);
}

.auth-error {
  padding: 10px 14px;
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--danger);
}

/* ─────────────────────────────────────────────
   Forms
   ───────────────────────────────────────────── */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}

.form-field small {
  font-size: 11px;
  color: var(--text-3);
}

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

.form-field input,
.form-field textarea,
.form-field select {
  padding: 9px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  transition:
    border-color var(--transition),
    background var(--transition);
  outline: none;
}

.form-field input:focus,
.form-field textarea:focus {
  border-color: var(--accent);
  background: var(--bg);
}

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

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.form-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px 0;
  border-bottom: 1px solid var(--border);
}

.form-section:last-of-type {
  border-bottom: none;
}

.form-section-title {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.form-section-title small {
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
}

.form-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-top: 24px;
}

/* File drop */
.file-drop {
  position: relative;
}

.file-drop input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
  width: 100%;
  height: 100%;
}

.file-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px 24px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  color: var(--text-3);
  cursor: pointer;
  transition:
    border-color var(--transition),
    background var(--transition);
}

.file-label:hover,
.file-drop.drag-over .file-label {
  border-color: var(--accent);
  background: var(--bg-2);
  color: var(--text-2);
}

#fileName {
  font-size: 13px;
  color: var(--text-2);
}

.file-preview-wrap img {
  max-height: 200px;
  margin: 8px auto 0;
  border-radius: var(--radius);
  object-fit: contain;
}

/* ─────────────────────────────────────────────
   Admin layout
   ───────────────────────────────────────────── */
.admin-layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
  flex-wrap: wrap;
  gap: 12px;
}

.admin-title {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 400;
  font-style: italic;
}

.admin-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.flash-message {
  padding: 10px 16px;
  background: var(--success-bg);
  border: 1px solid var(--success);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--success);
  margin-bottom: 24px;
}

/* Stats */
.stats-row {
  display: flex;
  gap: 16px;
  margin-bottom: 40px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 32px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 100px;
}

.stat-number {
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 300;
  line-height: 1;
  color: var(--text);
}

.stat-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-top: 4px;
}

/* Admin sections */
.admin-section {
  margin-bottom: 48px;
}

.admin-section-title {
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* Tag stats */
.tag-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tag-stat-item {
  display: grid;
  grid-template-columns: 120px 1fr 40px;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.tag-stat-name {
  color: var(--text-2);
}

.tag-stat-bar-wrap {
  height: 3px;
  background: var(--bg-3);
  border-radius: 100px;
  overflow: hidden;
}

.tag-stat-bar {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 100px;
  transition: width 0.5s ease;
}

.tag-stat-count {
  font-size: 12px;
  color: var(--text-3);
  text-align: right;
}

/* Admin photo list */
.admin-photo-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.admin-photo-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.admin-thumb {
  width: 56px;
  height: 40px;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--bg-2);
}

.admin-photo-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.admin-photo-title {
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color var(--transition);
}

.admin-photo-title:hover {
  color: var(--accent);
}

.admin-photo-tags {
  font-size: 11px;
  color: var(--text-3);
}

.admin-photo-date {
  font-size: 11px;
  color: var(--text-3);
}

/* Upload form */
.upload-form {
  max-width: 640px;
}

/* ─────────────────────────────────────────────
   Lazy load fade-in
   ───────────────────────────────────────────── */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.photo-card {
  animation: fadeIn 0.4s ease both;
}

/* Stagger animation for initial load */
.photo-card:nth-child(1) {
  animation-delay: 0.02s;
}
.photo-card:nth-child(2) {
  animation-delay: 0.04s;
}
.photo-card:nth-child(3) {
  animation-delay: 0.06s;
}
.photo-card:nth-child(4) {
  animation-delay: 0.08s;
}
.photo-card:nth-child(5) {
  animation-delay: 0.1s;
}
.photo-card:nth-child(6) {
  animation-delay: 0.12s;
}
.photo-card:nth-child(7) {
  animation-delay: 0.14s;
}
.photo-card:nth-child(8) {
  animation-delay: 0.16s;
}

/* ─────────────────────────────────────────────
   HTMX indicator
   ───────────────────────────────────────────── */
.htmx-indicator {
  opacity: 0;
  transition: opacity 0.2s;
}
.htmx-request .htmx-indicator {
  opacity: 1;
}
