/*
 * Admin area, mobile-first. One light theme: photos first, little chrome.
 * Components: .btn, .card, .form-field, .table, .alert, .badge, .album-grid, .photo-grid, .picker, .upload
 */

@font-face {
  font-family: "DM Sans";
  src: url("/assets/dm-sans-6b17fafd.woff2") format("woff2");
  font-weight: 100 1000;
  font-display: swap;
}

:root {
  color-scheme: light;

  --color-bg: #f3f6f9;
  --color-surface: #ffffff;
  --color-text: #15212b;
  --color-muted: #566675;
  --color-border: #d9e2ea;
  --color-primary: #15212b;
  --color-primary-text: #ffffff;
  --color-danger: #c8102e;
  --color-marker: #d3122f;
  --color-warning-bg: #fff1d6;
  --color-warning-text: #694400;
  --color-notice-bg: #e2f4ea;
  --color-notice-text: #15522f;
  --color-error-bg: #fde8e6;
  --color-error-text: #8a1c12;
  --color-focus: #3b82f6;

  --font-body: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-size-small: 0.875rem;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  --radius: 0.625rem;
  --tap-size: 2.75rem;
  --content-width: 73.75rem;
}

/* Base */

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

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  line-height: 1.5;
}

h1, h2 { line-height: 1.15; margin: 0; font-weight: 600; }
h1 { font-size: clamp(2rem, 4vw, 2.8rem); letter-spacing: -0.02em; text-wrap: balance; }
h2 { font-size: 1.15rem; }
a { color: var(--color-primary); }
img { max-width: 100%; height: auto; display: block; }
:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

.hint { color: var(--color-muted); font-size: var(--font-size-small); margin: 0 0 var(--space-3); }

/* Layout. Phone and tablet: floating dock at the bottom. Desktop: sticky bar at the top. */

.admin-header {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3) var(--space-4) 0;
}

.admin-header__brand { color: var(--color-muted); text-decoration: none; }

.admin-tools { display: flex; align-items: center; gap: var(--space-2); }

.admin-nav {
  position: fixed; left: 50%; bottom: var(--space-4); z-index: 10;
  transform: translateX(-50%);
  display: flex; gap: 2px;
  max-width: calc(100vw - 1.5rem);
  overflow-x: auto;
  scrollbar-width: none;
  padding: 5px;
  background: var(--color-text);
  border-radius: 999px;
  box-shadow: 0 10px 28px rgb(21 33 43 / 0.32);
}

.admin-nav__link {
  display: inline-flex; align-items: center;
  min-height: 2.25rem;
  padding: var(--space-1) 0.625rem;
  border-radius: 999px;
  color: #dbe3ea;
  font-size: 0.8rem;
  text-decoration: none;
  white-space: nowrap;
}

.admin-nav__link[aria-current] { background: var(--color-surface); color: var(--color-text); }

.admin-main {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: var(--space-6) var(--space-4) 6.5rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-6);
}

@media (min-width: 54rem) {
  .admin-header {
    position: sticky; top: 0; z-index: 10;
    flex-wrap: nowrap; justify-content: flex-start;
    gap: var(--space-6);
    padding: var(--space-3) var(--space-6);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
  }

  .admin-header__brand { color: var(--color-text); font-weight: 600; }
  .admin-tools { margin-left: auto; }

  .admin-nav {
    position: static; transform: none;
    gap: var(--space-1);
    max-width: none;
    padding: 0;
    background: none;
    border-radius: 0;
    box-shadow: none;
  }

  .admin-nav__link { padding: var(--space-1) var(--space-4); color: var(--color-muted); font-size: 1rem; }
  .admin-nav__link:hover { color: var(--color-text); }
  .admin-nav__link[aria-current] { background: var(--color-text); color: var(--color-surface); }

  .admin-main { padding-top: var(--space-8); padding-bottom: 3rem; }
}

.page-header {
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between;
  gap: var(--space-3);
}

.page-header__meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2);
  margin: var(--space-1) 0 0; color: var(--color-muted);
}

/* Buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap-size);
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover { border-color: var(--color-muted); }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn--primary { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-primary-text); }
.btn--danger { background: var(--color-surface); color: var(--color-danger); border-color: currentColor; }
.btn--ghost { background: transparent; }
.btn--small { min-height: 2.25rem; padding: var(--space-1) var(--space-3); font-size: var(--font-size-small); }

form.button_to { display: inline; }

/* Cards */

.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgb(21 33 43 / 0.06), 0 8px 24px rgb(21 33 43 / 0.05);
  padding: var(--space-4);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
}

.card__header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); }
.card__title { font-size: 1.15rem; margin: 0; }
.card--empty { color: var(--color-muted); margin: 0; }
.card--narrow { max-width: 26rem; width: 100%; margin: var(--space-8) auto 0; }
.card--danger .card__title { color: var(--color-danger); }
.card--bare { background: none; box-shadow: none; padding: 0; }

.card--split { align-items: start; }
.card__media img { border-radius: var(--radius); }

