/* ==========================================================================
   Components
   Everything the app renders. Mobile-first; desktop refinements sit in
   @media (min-width: 860px) blocks beside the component they adjust.
   ========================================================================== */

/* --- icons and loading --------------------------------------------------- */

.icon {
  flex: none;
}

.spinner {
  display: inline-block;
  width: var(--spinner-size, 20px);
  height: var(--spinner-size, 20px);
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  opacity: 0.75;
  animation: spin 0.7s linear infinite;
}

.spinner--lg {
  --spinner-size: 30px;
  color: var(--color-text-muted);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-target);
  padding: 0 var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
  color: var(--color-text);
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease),
    transform var(--duration-fast) var(--ease);
}

.btn:active {
  transform: scale(0.98);
}

.btn[disabled],
.btn.is-busy {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--color-primary-bg);
  color: var(--color-primary-text);
}

.btn--primary:hover:not([disabled]) {
  background: var(--color-primary-bg-hover);
}

.btn--ghost {
  background: transparent;
  border-color: var(--color-border-strong);
  color: var(--color-text);
}

.btn--ghost:hover:not([disabled]) {
  background: var(--color-surface-raised);
}

.btn--danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}

.btn--sm {
  min-height: 36px;
  padding: 0 var(--space-3);
  font-size: 13.5px;
  border-radius: var(--radius-sm);
}

.btn--block {
  width: 100%;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap-target);
  height: var(--tap-target);
  border-radius: var(--radius-full);
  color: var(--color-text);
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}

.icon-btn:hover {
  background: var(--color-surface-raised);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn.is-active {
  color: var(--color-accent);
  background: var(--color-accent-soft);
}

/* --- form controls ------------------------------------------------------- */

.form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.field__hint {
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--color-text-faint);
}

.field__control {
  position: relative;
  display: flex;
  align-items: center;
}

.field__reveal {
  position: absolute;
  right: 4px;
  color: var(--color-text-muted);
}

.field--checkbox {
  flex-direction: row;
  align-items: center;
  gap: var(--space-3);
}

.field--checkbox .field__label {
  font-size: 14.5px;
  color: var(--color-text);
}

.input {
  width: 100%;
  min-height: var(--tap-target);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-input);
  color: var(--color-text);
  font-size: 16px; /* 16px prevents iOS zoom-on-focus */
  transition: border-color var(--duration-fast) var(--ease), background var(--duration-fast) var(--ease);
}

.field__control .input {
  padding-right: 52px;
}

.input::placeholder {
  color: var(--color-text-faint);
}

.input:hover {
  border-color: var(--color-border-strong);
}

.input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

select.input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: var(--space-8);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 20px) calc(50% + 1px), calc(100% - 15px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.checkbox {
  width: 20px;
  height: 20px;
  accent-color: var(--color-accent);
}

.form-error {
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-danger-soft);
  color: var(--color-danger);
  font-size: 13.5px;
  font-weight: 550;
}

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

.radio-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-input);
  cursor: pointer;
}

.radio-row:has(.radio-row__input:checked) {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}

.radio-row__input {
  margin: 2px 0 0;
  width: 18px;
  height: 18px;
  flex: none;
  accent-color: var(--color-accent);
}

.radio-row__label {
  display: block;
  font-size: 14.5px;
  font-weight: 600;
}

/* --- segmented control --------------------------------------------------- */

.segmented {
  display: flex;
  padding: 3px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-input);
}

.segmented__option {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 38px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 13.5px;
  font-weight: 600;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}

.segmented__option:hover {
  color: var(--color-text);
}

