:root {
  --fundo: #f6f1ea;
  --texto: #2d2620;
  --apagado: #8a7f74;
  --acento: #c8643b;
  --acento-escuro: #a24c27;
  --cartao: #ffffff;
  --linha: #e6ddd2;
  --barra: #fffaf4;
  --erro: #b3261e;
  --raio: 18px;
  --seguro-baixo: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--fundo);
  color: var(--texto);
  font-family: Nunito, system-ui, sans-serif;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

.tela { min-height: 100%; display: flex; flex-direction: column; }

/* ---------- login ---------- */
#tela-login { justify-content: flex-end; }
/* as fotos da família só aparecem depois do login */
.login-foto {
  position: fixed; inset: 0; background: var(--fundo);
  display: flex; justify-content: center; padding-top: 18vh;
}
.login-foto img {
  width: 46vmin; height: 46vmin; max-width: 240px; max-height: 240px;
  border-radius: 24%; box-shadow: 0 10px 30px rgba(13, 24, 40, .35);
}
.login-caixa {
  position: relative; padding: 24px 24px calc(40px + var(--seguro-baixo));
  display: flex; flex-direction: column; gap: 12px; max-width: 460px; width: 100%; margin: 0 auto;
}
.login-caixa h1 { margin: 0; font-size: 30px; font-weight: 800; }
.login-caixa p { margin: 0; color: var(--apagado); }
input {
  font: inherit; font-size: 17px; color: var(--texto);
  background: var(--cartao); border: 1.5px solid var(--linha); border-radius: 14px;
  padding: 13px 16px; outline: none; width: 100%;
}
input:focus { border-color: var(--acento); }
.botao-principal {
  background: var(--acento); color: #fff; font-weight: 700; font-size: 16px;
  border-radius: 14px; padding: 13px 18px;
}
.botao-principal:active { background: var(--acento-escuro); }
.erro { color: var(--erro) !important; font-size: 14px; }

/* ---------- topo ---------- */
.topo {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 18px 12px;
}
.saudacao { font-size: 13px; color: var(--apagado); }
.titulo { font-size: 22px; font-weight: 800; line-height: 1.1; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  border: 2.5px solid var(--acento); background: center / cover no-repeat;
}

.aba { flex: 1; padding-bottom: calc(86px + var(--seguro-baixo)); }

/* ---------- vídeo ---------- */
.video-caixa {
  position: relative; margin: 0 14px; border-radius: 22px; overflow: hidden;
  background: #1e1a17; aspect-ratio: 16 / 9;
}
.video-fundo {
  position: absolute; inset: 0; background: center / cover no-repeat;
  filter: blur(2px) brightness(.7); transform: scale(1.05);
}
.video-lugar, .video-lugar cam-video { position: absolute; inset: 0; display: block; }
.video-lugar video { width: 100%; height: 100%; object-fit: contain; background: transparent; }
.video-aviso {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px;
  color: #fff; font-weight: 700; font-size: 15px; text-shadow: 0 1px 4px rgba(0,0,0,.6);
}
.girando {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: gira .8s linear infinite;
}
.video-aviso.sem-sinal .girando { display: none; }
@keyframes gira { to { transform: rotate(360deg); } }
.ao-vivo {
  position: absolute; top: 10px; left: 10px; background: #e5484d; color: #fff;
  font-size: 11px; font-weight: 800; letter-spacing: .4px; padding: 3px 8px; border-radius: 6px;
}
.nome-camera {
  position: absolute; left: 12px; bottom: 10px; color: #fff; font-weight: 800; font-size: 15px;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
}
.icone-video {
  position: absolute; width: 36px; height: 36px; border-radius: 50%;
  background: rgba(0,0,0,.42); color: #fff; display: grid; place-items: center;
}
.icone-video.som { top: 8px; right: 8px; }
.icone-video.cheia { top: 8px; right: 50px; }
.ptz {
  position: absolute; right: 10px; bottom: 10px; width: 108px; height: 108px; border-radius: 50%;
  background: rgba(0,0,0,.38); color: #fff;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.ptz button { display: grid; place-items: center; touch-action: none; }
.ptz button svg { width: 22px; height: 22px; stroke-width: 2.4; pointer-events: none; }
.ptz button.pressionado { color: #ffcfb8; }
.ptz [data-dir="up"] { grid-column: 2; grid-row: 1; }
.ptz [data-dir="left"] { grid-column: 1; grid-row: 2; }
.ptz-meio { grid-column: 2; grid-row: 2; place-self: center; width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,.7); }
.ptz [data-dir="right"] { grid-column: 3; grid-row: 2; }
.ptz [data-dir="down"] { grid-column: 2; grid-row: 3; }

/* tela cheia */
.video-caixa.cheia, .video-caixa:fullscreen {
  margin: 0; border-radius: 0; aspect-ratio: auto; width: 100vw; height: 100vh; background: #000;
}
.video-caixa.cheia { position: fixed; inset: 0; z-index: 50; }

.volume {
  display: flex; align-items: center; gap: 10px; margin: 10px 18px 0; color: var(--apagado);
}
.volume input { padding: 0; border: 0; background: none; accent-color: var(--acento); }

.acoes { display: flex; gap: 8px; padding: 12px 14px 10px; }
.acao {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--cartao); border-radius: 20px; padding: 10px 6px; font-size: 14px; font-weight: 600;
  box-shadow: 0 1px 0 var(--linha);
}
.acao svg { color: var(--acento); width: 18px; height: 18px; }
.acao.ligado svg { fill: var(--acento); }