@media (min-width: 48rem) {
  .card--split { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
}

/* Forms */

.form { display: grid; gap: var(--space-4); }
.form > .btn { justify-self: start; }

.form-field { display: grid; gap: var(--space-1); margin: 0; padding: 0; border: 0; min-width: 0; }
.form-field__label { font-weight: 600; }
.form-field__label abbr { text-decoration: none; color: var(--color-muted); }

.form-field__input {
  width: 100%;
  min-height: var(--tap-size);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-text);
  font: inherit;
}

textarea.form-field__input { resize: vertical; }
input[type="file"].form-field__input { padding: var(--space-2); }
.form-field__input--error { border-color: var(--color-danger); }

.form-field__hint { margin: 0; color: var(--color-muted); font-size: var(--font-size-small); }
.form-field__error { margin: 0; color: var(--color-danger); font-size: var(--font-size-small); }

/* Checkbox in its label: whole row is the tap target. */
.form-field--toggle .form-field__label,
.form-field__choice label {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--tap-size);
  font-weight: 400;
  cursor: pointer;
}

.form-field--toggle input,
.form-field__choice input { width: 1.25rem; height: 1.25rem; margin: 0; accent-color: var(--color-primary); }

.form-field--choices legend { padding: 0; margin-bottom: var(--space-1); }
.form-field__choices { display: grid; gap: 0 var(--space-4); }

@media (min-width: 40rem) {
  .form-field__choices { grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); }
}

.form-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.form--columns { grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)); align-items: start; }
.form--columns > .alert, .form--columns > .form-actions { grid-column: 1 / -1; }

/* Search field that picks many records: results list, chips for the chosen ones. */

.picker { position: relative; display: grid; gap: var(--space-2); }
.picker__chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-1); }
.picker__chips:not(:has(> :not([hidden]))) { display: none; }

.picker__chip {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-1) 2px var(--space-3);
  border: 1px solid var(--color-muted);
  border-radius: 999px;
  font-size: var(--font-size-small);
}

.picker__remove { padding: 0 var(--space-2); border: 0; background: none; color: inherit; font: inherit; font-size: 1rem; line-height: 1.3; cursor: pointer; }

.picker__list {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 8;
  list-style: none; margin: var(--space-1) 0 0; padding: 0;
  max-height: 14rem; overflow: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 22px rgb(21 33 43 / 0.22);
}

.picker__option { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); padding: var(--space-2) var(--space-3); cursor: pointer; }
.picker__option small { opacity: 0.75; }
.picker__option:hover, .picker__option--active { background: var(--color-primary); color: var(--color-primary-text); }
.picker__empty { padding: var(--space-2) var(--space-3); color: var(--color-muted); }

/* Alerts and badges */

.alert { padding: var(--space-3) var(--space-4); border-radius: var(--radius); }
.alert--notice { background: var(--color-notice-bg); color: var(--color-notice-text); }
.alert--warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.alert--error { background: var(--color-error-bg); color: var(--color-error-text); }

.badge {
  display: inline-block;
  padding: 0 var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  font-size: var(--font-size-small);
  white-space: nowrap;
}

.badge--locked { background: var(--color-text); border-color: var(--color-text); color: var(--color-surface); }
.badge--hidden { border-style: dashed; color: var(--color-muted); }
.badge--cover { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-primary-text); }

/* Album index: grid of covers at a fixed height, caption over the picture. */

.album-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }

@media (min-width: 40rem) { .album-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 64rem) { .album-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.album-tile__link {
  position: relative; display: block; overflow: hidden;
  height: 15rem;
  border-radius: var(--radius);
  background: var(--color-border);
  color: #ffffff;
  text-decoration: none;
}

.album-tile__link img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.35s; }
.album-tile__link:hover img { transform: scale(1.03); }
.album-tile__link .rendition-placeholder { height: 100%; aspect-ratio: auto; border-radius: 0; }

.album-tile__link--empty {
  background: repeating-linear-gradient(135deg, var(--color-border) 0 6px, transparent 6px 12px);
}

.album-tile__caption {
  position: absolute; inset: auto 0 0;
  display: grid; gap: var(--space-1); justify-items: start;
  padding: 2.5rem var(--space-3) var(--space-3);
  background: linear-gradient(transparent, rgb(8 14 20 / 0.82));
}