.segmented__option.is-active {
  background: var(--color-surface-raised);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

/* --- dialogs and sheets -------------------------------------------------- */

.dialog {
  padding: 0;
  border: 0;
  background: transparent;
  max-width: 100vw;
  max-height: 100dvh;
  overflow: visible;
}

.dialog::backdrop {
  background: var(--color-backdrop);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.dialog__card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: min(560px, calc(100vw - var(--space-6)));
  max-height: min(86dvh, 780px);
  padding: var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  background: var(--color-surface-dialog);
  box-shadow: var(--shadow-lg);
  animation: dialog-in var(--duration) var(--ease);
}

.dialog__card--sm {
  width: min(440px, calc(100vw - var(--space-6)));
}

.dialog__card--lg {
  width: min(760px, calc(100vw - var(--space-6)));
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
}

.dialog__header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

.dialog__title {
  flex: 1;
  font-size: 18px;
}

.dialog__close {
  margin: -8px -8px 0 0;
  color: var(--color-text-muted);
}

.dialog__description {
  font-size: 14px;
  color: var(--color-text-muted);
}

.dialog__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.dialog__footer {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  padding-top: var(--space-2);
}

/* Bottom sheet: the mobile-friendly variant of a dialog card. */
.dialog__card--sheet {
  gap: var(--space-2);
  padding: var(--space-3);
}

.sheet__list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sheet__item {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  min-height: 52px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  text-align: left;
  color: var(--color-text);
}

.sheet__item:hover {
  background: var(--color-surface-raised);
}

.sheet__item[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.sheet__item--cancel {
  justify-content: center;
  margin-top: var(--space-1);
  border-top: 1px solid var(--color-border-subtle);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  color: var(--color-text-muted);
  font-weight: 600;
}

.sheet__icon {
  display: flex;
  color: var(--color-text-muted);
}

.sheet__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sheet__label {
  font-size: 15px;
  font-weight: 550;
}

.sheet__sublabel {
  font-size: 12.5px;
  color: var(--color-text-faint);
}

@media (max-width: 559px) {
  /* Sheets slide up from the bottom edge, where a thumb can reach them. */
  .dialog__card--sheet {
    width: 100vw;
    max-width: 100vw;
    margin: auto auto 0;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding-bottom: calc(var(--space-4) + var(--safe-bottom));
  }

  .dialog {
    margin: 0;
  }

  .dialog__card:not(.dialog__card--sheet) {
    margin: auto;
  }
}

/* --- progress ------------------------------------------------------------ */

.progress {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.progress__phase {
  font-size: 14px;
  font-weight: 550;
}

.progress__bar {
  height: 8px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--color-surface-input);
  box-shadow: inset 0 0 0 1px var(--color-border-subtle);
}

.progress__fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--color-accent);
  transition: width var(--duration) var(--ease);
}

.progress__fill--indeterminate {
  width: 35% !important;
  animation: indeterminate 1.15s var(--ease) infinite;
}

@keyframes indeterminate {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(320%);
  }
}

.progress__percent {
  font-size: 12.5px;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.progress__actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  padding-top: var(--space-1);
}

/* --- toasts -------------------------------------------------------------- */

.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-height) + var(--safe-bottom) + var(--space-3));
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(520px, calc(100vw - var(--space-6)));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-toast-bg);
  color: var(--color-toast-text);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toast-in var(--duration) var(--ease);
}

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

.toast--success {
  border-color: var(--color-success);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

.toast--out {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--duration) var(--ease), transform var(--duration) var(--ease);
}

.toast__icon {
  display: flex;
  flex: none;
  color: var(--color-accent);
}

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

.toast--success .toast__icon {
  color: var(--color-success);
}

.toast__message {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  line-height: 1.4;
}

.toast__action {
  flex: none;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-xs);
  color: var(--color-accent-strong);
  font-size: 13px;
  font-weight: 650;
}

.toast__close {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
}

@media (min-width: 860px) {
  .toast-host {
    bottom: calc(var(--space-6) + var(--safe-bottom));
  }
}

/* --- notices, pills, empty states, rows --------------------------------- */

.notice {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-left-width: 3px;
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--color-text-muted);
}

.notice__title {
  font-size: 13.5px;
  font-weight: 650;
  color: var(--color-text);
}

.notice--warn {
  border-left-color: var(--color-accent);
  background: var(--color-accent-soft);
}

.notice--info {
  border-left-color: var(--color-info);
  background: var(--color-info-soft);
}

