/* Dark photo-canvas: a fixed dark identity for the app chrome (not an
   OS-linked light/dark toggle) -- the ground stays near-black regardless
   of system theme, so photos stay the brightest thing on screen. See the
   design pitch this was built from for the rationale/token names. */

* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;

  --ground: #171512;
  --surface: #201c18;
  --surface-2: #2a241e;
  --surface-3: #332c24;
  --hairline: #3d352b;
  --text: #f2ece1;
  --text-muted: #a89b88;
  --text-faint: #6f6355;
  --brass: #d6a75c;
  --brass-strong: #e7bd7a;
  --brass-dim: rgba(214, 167, 92, 0.14);
  --brass-dim-strong: rgba(214, 167, 92, 0.28);
  --success: #7cab7f;
  --success-dim: rgba(124, 171, 127, 0.16);
  --danger: #c47060;
  --danger-dim: rgba(196, 112, 96, 0.16);
  --black: #0a0908;

  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, ui-serif, serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, ui-sans-serif, system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, monospace;

  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-full: 999px;

  font-family: var(--font-ui);
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--brass-dim-strong);
  color: var(--text);
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 500;
  margin: 0 0 var(--sp-4);
}

p {
  margin: 0 0 var(--sp-3);
}

a {
  color: var(--brass);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

label {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

input:not([type="checkbox"]):not([type="file"]),
select,
textarea {
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  font-size: 0.8125rem;
  font-family: inherit;
}
input::placeholder,
textarea::placeholder {
  color: var(--text-faint);
}
input[type="checkbox"] {
  accent-color: var(--brass);
  width: 1rem;
  height: 1rem;
}
input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 1px;
}

button {
  font-family: inherit;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  font-size: 0.8125rem;
  cursor: pointer;
}
button:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-faint);
  background: var(--surface-3);
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
/* Buttons that are actually a form's primary action carry an explicit
   type="submit" in the markup (Upload, Add person, ...) -- style those as
   the one filled/brass affordance, everything else stays a quiet ghost
   button, matching a dense admin-table UI. */
button[type="submit"] {
  background: var(--brass);
  border-color: var(--brass);
  color: var(--ground);
  font-weight: 600;
}
button[type="submit"]:hover:not(:disabled) {
  background: var(--brass-strong);
  border-color: var(--brass-strong);
}

form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin: var(--sp-4) 0;
}

table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--hairline);
}
th {
  text-align: left;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 500;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--hairline);
  background: var(--surface-2);
}
td {
  text-align: left;
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--hairline);
  font-size: 0.8125rem;
  vertical-align: middle;
}
tr:last-child td {
  border-bottom: none;
}
tr:hover td {
  background: var(--surface-2);
}

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

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

.nav {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}

.nav .brand {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.25rem;
  letter-spacing: 0.01em;
  text-transform: none;
  color: var(--text);
  margin-right: auto;
}

.nav a {
  text-decoration: none;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.nav a:hover {
  color: var(--brass-strong);
}

.nav-user {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ---------- layout ---------- */

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-6);
}

/* ---------- gallery grid ---------- */

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--sp-2);
  margin: var(--sp-4) 0;
}

.thumb {
  display: block;
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid transparent;
}

.thumb.selected {
  border-color: var(--brass);
}

.thumb-checkbox {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  z-index: 1;
  width: 1.1rem;
  height: 1.1rem;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.7));
}

.progressive-thumb {
  position: relative;
  overflow: hidden;
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-3) 50%, var(--surface) 70%);
  background-size: 200% 100%;
  animation: thumb-shimmer 1.4s ease-in-out infinite;
}

.progressive-thumb.loaded {
  animation: none;
  background: none;
}

.progressive-thumb-img {
  display: block;
  width: 100%;
  height: 160px;
  object-fit: cover;
  opacity: 0;
  filter: blur(8px);
  transition: opacity 0.3s ease, filter 0.3s ease;
}

.progressive-thumb.loaded .progressive-thumb-img {
  opacity: 1;
  filter: blur(0);
}

@keyframes thumb-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.gallery-toolbar {
  display: flex;
  justify-content: flex-end;
  margin: var(--sp-2) 0;
}

.select-mode-toggle {
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
}

