/* Havenga Fotos
 *
 * The photographs are the only decoration. Everything else is cool granite
 * graphite so the pictures hold the colour, with warm bone text over it — the
 * warm/cool tension is what keeps this from reading as a cold professional tool.
 * The single accent is vygie magenta, the flower that carpets the Namaqualand
 * veld these photographs come from. It appears only where something is selected,
 * focused or active; never as decoration.
 *
 * The year, set in a serif with old-style numerals, is the spine of the archive.
 */

:root {
  --ink:        #171A1C;   /* granite in shade — the ground */
  --ink-sunk:   #101314;   /* behind the lightbox */
  --ink-raise:  #212629;   /* sidebar, bars, panels */
  --ink-raise2: #2A3033;   /* hover, inputs */
  --line:       #333A3E;   /* hairlines */
  --bone:       #E8E4DC;   /* primary text — weathered quartz, warm */
  --bone-dim:   #9AA0A2;   /* secondary text */
  --bone-faint: #6E7477;   /* tertiary, placeholders */
  --vygie:      #C2407A;   /* the accent: selection, focus, active */
  --vygie-deep: #8E2A57;
  --veld:       #B8892F;   /* favourites only */
  --alarm:      #C9503F;

  --serif: Georgia, 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  --rail: 232px;
  --topbar: 52px;
  --gap: 4px;              /* between photos: tight, like an album page */
  --radius-print: 2px;     /* a print edge, not a SaaS card */
  --radius-panel: 6px;
}

* { box-sizing: border-box; }

/* The hidden attribute must beat the layout rules below. Without this, any
 * element given `display: flex/grid` stays visible while marked hidden — which
 * showed the sign-in gate, the gallery and the lightbox all stacked together. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--bone);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible {
  outline: 2px solid var(--vygie);
  outline-offset: 2px;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- sign in */

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-card {
  width: min(380px, 100%);
  background: var(--ink-raise);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  padding: 32px 28px;
}

.gate-title {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin: 0 0 6px;
}

.gate-sub { margin: 0 0 24px; color: var(--bone-dim); font-size: 14px; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; color: var(--bone-dim); margin-bottom: 6px; }

.field input, .modal-card input, .modal-card select, .modal-card textarea,
.lb-panel input, .lb-panel select, .lb-panel textarea {
  width: 100%;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 9px 11px;
  color: var(--bone);
}

.field input:focus, .modal-card input:focus, .modal-card textarea:focus,
.lb-panel input:focus, .lb-panel textarea:focus {
  border-color: var(--vygie);
  outline: none;
}

.gate-swap { margin: 16px 0 0; font-size: 14px; color: var(--bone-dim); text-align: center; }

.linkish {
  border: 0;
  background: none;
  padding: 0;
  color: var(--vygie);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
}

.field-hint { display: block; margin-top: 5px; font-size: 12px; color: var(--bone-faint); }

.check { display: flex; gap: 9px; align-items: flex-start; margin: 4px 0 18px; font-size: 13px; color: var(--bone-dim); }
.check input { margin-top: 2px; accent-color: var(--vygie); }

.gate-error, .form-error {
  color: #F0A79A;
  background: rgba(201, 80, 63, 0.14);
  border-left: 2px solid var(--alarm);
  padding: 8px 11px;
  font-size: 14px;
  margin: 0 0 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--ink-raise2);
  color: var(--bone);
  cursor: pointer;
}

.btn:hover { background: #343B3F; }
.btn-primary { background: var(--vygie); border-color: var(--vygie); color: #fff; }
.btn-primary:hover { background: var(--vygie-deep); border-color: var(--vygie-deep); }
.btn-quiet { background: transparent; }
/* The confirmation page is served by the application, under the same policy as
 * the gallery — style-src 'self' blocks inline style attributes, so links that
 * look like buttons need a class. */
.btn-link { text-decoration: none; }
.btn-danger { color: #F0A79A; border-color: #5A3A36; }
.btn:disabled { opacity: 0.5; cursor: default; }
.gate-card .btn { width: 100%; }

/* ---------------------------------------------------------------- frame */

.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  height: var(--topbar);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: var(--ink-raise);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--serif);
  font-size: 19px;
  color: var(--bone);
  text-decoration: none;
  white-space: nowrap;
}

.search { position: relative; flex: 1 1 auto; max-width: 420px; }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--bone-faint); }

.search input {
  width: 100%;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 11px 7px 36px;
  color: var(--bone);
}

.search input::placeholder { color: var(--bone-faint); }
.search input:focus { border-color: var(--vygie); outline: none; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--bone-dim);
  cursor: pointer;
}

.icon-btn:hover { background: var(--ink-raise2); color: var(--bone); }
.icon-btn.is-on { color: var(--veld); }
.icon-btn.is-on svg { fill: var(--veld); }