.notice--danger {
  border-left-color: var(--color-danger);
  background: var(--color-danger-soft);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px var(--space-2);
  border-radius: var(--radius-full);
  background: var(--color-surface-raised);
  color: var(--color-text-muted);
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.pill--ok {
  background: var(--color-success-soft);
  color: var(--color-success);
}

.pill--warn {
  background: var(--color-accent-soft);
  color: var(--color-accent-strong);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  max-width: 30rem;
  margin: 0 auto;
  padding: clamp(48px, 14vh, 120px) var(--space-5);
  text-align: center;
}

.empty-state__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  margin-bottom: var(--space-1);
  border-radius: var(--radius-full);
  background: var(--color-surface-raised);
  color: var(--color-text-faint);
}

.empty-state__title {
  font-size: 17px;
}

.empty-state__text {
  font-size: 14px;
  color: var(--color-text-muted);
  max-width: 26rem;
}

.empty-state__action {
  margin-top: var(--space-2);
}

.list-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 52px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  text-align: left;
}

.list-row:hover {
  background: var(--color-surface-raised);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-3) var(--space-2);
}

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

.gallery {
  display: flex;
  flex-direction: column;
}

.gallery__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-3) var(--space-2);
}

.gallery__header-text {
  flex: 1;
  min-width: 0;
}

.gallery__header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}

.gallery__title {
  font-size: 15px;
  font-weight: 620;
}

.gallery__subtitle {
  font-size: 12.5px;
  color: var(--color-text-muted);
}

.folder-strip {
  display: flex;
  gap: var(--space-2);
  padding: 0 var(--space-3) var(--space-3);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.folder-strip::-webkit-scrollbar {
  display: none;
}

.folder-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
  min-height: 38px;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 13px;
  font-weight: 560;
}

.folder-chip:hover {
  border-color: var(--color-border-strong);
}

.folder-chip__icon {
  display: flex;
  color: var(--color-text-muted);
}

.folder-chip__name {
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The grid: 3 tight columns on a phone, widening with the viewport. */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 0 0 var(--space-2);
}

.grid__cell {
  position: relative;
  margin: 0;
  aspect-ratio: 1 / 1;
}

.grid__tile {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  overflow: hidden;
  border-radius: 3px;
  background: var(--color-skeleton);
  cursor: pointer;
}

.grid__skeleton {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    100deg,
    var(--color-skeleton) 30%,
    var(--color-skeleton-sheen) 50%,
    var(--color-skeleton) 70%
  );
  background-size: 220% 100%;
  animation: skeleton-sheen 1.6s linear infinite;
}

@keyframes skeleton-sheen {
  from {
    background-position: 140% 0;
  }
  to {
    background-position: -40% 0;
  }
}

.grid__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
}

.grid__img--loaded {
  opacity: 1;
}

/* A thumbnail that could not be decrypted leaves a neutral placeholder rather
   than a broken-image icon; the original may still download fine. */
.grid__img--failed {
  display: none;
}

.grid__fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface-raised);
  color: var(--color-text-faint);
}

.grid__check {
  position: absolute;
  top: 5px;
  right: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--radius-full);
  background: rgba(12, 13, 16, 0.35);
  color: transparent;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}

.grid__tile.is-selected .grid__check {
  background: var(--color-selection);
  border-color: var(--color-selection);
  color: var(--color-accent-contrast);
}

.grid__tile.is-selected::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 3px solid var(--color-selection);
  border-radius: inherit;
  pointer-events: none;
}

.grid__tile.is-selected {
  transform: scale(0.965);
  transition: transform var(--duration-fast) var(--ease);
}

.grid__sentinel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 64px;
  padding: var(--space-4);
  color: var(--color-text-muted);
  font-size: 13px;
}

.gallery__status {
  padding: var(--space-3);
  text-align: center;
  color: var(--color-text-faint);
  font-size: 12.5px;
}

/* One compact row of filters: All / Photos / Videos / Favourites / Folders.
   Horizontally scrollable so a phone never wraps it into three lines. */
