/* ============================================
   ALVORADA IMPORT · PWA STYLES
   Color corporativo: verde #1e6b10
   ============================================ */

:root {
  --green-900: #0d3a07;
  --green-800: #155a0c;
  --green-700: #1a6b0e;
  --green-600: #2a8a1a;
  --green-500: #3aaa28;
  --green-200: #b8e8a8;
  --green-100: #e8f5e3;
  --green-50:  #f2faf0;

  --white:     #ffffff;
  --gray-50:   #f8fafb;
  --gray-100:  #f0f3f5;
  --gray-200:  #dde3e8;
  --gray-400:  #9aa5b0;
  --gray-600:  #5a6472;
  --gray-900:  #1a2028;

  --sidebar-w: 260px;
  --topbar-h:  58px;
  --radius:    10px;
  --shadow:    0 2px 12px rgba(0,0,0,0.10);
  --shadow-lg: 0 6px 28px rgba(0,0,0,0.16);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--gray-100);
  color: var(--gray-900);
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ============ SPLASH ============ */
#splash {
  position: fixed; inset: 0;
  background: linear-gradient(160deg, var(--green-700) 0%, var(--green-900) 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  transition: opacity 0.5s ease;
}
#splash.fade-out { opacity: 0; pointer-events: none; }

.splash-inner { text-align: center; }

.splash-logo svg { width: 110px; height: 110px; filter: drop-shadow(0 4px 16px rgba(0,0,0,0.3)); }

.splash-title {
  color: var(--white);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  margin-top: 8px;
}
.splash-sub {
  color: var(--green-200);
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  margin-top: 2px;
}

.splash-spinner {
  width: 32px; height: 32px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 28px auto 0;
}

/* ============ APP SHELL ============ */
#app {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar main";
  height: 100vh;
  overflow: hidden;
}

/* ============ TOPBAR ============ */
#topbar {
  grid-area: topbar;
  background: linear-gradient(90deg, var(--green-700), var(--green-800));
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  z-index: 100;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}
.topbar-right { margin-left: auto; }

.topbar-brand {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.brand-name {
  color: var(--white);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.brand-sub {
  color: var(--green-200);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--white);
  width: 38px; height: 38px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.12); }
.icon-btn svg { width: 22px; height: 22px; }

/* Sync pill */
.sync-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255,255,255,0.12);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 0.72rem;
  color: var(--white);
  cursor: default;
}
.sync-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--gray-400);
  flex-shrink: 0;
}
.sync-dot.online  { background: #6ee45e; box-shadow: 0 0 6px #6ee45e; }
.sync-dot.offline { background: #f87171; }
.sync-dot.syncing { background: #fbbf24; animation: pulse 1s infinite; }

/* ============ SIDEBAR ============ */
#sidebar-overlay {
  position: fixed; inset: 0; top: var(--topbar-h);
  background: rgba(0,0,0,0.45);
  z-index: 200;
  animation: fadeIn 0.2s ease;
}

#sidebar {
  grid-area: sidebar;
  background: linear-gradient(180deg, var(--green-800) 0%, var(--green-900) 100%);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 50;
  transition: transform 0.3s cubic-bezier(.4,0,.2,1);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-brand {
  color: var(--white);
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.1em;
}
.sidebar-brand-sub {
  color: var(--green-200);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  margin-top: 1px;
}

.sidebar-section-label {
  padding: 16px 16px 6px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: rgba(255,255,255,0.35);
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
  width: 100%;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
}
.sidebar-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.sidebar-item:hover { background: rgba(255,255,255,0.08); color: white; }
.sidebar-item.active {
  background: rgba(255,255,255,0.14);
  color: white;
  font-weight: 600;
  border-right: 3px solid var(--green-200);
}

.sidebar-info-block {
  margin: 0 12px 8px;
  background: rgba(0,0,0,0.2);
  border-radius: 8px;
  padding: 12px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 4px 0;
}
.info-label { font-size: 0.72rem; color: rgba(255,255,255,0.45); }
.info-val   { font-size: 0.75rem; color: rgba(255,255,255,0.8); font-weight: 600; text-align: right; }

.sidebar-sync-btn {
  margin: 8px 12px 20px;
  background: var(--green-600);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 11px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s;
}
.sidebar-sync-btn:hover { background: var(--green-500); }

/* ============ MAIN ============ */
#main {
  grid-area: main;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--gray-50);
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  flex-wrap: wrap;
  gap: 8px;
}
.view-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--gray-900);
}
.view-meta {
  font-size: 0.78rem;
  color: var(--gray-400);
}

/* Search bar */
.search-bar-wrap { margin-bottom: 16px; }
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  border-radius: 10px;
  padding: 9px 14px;
  box-shadow: var(--shadow);
  transition: border-color 0.2s;
}
.search-bar:focus-within { border-color: var(--green-600); }
.search-bar svg { color: var(--gray-400); flex-shrink: 0; }
.search-bar input {
  border: none; outline: none;
  font-size: 0.92rem;
  color: var(--gray-900);
  background: transparent;
  width: 100%;
}
.search-bar input::placeholder { color: var(--gray-400); }

/* ============ IMAGE GRID ============ */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.img-card {
  background: var(--white);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.18s, box-shadow 0.18s;
  aspect-ratio: 3/4;
  display: flex;
  flex-direction: column;
}
.img-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.img-card:active { transform: scale(0.97); }

