/* =====================================================================
   Partilha de Fotos — "mesa de luz"
   As fotos são tiras de película 35 mm pousadas numa mesa de luz.
   Seleção = marca a lápis dermatográfico vermelho, como nas folhas de provas.
   ===================================================================== */

@font-face { font-family: "Heros"; src: url("/static/fonts/texgyreheros-regular.otf") format("opentype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Heros"; src: url("/static/fonts/texgyreheros-bold.otf") format("opentype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Heros Cn"; src: url("/static/fonts/texgyreheroscn-bold.otf") format("opentype"); font-weight: 700; font-display: swap; }

:root {
  --light: #e9ecef;        /* mesa de luz */
  --paper: #ffffff;        /* papel fotográfico */
  --film: #000000;         /* película */
  --ink: #23262b;          /* texto */
  --graphite: #686e77;     /* texto secundário */
  --rule: #cfd4da;         /* linhas finas */
  --grease: #d4231b;       /* lápis dermatográfico */
  --edge: #f0a530;         /* inscrições da orla da película */
  --ok: #1f8a52;

  --display: "Heros Cn", "Arial Narrow", "Helvetica Neue", sans-serif;
  --text: "Heros", "Helvetica Neue", Helvetica, Arial, sans-serif;

  --r-frame: 2px;
  --r-ctrl: 8px;
  --r-sheet: 16px;
  --lift: 0 1px 2px rgba(20, 24, 30, .12), 0 12px 28px -14px rgba(20, 24, 30, .35);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--light);
  /* luz da mesa: mais intensa ao centro */
  background-image: radial-gradient(120% 70% at 50% 0%, #f7f8f9 0%, var(--light) 60%);
  background-attachment: fixed;
  color: var(--ink);
  font: 400 16px/1.5 var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: inherit; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--film); outline-offset: 2px; }
.hidden { display: none !important; }
.muted { color: var(--graphite); }
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 18px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- controlos ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 9px 16px; border-radius: var(--r-ctrl);
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink);
  font: 700 15px/1.2 var(--text); text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { border-color: #aeb4bc; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--film); border-color: var(--film); color: #fff; }
.btn.primary:hover { background: #2a2a2a; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--grease); border-color: #efb3ae; background: var(--paper); }
.btn.small { min-height: 36px; padding: 7px 12px; font-size: 14px; }
.btn svg { width: 18px; height: 18px; flex: none; }
.icon-btn { background: transparent; border: 0; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; color: inherit; flex: none; }
.icon-btn:hover { background: rgba(0, 0, 0, .06); }
.icon-btn svg { width: 22px; height: 22px; }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > label { font-size: 14px; font-weight: 700; color: var(--ink); }
.input { width: 100%; padding: 12px 14px; border-radius: var(--r-ctrl); border: 1px solid var(--rule); background: var(--paper); outline: none; }
.input:focus { border-color: var(--film); box-shadow: 0 0 0 3px rgba(0, 0, 0, .08); }
.card { background: var(--paper); border-radius: var(--r-sheet); padding: 24px; box-shadow: var(--lift); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; font-weight: 700; padding: 6px 4px; }
.switch input { width: 40px; height: 24px; appearance: none; -webkit-appearance: none; background: var(--rule); border-radius: 999px; position: relative; cursor: pointer; transition: background .15s; margin: 0; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: left .15s; }
.switch input:checked { background: var(--film); }
.switch input:checked::after { left: 19px; }

.progress { height: 4px; background: #dde1e6; border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--film); transition: width .2s; }

/* ---------- película (usada na galeria e nos desenhos) ---------- */
.film, .tile {
  background-color: var(--film);
  background-image:
    repeating-linear-gradient(90deg, transparent 0 5px, var(--light) 5px 11px, transparent 11px 16px),
    repeating-linear-gradient(90deg, transparent 0 5px, var(--light) 5px 11px, transparent 11px 16px);
  background-size: 100% 6px, 100% 6px;
  background-position: 0 4px, 0 calc(100% - 4px);
  background-repeat: no-repeat;
}

/* ---------- barra de topo ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(233, 236, 239, .86); backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2); border-bottom: 1px solid var(--rule); }
.topbar .wrap { display: flex; align-items: center; gap: 12px; padding-top: 12px; padding-bottom: 12px; }
.ev-title { flex: 1; min-width: 0; }
.ev-title h1 { font: 700 clamp(26px, 5.4vw, 40px)/1 var(--display); letter-spacing: -.01em; margin: 0 0 5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ev-title .stats { display: flex; flex-wrap: wrap; gap: 2px 14px; font-size: 13px; color: var(--graphite); }
.top-actions { display: flex; gap: 8px; }
@media (max-width: 640px) { .top-actions .label { display: none; } .top-actions .btn { padding: 0; width: 42px; } }

.adminbar { background: var(--paper); border-bottom: 1px solid var(--rule); }
.adminbar .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding-top: 10px; padding-bottom: 10px; }
.adminbar .tag { font: 700 16px/1 var(--display); margin-right: 6px; }
.pinbox { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; flex-wrap: wrap; }
.pinbox code { font: 700 20px/1 var(--display); letter-spacing: .18em; padding: 7px 10px 6px; border-radius: 6px; background: var(--film); color: var(--edge); }

.installbar { background: var(--film); color: #fff; }
.installbar .wrap { display: flex; align-items: center; gap: 12px; padding-top: 10px; padding-bottom: 10px; font-size: 14px; }
.installbar img { width: 36px; height: 36px; border-radius: 9px; }
.installbar span { flex: 1; }
.installbar .btn.primary { background: #fff; color: var(--film); border-color: #fff; }
.installbar .icon-btn:hover { background: rgba(255, 255, 255, .12); }

.banner { margin: 16px 0 0; padding: 12px 14px; border-radius: var(--r-ctrl); background: var(--paper); border: 1px solid var(--rule); color: var(--graphite); font-size: 14px; }

/* ---------- filtros ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; padding: 18px 0 14px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: 1; padding: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--rule); background: var(--paper); border-radius: 999px; padding: 6px 13px; font-size: 14px; cursor: pointer; color: var(--ink); }
.chip b { font-weight: 700; color: var(--graphite); margin-left: 2px; }
.chip.on { background: var(--film); color: #fff; border-color: var(--film); }
.chip.on b { color: var(--edge); }

/* ---------- folha de provas ---------- */
/* As colunas encostam-se (gap 0) e cada linha fica uma tira contínua de película */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); column-gap: 0; row-gap: 14px; padding-bottom: 150px; }
@media (max-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); row-gap: 10px; } .grid-wrap { padding: 0 8px; } }
.tile { position: relative; padding: 16px 3px 24px; cursor: pointer; }
.tile img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--r-frame); background: #1b1b1b; }
.tile .edge { position: absolute; left: 7px; bottom: 11px; font: 700 10px/1 var(--display); letter-spacing: .06em; color: var(--edge); pointer-events: none; }
.tile .badge { position: absolute; right: 7px; bottom: 11px; font: 700 10px/1 var(--display); letter-spacing: .06em; color: var(--edge); }
.tile .check { display: none; }
.tile::after { content: ""; position: absolute; inset: 6px -3px 12px; pointer-events: none; opacity: 0; transform: scale(.94) rotate(-2deg); transition: opacity .12s, transform .12s; }
.tile.sel::after {
  opacity: 1; transform: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cpath d='M8 14C30 4 74 3 92 12c6 22 5 54-1 76C68 97 28 97 9 89 3 66 2 36 9 12' fill='none' stroke='%23d4231b' stroke-width='3.4' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
}
.selecting .tile img { filter: saturate(.85); }
.tile.sel img { filter: none; }
@media (hover: hover) { .tile:hover img { outline: 2px solid rgba(255, 255, 255, .9); outline-offset: -2px; } }