.who { position: relative; margin-left: auto; }

.who-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--bone);
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.menu {
  position: absolute;
  right: 0; top: calc(100% + 6px);
  min-width: 200px;
  background: var(--ink-raise);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  padding: 5px;
  z-index: 60;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
}

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 11px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}

.menu-item:hover { background: var(--ink-raise2); }

.body { flex: 1 1 auto; display: flex; min-height: 0; }

/* ---------------------------------------------------------------- sidebar */

.sidebar {
  flex: 0 0 var(--rail);
  width: var(--rail);
  overflow-y: auto;
  padding: 18px 0 28px;
  background: var(--ink-raise);
  border-right: 1px solid var(--line);
}

.nav-group { margin-bottom: 22px; }

/* Sentence case in a quiet serif italic — a section heading, not a shouted label. */
.nav-head {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 13px;
  color: var(--bone-faint);
  margin: 0 0 6px;
  padding: 0 16px;
}

.nav-list { list-style: none; margin: 0; padding: 0; }

.nav-list button {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 6px 16px;
  border: 0;
  border-left: 2px solid transparent;
  background: transparent;
  color: var(--bone-dim);
  cursor: pointer;
}

.nav-list button:hover { background: var(--ink-raise2); color: var(--bone); }

.nav-list button[aria-current="true"] {
  color: var(--bone);
  border-left-color: var(--vygie);
  background: var(--ink-raise2);
}

.nav-label { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count { flex: 0 0 auto; font-size: 12px; color: var(--bone-faint); font-variant-numeric: tabular-nums; }

.nav-tags { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 16px; }
.nav-tags li { list-style: none; }

.nav-tags button {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-left-width: 1px;
  border-radius: 11px;
  font-size: 13px;
  width: auto;
}

.nav-tags button[aria-current="true"] { border-color: var(--vygie); background: rgba(194, 64, 122, 0.16); }

.crumbs { list-style: none; display: flex; flex-wrap: wrap; gap: 3px; margin: 0 0 6px; padding: 0 16px; font-size: 12px; }
.crumbs button { border: 0; background: transparent; color: var(--vygie); cursor: pointer; padding: 0; }
.crumbs li:not(:last-child)::after { content: '/'; color: var(--bone-faint); margin-left: 3px; }

.nav-foot { padding: 0 16px; font-size: 12px; color: var(--bone-faint); margin: 0; }

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

.main { flex: 1 1 auto; overflow-y: auto; padding: 0 var(--gap) 80px; }

.context { padding: 22px 8px 4px; }

.context-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 26px;
  margin: 0;
  letter-spacing: -0.01em;
}

.context-sub { margin: 2px 0 0; color: var(--bone-dim); font-size: 14px; }

/* A date group: the year hangs at the left as the spine, the month sits under it. */
.group { margin-top: 30px; }

.group-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 0 8px 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--gap);
}

.group-year {
  font-family: var(--serif);
  font-size: 34px;
  line-height: 1;
  font-weight: 400;
  font-variant-numeric: oldstyle-nums;
  letter-spacing: -0.015em;
}

.group-month { font-family: var(--serif); font-size: 17px; color: var(--bone-dim); }
.group-count { margin-left: auto; font-size: 13px; color: var(--bone-faint); font-variant-numeric: tabular-nums; }

/* Justified rows. Each row's height is computed in JS from the real aspect
 * ratios so the row fills the width exactly — photos keep their true shape.
 * Nothing is cropped to a square: a family archive is full of portraits and
 * panoramas, and squaring them off tells a lie about the picture. */
.row { display: flex; gap: var(--gap); margin-bottom: var(--gap); max-width: 100%; }
.main, .grid { overflow-x: hidden; }

.cell {
  position: relative;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  background: var(--ink-raise);
  border-radius: var(--radius-print);
  overflow: hidden;
  cursor: zoom-in;
  display: block;
}

.cell img {
  display: block;
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 220ms ease;
}

.cell img.is-loaded { opacity: 1; }
.cell:hover { outline: 2px solid var(--bone-faint); outline-offset: -2px; }
.cell:focus-visible { outline: 2px solid var(--vygie); outline-offset: -2px; }

.cell-badge {
  position: absolute;
  bottom: 5px; left: 6px;
  display: flex; align-items: center; gap: 4px;
  font-size: 11px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  font-variant-numeric: tabular-nums;
}

.cell-badge svg { width: 13px; height: 13px; }
.cell-fav { position: absolute; top: 5px; right: 6px; color: var(--veld); }
.cell-fav svg { width: 15px; height: 15px; fill: var(--veld); filter: drop-shadow(0 1px 2px rgba(0,0,0,.8)); }

.empty { padding: 60px 10px; max-width: 46ch; color: var(--bone-dim); }
.empty h2 { font-family: var(--serif); font-weight: 400; font-size: 22px; color: var(--bone); margin: 0 0 8px; }
.loading { padding: 20px 10px; color: var(--bone-faint); }
.sentinel { height: 1px; }

