/* 6P Gallery — layered on top of 6p-base.css, which owns the palette.
   Only what a gallery needs: a dark header, a folder/media grid, a lightbox,
   and the share manager. */

:root {
  --header-green: #1e5c35;   /* matches the fork being replaced, and 6P Timetable */
  --tile-gap: 10px;
}

/* ---------------------------------------------------------------- header -- */
/* The house .header is a white surface. A gallery reads better with dark
   chrome, and this keeps the visual change from the PiGallery2 fork close to
   zero for staff who use it every week. */
.header {
  background: var(--header-green);
  border-bottom: none;
  color: #fff;
  gap: 10px;
}
.header-title, .header-subtitle { color: #fff; }
.header-subtitle { color: rgba(255, 255, 255, 0.72); }
.header .spacer { flex: 1 1 auto; }

.hbtn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  min-height: 34px;
}
.hbtn:hover { background: rgba(255, 255, 255, 0.22); }
.hbtn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ------------------------------------------------------------ breadcrumb -- */
.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 10px max(16px, env(safe-area-inset-left, 0px));
  font-size: 13px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  z-index: 50;
}
.crumbs a { color: var(--green-dark); text-decoration: none; font-weight: 600; }
.crumbs a:hover { text-decoration: underline; }
.crumbs .sep { color: var(--text-2); }
.crumbs .here { color: var(--text); font-weight: 700; }
.crumbs .count { color: var(--text-2); margin-left: auto; font-weight: 500; }

/* ------------------------------------------------------------------ grid -- */
.wrap {
  max-width: 1600px;
  margin: 0 auto;
  padding: 16px max(12px, env(safe-area-inset-left, 0px))
           calc(32px + env(safe-area-inset-bottom, 0px));
}

.section-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-2);
  margin: 4px 2px 8px;
}

.folders {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--tile-gap);
  margin-bottom: 22px;
}
.folder {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  padding: 0;
  width: 100%;
}
.folder:hover { border-color: var(--green); box-shadow: var(--shadow); }
.folder .cover {
  aspect-ratio: 4 / 3;
  background: var(--bg) center/cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  color: var(--text-2);
}
.folder .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.folder .meta { padding: 9px 10px; }
.folder .name {
  font-size: 13px; font-weight: 600; line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.folder .sub { font-size: 11.5px; color: var(--text-2); margin-top: 2px; }

.media {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), 1fr);
  gap: var(--tile-gap);
}
.tile {
  position: relative;
  margin: 0;
  aspect-ratio: 3 / 2;
  background: #e7eae8;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  border: none;
  padding: 0;
}
.tile img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  background: #e7eae8;
}
.tile .play {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.tile .play span {
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff; font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  padding-left: 3px;
}
.tile .dur {
  position: absolute; right: 6px; bottom: 6px;
  background: rgba(0, 0, 0, 0.66); color: #fff;
  font-size: 11px; font-weight: 600;
  padding: 1px 5px; border-radius: 4px;
  pointer-events: none;
}
.tile .pending {
  position: absolute; left: 6px; top: 6px;
  background: var(--warn); color: #fff;
  font-size: 10.5px; font-weight: 700;
  padding: 2px 6px; border-radius: 4px;
  pointer-events: none;
}

.empty {
  text-align: center;
  color: var(--text-2);
  padding: 60px 20px;
  font-size: 14px;
}

/* ----------------------------------------------------- selection basket -- */
.section-label { display: flex; align-items: center; gap: 10px; }
.linkish {
  background: none; border: none; padding: 0;
  font: inherit; font-size: 11.5px; font-weight: 700; letter-spacing: 0.04em;
  color: var(--green-dark); cursor: pointer; text-transform: uppercase;
}
.linkish:hover { text-decoration: underline; }

.tile .pick {
  position: absolute; left: 7px; top: 7px;
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.82);
  border: 2px solid rgba(0, 0, 0, 0.28);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}

/* A checkbox on every tile is noise in a gallery whose job is showing photos.
   Reveal it on hover where there IS a hover — and leave it permanently visible
   on touch, where there is not and where an invisible control is an undiscovered
   one. A selected tile always shows its tick. */
@media (hover: hover) and (pointer: fine) {
  .tile .pick { opacity: 0; }
  .tile:hover .pick,
  .tile:focus-within .pick,
  .tile .pick:focus,
  .tile .pick.on { opacity: 1; }
}
.tile .pick.on {
  background: var(--green);
  border-color: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.tile .pick.on::after {
  content: '';
  position: absolute; left: 6px; top: 2px;
  width: 6px; height: 12px;
  border: solid #fff; border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}
.tile.picked { outline: 3px solid var(--green); outline-offset: -3px; }

.basket {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 180;
  display: none;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 9px 12px 9px 18px;
  max-width: calc(100vw - 24px);
}
.basket.show { display: flex; }
.basket .count { font-size: 13px; font-weight: 600; white-space: nowrap; }

/* ------------------------------------------------------------- lightbox -- */
.lb {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(12, 14, 13, 0.94);
  display: none;
  flex-direction: column;
}
.lb.open { display: flex; }
.lb-bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
  color: #fff; font-size: 13px;
}
.lb-bar .name {
  flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lb-bar button {
  background: rgba(255, 255, 255, 0.14); border: none; color: #fff;
  border-radius: var(--radius-sm); padding: 8px 12px;
  font-size: 13px; font-family: inherit; cursor: pointer; min-height: 40px;
}
.lb-bar button:hover { background: rgba(255, 255, 255, 0.26); }
.lb-bar .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.lb-act {
  background: rgba(255, 255, 255, 0.14); border: none; color: #fff;
  border-radius: var(--radius-sm); padding: 8px 12px;
  font-size: 13px; font-family: inherit; cursor: pointer;
  min-height: 40px; display: inline-flex; align-items: center;
  text-decoration: none; white-space: nowrap;
}
.lb-act:hover { background: rgba(255, 255, 255, 0.26); }
.lb-body {
  flex: 1 1 auto; position: relative;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  padding: 0 8px calc(8px + env(safe-area-inset-bottom, 0px));
}
.lb-body img, .lb-body video {
  max-width: 100%; max-height: 100%;
  object-fit: contain; border-radius: 4px;
}
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 52px; height: 84px;
  background: rgba(255, 255, 255, 0.10); border: none; color: #fff;
  font-size: 24px; cursor: pointer; border-radius: var(--radius-sm);
}
.lb-nav:hover { background: rgba(255, 255, 255, 0.24); }
.lb-nav.prev { left: 10px; }
.lb-nav.next { right: 10px; }
.lb-note {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7); color: #fff;
  padding: 8px 14px; border-radius: 20px; font-size: 13px;
}