.empty { text-align: center; padding: 70px 20px 40px; color: var(--graphite); max-width: 460px; margin: 0 auto; }
.empty .film { display: grid; grid-template-columns: repeat(4, 1fr); padding: 16px 3px 24px; margin: 0 auto 26px; max-width: 360px; }
.empty .film i { aspect-ratio: 1; margin: 0 3px; background: #1d1d1d; border-radius: var(--r-frame); }
.empty h2 { font: 700 28px/1.1 var(--display); color: var(--ink); margin: 0 0 8px; }

/* ---------- acções em baixo ---------- */
.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); display: flex; justify-content: center; pointer-events: none; }
.dock > * { pointer-events: auto; }
.fab { min-height: 56px; padding: 0 26px 0 18px; font-size: 17px; border-radius: 999px; box-shadow: 0 10px 30px -8px rgba(0, 0, 0, .55); }
.fab .shutter { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; display: grid; place-items: center; }
.fab .shutter::after { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--grease); }
.selbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; background: var(--paper); border-radius: var(--r-sheet); padding: 10px 12px; box-shadow: var(--lift); max-width: 100%; }
.selbar .count { font: 700 17px/1 var(--display); padding: 0 6px; color: var(--grease); }

/* ---------- envios ---------- */
.uploads { position: fixed; z-index: 40; right: 16px; bottom: calc(92px + env(safe-area-inset-bottom)); width: min(380px, calc(100vw - 32px)); background: var(--paper); border-radius: var(--r-sheet); box-shadow: var(--lift); overflow: hidden; }
.uploads header { display: flex; align-items: center; gap: 10px; padding: 12px 10px 10px 16px; }
.uploads header strong { flex: 1; font: 700 18px/1.1 var(--display); }
.uploads .total { padding: 0 16px 12px; border-bottom: 1px solid var(--rule); }
.uploads ul { list-style: none; margin: 0; padding: 6px 0; max-height: 250px; overflow: auto; }
.uploads li { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 7px 16px; font-size: 13px; }
.uploads li .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads li .st { color: var(--graphite); }
.uploads li .st.ok { color: var(--ok); }
.uploads li .st.err { color: var(--grease); }
.uploads li .progress { grid-column: 1 / -1; height: 3px; }

