/* ── Reset e variáveis ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0 }

:root {
  --bg:         #0f0f0f;
  --bg2:        #1a1a1a;
  --bg3:        #252525;
  --border:     #333;
  --text:       #e8e8e8;
  --text2:      #888;
  --accent:     #4f90ff;
  --danger:     #e05a5a;
  --radius:     8px;
  --shadow:     0 4px 20px rgba(0,0,0,.5);
}

html { font-size: 16px; scroll-behavior: smooth }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

/* ── Utilitários ────────────────────────────────────────────────────────── */
.hidden { display: none !important }
.error  { color: var(--danger); font-size: .875rem; margin-top: .5rem }

/* ── Botões ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem 1rem; border-radius: var(--radius);
  border: none; cursor: pointer; font-size: .9rem;
  transition: opacity .15s, background .15s;
}
.btn:disabled { opacity: .4; cursor: not-allowed }
.btn-primary  { background: var(--accent); color: #fff }
.btn-primary:hover:not(:disabled) { opacity: .85 }
.btn-ghost    { background: transparent; color: var(--text2); border: 1px solid var(--border) }
.btn-ghost:hover:not(:disabled) { background: var(--bg3); color: var(--text) }
.btn-ghost.active { color: var(--text); border-color: var(--accent) }

/* ── Login ──────────────────────────────────────────────────────────────── */
.login-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
}
.login-box {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: 2.5rem 2rem; width: 100%; max-width: 380px;
  box-shadow: var(--shadow);
}
.login-box h1 { font-size: 1.6rem; margin-bottom: .25rem }
.login-box .subtitle { color: var(--text2); margin-bottom: 1.5rem; font-size: .9rem }
.field { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem }
.field label { font-size: .85rem; color: var(--text2) }
.field input, .field select {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  padding: .6rem .75rem; font-size: .95rem; width: 100%;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--accent);
}
.login-box .btn { width: 100%; justify-content: center; margin-top: .5rem }

/* ── Header ─────────────────────────────────────────────────────────────── */
#appHeader {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  padding: .75rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap;
}
.header-left { display: flex; align-items: center; gap: .75rem }
.logo         { font-size: 1.1rem; font-weight: 600 }
.album-title  { color: var(--text2); font-size: .9rem }
.header-right { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap }

/* ── Galeria ─────────────────────────────────────────────────────────────── */
.view { padding: 1.25rem }

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}
@media (max-width: 480px) {
  .media-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px }
}

/* Item = thumbnail quadrada + label abaixo */
.media-item {
  display: flex; flex-direction: column;
  border-radius: 6px; overflow: hidden;
  background: var(--bg3); cursor: pointer;
}
.media-item .thumb-wrap {
  position: relative; aspect-ratio: 1; overflow: hidden;
}
.media-item .thumb-wrap img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform .2s; display: block;
}
.media-item:hover .thumb-wrap img { transform: scale(1.04) }

/* Label sempre visível abaixo da miniatura */
.media-item .caption {
  padding: 4px 6px 5px;
  font-size: .72rem; color: var(--text2);
  text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.3;
  flex-shrink: 0;
}

.media-item .badge-video {
  position: absolute; bottom: 6px; right: 6px;
  background: rgba(0,0,0,.7); border-radius: 4px;
  padding: 2px 6px; font-size: .75rem; color: #fff;
  pointer-events: none;
}
.media-item .duration {
  position: absolute; bottom: 6px; left: 6px;
  background: rgba(0,0,0,.7); border-radius: 4px;
  padding: 2px 6px; font-size: .75rem; color: #fff;
  pointer-events: none;
}

/* Placeholder enquanto a foto carrega: mantém tamanho natural, não estica */
.pswp__img--placeholder {
  object-fit: contain !important;
  filter: blur(8px);
}

/* Legenda no rodapé do PhotoSwipe */
.pswp-caption {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: .5rem 1rem;
  background: linear-gradient(transparent, rgba(0,0,0,.7));
  color: #fff; font-size: .85rem; text-align: center;
  pointer-events: none;
}

/* Slide de vídeo dentro do PhotoSwipe */
.pswp-video-slide {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
}
.pswp-video {
  max-width: 100%; max-height: 100%;
  outline: none; background: #000;
}

/* ── Álbuns ─────────────────────────────────────────────────────────────── */
.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}
.album-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.album-card:hover { border-color: var(--accent); transform: translateY(-2px) }
.album-card .cover {
  width: 100%; aspect-ratio: 16/9; background: var(--bg3); overflow: hidden;
}
.album-card .cover img { width: 100%; height: 100%; object-fit: cover }
.album-cover-placeholder {
  width: 100%; height: 100%; display: flex;
  align-items: center; justify-content: center;
  font-size: 2.5rem; color: var(--text2);
}
.album-info { padding: .75rem }
.album-info h3 { font-size: .95rem; margin-bottom: .2rem }
.album-info span { font-size: .8rem; color: var(--text2) }

