/* ==========================================================================
   WP School Gallery — Mobile-First CSS
   Fully standalone, no dependency on WordPress theme styles.
   ========================================================================== */

/* === RESET & VARIABLES === */
:root {
  --sg-theme: #1e40af;
  --sg-accent: #3b82f6;
  --sg-bg: #f8fafc;
  --sg-card: #ffffff;
  --sg-text: #0f172a;
  --sg-text-light: #64748b;
  --sg-radius: 12px;
  --sg-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --sg-nav-height: calc(64px + env(safe-area-inset-bottom, 0px));
}

/* Hard reset — override any theme styles */
.sg-app,
.sg-app *,
.sg-app *::before,
.sg-app *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

.sg-app a { color: inherit; text-decoration: none; }
.sg-app img { display: block; max-width: 100%; height: auto; border: none; }
.sg-app button { font-family: inherit; cursor: pointer; }
.sg-app h1, .sg-app h2, .sg-app h3, .sg-app h4, .sg-app h5, .sg-app h6 {
  color: var(--sg-text);
  font-weight: 700;
  line-height: 1.3;
  margin: 0;
}
.sg-app p { color: var(--sg-text); margin: 0; }

/* === LAYOUT === */
body.sg-app {
  background-color: var(--sg-bg) !important;
  color: var(--sg-text) !important;
  overflow-x: hidden;
  margin: 0 !important;
  padding: 0 !important;
  min-height: 100vh;
}

.sg-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0 auto;
  position: relative;
  background-color: var(--sg-bg);
  color: var(--sg-text);
}

@media(min-width: 600px) {
  html {
    background-color: #e2e8f0 !important;
    display: flex !important;
    justify-content: center !important;
  }
  body.sg-app {
    max-width: 480px !important;
    width: 100% !important;
    min-height: 100vh;
    box-shadow: 0 0 30px rgba(0,0,0,0.12);
    position: relative !important;
    background-color: var(--sg-bg) !important;
  }
  .sg-bottom-nav {
    max-width: 480px;
    left: 0 !important;
    right: 0 !important;
    margin: 0 auto;
  }
  .sg-search-overlay,
  .sg-viewer {
    max-width: 480px;
    left: 0 !important;
    right: 0 !important;
    margin: 0 auto;
  }
  .sg-sidebar-overlay {
    max-width: 480px;
    left: 0 !important;
    right: 0 !important;
    margin: 0 auto;
  }
  .sg-sidebar {
    /* Set off-canvas position relative to the container */
    left: calc(50% - 240px - 300px); 
  }
  .sg-sidebar.open {
    left: calc(50% - 240px) !important;
  }
}

/* === HEADER === */
.sg-app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: var(--sg-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.08);
  padding-top: max(12px, env(safe-area-inset-top));
}

.sg-header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--sg-text);
}

.sg-header-brand img { height: 32px; width: auto; object-fit: contain; }

.sg-header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.sg-header-actions button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--sg-text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}
.sg-header-actions button:active { transform: scale(0.92); }
.sg-header-actions svg { width: 24px; height: 24px; fill: var(--sg-text); }

/* === MAIN BODY === */
.sg-app-body {
  flex: 1;
  padding-bottom: var(--sg-nav-height);
  position: relative;
}

/* === TABS === */
.sg-tab-panel {
  display: none;
  animation: sgFadeIn 0.25s ease;
}
.sg-tab-panel.active { display: block; }
@keyframes sgFadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* === BOTTOM NAV === */
.sg-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--sg-nav-height);
  background-color: var(--sg-card);
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -1px 4px 0 rgb(0 0 0 / 0.08);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 40;
}
.sg-bottom-nav button {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  color: var(--sg-text-light);
  cursor: pointer;
  font-size: 10px;
  font-weight: 500;
  gap: 3px;
  transition: color 0.2s;
}
.sg-bottom-nav button svg { width: 24px; height: 24px; fill: currentColor; }
.sg-bottom-nav button span { font-size: 10px; }
.sg-bottom-nav button.active { color: var(--sg-theme); }
.sg-bottom-nav button:active { transform: scale(0.93); }