/* ---------- folhas (janelas) ---------- */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(20, 22, 26, .45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); display: grid; place-items: center; padding: 16px; }
.modal .card { width: min(440px, 100%); }
.modal h2 { font: 700 28px/1.05 var(--display); margin: 0 0 8px; }
.modal p { margin: 0 0 18px; color: var(--graphite); }
.modal .qr-big { width: 100%; max-width: 300px; display: block; margin: 0 auto 14px; }
.install-steps { text-align: left; padding-left: 22px; margin: 0 0 22px; display: grid; gap: 10px; }
.install-steps li::marker { font-family: var(--display); font-weight: 700; color: var(--grease); }

/* ---------- visualizador (projeção) ---------- */
.lightbox { position: fixed; inset: 0; z-index: 50; background: #000; color: #fff; display: flex; flex-direction: column; }
.lb-top, .lb-bottom { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.lb-top { padding-top: calc(10px + env(safe-area-inset-top)); }
.lb-bottom { padding-bottom: calc(14px + env(safe-area-inset-bottom)); flex-wrap: wrap; justify-content: center; }
.lb-info { flex: 1; min-width: 0; padding-left: 6px; }
.lb-info strong { display: block; font: 700 20px/1.1 var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-info span { color: var(--edge); font: 700 13px/1.45 var(--display); letter-spacing: .04em; white-space: pre-line; }
.lb-stage { flex: 1; position: relative; display: grid; place-items: center; overflow: hidden; touch-action: pan-y; }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255, 255, 255, .1); color: #fff; border: 0; width: 46px; height: 46px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; }
.lb-nav svg { width: 22px; height: 22px; }
.lb-prev { left: 12px; } .lb-next { right: 12px; }
@media (hover: none) { .lb-nav { display: none; } }
.lightbox .icon-btn:hover { background: rgba(255, 255, 255, .1); }
.lightbox .btn { background: #1b1b1b; border-color: #333; color: #fff; }
.lightbox .btn.primary { background: #fff; color: #000; border-color: #fff; }
.lightbox .btn.danger { color: #ff7a72; border-color: #5a2421; }

.toast { position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 70; background: var(--film); color: #fff; padding: 11px 16px; border-radius: var(--r-ctrl); font-weight: 700; font-size: 14px; box-shadow: var(--lift); max-width: calc(100vw - 32px); }

/* ---------- PIN ---------- */
.lock { min-height: calc(100vh - 80px); display: grid; place-items: center; padding: 24px 16px 80px; }
.lock-card { width: min(400px, 100%); text-align: center; background: var(--paper); border-radius: var(--r-sheet); box-shadow: var(--lift); overflow: hidden; }
.lock-card .film { height: 64px; display: grid; place-items: center; color: var(--edge); font: 700 12px/1 var(--display); letter-spacing: .3em; }
.lock-inner { padding: 26px 24px 24px; }
.lock h1 { font: 700 34px/1.02 var(--display); margin: 0 0 6px; }
.lock p { margin: 0 0 18px; }
.pin-input { text-align: center; font: 700 34px/1 var(--display); letter-spacing: .45em; padding: 14px 14px 12px calc(14px + .45em); margin-bottom: 12px; }
.lock-err { color: var(--grease); font-weight: 700; margin: 12px 0 0 !important; }
.qr-pin { color: var(--ink) !important; }
.qr-pin b { font: 700 26px/1 var(--display); letter-spacing: .2em; margin-left: 6px; }

/* ---------- página inicial (criar evento) ---------- */
.home { max-width: 600px; margin: 0 auto; padding: 28px 18px 80px; }
.brand { display: flex; align-items: center; gap: 10px; font: 700 20px/1 var(--display); margin-bottom: 34px; }
.brand img { width: 32px; height: 32px; border-radius: 8px; }
.hero-strip { display: grid; grid-template-columns: repeat(5, 1fr); padding: 16px 3px 24px; margin: 0 -18px 26px; position: relative; }
.hero-strip i { position: relative; aspect-ratio: 1; margin: 0 3px; border-radius: var(--r-frame); background: #1d1d1d; }
.hero-strip i::after { content: attr(data-n); position: absolute; left: 4px; bottom: -13px; font: 700 10px/1 var(--display); color: var(--edge); letter-spacing: .06em; }
.hero-strip i.lit { background: radial-gradient(circle at 50% 40%, #fff 0 10%, #f5d9a8 30%, #e59a4a 60%, #5c2d1a 100%); }
.home h1 { font: 700 clamp(40px, 9vw, 64px)/.95 var(--display); letter-spacing: -.015em; margin: 0 0 16px; }
.home .lead { color: var(--graphite); font-size: 18px; line-height: 1.55; margin: 0 0 18px; max-width: 34em; }
.points { list-style: none; padding: 0; margin: 0 0 30px; display: grid; gap: 8px; }
.points li { padding-left: 26px; position: relative; }
.points li::before { content: ""; position: absolute; left: 0; top: 6px; width: 14px; height: 10px; background: var(--grease); border-radius: 2px; transform: rotate(-4deg); }
.result h1 { font: 700 44px/1 var(--display); margin: 0 0 6px; }
.result h2 { font: 700 22px/1.1 var(--display); margin: 0 0 8px; }
.linkbox { display: flex; gap: 8px; align-items: center; border: 1px solid var(--rule); border-radius: var(--r-ctrl); padding: 5px 5px 5px 12px; margin: 6px 0 16px; background: var(--light); }
.linkbox code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.warn { border-left: 3px solid var(--grease); background: #fbeceb; color: #7c1712; border-radius: 4px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }
.qr-mini { width: 170px; display: block; margin: 6px 0 16px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; }
.bigpin { font: 700 52px/1 var(--display); letter-spacing: .2em; color: var(--film); }
.my-events { margin-top: 40px; }
.my-events h3 { font: 700 20px/1 var(--display); margin: 0 0 12px; }
.my-events a { display: flex; justify-content: space-between; padding: 13px 14px; border-radius: var(--r-ctrl); margin-bottom: 8px; text-decoration: none; background: var(--paper); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

/* ---------- app: os meus eventos (provas pousadas na mesa) ---------- */
.apphome { max-width: 760px; padding-top: 22px; padding-bottom: 70px; }
.apphome-title { font: 700 clamp(36px, 8vw, 52px)/.95 var(--display); margin: 4px 0 20px; letter-spacing: -.015em; }
.installcard { display: flex; align-items: center; gap: 12px; background: var(--film); color: #fff; border-radius: var(--r-sheet); padding: 12px 14px; margin-bottom: 22px; font-size: 14px; }
.installcard img { width: 44px; height: 44px; border-radius: 11px; }
.installcard > div { flex: 1; }
.installcard .muted { color: #b9bec5; }
.installcard .btn.primary { background: #fff; color: #000; border-color: #fff; }
.evlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 22px 18px; margin-bottom: 30px; }
@media (max-width: 480px) { .evlist { grid-template-columns: 1fr 1fr; gap: 16px 12px; } }
.evcard { display: block; position: relative; text-decoration: none; background: var(--paper); padding: 8px 8px 12px; border-radius: 3px; box-shadow: var(--lift); }
.evcover { aspect-ratio: 4 / 3; background: #1d1d1d; display: grid; place-items: center; color: #8d939b; overflow: hidden; }
.evcover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.evcover svg { width: 30px; height: 30px; }
.evbody { display: grid; gap: 3px; padding: 10px 2px 0; }
.evbody strong { font: 700 20px/1.05 var(--display); }
.evbody .muted { font-size: 13px; line-height: 1.35; }
.evtag { justify-self: start; font-size: 12px; font-weight: 700; color: var(--grease); }
.evrm { position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; background: rgba(0, 0, 0, .55); color: #fff; }
.evrm svg { width: 16px; height: 16px; }
.evrm:hover { background: rgba(0, 0, 0, .75); }
.joincard h3 { font: 700 22px/1 var(--display); margin: 0 0 14px; }
.joinrow { display: flex; gap: 8px; }
.joinrow .input { flex: 1; min-width: 0; }
.scanvideo { width: 100%; border-radius: 12px; background: #000; aspect-ratio: 1; object-fit: cover; }
#deleteEventBtn { margin-left: auto; }

/* lista de eventos do administrador */
.adm-ev { align-items: center; gap: 12px; }
.adm-ev > span { display: grid; gap: 2px; min-width: 0; }
.adm-ev strong { font: 700 19px/1.1 var(--display); }
.adm-ev .muted { font-size: 13px; }
.adm-ev code { flex: none; font: 700 13px/1 var(--display); letter-spacing: .08em; background: var(--film); color: var(--edge); padding: 6px 8px; border-radius: 5px; }

/* espaço do servidor (administrador) */
.storage { margin-bottom: 30px; padding: 20px 22px; }
.st-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.st-head h2 { font: 700 22px/1 var(--display); margin: 0; }
.st-pct { font: 700 22px/1 var(--display); }
.st-warn .st-pct { color: var(--grease); }
.st-bar { display: flex; height: 14px; border-radius: 3px; overflow: hidden; background: var(--light); box-shadow: inset 0 0 0 1px var(--rule); }
.st-bar i { display: block; height: 100%; }
i.st-photos { background: var(--film); }
i.st-other { background: #9aa1aa; }
i.st-free { background: var(--light); box-shadow: inset 0 0 0 1px var(--rule); }
.st-warn .st-bar i.st-photos { background: var(--grease); }
.st-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 0; margin: 12px 0 10px; font-size: 14px; }
.st-legend li { display: inline-flex; align-items: center; gap: 7px; }
.st-legend i { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.st-note { margin: 0 0 4px; font-size: 14px; }
.st-warn .st-note { color: var(--grease); font-weight: 700; }
.st-sys { margin: 0; font-size: 13px; }