.media-filter {
  display: flex;
  gap: var(--space-2);
  padding: 0 var(--space-3) var(--space-3);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.media-filter::-webkit-scrollbar {
  display: none;
}

.media-filter__chip {
  flex: none;
  min-height: 34px;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 560;
  white-space: nowrap;
}

.media-filter__chip:hover {
  border-color: var(--color-border-strong);
}

.media-filter__chip.is-active {
  border-color: var(--color-accent);
  background: var(--color-accent);
  color: var(--color-accent-contrast);
}

/* --- video tiles ---------------------------------------------------------- */

/* A play badge (and a duration where we know one) marks a video in the grid. */
.grid__badge {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 2px 5px;
  border-radius: var(--radius-xs);
  background: rgba(12, 13, 16, 0.62);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.grid__badge--video {
  top: 5px;
  left: 5px;
  padding: 3px;
}

.grid__badge--duration {
  right: 5px;
  bottom: 5px;
}

/* No poster frame could be extracted (or ffmpeg is not installed): say so
   plainly rather than leaving an empty tile. Playback is unaffected. */
.grid__poster-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: var(--color-surface-raised);
  color: var(--color-text-faint);
}

.grid__poster-icon {
  display: flex;
}

.grid__poster-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

@media (min-width: 480px) {
  .grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 3px;
  }
}

@media (min-width: 700px) {
  .grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
  }

  .grid__tile {
    border-radius: 5px;
  }
}

@media (min-width: 1000px) {
  .grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media (min-width: 1300px) {
  .grid {
    grid-template-columns: repeat(7, 1fr);
  }
}

@media (min-width: 1600px) {
  .grid {
    grid-template-columns: repeat(8, 1fr);
  }
}

@media (min-width: 860px) {
  .gallery__header,
  .folder-strip {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }

  /* Hover affordances only exist where a pointer does. */
  .grid__tile:hover .grid__img {
    transform: scale(1.03);
    transition: transform var(--duration-slow) var(--ease);
  }
}

/* --- breadcrumbs --------------------------------------------------------- */

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  font-size: 12.5px;
  color: var(--color-text-muted);
}

.breadcrumbs::-webkit-scrollbar {
  display: none;
}

.breadcrumbs__item {
  flex: none;
  max-width: 36vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text-muted);
  font-weight: 550;
}

.breadcrumbs__item:hover {
  color: var(--color-text);
}

.breadcrumbs__separator {
  flex: none;
  color: var(--color-text-faint);
}

/* --- folders ------------------------------------------------------------- */

.folders {
  display: flex;
  flex-direction: column;
}

.folders__toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
}

.folders__list {
  display: flex;
  flex-direction: column;
  padding: 0 var(--space-2) var(--space-4);
}

.folder-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 58px;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  text-align: left;
  cursor: pointer;
}

.folder-row:hover {
  background: var(--color-surface-raised);
}

.folder-row__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: var(--radius-sm);
  background: var(--color-accent-soft);
  color: var(--color-accent-strong);
}

.folder-row__text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.folder-row__name {
  font-size: 15px;
  font-weight: 570;
}

.folder-row__meta {
  font-size: 12.5px;
  color: var(--color-text-muted);
}

.folder-row__action {
  flex: none;
  color: var(--color-text-muted);
}

.folder-row--muted {
  min-height: 46px;
  color: var(--color-text-faint);
  cursor: default;
}

.folder-row--muted:hover {
  background: none;
}

/* --- folder picker ------------------------------------------------------- */

.folder-picker {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.folder-picker__list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: min(46dvh, 360px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-input);
}

.folder-picker__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 46px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  text-align: left;
  color: var(--color-text);
}

.folder-picker__item:hover {
  background: var(--color-surface-raised);
}

.folder-picker__item.is-selected {
  background: var(--color-accent-soft);
  color: var(--color-accent-strong);
  font-weight: 600;
}

.folder-picker__item[aria-disabled='true'],
.folder-picker__item[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.folder-picker__indent {
  flex: none;
  width: 16px;
}

.folder-picker__create {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-sm);
  color: var(--color-accent-strong);
  font-size: 14px;
  font-weight: 600;
}

/* --- settings ------------------------------------------------------------ */

.settings {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding: var(--space-4) var(--space-3) var(--space-8);
}

.settings__group {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.settings__group-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--color-text-faint);
  padding: 0 var(--space-2);
}

.settings__row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: 54px;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border-subtle);
  background: var(--color-surface);
}