/* === FAB (Unggah) === */
.sg-nav-fab { position: relative; }
.sg-nav-fab .fab-inner {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, var(--sg-theme), var(--sg-accent));
  color: white;
  width: 52px;
  height: 52px;
  border-radius: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.sg-nav-fab .fab-inner svg { fill: white; width: 24px; height: 24px; }
.sg-nav-fab span { margin-top: 30px; }
.sg-nav-fab:active .fab-inner { transform: translateX(-50%) scale(0.9); }

/* === HERO === */
.sg-hero {
  position: relative;
  height: 200px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--sg-theme), var(--sg-accent));
}
.sg-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.35;
}
.sg-hero-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px;
  background: linear-gradient(transparent, rgba(0,0,0,0.5));
  color: white;
}
.sg-hero-content h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: white;
  margin-bottom: 4px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.sg-hero-content p {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* === SECTIONS === */
.sg-section { padding: 16px 16px 4px; }
.sg-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.sg-section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--sg-text);
}
.sg-section-link {
  color: var(--sg-accent);
  font-size: 0.85rem;
  text-decoration: none;
  font-weight: 600;
}
.sg-section-link:active { opacity: 0.7; }

/* === CATEGORY PILLS === */
.sg-category-bar {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  padding: 8px 16px 12px;
  scrollbar-width: none;
}
.sg-category-bar::-webkit-scrollbar { display: none; }
.sg-pill {
  padding: 7px 18px;
  border-radius: 20px;
  background-color: #e2e8f0;
  font-size: 0.85rem;
  white-space: nowrap;
  border: none;
  cursor: pointer;
  color: var(--sg-text);
  font-weight: 500;
  transition: all 0.2s;
}
.sg-pill:active { transform: scale(0.95); }
.sg-pill.active {
  background-color: var(--sg-accent);
  color: white;
}

/* === HORIZONTAL ALBUM SCROLL === */
.sg-album-scroll {
  display: flex;
  overflow-x: auto;
  gap: 12px;
  padding: 4px 16px 16px;
  scrollbar-width: none;
}
.sg-album-scroll::-webkit-scrollbar { display: none; }

.sg-album-card {
  flex: 0 0 160px;
  background: var(--sg-card);
  border-radius: var(--sg-radius);
  overflow: hidden;
  box-shadow: var(--sg-shadow);
  text-decoration: none;
  color: var(--sg-text);
  display: flex;
  flex-direction: column;
}
.sg-album-card:active { transform: scale(0.97); }

.sg-album-card-img {
  width: 100%;
  aspect-ratio: 4/3;
  background: #e2e8f0;
  position: relative;
  overflow: hidden;
}
.sg-album-card-img img { width: 100%; height: 100%; object-fit: cover; }

.sg-badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,0.65);
  color: white;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}
.sg-badge svg { width: 12px; height: 12px; fill: white; }

.sg-album-card-info { padding: 10px 12px; }
.sg-album-card-title {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--sg-text);
  margin-bottom: 3px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sg-album-card-date {
  font-size: 0.75rem;
  color: var(--sg-text-light);
}

/* === PHOTO GRID / FEED === */
.sg-photo-feed {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 0 3px;
}
.sg-photo-item {
  width: 100%;
  aspect-ratio: 1;
  background-color: #e2e8f0;
  position: relative;
  overflow: hidden;
  border-radius: 4px;
  cursor: pointer;
}
.sg-photo-item img, .sg-photo-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
}
.sg-photo-item img.loaded, .sg-photo-item video.loaded {
  opacity: 1;
}
.sg-video-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  background: rgba(0,0,0,0.5);
  border-radius: 50%;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

