/* =========================================================
   Gallery — Apple-inspired design system
   ========================================================= */

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

:root {
  --bg:        #f5f5f7;
  --surface:   #ffffff;
  --text:      #1d1d1f;
  --text2:     #6e6e73;
  --accent:    #0071e3;
  --accent-hv: #0077ed;
  --border:    rgba(0,0,0,0.1);
  --shadow-sm: 0 2px 12px rgba(0,0,0,0.07);
  --shadow-md: 0 8px 32px rgba(0,0,0,0.10);
  --nav-bg:    rgba(255,255,255,0.85);
  --font: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  --radius: 12px;
}

/* ── Shared base ─────────────────────────────────────────── */
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Nav bar (light pages) ───────────────────────────────── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--nav-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 8px;
}
.nav-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-actions { display: flex; gap: 2px; align-items: center; }

.nav-btn {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 980px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.nav-btn:hover  { background: rgba(0,0,0,0.06); color: var(--text); }
.nav-btn.accent { color: var(--accent); }
.nav-btn.accent:hover { background: rgba(0,113,227,0.08); }

/* ── Nav bar (viewer pages) ──────────────────────────────── */
.nav-dark {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--nav-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 8px;
}
.nav-dark-title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.2px;
  color: var(--text);
}
.nav-dark-user {
  font-size: 13px;
  color: var(--text2);
  white-space: nowrap;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--accent);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 980px;
  transition: background 0.15s;
  white-space: nowrap;
}
.back-btn:hover { background: rgba(0,113,227,0.08); }

/* ── Generic button ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 15px;
  min-height: 36px;
  border-radius: 980px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.btn:hover { background: rgba(0,0,0,0.05); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover {
  background: var(--accent-hv);
  border-color: var(--accent-hv);
}

.btn-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

/* Controls row (viewer pages) */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 12px 20px;
  flex-wrap: wrap;
}

/* ── Login page ──────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 48px 40px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md), 0 1px 4px rgba(0,0,0,0.04);
}
.login-logo {
  font-size: 48px;
  text-align: center;
  line-height: 1;
  margin-bottom: 16px;
}
.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}
.login-card .subtitle {
  font-size: 15px;
  color: var(--text2);
  text-align: center;
  margin-bottom: 32px;
}
.error-banner {
  background: #fff2f2;
  border: 1px solid rgba(255,59,48,0.25);
  color: #cc0000;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
  margin-bottom: 20px;
}
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 7px;
}
.field input[type=text],
.field input[type=password] {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  font-family: var(--font);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fafafa;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,113,227,0.15);
  background: #fff;
}
.submit-btn {
  width: 100%;
  margin-top: 8px;
  padding: 13px;
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 980px;
  cursor: pointer;
  letter-spacing: -0.2px;
  transition: background 0.15s, transform 0.1s;
}
.submit-btn:hover  { background: var(--accent-hv); }
.submit-btn:active { transform: scale(0.98); }

/* ── Gallery page ────────────────────────────────────────── */
.breadcrumb {
  padding: 14px 24px 4px;
  font-size: 14px;
  color: var(--text2);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { color: var(--text2); font-size: 13px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(156px, 1fr));
  gap: 12px;
  padding: 16px 24px 32px;
}