.bulk-tag-bar {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin: var(--sp-2) 0;
  padding: var(--sp-3);
  border: 1px solid var(--brass-dim-strong);
  border-radius: var(--radius-md);
  background: var(--brass-dim);
}

.bulk-tag-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-weight: 600;
  color: var(--brass-strong);
}

.bulk-tag-busy {
  font-weight: normal;
  color: var(--text-muted);
}

.bulk-tag-status {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.bulk-tag-rows {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.gallery-sentinel {
  min-height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
}

/* ---------- lightbox / image viewer ---------- */

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--black);
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-viewer .viewer-loading {
  color: var(--text);
}

.full-image {
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
  display: block;
}

.viewer-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.viewer-controls.hidden {
  opacity: 0;
}

.viewer-controls > * {
  pointer-events: auto;
}

.viewer-top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: linear-gradient(rgba(0, 0, 0, 0.65), transparent);
  color: var(--text);
}

.viewer-back {
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  font-size: 0.8125rem;
}

.viewer-meta {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-delete {
  white-space: nowrap;
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
}
.viewer-delete:hover:not(:disabled) {
  background: var(--danger-dim);
  border-color: var(--danger);
  color: var(--danger);
}

.viewer-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(10, 9, 8, 0.45);
  color: var(--text);
  border: none;
  font-size: 2rem;
  line-height: 1;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
}
.viewer-nav-btn:hover:not(:disabled) {
  background: var(--brass-dim-strong);
  color: var(--brass-strong);
}

.viewer-nav-btn.prev {
  left: var(--sp-4);
}

.viewer-nav-btn.next {
  right: var(--sp-4);
}

.viewer-nav-btn:disabled {
  opacity: 0.15;
}

.viewer-tag-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--sp-3) var(--sp-4);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
}

/* ---------- tag editing (viewer tag bar, bulk-tag rows, person tag editor) ---------- */

.tag-editor {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-5);
}

.tag-dimension {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  position: relative;
}

.tag-dimension-label {
  font-size: 0.75rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--surface-3);
  border: 1px solid var(--hairline);
  color: var(--text);
  border-radius: var(--radius-full);
  padding: 0.15rem 0.3rem 0.15rem 0.6rem;
  font-size: 0.85rem;
}

.tag-chip-remove {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0.1rem 0.3rem;
}
.tag-chip-remove:hover {
  color: var(--danger);
}

.tag-input-row {
  position: relative;
}

.tag-input {
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.25rem 0.55rem;
  font-size: 0.85rem;
}

