/* Mídia Vida Nova — mobile primeiro, tema claro/escuro seguindo o sistema */

:root {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-2: #f0f0f4;
  --text: #16161d;
  --text-2: #5d5d6b;
  --text-3: #8e8e9c;
  --border: #e6e6ec;
  --accent: #5b5bd6;
  --accent-hover: #4b4bc4;
  --accent-soft: #ececfb;
  --on-accent: #ffffff;
  --ok: #18794e;
  --ok-soft: #e3f5ec;
  --warn: #a35200;
  --warn-soft: #fdf0e1;
  --danger: #cd2b31;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgb(16 16 29 / 0.04), 0 4px 16px rgb(16 16 29 / 0.06);
  --shadow-lg: 0 8px 40px rgb(16 16 29 / 0.18);
  --radius: 16px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e12;
    --surface: #18181e;
    --surface-2: #222229;
    --text: #ededf2;
    --text-2: #a8a8b6;
    --text-3: #75757f;
    --border: #2a2a33;
    --accent: #8b8bff;
    --accent-hover: #a0a0ff;
    --accent-soft: #23234a;
    --on-accent: #0e0e12;
    --ok: #4cc38a;
    --ok-soft: #133024;
    --warn: #f1a10d;
    --warn-soft: #33260c;
    --danger: #ff6369;
    --danger-soft: #3b1618;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 8px 40px rgb(0 0 0 / 0.6);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }

svg.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Botões ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid transparent; border-radius: 999px;
  background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 15px; text-decoration: none;
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background .15s, transform .1s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible, .icon-btn:focus-visible, .field input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border: 0; border-radius: 999px;
  background: transparent; color: var(--text-2); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- Cabeçalho ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--border); }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px;
  background: var(--accent); color: var(--on-accent);
}
.brand-mark svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }

.topbar .spacer { flex: 1; }
.user-name { color: var(--text-2); font-size: 14px; display: none; }

/* ---------- Conteúdo ---------- */

.container { width: 100%; max-width: 760px; margin: 0 auto; padding: 8px 16px 120px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 16px; }
.page-head h1 { margin: 0; font-size: 28px; line-height: 1.2; letter-spacing: -.02em; }
.page-head .count { color: var(--text-3); font-weight: 500; font-size: 15px; margin-left: 6px; }

/* No celular o botão de enviar fica fixo embaixo, perto do polegar */
.upload-btn {
  position: fixed; z-index: 20; left: 16px; right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  min-height: 54px; font-size: 16px; box-shadow: var(--shadow-lg);
}

/* ---------- Lista ---------- */

.list { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }

.card {
  display: grid; grid-template-columns: 112px 1fr; gap: 14px;
  padding: 12px; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  animation: entrar .25s ease-out;
}
@keyframes entrar { from { opacity: 0; transform: translateY(6px); } }

.thumb {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius-sm); overflow: hidden;
  background: var(--surface-2); display: grid; place-items: center; color: var(--text-3);
  align-self: start;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .dur {
  position: absolute; right: 6px; bottom: 6px; padding: 1px 6px; border-radius: 6px;
  background: rgb(0 0 0 / .7); color: #fff; font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
}

.info { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.title {
  margin: 0; font-size: 15px; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word;
}
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; color: var(--text-3); font-size: 13px; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill svg { width: 13px; height: 13px; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.busy { background: var(--warn-soft); color: var(--warn); }
.pill.error { background: var(--danger-soft); color: var(--danger); }
.pill.hdr { background: var(--accent-soft); color: var(--accent); }

.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .4s ease; }
.progress.indeterminate > span { width: 35%; animation: vai-e-vem 1.2s ease-in-out infinite; }
@keyframes vai-e-vem { 0% { transform: translateX(-100%); } 100% { transform: translateX(290%); } }

.error-text { margin: 0; color: var(--danger); font-size: 13px; }

.actions { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.actions .btn { flex: 1; }

.spin { animation: girar 1s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }

/* ---------- Estado vazio / carregando ---------- */

.empty { text-align: center; padding: 64px 24px; color: var(--text-2); }
.empty .empty-icon {
  display: inline-grid; place-items: center; width: 64px; height: 64px; margin-bottom: 16px;
  border-radius: 20px; background: var(--accent-soft); color: var(--accent);
}
.empty .empty-icon svg { width: 28px; height: 28px; }
.empty h2 { margin: 0 0 4px; color: var(--text); font-size: 18px; }
.empty p { margin: 0; }

.skeleton { height: 88px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); position: relative; overflow: hidden; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface-2) 70%, transparent), transparent);
  animation: brilho 1.4s infinite; transform: translateX(-100%);
}
@keyframes brilho { to { transform: translateX(100%); } }

/* ---------- Diálogos (bottom sheet no celular, modal no desktop) ---------- */

dialog {
  width: 100%; max-width: 100%; margin: auto 0 0; padding: 0; border: 0;
  border-radius: 24px 24px 0 0; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg);
}
dialog[open] { animation: subir .25s cubic-bezier(.2, .8, .2, 1); }
dialog::backdrop { background: rgb(0 0 0 / .45); backdrop-filter: blur(2px); }
@keyframes subir { from { transform: translateY(40px); opacity: 0; } }