.img-card-thumb {
  flex: 1;
  overflow: hidden;
  background: var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
}
.img-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s;
}
.img-card:hover .img-card-thumb img { transform: scale(1.04); }
.img-card-label {
  padding: 6px 8px;
  font-size: 0.7rem;
  color: var(--gray-600);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-top: 1px solid var(--gray-100);
  background: var(--white);
}

/* Skeleton loading */
.img-card.skeleton .img-card-thumb {
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
.img-card.skeleton .img-card-label {
  background: var(--gray-100);
  animation: shimmer 1.4s infinite;
  color: transparent;
}

/* ============ CATEGORIES GRID ============ */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.cat-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  padding: 20px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform 0.18s, box-shadow 0.18s;
  border-left: 4px solid var(--green-600);
}
.cat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.cat-card:active { transform: scale(0.97); }

.cat-icon {
  width: 44px; height: 44px;
  background: var(--green-100);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--green-700);
}
.cat-icon svg { width: 24px; height: 24px; }
.cat-name { font-weight: 600; font-size: 0.95rem; color: var(--gray-900); }
.cat-count { font-size: 0.75rem; color: var(--gray-400); margin-top: 2px; }

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.82rem;
  color: var(--gray-600);
  cursor: pointer;
  transition: background 0.15s;
}
.back-btn:hover { background: var(--gray-100); }

/* ============ EMPTY STATE ============ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--gray-400);
  text-align: center;
  gap: 12px;
}
.empty-state svg { opacity: 0.5; }
.empty-state p { font-size: 1rem; font-weight: 600; }
.empty-state small { font-size: 0.82rem; }

/* ============ SYNC OVERLAY ============ */
#sync-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
  animation: fadeIn 0.2s ease;
}
#sync-overlay.hidden { display: none !important; }

.sync-modal {
  background: white;
  border-radius: 16px;
  padding: 32px 28px;
  width: min(340px, 90vw);
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.sync-modal-icon {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--green-600), var(--green-800));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}
.sync-modal-title { font-size: 1.15rem; font-weight: 700; margin-bottom: 6px; }
.sync-modal-msg   { font-size: 0.85rem; color: var(--gray-400); margin-bottom: 20px; min-height: 18px; }

.sync-progress-wrap { display: flex; align-items: center; gap: 10px; }
.sync-progress-bar {
  flex: 1;
  height: 8px;
  background: var(--gray-100);
  border-radius: 4px;
  overflow: hidden;
}
#sync-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green-600), var(--green-500));
  border-radius: 4px;
  transition: width 0.4s ease;
}
.sync-progress-label { font-size: 0.78rem; font-weight: 700; color: var(--green-700); width: 32px; text-align: right; }

/* ============ LIGHTBOX ============ */
#lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
#lightbox.hidden { display: none !important; }

#lb-close {
  position: absolute; top: 16px; right: 16px;
  background: rgba(255,255,255,0.1);
  border: none; cursor: pointer; border-radius: 50%;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
  transition: background 0.15s;
}
#lb-close:hover { background: rgba(255,255,255,0.2); }

#lb-prev, #lb-next {
  position: absolute;
  background: rgba(255,255,255,0.1);
  border: none; cursor: pointer;
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
  transition: background 0.15s;
}
#lb-prev:hover, #lb-next:hover { background: rgba(255,255,255,0.2); }
#lb-prev { left: 16px; }
#lb-next { right: 16px; }

#lb-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: calc(100vw - 130px);
  max-height: calc(100vh - 80px);
}
#lb-img {
  max-width: 100%;
  max-height: calc(100vh - 120px);
  object-fit: contain;
  border-radius: 6px;
  user-select: none;
}
#lb-info {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 10px 4px 0;
  gap: 12px;
}
#lb-name   { color: rgba(255,255,255,0.8); font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lb-counter{ color: rgba(255,255,255,0.45); font-size: 0.82rem; flex-shrink: 0; }

/* ============ TOAST ============ */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--gray-900);
  color: white;
  border-radius: 24px;
  padding: 10px 20px;
  font-size: 0.88rem;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 900;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { background: var(--green-700); }
.toast.error   { background: #dc2626; }

/* ============ MOBILE RESPONSIVE ============ */
@media (max-width: 700px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }

  #sidebar {
    position: fixed;
    top: var(--topbar-h); left: 0; bottom: 0;
    width: var(--sidebar-w);
    z-index: 300;
    transform: translateX(-100%);
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar-overlay { display: block; }
  #sidebar-overlay.hidden { display: none !important; }

  .image-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
  #main { padding: 14px; }

  #lb-prev { left: 8px; width: 40px; height: 40px; }
  #lb-next { right: 8px; width: 40px; height: 40px; }
  #lb-content { max-width: calc(100vw - 100px); }
}

@media (min-width: 701px) {
  #btn-menu { display: none; }
  #sidebar-overlay { display: none !important; }
}

/* ============ ANIMATIONS ============ */
@keyframes spin    { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes pulse   { 0%,100% { opacity:1; } 50% { opacity:.4; } }
@keyframes fadeIn  { from { opacity:0; } to { opacity:1; } }

.spin { animation: spin 1s linear infinite; }