.tag-suggestions {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 0.25rem;
  background: var(--surface-3);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  max-height: 10rem;
  overflow-y: auto;
  min-width: 8rem;
  z-index: 5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.tag-suggestion {
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  font-size: 0.85rem;
  border-radius: 0;
}
.tag-suggestion:hover {
  background: var(--surface-2);
  border-color: transparent;
  color: var(--text);
}
.tag-suggestion-create {
  color: var(--brass-strong);
  font-style: italic;
}

/* Bulk-tag bar and filter panel sit near the top of the page, so their
   popovers open downward instead of the viewer/tag-editor default
   (upward, since those sit at the bottom of the screen). */
.bulk-tag-bar .tag-suggestions,
.filter-panel .tag-suggestions {
  top: 100%;
  bottom: auto;
  margin-top: 0.25rem;
  margin-bottom: 0;
}

.person-create-dialog {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.date-editor {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.date-display {
  font-family: var(--font-mono);
}

/* ---------- filter panel ---------- */

.filter-panel {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin: var(--sp-4) 0;
  padding: var(--sp-4);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.filter-dimension {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  position: relative;
}

.filter-dimension-label {
  font-size: 0.75rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  min-width: 4.5rem;
}

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

.filter-chip {
  border-radius: var(--radius-full);
  padding: 0.15rem 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
  border: 1px solid var(--hairline);
  color: var(--text-muted);
  background: none;
}

.filter-chip.include {
  border-color: var(--brass);
  color: var(--brass-strong);
  background: var(--brass-dim);
}

.filter-chip.exclude {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-dim);
  text-decoration: line-through;
}

.filter-chip-off {
  border-color: var(--hairline);
  color: var(--text-faint);
  background: none;
  font-style: italic;
}

.filter-date-range {
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-year-input {
  width: 4.5rem;
  text-align: center;
}

.filter-unknown-date {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.filter-clear {
  align-self: flex-start;
  background: none;
  border: 1px solid var(--hairline);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.6rem;
  font-size: 0.85rem;
}

/* ---------- browse-by-dimension (date taken / event) ---------- */

.browse-hint {
  color: var(--text-faint);
  font-size: 0.75rem;
  margin: 0 0 var(--sp-3);
}

.group-header {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  margin: var(--sp-5) 0 var(--sp-3);
}
.group-header:first-child {
  margin-top: 0;
}
.group-header h3 {
  font-size: 1.0625rem;
  white-space: nowrap;
}
.group-header .group-count {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--text-faint);
  white-space: nowrap;
}
.group-header .rule {
  flex: 1;
  height: 1px;
  background: var(--hairline);
}

.event-group {
  margin-bottom: var(--sp-5);
}

.browse-switch {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 2px;
  margin-right: auto;
}

.browse-btn {
  background: none;
  border: none;
  padding: 5px 13px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  color: var(--text-muted);
}
.browse-btn:hover {
  color: var(--text);
  background: none;
  border: none;
}
.browse-btn.active {
  background: var(--brass);
  color: var(--ground);
  font-weight: 600;
}

.gallery-toolbar {
  justify-content: flex-start;
}

.taken-shell {
  display: flex;
  gap: var(--sp-5);
  align-items: flex-start;
}
.taken-main {
  flex: 1;
  min-width: 0;
}

.tm-tick-undated {
  margin-top: var(--sp-3);
  padding-top: var(--sp-2);
  border-top: 1px dashed var(--hairline);
}
.tm-tick-undated .yr {
  font-style: italic;
}

.tm-rail {
  width: 60px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  /* Fixed to the browser window's own right margin -- outside the
     (centered, max-width) content column -- rather than sitting at the
     edge of the gallery grid, so it stays put regardless of scroll
     position or how wide the viewport is. */
  position: fixed;
  right: var(--sp-5);
  top: 50%;
  transform: translateY(-50%);
  max-height: 80vh;
  overflow-y: auto;
  z-index: 20;
}
.tm-tick {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.tm-tick .dash {
  width: 14px;
  height: 1px;
  background: var(--hairline);
}
.tm-tick .yr {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--text-faint);
}
.tm-tick:hover .dash,
.tm-tick.active .dash {
  background: var(--brass);
  width: 20px;
  height: 2px;
}
.tm-tick:hover .yr,
.tm-tick.active .yr {
  color: var(--brass-strong);
}
.tm-flyout {
  position: absolute;
  right: 100%;
  margin-right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface-3);
  border: 1px solid var(--brass-dim-strong);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
}
.tm-tick:hover .tm-flyout,
.tm-tick.active .tm-flyout {
  opacity: 1;
}

.event-shell {
  display: flex;
  gap: var(--sp-4);
  align-items: flex-start;
}
.event-list-panel {
  width: 260px;
  flex-shrink: 0;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}
.event-search {
  display: block;
  width: 100%;
  border-radius: 0;
  border: none;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface-2);
}
.event-rows {
  max-height: 26rem;
  overflow-y: auto;
}
.event-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-2) var(--sp-3);
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--hairline);
  cursor: pointer;
}
.event-row:last-child {
  border-bottom: none;
}
.event-row:hover {
  background: var(--surface-2);
}
.event-row.active {
  border-left-color: var(--brass);
  background: var(--brass-dim);
}
.event-row .ev-name {
  font-size: 0.8125rem;
  color: var(--text);
}
.event-row .ev-meta {
  font-size: 0.6875rem;
  color: var(--text-faint);
  font-family: var(--font-mono);
}
.event-main {
  flex: 1;
  min-width: 0;
}
.event-main-head {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}
.event-main-head span {
  color: var(--text-faint);
  font-size: 0.75rem;
  font-family: var(--font-mono);
}

@media (prefers-reduced-motion: reduce) {
  .viewer-controls,
  .progressive-thumb-img,
  .progressive-thumb {
    transition: none;
    animation: none;
  }
}