.grid-item a {
  text-decoration: none;
  color: inherit;
  display: block;
}
.thumb-wrap {
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: #e0e0e8;
  position: relative;
  transition: transform 0.2s cubic-bezier(.34,1.56,.64,1), box-shadow 0.2s;
}
.grid-item a:hover .thumb-wrap {
  transform: scale(1.03);
  box-shadow: var(--shadow-md);
}
.thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.folder-thumb {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 60px;
  background: linear-gradient(145deg, #ecf0fb, #dde5f7);
  user-select: none;
}
.folder-thumb.up {
  font-size: 42px;
  background: linear-gradient(145deg, #f0f0f5, #e5e5ea);
  color: var(--text2);
}
.item-info {
  padding: 6px 2px 0;
}
.item-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-date {
  font-size: 11px;
  color: var(--text2);
  margin-top: 2px;
}

/* Empty state */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 24px;
  color: var(--text2);
}
.empty-state .empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-state p { font-size: 17px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.empty-state small { font-size: 14px; }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 24px 40px;
  flex-wrap: wrap;
}
.pg-link, .pg-current, .pg-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s;
}
.pg-link   { color: var(--accent); }
.pg-link:hover { background: rgba(0,113,227,0.09); }
.pg-current { background: var(--accent); color: #fff; pointer-events: none; }
.pg-nav { color: var(--text2); font-size: 13px; }
.pg-nav:hover { background: rgba(0,0,0,0.06); color: var(--text); }

/* ── Image viewer ────────────────────────────────────────── */
.viewer-body {
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
.viewer-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 4px 20px 10px;
  font-size: 13px;
  color: var(--text2);
  flex-wrap: wrap;
}
.viewer-meta span { display: flex; align-items: center; gap: 5px; }
.img-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 20px 48px;
}
.img-wrap img {
  max-width: 100%;
  max-height: calc(100vh - 200px);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  display: block;
}

/* ── Video viewer ────────────────────────────────────────── */
.video-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 20px 48px;
}
.video-wrap video {
  max-width: 100%;
  max-height: calc(100vh - 200px);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  background: #000;
  display: block;
}

/* ── Rescan page ─────────────────────────────────────────── */
.rescan-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.rescan-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 48px 40px 40px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-md);
  text-align: center;
}
.rescan-icon {
  font-size: 48px;
  margin-bottom: 20px;
  display: block;
}
.rescan-card h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
  margin-bottom: 8px;
}
.rescan-status {
  font-size: 14px;
  color: var(--text2);
  min-height: 20px;
  margin-bottom: 24px;
  word-break: break-all;
}
.progress-track {
  width: 100%;
  height: 4px;
  background: rgba(0,0,0,0.08);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 28px;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.4s ease;
  animation: progress-pulse 1.8s ease-in-out infinite;
}
@keyframes progress-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}
.progress-fill.done {
  width: 100% !important;
  animation: none;
  background: #34c759;
}
.rescan-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 22px;
  border-radius: 980px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
}
.rescan-back:hover  { background: var(--accent-hv); }
.rescan-back:active { transform: scale(0.97); }

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 640px) {

  /* Nav */
  .nav, .nav-dark {
    padding: 0 12px;
    gap: 4px;
  }
  .nav-title {
    font-size: 15px;
  }
  .nav-btn {
    padding: 6px 10px;
    font-size: 13px;
  }
  /* Hide username in viewer nav — redundant on small screen */
  .nav-dark-user { display: none; }

  /* Login */
  .login-body { padding: 16px; align-items: flex-start; padding-top: 60px; }
  .login-card {
    padding: 36px 24px 28px;
    border-radius: 16px;
  }

  /* Gallery */
  .breadcrumb { padding: 10px 12px 4px; }
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
    padding: 12px 12px 24px;
  }
  .pagination { padding: 0 12px 28px; }

  /* Viewer controls */
  .controls-bar {
    padding: 10px 10px;
    gap: 4px;
  }
  .btn {
    padding: 7px 11px;
    font-size: 12px;
  }
  /* Separators don't render well when buttons wrap to new rows */
  .btn-sep { display: none; }
  .viewer-meta { padding: 2px 12px 8px; gap: 10px; }

  /* Image / video sizing */
  .img-wrap  { padding: 8px 12px 28px; }
  .video-wrap { padding: 8px 12px 28px; }
  .img-wrap img,
  .video-wrap video {
    max-height: calc(100svh - 160px);
    border-radius: 8px;
  }

  /* Rescan */
  .rescan-body { padding: 16px; justify-content: flex-start; padding-top: 60px; }
  .rescan-card {
    padding: 36px 24px 28px;
    border-radius: 16px;
  }
}

/* Fallback for browsers without svh support */
@supports not (height: 100svh) {
  .img-wrap img,
  .video-wrap video {
    max-height: calc(100vh - 160px);
  }
}
