/* ==========================================================================
   App (PWA) — ecrãs leves no "chão" claro, registo ao vivo em modo marcador.
   ========================================================================== */
html, body { height: 100%; }
body.app { background: var(--floor); overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; padding-bottom: env(safe-area-inset-bottom); }
button { touch-action: manipulation; }

/* Barra superior e navegação */
.app-top { position: sticky; top: 0; z-index: 30; background: var(--navy); color: #fff; padding: calc(.55rem + env(safe-area-inset-top)) 1rem .55rem; display: flex; align-items: center; gap: .75rem; min-height: 56px; }
.app-top h1 { font-size: 1.45rem; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-top .icon-btn { color: #fff; }
.icon-btn { background: none; border: 0; width: 42px; height: 42px; border-radius: 8px; display: inline-grid; place-items: center; font-size: 1.3rem; color: var(--navy); flex-shrink: 0; }
.icon-btn:hover { background: rgba(127,127,127,.15); }
.sync-pill { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; color: #c7d0e0; background: rgba(255,255,255,.08); border: 0; border-radius: 99px; padding: .3rem .65rem; white-space: nowrap; }
.sync-pill .dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--made); }
.sync-pill.pending .dot { background: var(--amber); }
.sync-pill.offline .dot, .sync-pill.error .dot { background: var(--miss); }
.sync-pill.syncing .dot { animation: pulse 1s infinite; }

.app-main { padding: 1rem 1rem 6rem; max-width: 980px; margin: 0 auto; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(4, 1fr); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: .1rem; padding: .5rem 0 .45rem; color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 600; }
.tabbar a i { font-size: 1.35rem; }
.tabbar a.active { color: var(--paint); }
@media (min-width: 900px) {
  .tabbar { top: 56px; bottom: auto; right: auto; width: 96px; height: calc(100vh - 56px); grid-template-columns: 1fr; grid-auto-rows: 76px; border-top: 0; border-right: 1px solid var(--line); }
  .with-tabbar .app-main { padding-left: calc(96px + 1.5rem); max-width: calc(980px + 96px); padding-bottom: 2rem; }
}

/* Listas */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.list-row { display: flex; align-items: center; gap: .85rem; padding: .8rem 1rem; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: #f8fafc; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .sub { color: var(--muted); font-size: .85rem; }
.list-row .num-badge { font-family: var(--font-score); font-weight: 700; font-size: 1.35rem; width: 2.4rem; text-align: center; color: var(--paint); }
.section-title { display: flex; justify-content: space-between; align-items: end; margin: 1.5rem 0 .6rem; }
.section-title h2 { font-size: 1.35rem; margin: 0; }
.game-score { font-family: var(--font-score); font-weight: 700; font-size: 1.5rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

.fab { position: fixed; right: 1rem; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 31; border-radius: 99px; padding: .8rem 1.2rem; box-shadow: 0 6px 18px rgba(20,33,61,.3); }
@media (min-width: 900px) { .fab { bottom: 1.5rem; } }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty-state i { font-size: 2.4rem; color: var(--line); display: block; margin-bottom: .5rem; }

/* Bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: 1000; background: rgba(10, 18, 36, .5); display: flex; align-items: flex-end; justify-content: center; opacity: 0; transition: opacity .16s; }
.sheet-backdrop.in { opacity: 1; }
.sheet-backdrop.out { opacity: 0; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; border-radius: 14px 14px 0 0; display: flex; flex-direction: column; transform: translateY(30px); transition: transform .18s; padding-bottom: env(safe-area-inset-bottom); }
.sheet.wide { max-width: 760px; }
.sheet-backdrop.in .sheet { transform: none; }
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 12px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: .9rem 1rem .5rem; }
.sheet-head strong { font-family: var(--font-score); font-size: 1.35rem; }
.sheet-close { background: none; border: 0; font-size: 1.1rem; width: 40px; height: 40px; color: var(--muted); }
.sheet-body { padding: .25rem 1rem 1rem; overflow-y: auto; }
@media (prefers-reduced-motion: reduce) { .sheet-backdrop, .sheet { transition: none; } }

/* Toasts */
#toasts { position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 2000; display: grid; gap: .4rem; width: min(92vw, 420px); pointer-events: none; }
.toast-msg { background: var(--navy); color: #fff; padding: .6rem .9rem; border-radius: 8px; font-weight: 500; box-shadow: 0 6px 18px rgba(0,0,0,.2); transition: opacity .25s; }
.toast-msg.success { border-left: 4px solid var(--made); }
.toast-msg.error { border-left: 4px solid var(--miss); }
.toast-msg.out { opacity: 0; }

/* Login */
.login-screen { min-height: 100vh; background: var(--navy); color: #c7d0e0; display: flex; flex-direction: column; justify-content: center; padding: calc(2rem + env(safe-area-inset-top)) 1.25rem 2rem; }
.login-screen .card-in { background: var(--surface); color: var(--navy); border-radius: 12px; padding: 1.5rem; max-width: 420px; width: 100%; margin: 0 auto; }
.login-brand { display: flex; align-items: center; gap: .7rem; justify-content: center; margin-bottom: 1.5rem; }
.login-brand strong { font-family: var(--font-score); font-size: 2.4rem; color: #fff; }

/* Seleção de jogadores (convocatória / quinteto) */
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; }
.pick { border: 2px solid var(--line); background: var(--surface); border-radius: 8px; padding: .55rem .65rem; text-align: left; display: flex; gap: .55rem; align-items: center; color: var(--navy); }
.pick .n { font-family: var(--font-score); font-weight: 700; font-size: 1.5rem; width: 2rem; text-align: center; color: var(--paint); }
.pick .nm { font-weight: 600; font-size: .92rem; line-height: 1.15; }
.pick.on { border-color: var(--paint); background: #eaf1fb; }
.pick.on .n { color: var(--navy); }
.pick:disabled { opacity: .4; }

/* ==========================================================================
   Registo ao vivo
   ========================================================================== */
body.tracking { background: #0e1830; color: #e6ebf3; }
.trk { display: grid; grid-template-rows: auto 1fr; height: 100dvh; padding-top: env(safe-area-inset-top); }
.trk-bar { background: var(--navy); display: grid; grid-template-columns: auto 1fr auto 1fr auto; align-items: center; gap: .4rem; padding: .35rem .5rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.trk-bar .icon-btn { color: #c7d0e0; }
.trk-team { min-width: 0; display: flex; align-items: center; gap: .5rem; }
.trk-team.opp { justify-content: flex-end; text-align: right; }
.trk-team .nm { font-family: var(--font-score); font-weight: 600; font-size: 1rem; color: #c7d0e0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trk-team .fouls { font-size: .72rem; color: #93a0b8; }
.trk-team .fouls.bonus { color: var(--amber); font-weight: 700; }
.trk-score { font-family: var(--font-score); font-weight: 700; font-size: 2.6rem; line-height: 1; color: var(--amber); font-variant-numeric: tabular-nums; }
.trk-clock { display: flex; flex-direction: column; align-items: center; gap: .1rem; }
.clock-btn { background: #0a1226; border: 1px solid rgba(255,255,255,.12); color: #fff; border-radius: 8px; padding: .15rem .65rem; font-family: var(--font-score); font-weight: 700; font-size: 1.5rem; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: .4rem; }
.clock-btn.running { border-color: var(--made); }
.clock-btn i { font-size: 1rem; color: var(--amber); }
.trk-period { font-family: var(--font-score); font-size: .9rem; color: #93a0b8; background: none; border: 0; padding: 0; }

.trk-body { display: grid; gap: .5rem; padding: .5rem; overflow: hidden; min-height: 0;
  grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr) auto; }
@media (min-aspect-ratio: 1/1) and (min-width: 700px) {
  .trk-body { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .trk-court-wrap { grid-row: 1 / span 2; }
}
.trk-court-wrap { position: relative; min-height: 0; display: flex; align-items: center; justify-content: center; }
.trk-court { width: 100%; height: 100%; max-height: 100%; touch-action: manipulation; cursor: crosshair; display: block; }
@media (max-aspect-ratio: 999/1000) { .trk-court-wrap { order: 2; } .trk-court { max-height: 34dvh; } }
.court-hint { position: absolute; bottom: .3rem; left: 50%; transform: translateX(-50%); font-size: .75rem; color: #93a0b8; pointer-events: none; white-space: nowrap; }

.trk-side { display: flex; flex-direction: column; gap: .5rem; min-height: 0; overflow-y: auto; }
@media (max-aspect-ratio: 999/1000) { .trk-side { order: 1; } .trk-actions { order: 3; } }

/* Jogadores em campo */
.oncourt { display: grid; grid-template-columns: repeat(5, 1fr); gap: .35rem; }
.oncourt.f3 { grid-template-columns: repeat(3, 1fr); }
.ptile { background: #18264a; border: 2px solid transparent; border-radius: 10px; padding: .4rem .3rem .35rem; color: #fff; text-align: center; position: relative; min-height: 78px; user-select: none; -webkit-user-select: none; }
.ptile .n { font-family: var(--font-score); font-weight: 700; font-size: 1.9rem; line-height: 1; }
.ptile .nm { font-size: .72rem; color: #c7d0e0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ptile .ln { font-size: .72rem; color: #93a0b8; font-variant-numeric: tabular-nums; }
.ptile .pf { position: absolute; top: .2rem; right: .3rem; font-size: .68rem; font-weight: 700; color: #93a0b8; }
.ptile .pf.warn { color: var(--amber); }
.ptile .pf.out { color: var(--miss); }
.ptile.sel { border-color: var(--amber); background: #22345c; }
.ptile.drop { border-color: var(--made); background: #1c3d40; transform: scale(1.04); }
.ptile.armed-target { outline: 2px dashed rgba(242,169,0,.6); outline-offset: 1px; }
.bench { display: flex; gap: .3rem; overflow-x: auto; padding-bottom: .1rem; scrollbar-width: thin; }
.btile { flex-shrink: 0; background: transparent; border: 1px solid rgba(255,255,255,.14); color: #c7d0e0; border-radius: 8px; padding: .25rem .5rem; font-size: .8rem; display: flex; gap: .35rem; align-items: center; }
.btile b { font-family: var(--font-score); font-size: 1.1rem; color: #fff; }
.btile.sel { border-color: var(--amber); color: #fff; background: #22345c; }
.bench-label { font-size: .75rem; color: #93a0b8; display: flex; justify-content: space-between; align-items: center; }
.bench-label button { background: none; border: 0; color: var(--amber); font-size: .8rem; font-weight: 600; padding: 0; }

/* Paleta de ações (arrastar ou tocar) */
.trk-actions { display: grid; gap: .35rem; }
.act-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: .3rem; }
.act { background: #1d2c50; border: 1px solid rgba(255,255,255,.1); color: #fff; border-radius: 8px; padding: .5rem .2rem; font-weight: 700; font-size: .92rem; line-height: 1.1; touch-action: none; user-select: none; -webkit-user-select: none; min-height: 46px; }
.act small { display: block; font-weight: 500; font-size: .66rem; color: #93a0b8; }
.act.made { background: #17402f; border-color: #1e8e5a; }
.act.miss { background: #4a1c22; border-color: #8f2f35; }
.act.armed { background: var(--amber); color: var(--navy); border-color: var(--amber); }
.act.armed small { color: var(--navy); }
.act:active { transform: scale(.97); }
.opp-row { display: grid; grid-template-columns: auto repeat(7, 1fr); gap: .3rem; align-items: stretch; }
.opp-row .lbl { font-family: var(--font-score); font-weight: 600; color: #b9a6dd; display: flex; align-items: center; font-size: .9rem; padding-right: .2rem; max-width: 5.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.act.opp { background: #2b2347; border-color: #4b3b7a; }
.act.opp.made { background: #3a2b62; border-color: #8a6fd0; }
.trk-tools { display: flex; gap: .3rem; }
.trk-tools .tool { flex: 1; background: transparent; border: 1px solid rgba(255,255,255,.14); color: #c7d0e0; border-radius: 8px; padding: .45rem .3rem; font-size: .82rem; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: .3rem; }
.trk-tools .tool.live { border-color: var(--miss); color: #fff; }
.drag-ghost { position: fixed; z-index: 3000; pointer-events: none; background: var(--amber); color: var(--navy); font-weight: 700; border-radius: 8px; padding: .4rem .7rem; transform: translate(-50%, -120%); box-shadow: 0 8px 20px rgba(0,0,0,.35); }
.last-ev { font-size: .78rem; color: #93a0b8; min-height: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.last-ev b { color: #fff; font-weight: 600; }

/* Folha de lançamento */
.shot-result { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-top: .75rem; }
.shot-result button { padding: 1rem .5rem; font-size: 1.15rem; font-weight: 700; border-radius: 10px; border: 0; }
.shot-result .ok { background: var(--made); color: #fff; }
.shot-result .ko { background: var(--miss); color: #fff; }
.value-toggle { display: flex; gap: .35rem; }
.value-toggle button { flex: 1; border: 2px solid var(--line); background: var(--surface); border-radius: 8px; padding: .4rem; font-weight: 700; }
.value-toggle button.on { border-color: var(--paint); background: #eaf1fb; }
.who-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: .4rem; }
.who { border: 2px solid var(--line); background: var(--surface); border-radius: 8px; padding: .45rem .3rem; text-align: center; color: var(--navy); }
.who .n { font-family: var(--font-score); font-weight: 700; font-size: 1.5rem; line-height: 1; color: var(--paint); }
.who .nm { font-size: .75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who.on { border-color: var(--paint); background: #eaf1fb; }
.who.opp { border-color: #d9cdf0; }
.who.opp .n { color: var(--opp); font-size: 1rem; padding: .35rem 0; }
.who.none .n { color: var(--muted); font-size: 1rem; padding: .35rem 0; }

.ev-list { max-height: 60vh; overflow-y: auto; }
.ev-item { display: flex; align-items: center; gap: .6rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.ev-item .t { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .8rem; width: 4.6rem; flex-shrink: 0; }
.ev-item .d { flex: 1; min-width: 0; font-size: .92rem; }
.ev-item.opp .d { color: var(--opp); }

.install-banner { background: var(--navy); color: #fff; border-radius: 8px; padding: .8rem 1rem; display: flex; gap: .75rem; align-items: center; margin-bottom: 1rem; }
.install-banner p { margin: 0; flex: 1; font-size: .92rem; color: #c7d0e0; }
.install-banner strong { color: #fff; }
.offline-note { background: #fff6dd; border: 1px solid #f5d27a; border-radius: 8px; padding: .55rem .8rem; font-size: .88rem; margin-bottom: 1rem; }

/* Toasts durante o registo: sobre o campo, sem tapar jogadores nem ações */
body.tracking #toasts { top: 42%; }
@media (min-aspect-ratio: 1/1) and (min-width: 700px) { body.tracking #toasts { left: 26%; width: min(46vw, 420px); } }

/* Em ecrãs largos e altos (tablets/portáteis) os alvos crescem para ocupar o espaço */
@media (min-aspect-ratio: 1/1) and (min-width: 700px) and (min-height: 600px) {
  .trk-side { justify-content: flex-start; }
  .ptile { min-height: 132px; padding-top: .9rem; }
  .ptile .n { font-size: 2.8rem; }
  .ptile .nm { font-size: .9rem; }
  .ptile .ln { font-size: .82rem; }
  .btile { padding: .45rem .7rem; font-size: .9rem; }
  .act { min-height: 58px; font-size: 1.02rem; }
  .last-ev { font-size: .9rem; margin-top: .25rem; }
}

/* Telemóvel deitado: alvos mais compactos para caber o banco */
@media (min-aspect-ratio: 1/1) and (max-height: 500px) {
  .ptile { min-height: 62px; padding: .25rem .2rem; }
  .ptile .n { font-size: 1.5rem; }
  .act { min-height: 40px; padding: .3rem .15rem; font-size: .85rem; }
  .act small { display: none; }
  .trk-tools .tool { padding: .3rem; }
  .court-hint { display: none; }
}