.settings__row:first-of-type {
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.settings__row:last-of-type {
  border-bottom: 0;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.settings__row:only-of-type {
  border-radius: var(--radius-md);
}

.settings__row-label {
  flex: 1;
  min-width: 0;
  font-size: 14.5px;
  font-weight: 550;
}

.settings__row-desc {
  display: block;
  margin-top: 2px;
  font-size: 12.5px;
  font-weight: 400;
  color: var(--color-text-muted);
}

.settings__row-value {
  flex: none;
  max-width: 46%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13.5px;
  color: var(--color-text-muted);
  text-align: right;
}

.settings__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2) 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-3);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.stat__value {
  font-size: 20px;
  font-weight: 640;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat__label {
  font-size: 12px;
  color: var(--color-text-muted);
}

.about-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-surface);
}

.about-list__row {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border-subtle);
}

.about-list__row:last-child {
  border-bottom: 0;
}

.about-list__key {
  flex: none;
  width: 42%;
  font-size: 13px;
  color: var(--color-text-muted);
}

.about-list__value {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 550;
  overflow-wrap: anywhere;
}

@media (min-width: 700px) {
  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 860px) {
  .settings {
    gap: var(--space-8);
    padding: var(--space-6) var(--space-4) var(--space-8);
    max-width: 820px;
  }
}

/* --- import / export ----------------------------------------------------- */

.import-file {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 64px;
  padding: var(--space-3) var(--space-4);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface-input);
  text-align: left;
}

.import-file:hover,
.import-file--over {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}

.import-file__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: var(--radius-sm);
  background: var(--color-surface-raised);
  color: var(--color-accent-strong);
}

.import-file__label {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.import-file__name {
  font-size: 14.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.import-mode {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.import-mode__option {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-input);
  cursor: pointer;
}

.import-mode__option:has(input:checked) {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}

.import-mode__hint {
  display: block;
  font-size: 12.5px;
  color: var(--color-text-muted);
}

.import-summary {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.import-summary__row {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  font-size: 14px;
}

.import-summary__count {
  flex: none;
  min-width: 3.5ch;
  font-size: 16px;
  font-weight: 660;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.import-summary__errors {
  max-height: 30dvh;
  overflow-y: auto;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-surface-input);
  font-size: 12.5px;
  color: var(--color-text-muted);
}

/* --- photo viewer -------------------------------------------------------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: #08090b;
  color: #f2f3f6;
  touch-action: none;
}

html[data-theme='light'] .viewer {
  background: #0c0d10;
}

.viewer__stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

.viewer__backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(28px) saturate(140%);
  opacity: 0.42;
  transform: scale(1.12);
  pointer-events: none;
}

.viewer__image {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* A zoomed picture can be dragged around with the mouse; the cursor says so. */
.viewer__stage.is-zoomed {
  cursor: grab;
}

.viewer__stage.is-panning {
  cursor: grabbing;
}

.viewer__spinner {
  position: absolute;
  display: flex;
  color: rgba(255, 255, 255, 0.8);
}

/* --- native video player ------------------------------------------------- */

/* The player fills the stage. `touch-action: auto` overrides the stage's `none`
   so the seek bar and volume slider can actually be dragged on a phone. */
.viewer__video {
  position: absolute;
  inset: 0;
  touch-action: auto;
  background: #000;
}

.video {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background: #000;
}

.video__el {
  flex: 1;
  min-height: 0;
  width: 100%;
  background: #000;
  object-fit: contain;
}

.video__fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-5);
  text-align: center;
  background: rgba(8, 9, 11, 0.94);
  color: #f2f3f6;
}

.video__fallback-title {
  font-size: 15px;
  font-weight: 640;
}

.video__fallback-text {
  max-width: 24rem;
  font-size: 13px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.72);
}

.video__controls {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-2) var(--space-3) calc(var(--space-2) + var(--safe-bottom));
  background: linear-gradient(to top, rgba(6, 7, 9, 0.94), rgba(6, 7, 9, 0.62));
}

.video__row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.video__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.video__btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* The primary action is the biggest target on the bar, by design. */
.video__btn--play {
  width: 48px;
  height: 48px;
  background: var(--color-accent);
  color: var(--color-accent-contrast);
}