/* ---------- cartões ---------- */
.cartoes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 2px 14px; }
.cartao {
  position: relative; aspect-ratio: 4 / 3; border-radius: var(--raio); overflow: hidden;
  background: #ddd center / cover no-repeat; text-align: left;
}
.cartao.selecionado { outline: 3px solid var(--acento); outline-offset: -3px; }
.cartao .rotulo {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 10px 8px;
  color: #fff; font-weight: 800; font-size: 15px;
  background: linear-gradient(transparent, rgba(0,0,0,.72));
  display: flex; align-items: center; gap: 6px;
}
.ponto { width: 8px; height: 8px; border-radius: 50%; background: #3ddc84; flex: none; }
.ponto.fora { background: #9a9a9a; }
.cartao .estrela { position: absolute; top: 8px; right: 8px; color: #ffd166; }
.cartao .estrela svg { fill: #ffd166; stroke: #ffd166; width: 18px; height: 18px; }

/* ---------- todas ---------- */
.grade-todas { display: grid; grid-template-columns: 1fr; gap: 10px; padding: 0 14px; }
@media (min-width: 700px) { .grade-todas { grid-template-columns: 1fr 1fr; } }
.mini {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--raio); overflow: hidden;
  background: #1e1a17 center / cover no-repeat;
}
.mini cam-video, .mini video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.mini .rotulo { position: absolute; left: 10px; bottom: 8px; color: #fff; font-weight: 800; text-shadow: 0 1px 4px rgba(0,0,0,.8); }

/* ---------- gravações ---------- */
.vazio { text-align: center; padding: 40px 30px; color: var(--apagado); }
.vazio svg { width: 44px; height: 44px; color: var(--acento); }
.vazio h2 { color: var(--texto); margin: 10px 0 6px; font-size: 18px; }
.grav-cameras { display: flex; gap: 8px; padding: 0 14px 10px; overflow-x: auto; }
.grav-cameras button {
  flex: none; padding: 8px 14px; border-radius: 20px; background: var(--cartao);
  font-weight: 700; font-size: 14px; box-shadow: 0 1px 0 var(--linha);
}
.grav-cameras button.ativo { background: var(--acento); color: #fff; }
.grav-dia { display: flex; align-items: center; justify-content: space-between; padding: 0 14px 10px; }
.grav-dia > button { width: 40px; height: 40px; border-radius: 50%; background: var(--cartao); display: grid; place-items: center; }
.grav-dia > button:disabled { opacity: .35; }
.grav-dia-texto { position: relative; font-weight: 800; font-size: 17px; padding: 6px 14px; }
.grav-dia-texto input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.grav-player {
  position: relative; margin: 0 14px; border-radius: 18px; overflow: hidden;
  background: #1e1a17; aspect-ratio: 16 / 9;
}
.grav-player video { width: 100%; height: 100%; display: block; background: #000; }
.grav-aviso {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  gap: 10px; color: #fff; font-weight: 700; text-align: center; padding: 16px;
  background: rgba(30, 26, 23, .85);
}
.grav-atual { display: flex; align-items: center; justify-content: center; gap: 18px; padding: 10px 14px 4px; }
.grav-atual span { font-weight: 800; font-size: 16px; min-width: 120px; text-align: center; }
.grav-atual button { width: 38px; height: 38px; border-radius: 50%; background: var(--cartao); display: grid; place-items: center; }
.grav-atual button:disabled { opacity: .35; }
.grav-blocos { padding: 8px 14px 0; display: flex; flex-direction: column; gap: 8px; }
.grav-hora { background: var(--cartao); border-radius: 14px; padding: 10px 10px 8px; }
.grav-hora h3 { margin: 0 0 6px 4px; font-size: 14px; font-weight: 800; color: var(--apagado); }
.grav-hora .linha { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.grav-hora button {
  padding: 8px 0; border-radius: 10px; font-size: 13px; font-weight: 700;
  background: #f3e3d9; color: var(--acento-escuro);
}
.grav-hora button:disabled { background: #f1ede7; color: #c9c0b6; font-weight: 400; }
.grav-hora button.tocando { background: var(--acento); color: #fff; }

/* ---------- barra ---------- */
.barra {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--barra); border-top: 1px solid var(--linha);
  padding: 8px 0 calc(10px + var(--seguro-baixo));
}
.barra .item { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--apagado); min-width: 76px; }
.barra .item svg { width: 24px; height: 24px; }
.barra .item.ativo { color: var(--acento); font-weight: 700; }

/* ---------- folhas ---------- */
.folha-fundo { position: fixed; inset: 0; background: rgba(45,38,32,.35); z-index: 30; }
.folha {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; max-height: 80vh; overflow: auto;
  background: var(--fundo); border-radius: 24px 24px 0 0;
  padding: 10px 18px calc(24px + var(--seguro-baixo)); max-width: 560px; margin: 0 auto;
}
.folha-pega { width: 42px; height: 5px; border-radius: 3px; background: var(--linha); margin: 0 auto 12px; }
.folha h2 { margin: 0 0 4px; font-size: 20px; font-weight: 800; }
.folha-dica { margin: 0 0 14px; color: var(--apagado); font-size: 14px; }
.lista { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.lista li {
  display: flex; align-items: center; gap: 10px; background: var(--cartao);
  border-radius: 14px; padding: 12px 14px;
}
.lista li .nome { flex: 1; font-weight: 700; }
.lista li .estado { color: var(--apagado); font-size: 14px; }
.lista li .estado.ligado { color: var(--acento); font-weight: 700; }
.lista li button.ir { background: var(--acento); color: #fff; font-weight: 700; border-radius: 10px; padding: 7px 12px; font-size: 14px; }
.lista li button.apagar { color: var(--apagado); padding: 4px; }
.lista .vazia { color: var(--apagado); justify-content: center; }
.nova-posicao { display: flex; flex-direction: column; gap: 8px; }
.botao-secundario {
  background: var(--cartao); color: var(--acento-escuro); font-weight: 700; font-size: 15px;
  border-radius: 14px; padding: 12px 18px; border: 1.5px solid var(--linha); width: 100%;
}
.adicionar {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 12px 14px 0; width: calc(100% - 28px); padding: 13px; border-radius: 18px;
  border: 2px dashed #dccbbd; color: var(--acento-escuro); font-weight: 700;
}
.add-foto {
  position: relative; display: block; text-align: center; padding: 13px; border-radius: 14px;
  background: var(--cartao); border: 1.5px dashed var(--linha); color: var(--apagado); font-weight: 600;
}
.add-foto input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.lista li button.usar { background: var(--acento); color: #fff; font-weight: 700; border-radius: 10px; padding: 7px 12px; font-size: 14px; }

.aviso-rapido {
  position: fixed; left: 50%; bottom: calc(96px + var(--seguro-baixo)); transform: translateX(-50%);
  background: var(--texto); color: var(--fundo); padding: 10px 16px; border-radius: 12px;
  font-weight: 700; font-size: 14px; z-index: 60; max-width: 90vw; text-align: center;
}

@media (min-width: 760px) {
  #tela-app { max-width: 760px; margin: 0 auto; width: 100%; }
}
