/*
  app.css — single stylesheet for the family media app.
  Plain CSS, mobile-first, no framework/build step.

  Design intent: near-neutral background so photos/videos are the only
  saturated thing on screen. One restrained accent colour, used only for
  links, active states, and buttons. Minimum 44px tap targets and 17px
  body text throughout, for non-technical users on phones.
*/

:root {
  --bg: #f7f6f4;
  --surface: #ffffff;
  --text: #1c1c1c;
  --text-muted: #5a5a5a;
  --border: #d9d6d1;
  --accent: #2f6690;
  --accent-contrast: #ffffff;
  --accent-soft: #e4edf3;
  --error-bg: #fdecea;
  --error-border: #b3261e;
  --error-text: #7a1712;
  --focus-ring: #2f6690;
  --tile-bg: #e7e5e2;
  --video-glyph: #6b6b6b;

  --tap-min: 44px;
  --font-size-base: 17px;
  --radius: 10px;
  --radius-pill: 999px;
  --gap: 0.75rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --surface: #1f2023;
    --text: #edecea;
    --text-muted: #a9a9a9;
    --border: #3a3b3e;
    --accent: #7db8e8;
    --accent-contrast: #0b1720;
    --accent-soft: #223342;
    --error-bg: #3a1f1d;
    --error-border: #ff8a80;
    --error-text: #ffb4ab;
    --focus-ring: #7db8e8;
    --tile-bg: #2a2b2e;
    --video-glyph: #b7b7b7;
  }
}

/* ---------- Base ---------- */

* {
  box-sizing: border-box;
}

html {
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  line-height: 1.5;
}

main,
body > *:not(nav) {
  /* content areas: comfortable width, centered on larger screens */
}

body > * {
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
}

nav {
  max-width: none;
  padding-left: 0;
  padding-right: 0;
}

h1,
h2,
h3 {
  line-height: 1.25;
  color: var(--text);
}

p {
  color: var(--text);
}

a {
  color: var(--accent);
}

a:visited {
  color: var(--accent);
}

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

/* ---------- Focus visibility ---------- */

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Top nav ---------- */

nav {
  display: flex;
  align-items: center;
  gap: var(--gap);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1rem;
}

nav a,
nav button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-min);
  padding: 0.5rem 0.9rem;
  font-size: 1rem;
  text-decoration: none;
  color: var(--text);
  border-radius: var(--radius);
  transition: background-color 0.15s ease;
}

nav a:hover,
nav button:hover {
  background: var(--accent-soft);
}

nav form {
  margin: 0 0 0 auto;
}

nav button {
  background: transparent;
  border: 1px solid var(--border);
  cursor: pointer;
  font-family: inherit;
}

/* ---------- Forms (shared: login, upload, tag-add) ---------- */

form {
  display: block;
}

label {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  margin: 1rem 0 0.35rem;
  color: var(--text);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"] {
  display: block;
  width: 100%;
  min-height: var(--tap-min);
  font-size: 1rem;
  font-family: inherit;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="search"]:focus {
  border-color: var(--accent);
}

input[type="file"] {
  display: block;
  width: 100%;
  min-height: var(--tap-min);
  font-size: 1rem;
  padding: 0.6rem 0.5rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

/* The native "choose file(s)" button part of the file input */
input[type="file"]::file-selector-button {
  min-height: 36px;
  margin-right: 0.75rem;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
  filter: brightness(1.08);
}

button,
input[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  padding: 0.6rem 1.25rem;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  color: var(--accent-contrast);
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: filter 0.15s ease;
}

button:hover,
input[type="submit"]:hover {
  filter: brightness(1.08);
}

button:active,
input[type="submit"]:active {
  filter: brightness(0.95);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#upload-status {
  margin-left: 0.75rem;
  color: var(--text-muted);
  font-size: 1rem;
}

/* ---------- Errors / messages ---------- */

.errorlist {
  list-style: none;
  margin: 1rem 0;
  padding: 0;
}

.errorlist li {
  background: var(--error-bg);
  color: var(--error-text);
  border-left: 4px solid var(--error-border);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  border-radius: 6px;
  font-size: 1rem;
}

/* ---------- Tag chips (gallery filter + detail tag list) ---------- */

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
  padding: 0;
  list-style: none;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: var(--tap-min);
  padding: 0.4rem 0.9rem;
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.tag-chip:hover {
  background: var(--accent-soft);
}

.tag-chip-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.tag-count {
  font-size: 0.8rem;
  opacity: 0.75;
}

/* ---------- Month header ---------- */

.month-header {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 1.5rem 0 0.75rem;
  padding: 0.5rem 0;
  background: var(--bg);
  font-size: 1.15rem;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}

/* ---------- Gallery grid ---------- */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem;
  margin-bottom: 1rem;
}