.video__btn--play:hover {
  background: var(--color-accent-strong);
}

.video__btn.is-active {
  color: var(--color-accent);
}

.video__btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.video__time {
  flex: none;
  min-width: 42px;
  text-align: center;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.86);
}

/* Tall hit areas so the sliders are comfortable with a thumb. */
.video__seek,
.video__volume {
  height: 32px;
  margin: 0;
  accent-color: var(--color-accent);
}

.video__seek {
  flex: 1;
  min-width: 0;
}

.video__volume {
  width: 88px;
}

.video__spacer {
  flex: 1;
  min-width: 0;
}

@media (max-width: 420px) {
  /* On a narrow phone the volume slider yields to the transport controls. */
  .video__volume {
    display: none;
  }
}

.viewer__error {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  max-width: 22rem;
  padding: var(--space-5);
  text-align: center;
}

.viewer__error-title {
  font-size: 15px;
  font-weight: 640;
}

.viewer__nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  margin-top: -23px;
  border-radius: var(--radius-full);
  background: rgba(18, 20, 24, 0.55);
  color: #fff;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.viewer__nav[disabled] {
  opacity: 0.3;
  cursor: not-allowed;
}

.viewer__nav--prev {
  left: var(--space-3);
}

.viewer__nav--next {
  right: var(--space-3);
}

.viewer__topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: calc(var(--safe-top) + var(--space-2)) var(--space-2) var(--space-2);
  background: linear-gradient(to bottom, rgba(6, 7, 9, 0.78), transparent);
}

.viewer__counter {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.85);
}

.viewer__topbar .icon-btn {
  color: #fff;
}

.viewer__topbar .icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.viewer__toolbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-2) calc(var(--space-3) + var(--safe-bottom));
  background: linear-gradient(to top, rgba(6, 7, 9, 0.82), transparent);
}

.viewer__toolbar-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 60px;
  min-height: 52px;
  padding: var(--space-2);
  border-radius: var(--radius-md);
  color: rgba(255, 255, 255, 0.82);
  font-size: 10.5px;
  font-weight: 600;
}

.viewer__toolbar-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.viewer__toolbar-btn.is-active {
  color: var(--color-accent-strong);
}

.viewer__toolbar-btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.viewer__info {
  display: flex;
  flex-direction: column;
}

.viewer__info-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border-subtle);
}

.viewer__info-row:last-child {
  border-bottom: 0;
}

.viewer__info-key {
  flex: none;
  width: 40%;
  font-size: 12.5px;
  color: var(--color-text-muted);
}

.viewer__info-value {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 550;
  overflow-wrap: anywhere;
}

.viewer__mono {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 400;
  letter-spacing: -0.01em;
}

/* Chrome hides on tap so the photo can use the whole screen. */
.viewer--chrome-hidden .viewer__topbar,
.viewer--chrome-hidden .viewer__toolbar,
.viewer--chrome-hidden .viewer__nav {
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration) var(--ease);
}

.viewer--chrome-hidden {
  cursor: none;
}

/* --- search -------------------------------------------------------------- */

.search-bar__input {
  flex: 1;
  min-width: 0;
}

/* --- authentication ------------------------------------------------------ */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: var(--space-5) var(--space-4) calc(var(--space-6) + var(--safe-bottom));
  background:
    radial-gradient(120% 80% at 50% -10%, var(--color-accent-soft), transparent 55%),
    var(--color-bg);
}

.auth {
  width: 100%;
  max-width: 430px;
}

.auth__card {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-6) var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
}

.auth__brand {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.auth__logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  flex: none;
  border-radius: var(--radius-md);
  background: var(--color-accent-soft);
  color: var(--color-accent-strong);
}

.auth__eyebrow {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-faint);
}

.auth__title {
  font-size: 22px;
  letter-spacing: -0.02em;
}

.auth__lede {
  font-size: 14px;
  line-height: 1.55;
  color: var(--color-text-muted);
}

.auth__form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.auth__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border-subtle);
}

.auth__version {
  font-size: 11.5px;
  color: var(--color-text-faint);
  font-variant-numeric: tabular-nums;
}