/* ---------------------------------------------------------------- lightbox */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--ink-sunk);
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-stage { position: absolute; inset: 0 0 52px; display: grid; place-items: center; padding: 16px; }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: 100%; display: block; border-radius: var(--radius-print); }

/* The one piece of non-user-triggered motion in the interface: the photo
 * settling as it opens. Everything else waits to be asked. */
.lb-stage img.is-entering { animation: settle 240ms cubic-bezier(.2, .7, .3, 1); }

@keyframes settle {
  from { opacity: 0; transform: scale(0.965); }
  to { opacity: 1; transform: none; }
}

.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 52px; height: 76px;
  border: 0;
  background: rgba(23, 26, 28, 0.55);
  color: var(--bone);
  cursor: pointer;
  border-radius: 4px;
}

.lb-nav:hover { background: rgba(42, 48, 51, 0.9); }
.lb-nav svg { width: 26px; height: 26px; }
.lb-prev { left: 10px; }
.lb-next { right: 10px; }

.lb-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  background: var(--ink-raise);
  border-top: 1px solid var(--line);
}

.lb-count { font-size: 13px; color: var(--bone-dim); font-variant-numeric: tabular-nums; }
.lb-actions { margin-left: auto; display: flex; gap: 2px; }

.lb-panel {
  position: absolute;
  top: 0; right: 0; bottom: 52px;
  width: min(340px, 86vw);
  overflow-y: auto;
  padding: 20px;
  background: var(--ink-raise);
  border-left: 1px solid var(--line);
}

.lb-panel h2 { font-family: var(--serif); font-weight: 400; font-size: 19px; margin: 0 0 4px; }
.lb-panel .panel-path { font-size: 12px; color: var(--bone-faint); word-break: break-all; margin: 0 0 18px; }
.lb-panel dl { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0 0 18px; font-size: 13px; }
.lb-panel dt { color: var(--bone-faint); }
.lb-panel dd { margin: 0; font-variant-numeric: tabular-nums; }
.lb-panel h3 { font-size: 13px; color: var(--bone-dim); font-weight: 500; margin: 0 0 7px; }
.lb-panel textarea, .modal-card textarea { font-family: inherit; resize: vertical; margin-bottom: 12px; }
/* Keep the browser's own date/time picker glyphs legible on a dark field. */
.lb-panel input[type="date"]::-webkit-calendar-picker-indicator,
.modal-card input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.75); cursor: pointer; }
.panel-section { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 0 0 10px; padding: 0; list-style: none; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 5px 3px 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  font-size: 13px;
}

.chip button { border: 0; background: transparent; color: var(--bone-faint); cursor: pointer; padding: 0 2px; line-height: 1; }
.chip button:hover { color: var(--alarm); }
.row-actions { display: flex; gap: 6px; margin-top: 10px; }
.inline-form { display: flex; gap: 6px; }
.inline-form .btn { white-space: nowrap; }
.inline-form input { flex: 1 1 auto; }

/* ---------------------------------------------------------------- dialogs */

.modal {
  position: fixed; inset: 0; z-index: 120;
  background: rgba(16, 19, 20, 0.78);
  display: grid; place-items: center;
  padding: 20px;
}

.modal-card {
  width: min(560px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--ink-raise);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  padding: 26px;
}

.modal-card h2 { font-family: var(--serif); font-weight: 400; font-size: 23px; margin: 0 0 6px; }
.modal-card p.hint { color: var(--bone-dim); font-size: 14px; margin: 0 0 20px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 22px; }

.token {
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-size: 13px;
  word-break: break-all;
  background: var(--ink);
  border: 1px solid var(--vygie);
  border-radius: 4px;
  padding: 11px;
  margin: 0 0 6px;
}

table.plain { width: 100%; border-collapse: collapse; font-size: 14px; }
table.plain th { text-align: left; color: var(--bone-dim); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.plain td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.plain tr:last-child td { border-bottom: 0; }

.toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translateX(-50%);
  z-index: 140;
  background: var(--ink-raise);
  border: 1px solid var(--line);
  border-left: 2px solid var(--vygie);
  border-radius: 4px;
  padding: 10px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* ---------------------------------------------------------------- responsive */

.only-narrow { display: none; }

@media (max-width: 860px) {
  .only-narrow { display: inline-grid; }
  .sidebar {
    position: fixed;
    top: var(--topbar); bottom: 0; left: 0;
    z-index: 70;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
  }
  .sidebar.is-open { transform: none; }
  .brand { font-size: 17px; }
  .who-btn { padding: 6px 9px; }
  .group-year { font-size: 27px; }
  .lb-nav { width: 44px; height: 62px; }
  .lb-panel { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