.sheet { padding: 8px 20px max(20px, env(safe-area-inset-bottom)); }
.sheet::before { content: ""; display: block; width: 40px; height: 4px; margin: 4px auto 16px; border-radius: 999px; background: var(--border); }
.sheet h2 { margin: 0 0 4px; font-size: 20px; letter-spacing: -.01em; }
.sheet p { margin: 0 0 16px; color: var(--text-2); }
.sheet .buttons { display: flex; flex-direction: column-reverse; gap: 8px; margin-top: 20px; }

.file-box {
  display: flex; align-items: center; gap: 12px; padding: 12px; margin-bottom: 16px;
  border-radius: var(--radius-sm); background: var(--surface-2);
}
.file-box .file-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); flex: none; }
.file-box .file-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-box .file-size { color: var(--text-3); font-size: 13px; }
.file-box > div:last-child { min-width: 0; }

.aviso {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 4px 0 0 !important; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--warn-soft); color: var(--warn) !important; font-size: 14px; font-weight: 500;
}
.aviso svg { margin-top: 1px; width: 18px; height: 18px; }

.warn-text { margin: 0; color: var(--warn); font-size: 13px; font-weight: 500; }

/* Miniatura clicável abre o player */
.thumb.playable { cursor: pointer; padding: 0; border: 0; font: inherit; }
.thumb.playable::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 36px; height: 36px; margin: -18px 0 0 -18px;
  border-radius: 999px; background: rgb(0 0 0 / .55) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M9 6.5v11l9-5.5z'/%3E%3C/svg%3E") center / 20px no-repeat;
  transition: transform .15s;
}
.thumb.playable:hover::after { transform: scale(1.1); }

/* ---------- Player ---------- */

dialog.player { max-width: 960px; background: #000; color: #fff; overflow: hidden; }
.player-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px; }
.player-head strong { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.player-head .icon-btn { color: #fff; }
.player-head .icon-btn:hover { background: rgb(255 255 255 / .12); }
dialog.player video { display: block; width: 100%; max-height: 75dvh; background: #000; padding-bottom: env(safe-area-inset-bottom); }

/* ---------- Formulários ---------- */

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 14px; font-weight: 600; color: var(--text-2); }
.field input {
  width: 100%; min-height: 48px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  font-size: 16px; /* 16px evita zoom automático no iPhone */
  transition: border-color .15s;
}
.field input:focus { border-color: var(--accent); outline: none; }

/* ---------- Login ---------- */

.login-page { display: grid; place-items: center; min-height: 100dvh; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { flex-direction: column; gap: 14px; margin-bottom: 28px; text-align: center; }
.login-card .brand-mark { width: 56px; height: 56px; border-radius: 18px; }
.login-card .brand-mark svg { width: 24px; height: 24px; }
.login-card h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.login-card .subtitle { margin: 0; color: var(--text-2); font-weight: 400; font-size: 15px; }
.login-form { padding: 24px; border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 52px; }
.password-toggle {
  position: absolute; top: 50%; right: 4px; translate: 0 -50%;
  display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text-3); cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.password-toggle:hover { color: var(--text); }
.password-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.form-error { min-height: 22px; margin: -4px 0 10px; color: var(--danger); font-size: 14px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed; z-index: 50; left: 50%; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 70px);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: transform .25s, opacity .25s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------- Abas Vídeos / Fotos ---------- */

.brand-name { display: none; }
.tabs { display: flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--surface-2); }
.tabs a {
  padding: 6px 16px; border-radius: 999px; color: var(--text-2);
  font-size: 14px; font-weight: 600; text-decoration: none; -webkit-tap-highlight-color: transparent;
}
.tabs a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.icon-btn:disabled { opacity: .35; pointer-events: none; }
.hint { margin: 0; color: var(--text-3); font-size: 13px; }

/* ---------- Álbuns ---------- */

.album-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 0; padding: 0; list-style: none; }
.album-card {
  display: block; border-radius: var(--radius); overflow: hidden; background: var(--surface); box-shadow: var(--shadow);
  color: inherit; text-decoration: none; animation: entrar .25s ease-out; transition: transform .15s;
}
.album-card:active { transform: scale(.98); }
.album-cover { aspect-ratio: 4 / 3; display: grid; place-items: center; background: var(--surface-2); color: var(--text-3); }
.album-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.album-text { padding: 10px 12px 12px; display: grid; gap: 2px; }
.album-text .title { font-size: 14px; }
.album-text .meta { font-size: 12px; }

.skeleton.tall { height: 180px; }
.skeleton.square { height: auto; aspect-ratio: 1; border-radius: 6px; }

/* Painel de envio de fotos */
.upload-panel {
  display: grid; gap: 8px; margin-bottom: 16px; padding: 14px;
  border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
}
.upload-head { display: flex; align-items: center; gap: 8px; }
.upload-head .spacer { flex: 1; }
.upload-count { margin: 0; font-weight: 600; font-size: 15px; }
.falhas summary { cursor: pointer; color: var(--danger); font-size: 13px; font-weight: 600; }
.falhas ul { margin: 6px 0 0; padding-left: 18px; color: var(--text-2); font-size: 13px; max-height: 160px; overflow: auto; }

/* ---------- Página do álbum ---------- */

.back-link {
  display: inline-flex; align-items: center; gap: 2px; margin: 4px 0 4px -6px; padding: 6px 8px 6px 2px;
  color: var(--accent); font-weight: 600; font-size: 15px; text-decoration: none; border-radius: 8px;
}
.album-head { display: grid; gap: 12px; margin: 4px 0 16px; }
.album-head h1 { margin: 0; font-size: 24px; line-height: 1.25; letter-spacing: -.02em; word-break: break-word; }
.album-sub { margin: 2px 0 0; color: var(--text-3); font-size: 14px; }
.album-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.album-actions .btn { padding: 0 12px; }
.album-actions .btn.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 3px; margin: 0 -12px; padding: 0; list-style: none; }
.photo {
  position: relative; display: block; width: 100%; aspect-ratio: 1; padding: 0; border: 0; border-radius: 4px;
  overflow: hidden; background: var(--surface-2); cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .15s; }