/* ── Upload ─────────────────────────────────────────────────────────────── */
.upload-box {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 2rem; text-align: center; max-width: 520px; margin: 0 auto;
  transition: border-color .15s;
}
.upload-box.drag-over { border-color: var(--accent) }
.upload-box p { color: var(--text2); margin-bottom: 1rem }
.upload-box input[type=file] { display: none }
.upload-progress { max-width: 520px; margin: 1rem auto }
.progress-item {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .6rem .8rem; margin-bottom: .5rem;
  display: flex; align-items: center; gap: .75rem;
}
.progress-item .name { flex: 1; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.progress-item .status { font-size: .8rem; color: var(--text2); white-space: nowrap }
.progress-item .status.done  { color: #4caf50 }
.progress-item .status.error { color: var(--danger) }
.progress-item .status.processing { color: var(--accent) }
.progress-item .status.processing::after {
  content: '';
  display: inline-block;
  width: 9px; height: 9px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin-left: 5px;
  vertical-align: -1px;
}

/* ── Carregamento ────────────────────────────────────────────────────────── */
.load-more { text-align: center; padding: 1.5rem }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
  margin: 3rem auto;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* ── Modais ─────────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,.85);
}
.modal-content {
  position: relative; z-index: 1; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 1.5rem; max-width: 92vw; max-height: 92vh;
  overflow: auto; box-shadow: var(--shadow);
}
.modal-sm { width: 360px }
.modal-close {
  position: absolute; top: .75rem; right: .75rem;
  background: none; border: none; color: var(--text2);
  font-size: 1.1rem; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text) }
.modal-caption { color: var(--text2); font-size: .85rem; margin-top: .75rem; text-align: center }
.modal-content h2 { margin-bottom: 1rem }
.modal-content .btn { width: 100%; justify-content: center; margin-top: .5rem }

/* ── Player de vídeo ─────────────────────────────────────────────────────── */
.player-wrap { width: min(860px, 88vw) }
.player-wrap video { width: 100%; border-radius: var(--radius) }