/* === ALBUM GRID (Tab Album) === */
.sg-album-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 0 16px 16px;
}
@media(min-width: 768px) { .sg-album-grid { grid-template-columns: repeat(3, 1fr); } }

/* === FORMS / INPUT === */
.sg-input, .sg-select {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-size: 0.95rem;
  margin-bottom: 12px;
  font-family: inherit;
  color: var(--sg-text);
  background: var(--sg-card);
  outline: none;
  -webkit-appearance: none;
}
.sg-input:focus, .sg-select:focus {
  border-color: var(--sg-accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.sg-btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  display: inline-block;
  transition: transform 0.15s, opacity 0.15s;
}
.sg-btn-primary { background: var(--sg-theme); color: white; }
.sg-btn-primary:hover { opacity: 0.9; }
.sg-btn-outline { background: transparent; border: 2px solid var(--sg-theme); color: var(--sg-theme); }
.sg-btn:active { transform: scale(0.97); }
.sg-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* === UPLOAD === */
.sg-upload-form { padding: 16px; }
.sg-upload-zone {
  border: 2px dashed #cbd5e1;
  border-radius: var(--sg-radius);
  padding: 36px 16px;
  text-align: center;
  cursor: pointer;
  background: var(--sg-card);
  margin-bottom: 16px;
  transition: border-color 0.2s;
  color: var(--sg-text);
}
.sg-upload-zone:active { border-color: var(--sg-accent); }
.sg-upload-zone svg { width: 48px; height: 48px; fill: var(--sg-text-light); margin: 0 auto 12px; display: block; }
.sg-upload-preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.sg-upload-item { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; }
.sg-upload-item img, .sg-upload-item video { width: 100%; height: 100%; object-fit: cover; }

/* === SIDEBAR === */
.sg-sidebar {
  position: fixed;
  top: 0;
  left: -100%;
  bottom: 0;
  width: 280px;
  max-width: 80vw;
  background: var(--sg-card);
  z-index: 100;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 16px rgba(0,0,0,0.1);
}
.sg-sidebar.open { left: 0; }

.sg-sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
  display: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.sg-sidebar-overlay.open { display: block; opacity: 1; }

.sg-sidebar-header {
  padding: 20px 16px;
  background: var(--sg-bg);
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sg-sidebar-nav { padding: 8px 0; overflow-y: auto; flex: 1; }
.sg-sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  text-decoration: none;
  color: var(--sg-text);
  font-weight: 500;
  font-size: 0.95rem;
}
.sg-sidebar-nav a:active { background: var(--sg-bg); }
.sg-sidebar-nav svg { width: 20px; height: 20px; fill: var(--sg-text-light); flex-shrink: 0; }

/* === SEARCH OVERLAY === */
.sg-search-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--sg-bg);
  z-index: 80;
  display: none;
  flex-direction: column;
}
.sg-search-overlay.open { display: flex; }

.sg-search-header {
  padding: 12px 16px;
  display: flex;
  gap: 12px;
  background: var(--sg-card);
  align-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.sg-search-header input {
  flex: 1;
  border: none;
  background: #f1f5f9;
  padding: 10px 16px;
  border-radius: 20px;
  outline: none;
  font-size: 0.95rem;
  color: var(--sg-text);
  font-family: inherit;
}
.sg-search-results { flex: 1; overflow-y: auto; padding: 16px; }

/* === PHOTO VIEWER (LIGHTBOX) === */
.sg-viewer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #000;
  z-index: 9999;
  display: none;
  flex-direction: column;
  color: white;
}
.sg-viewer.open { display: flex; }

.sg-viewer-toolbar {
  display: flex;
  justify-content: space-between;
  padding: 12px 16px;
  align-items: center;
  background: linear-gradient(rgba(0,0,0,0.6), transparent);
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding-top: max(12px, env(safe-area-inset-top));
}

