/* ── Reset & tokens ─────────────────────────────────────────────────────── */
:root {
  --bg:       #0a0a0a;
  --surface:  #141414;
  --surface2: #1c1c1c;
  --border:   #2a2a2a;
  --text:     #f0f0f0;
  --muted:    #666;
  --accent:   #3b82f6;
  --danger:   #ef4444;
  --success:  #22c55e;
  --radius:   12px;
  --gap:      14px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button { cursor: pointer; font-family: inherit; }
input  { font-family: inherit; }

/* ── Layout shells ──────────────────────────────────────────────────────── */
#app { min-height: 100dvh; display: flex; flex-direction: column; }

/* ── Loading ─────────────────────────────────────────────────────────────── */
.loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

/* ── Login / Setup / Lock ────────────────────────────────────────────────── */
.login-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 40px 24px;
}

.logo {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.5px;
}
.logo span { color: var(--accent); }

.login-subtitle {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  margin-top: -18px;
}

/* Username input on login */
.username-field {
  width: 100%;
  max-width: 264px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 12px 16px;
  font-size: 16px;
  text-align: center;
  outline: none;
  transition: border-color .15s;
}
.username-field:focus { border-color: var(--accent); }
.username-field::placeholder { color: var(--muted); }

/* PIN dots */
.pin-dots {
  display: flex;
  gap: 14px;
}

.pin-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--border);
  transition: background .12s, transform .12s;
}
.pin-dot.filled {
  background: var(--accent);
  transform: scale(1.15);
}

/* PIN pad */
.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  gap: 10px;
}

.pin-btn {
  width: 72px; height: 72px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .08s, transform .08s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}
.pin-btn:active { background: var(--surface2); transform: scale(.93); }
.pin-btn.del    { font-size: 17px; color: var(--muted); }
.pin-btn.confirm {
  background: var(--accent);
  border-color: var(--accent);
  font-size: 17px;
}
.pin-btn.confirm:active { filter: brightness(.82); }
.pin-btn.confirm:disabled {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--muted);
  pointer-events: none;
}
.pin-btn.phantom { visibility: hidden; pointer-events: none; }

.login-error {
  min-height: 20px;
  font-size: 14px;
  color: var(--danger);
  text-align: center;
}

/* ── Gallery header ──────────────────────────────────────────────────────── */
.gallery-top {
  position: sticky;
  top: 0;
  z-index: 12;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.gallery-header {
  background: transparent;
  padding: 10px var(--gap);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.gallery-title { font-size: 17px; font-weight: 600; }

.header-actions { display: flex; gap: 8px; }

.gallery-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 var(--gap) 10px;
}

.album-chips {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.album-chips::-webkit-scrollbar { display: none; }

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  white-space: nowrap;
}
.chip.active {
  background: rgba(59,130,246,.18);
  border-color: rgba(59,130,246,.55);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  transition: filter .1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}
.btn:active { filter: brightness(.82); }

.btn-primary { background: var(--accent);   color: #fff; }
.btn-ghost   { background: var(--surface);  color: var(--text); border: 1px solid var(--border); }
.btn-danger  { background: var(--danger);   color: #fff; }

.btn-icon {
  width: 38px; height: 38px;
  padding: 0;
  border-radius: 8px;
}
.btn-icon.active {
  background: rgba(59,130,246,.18);
  border: 1px solid rgba(59,130,246,.55);
}

/* ── Media grid ──────────────────────────────────────────────────────────── */
.media-grid {
  flex: 1;
  overflow-y: auto;
  padding: 8px 6px 24px;
}

.timeline-group { margin-bottom: 16px; }
.timeline-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .05em;
  margin: 2px 6px 8px;
  text-transform: uppercase;
}

.timeline-items {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
}
@media (min-width: 540px)  { .timeline-items { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 768px)  { .timeline-items { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .timeline-items { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

.media-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 3px;
  cursor: pointer;
  background: var(--surface);
}

.media-item img,
.media-item .thumb-video {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .2s;
}
.media-item:hover img,
.media-item:hover .thumb-video { transform: scale(1.04); }

.media-item .fav-media-btn,
.media-item .move-media-btn,
.media-item .del-media-btn {
  position: absolute;
  top: 5px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0,0,0,.72);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  font-size: 13px;
}

.media-item .fav-media-btn { left: 5px; }
.media-item .fav-media-btn.active {
  background: rgba(239,68,68,.86);
  color: #fff;
}

.media-item .move-media-btn { left: 35px; display: none; }

.media-item .video-badge {
  position: absolute;
  bottom: 5px; right: 5px;
  background: rgba(0,0,0,.72);
  color: #fff;
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 3px;
  pointer-events: none;
}

.media-item .album-badge {
  position: absolute;
  left: 5px;
  bottom: 5px;
  background: rgba(0,0,0,.72);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  max-width: calc(100% - 14px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.media-item .del-media-btn {
  right: 5px;
  display: none;
}

.media-item:hover .move-media-btn,
.media-item:hover .del-media-btn,
.media-item:focus-within .move-media-btn,
.media-item:focus-within .del-media-btn { display: flex; }

@media (hover: none) {
  .media-item .move-media-btn,
  .media-item .del-media-btn { display: flex; }
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 55dvh;
  padding: 60px 24px;
  color: var(--muted);
}
.empty-state svg { opacity: .3; }
.empty-state p   { font-size: 15px; }

/* ── Lightbox ────────────────────────────────────────────────────────────── */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.96);
  z-index: 100;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.lightbox.open { display: flex; }

#lbMedia {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 96vw;
  max-height: 84vh;
  overflow: hidden;
}
#lbMedia img {
  max-width: 96vw;
  max-height: 84vh;
  object-fit: contain;
  border-radius: 4px;
}
#lbMedia img.zoomable {
  transition: transform .16s ease;
  transform-origin: center center;
  touch-action: none;
}
#lbMedia video {
  max-width: 96vw; max-height: 84vh;
  border-radius: 4px;
  outline: none;
  touch-action: auto;
}

.lightbox-nav {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  pointer-events: none;
}
.lightbox-nav .lb-btn { pointer-events: auto; }

.lightbox-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: min(86vw, 420px);
}
.lb-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: background .15s;
  cursor: pointer;
}
.lb-btn:hover { background: rgba(255,255,255,.22); }
.lb-btn.active { background: rgba(239,68,68,.42); }
.lb-btn:disabled { opacity: .35; pointer-events: none; }

