/* Trip photo gallery (r21). Self-contained: every rule is scoped to .tg / .tg-lb.
   Loaded from templates/trip_detail.php. Colours come from the Night trail tokens. */

/* ---- Trip page layout: photos get the full width under the two columns ---- */
@media (min-width: 1101px) {
  .app-v2 .trip-detail-tab-content { grid-template-rows: auto 1fr auto; }
  .app-v2 #tab-packing { grid-column: 1; grid-row: 1 / span 2; }
  .app-v2 #tab-overview { grid-column: 2; grid-row: 1; }
  .app-v2 #tab-weather { grid-column: 2; grid-row: 2; }
  .app-v2 #tab-photos { grid-column: 1 / -1; grid-row: 3; }
  /* No packing checklist yet: details take the wide column, weather sits beside them. */
  .app-v2 .trip-detail-tab-content:not(:has(#tab-packing)) #tab-overview { grid-column: 1; grid-row: 1 / span 2; }
  .app-v2 .trip-detail-tab-content:not(:has(#tab-packing)) #tab-weather { grid-column: 2; grid-row: 1; }
}

/* ---- Section shell ---- */
.tg {
  --tg-gap: 8px;
  container: tg / inline-size;
  position: relative;
  background: var(--nt-panel, #172019);
  border: 1px solid var(--nt-line, #2A3A2F);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 20px;
  color: var(--nt-text, #F3F0E8);
  font-family: var(--nt-body, Onest, system-ui, sans-serif);
}
.tg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.tg-title { display: flex; align-items: baseline; gap: 10px; margin: 0; font: 400 24px/1.1 var(--nt-display, Onest, sans-serif); letter-spacing: .02em; text-transform: uppercase; color: var(--nt-text, #F3F0E8); }
.tg-count { font: 500 14px/1 var(--nt-mono, ui-monospace, monospace); letter-spacing: 0; color: var(--nt-mist, #B4C2B6); }
.tg-count:empty { display: none; }
.tg-hint { margin: 0; font-size: 14px; color: var(--nt-mist, #B4C2B6); }
.tg-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.tg-add {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border-radius: 999px; border: 1px solid var(--nt-ember, #FF6A3D); background: var(--nt-ember, #FF6A3D);
  color: #1A0E08; font: 700 15px/1 var(--nt-body, Onest, sans-serif); cursor: pointer; white-space: nowrap;
  transition: transform .15s ease, filter .15s ease;
}
.tg-add:hover { filter: brightness(1.08); transform: translateY(-1px); }
.tg-add:focus-within { outline: 2px solid var(--nt-moss, #A6E36E); outline-offset: 2px; }
.tg-add svg { width: 18px; height: 18px; flex: none; }
.tg-add input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* Upload progress (ids are driven by the existing uploader in app.js) */
.tg .photo-upload-progress { position: relative; height: auto; margin: 0 0 14px; padding: 0; background: none; border: 0; border-radius: 0; overflow: visible; }
.tg .photo-upload-progress::before { content: ''; display: block; height: 6px; border-radius: 999px; background: var(--nt-line, #2A3A2F); }
.tg .photo-upload-progress-bar { position: absolute; left: 0; top: 0; height: 6px; width: 0; border-radius: 999px; background: var(--nt-moss, #A6E36E); transition: width .2s ease; }
.tg .photo-upload-progress-text { position: static; margin-top: 8px; font: 500 13px/1.3 var(--nt-mono, ui-monospace, monospace); color: var(--nt-mist, #B4C2B6); text-align: left; }

/* Drop target: the whole section accepts dropped photos */
.tg-dropveil { display: none; position: absolute; inset: 6px; z-index: 5; border: 2px dashed var(--nt-moss, #A6E36E); border-radius: 12px; background: rgba(14, 20, 17, .86); color: var(--nt-moss, #A6E36E); font: 700 18px/1 var(--nt-body, Onest, sans-serif); align-items: center; justify-content: center; pointer-events: none; }
.tg.is-dragover .tg-dropveil { display: flex; }

/* ---- Empty state ---- */
.tg-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 34px 16px; border: 1px dashed var(--nt-outline, #3B4E41); border-radius: 12px; text-align: center; cursor: pointer; }
.tg-empty svg { width: 34px; height: 34px; color: var(--nt-marker, #6E8474); }
.tg-empty strong { font-size: 17px; font-weight: 600; }
.tg-empty span { font-size: 14px; color: var(--nt-mist, #B4C2B6); }
.tg-empty:hover { border-color: var(--nt-moss, #A6E36E); }

/* ---- Justified grid: every row is the same height, photos keep their shape ---- */
.tg-grid { --tg-row: 100px; display: flex; flex-wrap: wrap; gap: var(--tg-gap); }
@container tg (min-width: 520px) { .tg-grid { --tg-row: 150px; } }
@container tg (min-width: 760px) { .tg-grid { --tg-row: 180px; } }
@container tg (min-width: 1100px) { .tg-grid { --tg-row: 220px; } }
.tg-grid::after { content: ''; flex: 1000 1 0; min-width: 0; height: 0; }
.tg-item {
  position: relative; margin: 0; overflow: hidden; border-radius: 10px; background: var(--nt-ground, #0E1411);
  flex: var(--r, 1.5) 1 calc(var(--r, 1.5) * var(--tg-row));
  aspect-ratio: var(--r, 1.5);
  max-height: calc(var(--tg-row) * 1.45);
  animation: tg-in .35s ease both;
}
@keyframes tg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.tg-open { display: block; width: 100%; height: 100%; padding: 0; margin: 0; border: 0; background: none; cursor: zoom-in; }
.tg-open img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease; }
.tg-item:hover .tg-open img { transform: scale(1.035); }
.tg-open:focus-visible { outline: 3px solid var(--nt-moss, #A6E36E); outline-offset: -3px; }

.tg-badge { position: absolute; left: 8px; top: 8px; display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px; border-radius: 999px; background: var(--nt-moss, #A6E36E); color: #10200A; font: 700 12px/1 var(--nt-body, Onest, sans-serif); pointer-events: none; }
.tg-badge svg { width: 12px; height: 12px; }

.tg-actions { position: absolute; right: 8px; top: 8px; display: flex; gap: 6px; opacity: 0; transform: translateY(-4px); transition: opacity .15s ease, transform .15s ease; }
.tg-item:hover .tg-actions, .tg-item:focus-within .tg-actions, .tg-actions.is-armed { opacity: 1; transform: none; }
/* Touch screens: keep the tiles clean; cover and delete live in the full-screen view. */
@media (hover: none) { .tg-actions { display: none; } }
.tg-act {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 36px; height: 36px; padding: 0 9px;
  border-radius: 999px; border: 1px solid rgba(243, 240, 232, .28); background: rgba(14, 20, 17, .78); color: var(--nt-text, #F3F0E8);
  font: 700 13px/1 var(--nt-body, Onest, sans-serif); cursor: pointer; backdrop-filter: blur(6px);
}
.tg-act svg { width: 16px; height: 16px; flex: none; pointer-events: none; }
.tg-act:hover { border-color: var(--nt-moss, #A6E36E); color: var(--nt-moss, #A6E36E); }
.tg-act.tg-delete:hover, .tg-act.is-armed { border-color: var(--nt-ember, #FF6A3D); color: #1A0E08; background: var(--nt-ember, #FF6A3D); }
.tg-act:focus-visible { outline: 2px solid var(--nt-moss, #A6E36E); outline-offset: 2px; }

/* ---- Lightbox ---- */
.tg-lb { position: fixed; inset: 0; z-index: 3000; display: none; flex-direction: column; background: rgba(8, 12, 10, .985); color: var(--nt-text, #F3F0E8); font-family: var(--nt-body, Onest, system-ui, sans-serif); }
.tg-lb.is-open { display: flex; animation: tg-fade .18s ease both; }
@keyframes tg-fade { from { opacity: 0; } to { opacity: 1; } }
.tg-lb-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
.tg-lb-count { font: 500 14px/1 var(--nt-mono, ui-monospace, monospace); color: var(--nt-mist, #B4C2B6); white-space: nowrap; }
.tg-lb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 600; }
.tg-lb-btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-width: 44px; height: 44px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--nt-outline, #3B4E41); background: var(--nt-panel, #172019); color: var(--nt-text, #F3F0E8); font: 600 14px/1 var(--nt-body, Onest, sans-serif); cursor: pointer; }
.tg-lb-btn svg { width: 18px; height: 18px; flex: none; pointer-events: none; }
.tg-lb-btn:hover { border-color: var(--nt-moss, #A6E36E); color: var(--nt-moss, #A6E36E); }
.tg-lb-btn.is-armed, .tg-lb-btn.tg-lb-del:hover { border-color: var(--nt-ember, #FF6A3D); background: var(--nt-ember, #FF6A3D); color: #1A0E08; }
.tg-lb-btn:focus-visible { outline: 2px solid var(--nt-moss, #A6E36E); outline-offset: 2px; }
.tg-lb-btn[hidden], .tg-fp-crop[hidden] { display: none; }
.tg-lb-stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0 8px 14px; touch-action: pan-y; user-select: none; }
.tg-lb-img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; transition: opacity .18s ease; }
.tg-lb-img.is-loading { opacity: .25; }
.tg-lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; padding: 0; }
.tg-lb-prev { left: 12px; }
.tg-lb-next { right: 12px; }
.tg-lb-nav:disabled { opacity: .25; cursor: default; }
.tg-lb-strip { display: flex; gap: 6px; padding: 0 14px max(12px, env(safe-area-inset-bottom)); overflow-x: auto; scrollbar-width: thin; justify-content: safe center; }
.tg-lb-thumb { flex: none; width: 58px; height: 44px; padding: 0; border: 2px solid transparent; border-radius: 6px; overflow: hidden; background: var(--nt-panel, #172019); cursor: pointer; opacity: .55; }
.tg-lb-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tg-lb-thumb[aria-current="true"] { border-color: var(--nt-ember, #FF6A3D); opacity: 1; }
.tg-lb-thumb:hover { opacity: 1; }
body.tg-lock { overflow: hidden; }

/* ---- Smaller screens ---- */
@media (max-width: 768px) {
  .tg { --tg-gap: 6px; padding: 14px; border-radius: 14px; }
  .tg-title { font-size: 20px; }
  .tg-hint { display: none; }
  .tg-item { border-radius: 8px; }
  .tg-lb-name { font-size: 14px; }
  .tg-lb-btn span { display: none; }
  .tg-lb-nav { display: none; }
  .tg-lb-stage { padding: 0 0 10px; }
  .tg-lb-img { border-radius: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .tg-item, .tg-lb.is-open { animation: none; }
  .tg-open img, .tg-actions, .tg-add, .tg-lb-img { transition: none; }
}
@media print { .tg-head .tg-tools, .tg-actions, .tg-lb { display: none !important; } }

/* ---- Trip page: "Edit details" on the details card (opens the normal edit mode) ---- */
.app-v2 .tg-card-edit { margin-left: auto; min-height: 40px; white-space: nowrap; }
.app-v2.trip-edit-mode-active .tg-card-edit { display: none; }

/* ---- Cover photo: focal point dialog ---- */
.tg-fp { position: fixed; inset: 0; z-index: 3100; display: none; align-items: center; justify-content: center; padding: 16px; background: rgba(8, 12, 10, .9); color: var(--nt-text, #F3F0E8); font-family: var(--nt-body, Onest, system-ui, sans-serif); }
.tg-fp.is-open { display: flex; animation: tg-fade .18s ease both; }
.tg-fp-panel { width: min(980px, 100%); max-height: 100%; overflow: auto; padding: 20px; border-radius: 18px; border: 1px solid var(--nt-outline, #3B4E41); background: var(--nt-panel, #172019); }
.tg-fp-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tg-fp-head h2 { margin: 0; font: 400 24px/1.1 var(--nt-display, Onest, sans-serif); letter-spacing: .02em; text-transform: uppercase; color: var(--nt-text, #F3F0E8); }
.tg-fp-help { margin: 8px 0 16px; font-size: 16px; line-height: 1.5; color: var(--nt-mist, #B4C2B6); }
.tg-fp-body { display: grid; grid-template-columns: minmax(0, 3fr) minmax(200px, 1.25fr); gap: 20px; align-items: start; }
.tg-fp-stage { position: relative; justify-self: center; line-height: 0; border-radius: 10px; overflow: hidden; cursor: crosshair; touch-action: none; user-select: none; background: var(--nt-ground, #0E1411); }
.tg-fp-stage:focus-visible { outline: 3px solid var(--nt-moss, #A6E36E); outline-offset: 3px; }
.tg-fp-src { display: block; max-width: 100%; max-height: min(60vh, 560px); pointer-events: none; }
.tg-fp-dot { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; border: 3px solid #fff; background: rgba(255, 106, 61, .28); box-shadow: 0 0 0 2px rgba(14, 20, 17, .75), inset 0 0 0 2px rgba(14, 20, 17, .55); pointer-events: none; }
.tg-fp-dot::after { content: ''; position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: var(--nt-ember, #FF6A3D); box-shadow: 0 0 0 2px #fff; }
.tg-fp-previews { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tg-fp-previews figure { margin: 0; }
.tg-fp-previews figure:first-child { grid-column: 1 / -1; }
.tg-fp-previews figcaption { margin-top: 6px; font: 500 12px/1.3 var(--nt-mono, ui-monospace, monospace); letter-spacing: .08em; text-transform: uppercase; color: var(--nt-mist, #B4C2B6); }
.tg-fp-pv { overflow: hidden; border-radius: 8px; border: 1px solid var(--nt-line, #2A3A2F); background: var(--nt-ground, #0E1411); }
.tg-fp-pv img { display: block; width: 100%; height: 100%; object-fit: cover; }
.tg-fp-pv-banner { aspect-ratio: 3.2 / 1; }
.tg-fp-pv-card { aspect-ratio: 4 / 3; }
.tg-fp-pv-tall { aspect-ratio: 3 / 4; }
.tg-fp-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.tg-fp-gap { flex: 1; }
.tg-fp-crop { border-color: transparent; background: none; color: var(--nt-mist, #B4C2B6); padding: 0 4px; text-decoration: underline; }
.tg-fp-save { border-color: var(--nt-ember, #FF6A3D); background: var(--nt-ember, #FF6A3D); color: #1A0E08; font-weight: 700; padding: 0 20px; }
.tg-fp-save:hover { color: #1A0E08; filter: brightness(1.08); border-color: var(--nt-ember, #FF6A3D); }
.tg-fp-save:disabled { opacity: .6; cursor: default; }
@media (max-width: 768px) {
  .tg-fp { padding: 0; align-items: stretch; }
  .tg-fp-panel { border-radius: 0; border: 0; padding: 14px; padding-top: max(14px, env(safe-area-inset-top)); }
  .tg-fp-head h2 { font-size: 19px; }
  .tg-fp-help { font-size: 15px; margin-bottom: 12px; }
  .tg-fp-body { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .tg-fp-src { max-height: 44vh; }
  .tg-fp-previews { grid-template-columns: 2fr 1fr 0.75fr; align-items: end; }
  .tg-fp-previews figure:first-child { grid-column: auto; }
  .tg-fp-actions .tg-lb-btn span { display: inline; }
  .tg-fp-gap { display: none; }
  .tg-fp-crop { flex-basis: 100%; justify-content: flex-start; height: 36px; }
  .tg-fp-cancel, .tg-fp-save { flex: 1; }
}
@media (prefers-reduced-motion: reduce) { .tg-fp.is-open { animation: none; } }

/* ---- Trip page: publish button and banner actions that wrap on phones ---- */
.app-v2 .trip-share-btn.is-published { border-color: var(--nt-moss, #A6E36E); color: var(--nt-moss, #A6E36E); }
.phone-app .trip-detail-banner-actions { flex-wrap: wrap !important; }

/* ---- Trip page: packing checklist grouped by gear category ---- */
.app-v2 #tab-packing .trip-pack-category { margin: 0; padding: 0; border: 0; }
.app-v2 #tab-packing .trip-pack-category-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0; padding: 10px 14px; background: var(--nt-ground, #0E1411); border-top: 1px solid var(--nt-line, #2A3A2F); border-bottom: 1px solid var(--nt-line, #2A3A2F); font: 500 13px/1.4 var(--nt-mono, ui-monospace, monospace); letter-spacing: .1em; text-transform: uppercase; color: var(--nt-moss, #A6E36E); }
.app-v2 #tab-packing .trip-pack-category:first-child .trip-pack-category-title { border-top: 0; }
.app-v2 #tab-packing .trip-pack-category-count { color: var(--nt-mist, #B4C2B6); letter-spacing: 0; }
/* A category with every entry filtered out disappears with its entries. */
.app-v2 #tab-packing .trip-pack-category:not(:has(.trip-pack-checklist-item:not([hidden]))) { display: none; }