.sg-viewer-btn {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s;
}
.sg-viewer-btn:active { background: rgba(255,255,255,0.15); }
.sg-viewer-btn svg { width: 24px; height: 24px; fill: white; }
.sg-viewer-counter { font-size: 0.9rem; font-weight: 600; color: white; }

.sg-viewer-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.sg-viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: opacity 0.2s;
}

.sg-viewer-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255,255,255,0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: sg-spin 1s linear infinite;
  display: none;
  z-index: 1;
}
@keyframes sg-spin { to { transform: translate(-50%, -50%) rotate(360deg); } }

.sg-viewer-actions {
  display: flex;
  justify-content: space-around;
  padding: 16px 32px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

/* === TOAST === */
.sg-toast {
  position: fixed;
  bottom: calc(var(--sg-nav-height) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1e293b;
  color: white;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 0.88rem;
  z-index: 10000;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  opacity: 0;
  white-space: nowrap;
  pointer-events: none;
}
.sg-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* === EMPTY STATE === */
.sg-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--sg-text-light);
  font-size: 0.9rem;
}
.sg-empty svg { width: 48px; height: 48px; fill: #cbd5e1; margin: 0 auto 12px; display: block; }
.sg-empty p { color: var(--sg-text-light); }

/* === SINGLE ALBUM PAGE === */
.sg-single-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--sg-card);
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.06);
  gap: 12px;
}
.sg-single-title {
  font-weight: 700;
  font-size: 1.05rem;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--sg-text);
}
.sg-album-meta {
  padding: 16px;
  background: var(--sg-card);
  margin-bottom: 8px;
}
.sg-album-desc {
  margin-top: 12px;
  color: var(--sg-text-light);
  font-size: 0.9rem;
  line-height: 1.6;
}

/* === Hide WP admin bar offset === */
html[style*="margin-top"] { margin-top: 0 !important; }

.sg-notif-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    background: #ef4444;
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 2px 3px;
    border-radius: 10px;
    line-height: 1;
    width: 8px;
    text-align: center;
    border: 1.5px solid var(--sg-card);
    box-sizing: content-box;
}
/* === NOTIFICATION SHAKE === */
#btn-notif-subscribe svg {
    transform-origin: top center;
}

#btn-notif-subscribe.shake svg {
    animation: sgNotifShake 0.8s ease-in-out;
}

@keyframes sgNotifShake {
    0%   { transform: rotate(0deg); }
    10%  { transform: rotate(14deg); }
    20%  { transform: rotate(-14deg); }
    30%  { transform: rotate(12deg); }
    40%  { transform: rotate(-10deg); }
    50%  { transform: rotate(7deg); }
    60%  { transform: rotate(-5deg); }
    70%  { transform: rotate(3deg); }
    80%  { transform: rotate(-2deg); }
    100% { transform: rotate(0deg); }
}

.sg-pwa-prompt {
  position: fixed;
  bottom: calc(var(--sg-nav-height) + 16px);
  right: 16px;
  background: var(--sg-card);
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 50;
  border: 1px solid #e2e8f0;
  transform: translateY(250%);
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s ease;
  max-width: calc(100vw - 32px);
}
.sg-pwa-prompt.show {
  transform: translateY(0);
  opacity: 1;
}
@media (min-width: 768px) {
  .sg-pwa-prompt {
    bottom: 24px;
    right: 24px;
  }
}
.pwa-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pwa-icon img {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  background: #f8fafc;
  display: block;
}
.pwa-text {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}
.pwa-text strong {
  font-size: 0.95rem;
  color: var(--sg-text);
  line-height: 1.2;
}
.pwa-text span {
  font-size: 0.75rem;
  color: var(--sg-text-light);
  margin-top: 2px;
}
#btn-pwa-install {
  width: auto;
  white-space: nowrap;
}
#btn-pwa-close {
  background: none;
  border: none;
  color: var(--sg-text-light);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: -4px;
}
#btn-pwa-close svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