/* ------------------------------------------------------- share manager --- */
.sheet {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(0, 0, 0, 0.4);
  display: none;
}
.sheet.open { display: block; }
.sheet-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(560px, 100%);
  background: var(--surface);
  display: flex; flex-direction: column;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.18);
}
.sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}
.sheet-body {
  flex: 1 1 auto; overflow-y: auto;
  padding: 16px 16px calc(28px + env(safe-area-inset-bottom, 0px));
}

.field { margin-bottom: 12px; }
.field label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-2); margin-bottom: 4px;
}
.field .hint { font-size: 11.5px; color: var(--text-2); margin-top: 4px; }
.row { display: flex; gap: 8px; align-items: center; }
.row label { font-size: 13px; font-weight: 500; color: var(--text); }

.share-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
  margin-bottom: 9px;
  background: var(--surface);
}
.share-row.expired { opacity: 0.62; border-style: dashed; }
.share-row .k {
  font-weight: 700; font-size: 13.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.share-row .r { font-size: 12px; color: var(--text-2); margin-top: 2px; word-break: break-word; }
.share-row .acts { display: flex; gap: 6px; margin-top: 9px; flex-wrap: wrap; }

/* Centred dialog, reusing the slide-over's chrome. */
.modal-panel {
  position: absolute;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(620px, calc(100% - 24px));
  max-height: min(86dvh, 780px);
  background: var(--surface);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}
.modal-panel .sheet-head { padding: 14px 16px; }
.warnbox {
  background: var(--warn-light);
  border: 1px solid var(--warn);
  color: #7a4a06;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}
.bulk-list { max-height: 300px; overflow-y: auto; margin-top: 12px; }
.field .copy { margin-top: 6px; }
code {
  background: var(--bg); padding: 1px 5px; border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
}

textarea, .copybox {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}
textarea:focus { outline: none; border-color: var(--green); }

/* --------------------------------------------------------------- share --- */
.intro {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
  line-height: 1.5;
  font-size: 14px;
}
.intro > :first-child { margin-top: 0; }
.intro > :last-child { margin-bottom: 0; }
.intro h1, .intro h2, .intro h3 { font-size: 16px; margin: 12px 0 6px; }
.intro ul, .intro ol { margin: 6px 0 6px 20px; }
.intro code {
  background: var(--bg); padding: 1px 4px; border-radius: 3px;
  font-size: 12.5px;
}
.intro a { color: var(--green-dark); }

/* Login page */
.login-wrap {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 24px;
  width: min(380px, 100%);
  text-align: center;
}
.login-card img { height: 52px; margin-bottom: 14px; }
.login-card h1 { font-size: 17px; margin-bottom: 6px; }
.login-card p { font-size: 13px; color: var(--text-2); margin-bottom: 16px; }
.login-card input { width: 100%; margin-bottom: 12px; }
.login-card .err {
  background: var(--danger-light); color: var(--danger);
  font-size: 13px; padding: 8px 10px; border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  background: #1A1A1A; color: #fff;
  padding: 10px 16px; border-radius: 22px;
  font-size: 13px; z-index: 300;
  box-shadow: var(--shadow);
  display: none;
}
.toast.show { display: block; }
.toast.bad { background: var(--danger); }

/* Job progress strip */
.job {
  background: var(--green-light);
  border-bottom: 1px solid var(--green-border);
  padding: 8px 16px;
  font-size: 12.5px;
  display: none;
}
.job.show { display: block; }
.job .bar {
  height: 4px; background: var(--green-mid);
  border-radius: 2px; margin-top: 5px; overflow: hidden;
}
.job .bar i { display: block; height: 100%; background: var(--green); width: 0; }

@media (max-width: 768px) {
  .folders { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .lb-nav { width: 42px; height: 68px; font-size: 20px; }
}

/* ---- hidden folders (owner only) -------------------------------------- */
/* The toggle sits over the tile rather than inside the <a>, so the anchor can
   still fill the tile for a normal click. */
.folder-wrap { position: relative; }
.folder-wrap .hide-toggle {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  border: 0; border-radius: 6px; cursor: pointer;
  background: rgba(0, 0, 0, .55); color: #fff;
  font-size: 13px; line-height: 1; padding: 5px 6px;
  opacity: 0; transition: opacity .12s;
}
.folder-wrap:hover .hide-toggle,
.folder-wrap .hide-toggle:focus-visible { opacity: 1; }
/* A hidden folder stays visible to the owner, but must never be mistaken for
   one everyone else can see. */
.folder-wrap.is-hidden .hide-toggle { opacity: 1; background: rgba(180, 40, 40, .8); }
.folder-wrap.is-hidden .folder .cover { opacity: .45; }
.folder-wrap.is-hidden .folder .name::after {
  content: ' · hidden'; color: #c0504d; font-weight: 600;
}