.photo .check {
  position: absolute; top: 6px; right: 6px; display: none; place-items: center; width: 24px; height: 24px;
  border-radius: 999px; border: 2px solid #fff; background: rgb(0 0 0 / .25); color: #fff; box-shadow: 0 1px 4px rgb(0 0 0 / .3);
}
.photo .check svg { width: 14px; height: 14px; stroke-width: 3; opacity: 0; }
.photo-grid.selecting .photo .check { display: grid; }
.photo.selected img { transform: scale(.88); border-radius: 6px; }
.photo.selected .check { background: var(--accent); border-color: var(--accent); }
.photo.selected .check svg { opacity: 1; }

/* Barra do modo seleção (fixa embaixo) */
.select-bar {
  position: fixed; z-index: 20; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 18px;
  border-radius: 999px; background: var(--surface); box-shadow: var(--shadow-lg); font-weight: 600;
  animation: subir .2s ease-out;
}
.select-bar .spacer { flex: 1; }

/* ---------- Visualizador de foto ---------- */

dialog.viewer {
  width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0; padding: 0;
  border-radius: 0; background: #000; color: #fff; display: none; animation: none;
}
dialog.viewer[open] { display: flex; flex-direction: column; }
dialog.viewer::backdrop { background: #000; }
.viewer-head { display: flex; align-items: center; gap: 4px; padding: 8px; padding-top: max(8px, env(safe-area-inset-top)); font-size: 14px; }
.viewer-head > span:first-child { padding-left: 8px; color: rgb(255 255 255 / .8); }
.viewer-head .spacer { flex: 1; }
.viewer-head .icon-btn { color: #fff; }
.viewer-head .icon-btn:hover { background: rgb(255 255 255 / .12); }
.viewer-stage { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; touch-action: pan-y pinch-zoom; }
.viewer-stage:focus { outline: none; }
.viewer-stage img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.viewer-nav {
  position: absolute; top: 50%; translate: 0 -50%; display: grid; place-items: center; width: 44px; height: 44px;
  border: 0; border-radius: 999px; background: rgb(0 0 0 / .45); color: #fff; cursor: pointer;
}
.viewer-nav.prev { left: 8px; }
.viewer-nav.next { right: 8px; }
.viewer-info { padding: 10px 16px max(12px, env(safe-area-inset-bottom)); color: rgb(255 255 255 / .7); font-size: 13px; text-align: center; }

/* ---------- Desktop ---------- */

@media (min-width: 640px) {
  .topbar { padding-left: 24px; padding-right: 24px; }
  .user-name { display: inline; }
  .container { padding: 16px 24px 64px; }
  .page-head { margin: 16px 0 24px; }
  .page-head h1 { font-size: 32px; }

  .upload-btn { position: static; min-height: 44px; font-size: 15px; box-shadow: none; }

  .card { grid-template-columns: 176px 1fr; gap: 18px; padding: 14px; }
  .title { font-size: 16px; }
  .actions .btn { flex: none; }

  dialog { width: calc(100% - 32px); max-width: 440px; margin: auto; border-radius: 24px; }
  dialog[open] { animation: aparecer .2s ease-out; }
  @keyframes aparecer { from { transform: scale(.96); opacity: 0; } }
  .sheet { padding: 24px; }
  .sheet::before { display: none; }
  .sheet .buttons { flex-direction: row; justify-content: flex-end; }

  .toast { bottom: 24px; }

  .brand-name { display: inline; }
  .tabs { margin-left: 12px; }
  .album-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
  .album-head { grid-template-columns: 1fr auto; align-items: end; }
  .album-head h1 { font-size: 30px; }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; margin: 0; }
  .select-bar { left: 50%; right: auto; translate: -50% 0; min-width: 420px; }
  dialog.viewer { width: 100%; max-width: 100%; border-radius: 0; }
  .viewer-nav { width: 52px; height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