.album-tile__title { font-size: 1.1rem; font-weight: 600; line-height: 1.2; }
.album-tile__meta { font-size: 0.78rem; }
.album-tile .badge { background: #ffffff; border-color: #ffffff; color: var(--color-text); }
.album-tile .badge--hidden { background: rgb(8 14 20 / 0.6); border-color: #ffffff; color: #ffffff; }

@media (prefers-reduced-motion: reduce) {
  .album-tile__link img { transition: none; }
}

/* Tables: cards on narrow screens, using each cell's data-label. */

.table { width: 100%; border-collapse: collapse; }
.table thead { display: none; }
.table tr {
  display: grid; gap: var(--space-1);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.table td { display: flex; justify-content: space-between; gap: var(--space-3); }
.table td[data-label]::before { content: attr(data-label); color: var(--color-muted); }
.table__actions { flex-wrap: wrap; justify-content: flex-end !important; padding-top: var(--space-2); }

@media (min-width: 48rem) {
  .table thead { display: table-header-group; }
  .table tr { display: table-row; padding: 0; margin: 0; border: 0; border-radius: 0; }
  .table th, .table td { display: table-cell; padding: var(--space-3); text-align: left; vertical-align: middle; border-bottom: 1px solid var(--color-border); }
  .table tbody tr:last-child td { border-bottom: 0; }
  .table td[data-label]::before { content: none; }
  .table th { color: var(--color-muted); font-weight: 600; font-size: var(--font-size-small); }
  .table__actions { text-align: right !important; white-space: nowrap; }
}

/* Sortable photo grid: pictures at a fixed height, cover on a dark background. */

.photo-grid {
  --photo-height: 10rem;
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: var(--space-6) var(--space-4);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 40rem) { .photo-grid { --photo-height: 11rem; grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 64rem) { .photo-grid { --photo-height: 15rem; } }

.photo-grid__item {
  display: grid; gap: var(--space-2); align-content: start;
  cursor: grab;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.photo-grid__media { position: relative; }
.photo-grid__media img { width: 100%; height: var(--photo-height); object-fit: cover; border-radius: var(--radius); }
.photo-grid__media .rendition-placeholder { height: var(--photo-height); aspect-ratio: auto; }

.photo-grid__media .badge { position: absolute; top: var(--space-2); left: var(--space-2); }

/* Negative margin: the picture stays aligned with the rest of the grid. */
.photo-grid__item--cover {
  margin: calc(var(--space-2) * -1);
  padding: var(--space-2);
  border-radius: calc(var(--radius) + var(--space-2));
  background: var(--color-text);
  color: var(--color-surface);
}

.photo-grid__title { margin: 0; font-size: var(--font-size-small); overflow-wrap: anywhere; }
.photo-grid__actions { display: flex; flex-wrap: wrap; gap: var(--space-1); }

.photo-grid .is-ghost { opacity: 0.4; }
.photo-grid .is-dragging { cursor: grabbing; box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 0.2); }

/* Upload */

.upload .form-field { padding: var(--space-4); border: 2px dashed var(--color-border); border-radius: var(--radius); }

.upload__list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-1); font-size: var(--font-size-small); }
.upload__item { padding-left: var(--space-6); position: relative; overflow-wrap: anywhere; }
.upload__item::before { position: absolute; left: 0; }
.upload__item[data-state="waiting"] { color: var(--color-muted); }
.upload__item[data-state="waiting"]::before { content: "·"; }
.upload__item[data-state="uploading"]::before { content: "…"; }
.upload__item[data-state="done"]::before { content: "✓"; color: var(--color-notice-text); }
.upload__item[data-state="error"] { color: var(--color-danger); }
.upload__item[data-state="error"]::before { content: "✕"; }

/* Rendition not generated yet */

.rendition-placeholder {
  display: grid; place-items: center;
  aspect-ratio: 1;
  padding: var(--space-1);
  background: var(--color-border);
  color: var(--color-muted);
  font-size: var(--font-size-small);
  text-align: center;
  border-radius: calc(var(--radius) / 2);
}

/* Map (Leaflet) */

.map {
  height: 16rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  z-index: 0;
}

@media (min-width: 48rem) { .map { height: 20rem; } }

.map-pin {
  background: var(--color-marker);
  border: 3px solid #ffffff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.4);
}

.position { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); margin: 0; }
.position__coordinates { color: var(--color-muted); font-variant-numeric: tabular-nums; }

.form-row { display: grid; gap: var(--space-4); }
@media (min-width: 40rem) { .form-row { grid-template-columns: 1fr 1fr; } }

/* Login code setup. The QR code stays dark on white, whatever the theme, or phones cannot read it. */

.totp__qr svg { display: block; width: 100%; max-width: 15rem; height: auto; padding: var(--space-3); background: #ffffff; border-radius: var(--radius); }
.totp__steps { display: grid; gap: var(--space-3); }
.totp__steps p { margin: 0; }
.totp__secret { font-size: var(--font-size-small); overflow-wrap: anywhere; user-select: all; }

/* Statistics */

.segmented { display: flex; flex-wrap: wrap; gap: var(--space-1); }

.table--numbers td[data-label] { font-variant-numeric: tabular-nums; }
.table tfoot tr { font-weight: 600; }
.table tfoot th { text-align: left; }

@media (min-width: 48rem) {
  .table--numbers td[data-label], .table--numbers thead th:not(:first-child) { text-align: right; }
  .table tfoot th, .table tfoot td { border-top: 2px solid var(--color-border); border-bottom: 0; }
}

/* Language switch */

.prefs { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); }
.prefs__option {
  min-height: 2.25rem;
  padding: var(--space-1) var(--space-3);
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--color-muted);
  font: inherit;
  font-size: var(--font-size-small);
  cursor: pointer;
}
.prefs__option:hover { border-color: var(--color-border); }
.prefs__option--current { background: var(--color-text); color: var(--color-surface); }