/* ── PhotoSwipe customização ─────────────────────────────────────────────── */
.pswp { --pswp-bg: #000 }

/* ── Menu de contexto (botão direito) ───────────────────────────────────── */
.context-menu {
  position: fixed; z-index: 1000;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .3rem 0; min-width: 210px;
  user-select: none;
}
.ctx-label {
  font-size: .75rem; color: var(--text2);
  padding: .4rem .85rem .2rem; text-transform: uppercase; letter-spacing: .04em;
}
.ctx-item {
  display: block; width: 100%; text-align: left;
  background: none; border: none; padding: .5rem .85rem;
  color: var(--text); cursor: pointer; font-size: .875rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ctx-item:hover  { background: var(--bg3) }
.ctx-danger      { color: var(--danger) }
.ctx-divider     { border: none; border-top: 1px solid var(--border); margin: .3rem 0 }

/* ── Painel de Segurança ────────────────────────────────────────────────── */
.security-panel {
  max-width: 540px;
  margin: 2rem auto;
  padding: 2rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.security-panel h2 {
  margin-bottom: 1.5rem;
  font-size: 1.1rem;
}

/* ── Overlay obrigatório (troca de senha / 2FA forçado) ─────────────────── */
.overlay-forced {
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.overlay-box {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: 2rem;
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow);
}
.overlay-box h2 { font-size: 1.15rem; margin-bottom: .25rem }
.overlay-box .btn { width: 100%; justify-content: center; margin-top: .75rem }
.overlay-box .field { margin-bottom: 1rem }

/* ── Admin panel ────────────────────────────────────────────────────────── */
.admin-panel {
  max-width: 900px; margin: 1.5rem auto; padding: 0 .5rem;
}
.admin-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem;
}
.admin-panel-header h2 { font-size: 1.1rem }

/* ── Tabela de usuários ─────────────────────────────────────────────────── */
.admin-table {
  width: 100%; border-collapse: collapse;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  font-size: .875rem;
}
.admin-table th {
  background: var(--bg3); color: var(--text2); font-weight: 600;
  padding: .65rem 1rem; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table td {
  padding: .6rem 1rem; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none }
.admin-table tr:hover td { background: var(--bg3) }
@media (max-width: 640px) {
  .admin-table { font-size: .78rem }
  .admin-table th, .admin-table td { padding: .5rem .6rem }
}

.td-actions { display: flex; gap: .4rem; align-items: center }
.btn-xs { padding: .2rem .45rem; font-size: .8rem; border-radius: 4px }

/* Role badges */
.role-badge {
  display: inline-block; padding: .15rem .5rem;
  border-radius: 4px; font-size: .75rem; font-weight: 600; text-transform: uppercase;
}
.role-admin  { background: rgba(79,144,255,.15); color: var(--accent) }
.role-viewer { background: rgba(136,136,136,.15); color: var(--text2) }

/* ── Botão de notificações ──────────────────────────────────────────────── */
.notify-btn { position: relative }
.badge-notification {
  position: absolute; top: 4px; right: 4px;
  width: 8px; height: 8px;
  background: var(--danger); border-radius: 50%;
  pointer-events: none;
}

/* ── Seleção de usuários (checkboxes em álbuns) ─────────────────────────── */
.user-checkboxes {
  max-height: 180px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .5rem .75rem; background: var(--bg3);
}

/* ── Botão de acesso em álbum card ─────────────────────────────────────── */
.btn-access-album {
  position: absolute; top: .4rem; right: .4rem;
  background: rgba(0,0,0,.6); border: none; border-radius: 4px;
  padding: .2rem .35rem; font-size: .8rem; cursor: pointer;
  opacity: 0; transition: opacity .15s;
}
.album-card { position: relative }
.album-card:hover .btn-access-album { opacity: 1 }

/* ── Barra de seleção em lote ─────────────────────────────── */
.bulk-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 150;
  background: var(--bg2); border-top: 1px solid var(--border);
  padding: .75rem 1.25rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  box-shadow: 0 -4px 20px rgba(0,0,0,.4);
}
.bulk-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-left: auto }
.btn-sm { padding: .35rem .75rem; font-size: .82rem }
.btn-danger-solid { background: var(--danger); color: #fff; border: none; border-radius: var(--radius); cursor: pointer; transition: opacity .15s }
.btn-danger-solid:hover:not(:disabled) { opacity: .85 }
.btn-danger-solid:disabled { opacity: .4; cursor: not-allowed }

/* ── Select mode — mídia ────────────────────────────────────── */
.media-item .select-cb {
  position: absolute; top: 6px; left: 6px; z-index: 2;
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,.75); border-radius: 50%;
  background: rgba(0,0,0,.45);
  display: none; align-items: center; justify-content: center;
  pointer-events: none;
}
.select-mode .media-item .select-cb { display: flex }
.media-item.selected .select-cb { background: var(--accent); border-color: var(--accent) }
.media-item.selected .select-cb::after { content: '✓'; color: #fff; font-size: .6rem; font-weight: 700 }
.media-item.selected .thumb-wrap img { opacity: .7 }
.media-item.selected { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 6px }
.select-mode .media-item { cursor: pointer }
.select-mode .media-item:hover .thumb-wrap img { transform: none }

/* ── Álbum — ações ──────────────────────────────────────────── */
.album-card-actions {
  display: flex; gap: .35rem; padding: .5rem .75rem;
  border-top: 1px solid var(--border); justify-content: flex-end;
}
.btn-album-action {
  background: none; border: 1px solid var(--border); border-radius: 4px;
  padding: .2rem .5rem; font-size: .78rem; cursor: pointer; color: var(--text2);
  transition: background .15s, color .15s; white-space: nowrap;
}
.btn-album-action:hover { background: var(--bg3); color: var(--text) }
.btn-album-action.danger { color: var(--danger); border-color: var(--danger) }
.btn-album-action.danger:hover { background: rgba(224,90,90,.1) }

/* ── Select mode — álbuns ────────────────────────────────────── */
.album-card .album-select-cb {
  display: none; position: absolute; top: .5rem; left: .5rem; z-index: 2;
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,.75); border-radius: 50%;
  background: rgba(0,0,0,.45);
  align-items: center; justify-content: center;
  pointer-events: none;
}
.album-select-mode .album-card .album-select-cb { display: flex }
.album-card.selected .album-select-cb { background: var(--accent); border-color: var(--accent) }
.album-card.selected .album-select-cb::after { content: '✓'; color: #fff; font-size: .6rem; font-weight: 700 }
.album-card.selected { outline: 2px solid var(--accent); outline-offset: -2px }
.album-select-mode .album-card { cursor: pointer }

/* Albums toolbar */
.albums-toolbar { display: flex; justify-content: flex-end; margin-bottom: .75rem }