@media (min-width: 480px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
}

@media (min-width: 900px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.6rem;
  }
}

.gallery-tile {
  display: block;
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 6px;
  background: var(--tile-bg);
}

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

.gallery-tile:focus-visible {
  outline-offset: -3px;
}

.video-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 2rem;
  color: var(--video-glyph);
  background: var(--tile-bg);
}

/* ---------- Pagination ---------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin: 1.5rem 0;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border);
}

.pagination a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-min);
  padding: 0.5rem 0.9rem;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}

.pagination a:hover {
  background: var(--accent-soft);
}

.pagination span {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ---------- Detail page ---------- */

.detail-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
}

.detail-nav a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-min);
  padding: 0.5rem 0.9rem;
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.detail-nav a:hover {
  background: var(--accent-soft);
}

.detail-media {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1rem;
}

.detail-media img,
.detail-media video {
  display: block;
  max-width: 100%;
  max-height: 80vh;
  width: auto;
  height: auto;
}

.detail-meta {
  margin: 1rem 0;
}

.detail-meta dt {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
}

.detail-meta dd {
  margin: 0.15rem 0 0;
  font-size: 1.05rem;
  color: var(--text);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
}

.tag-remove-form {
  display: inline-flex;
  margin: 0;
}

.tag-remove-form .tag-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
}

.tag-remove-form .tag-chip:hover {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}

.tag-add-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin: 1.5rem 0;
}

.tag-add-form label {
  margin: 0;
  flex-basis: 100%;
}

.tag-add-form input[type="text"] {
  flex: 1 1 200px;
  width: auto;
}

.tag-add-form button {
  flex: 0 0 auto;
}

/* ---------- Tag-input widget (chips + inline create) ---------- */

.tag-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  min-height: var(--tap-min);
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.tag-input:focus-within {
  border-color: var(--accent);
}

.tag-input-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tag-input-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.6rem;
  font-size: 0.9rem;
  background: var(--accent-soft);
  border-radius: var(--radius-pill);
  color: var(--text);
}

.tag-input-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: auto;
  min-width: auto;
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  font-size: 0.9rem;
  line-height: 1;
  color: var(--text-muted);
  background: transparent;
  border-radius: var(--radius-pill);
}

.tag-input-chip-remove:hover {
  background: var(--border);
  filter: none;
}

.tag-input input[type="text"].tag-input-field {
  display: block;
  flex: 1 1 140px;
  width: auto;
  min-height: 2rem;
  padding: 0.3rem;
  border: none;
  border-radius: 0;
  background: transparent;
}

/* ---------- Gallery multi-select (admin batch tagging) ---------- */

.tile-checkbox {
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  z-index: 2;
  display: none;
}

#batch-tag-form.selecting .tile-checkbox {
  display: block;
}

#batch-tag-form.selecting .gallery-tile {
  cursor: pointer;
}

.tile-checkbox input[type="checkbox"] {
  width: 1.5rem;
  height: 1.5rem;
  accent-color: var(--accent);
}

.gallery-tile.tile-selected {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.batch-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
}

.batch-bar[hidden] {
  display: none;
}

.batch-bar-count {
  flex: 0 0 auto;
  font-weight: 600;
  color: var(--text);
}

.batch-bar input[type="text"] {
  flex: 1 1 160px;
  width: auto;
}

/* ---------- Detail page: date/time correction (admin only) ---------- */

.link-button {
  display: inline;
  min-height: auto;
  min-width: auto;
  padding: 0;
  margin-left: 0.5rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--accent);
  background: transparent;
  border: none;
  text-decoration: underline;
  cursor: pointer;
}

.date-edit-form {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.date-edit-form[hidden] {
  display: none;
}

.date-edit-form label {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 500;
  flex-basis: 100%;
}

.date-edit-form input[type="datetime-local"] {
  min-height: var(--tap-min);
  font-size: 1rem;
  font-family: inherit;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