.lightbox.is-video #lbZoomIn,
.lightbox.is-video #lbZoomOut {
  display: none;
}

@media (max-width: 700px) {
  .lightbox-controls {
    top: auto;
    bottom: 14px;
    left: 12px;
    right: 12px;
    max-width: none;
    justify-content: center;
  }
  .lightbox-nav { padding: 0 6px; }

  .lightbox.is-video .lightbox-controls {
    top: 12px;
    bottom: auto;
    left: auto;
    right: 12px;
    justify-content: flex-end;
    max-width: min(92vw, 360px);
  }
}

.lb-info {
  margin-top: 12px;
  font-size: 12px;
  color: rgba(255,255,255,.4);
  text-align: center;
}

/* ── Modals ──────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 460px;
  max-height: 90dvh;
  overflow-y: auto;
}

.modal h2 { font-size: 18px; font-weight: 600; margin-bottom: 20px; }

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .2s, background .2s;
  font-size: 14px;
}
.drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(59,130,246,.05);
}
.drop-zone input[type="file"] { display: none; }

.upload-album-group { margin-top: 14px; }
.album-select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}
.album-select:focus { border-color: var(--accent); }

.move-media-name {
  color: var(--muted);
  font-size: 13px;
  margin: -8px 0 14px;
}

.upload-progress { margin-top: 16px; display: none; }
.upload-progress.active { display: block; }
.progress-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.progress-text { font-size: 12px; color: var(--muted); margin-top: 6px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* Admin */
.admin-section { margin-bottom: 28px; }
.admin-section h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.form-group label { font-size: 12px; color: var(--muted); }
.form-group input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 16px;
  outline: none;
  transition: border-color .15s;
}
.form-group select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 16px;
  outline: none;
  transition: border-color .15s;
}
.form-group input:focus { border-color: var(--accent); }
.form-group select:focus { border-color: var(--accent); }

.form-error { font-size: 13px; color: var(--danger); min-height: 18px; }

/* Mini PIN pad inside admin modal */
.mini-pin-dots {
  display: flex; gap: 8px; margin: 6px 0;
}
.mini-pin-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background .1s;
}
.mini-pin-dot.filled { background: var(--accent); }

.mini-pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 50px);
  gap: 6px;
  margin-top: 6px;
}
.mini-pin-btn {
  width: 50px; height: 50px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .08s;
  touch-action: manipulation;
  user-select: none;
}
.mini-pin-btn:active { background: var(--surface2); }
.mini-pin-btn.del    { font-size: 13px; color: var(--muted); }
.mini-pin-btn.confirm {
  background: var(--accent);
  border-color: var(--accent);
  font-size: 13px;
}

/* User list */
.user-list { display: flex; flex-direction: column; gap: 8px; }
.user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.user-item-name { font-size: 15px; font-weight: 500; }
.user-item-date { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── Notification toast ──────────────────────────────────────────────────── */
.notification {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 300;
  transition: transform .25s cubic-bezier(.34,1.56,.64,1);
  white-space: nowrap;
  pointer-events: none;
}
.notification.show            { transform: translateX(-50%) translateY(0); }
.notification.success         { border-color: var(--success); color: var(--success); }
.notification.error           { border-color: var(--danger);  color: var(--danger); }

/* ── Lock screen ─────────────────────────────────────────────────────────── */
.lock-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}
.lock-screen.active { display: flex; }
