:root {
  --bg: #0b1c2a; --panel: #12293b; --panel2: #183348; --line: #24465f;
  --txt: #e8f1f7; --mut: #90a9bb; --brand: #3fc1c9; --brand-d: #2a9aa2;
  --ok: #3ecf8e; --warn: #f5b942; --bad: #ff5d5d; --info: #5aa9ff;
  --r: 14px; --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--txt); min-height: 100%; }
body { font-size: 16px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; color: var(--mut); font-weight: 600; }
a { color: var(--brand); }
.mut { color: var(--mut); } .small { font-size: .85rem; }
.hide { display: none !important; }

/* Layout */
.shell { display: grid; grid-template-rows: auto 1fr auto; min-height: 100vh; min-height: 100dvh; }
.top { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top .logo { font-weight: 800; letter-spacing: .02em; color: var(--brand); }
.top .sp { flex: 1; }
.main { padding: 1rem; max-width: 1180px; width: 100%; margin: 0 auto; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; padding: 0 .5rem; background: var(--panel); border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; padding: .8rem .9rem; color: var(--mut); text-decoration: none; border-bottom: 3px solid transparent; font-weight: 600; white-space: nowrap; }
.tab.on { color: var(--txt); border-color: var(--brand); }
.grid { display: grid; gap: 1rem; }
@media (min-width: 760px) { .g2 { grid-template-columns: 1fr 1fr; } .g3 { grid-template-columns: repeat(3, 1fr); } .main { padding: 1.5rem; } }
@media (min-width: 1000px) { .g21 { grid-template-columns: 2fr 1fr; } }

/* Cartões */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 1rem; }
.card.alert { border-color: var(--bad); background: #3a1a22; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255,93,93,.18); } }
.row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.row.sp { justify-content: space-between; }
.stat { font-size: 1.9rem; font-weight: 700; }
.stat small { font-size: .9rem; color: var(--mut); font-weight: 500; }
.dot { width: .65rem; height: .65rem; border-radius: 50%; display: inline-block; background: var(--mut); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.badge { font-size: .75rem; padding: .15rem .55rem; border-radius: 999px; background: var(--panel2); color: var(--mut); border: 1px solid var(--line); }
.badge.ok { color: var(--ok); } .badge.bad { color: var(--bad); } .badge.warn { color: var(--warn); }

/* Formulários e botões */
label { display: block; font-size: .85rem; color: var(--mut); margin: .7rem 0 .25rem; }
input, select, textarea { width: 100%; padding: .75rem .8rem; background: #0e2132; border: 1px solid var(--line); border-radius: 10px; color: var(--txt); font-size: 1rem; }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
input[type=checkbox] { width: 1.25rem; height: 1.25rem; accent-color: var(--brand); }
input[type=file] { padding: .55rem; }
.btn { appearance: none; border: 0; border-radius: 10px; padding: .75rem 1.1rem; font-size: 1rem; font-weight: 700; background: var(--brand); color: #04222a; cursor: pointer; min-height: 44px; }
.btn:hover { background: var(--brand-d); } .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sec { background: var(--panel2); color: var(--txt); border: 1px solid var(--line); }
.btn.bad { background: var(--bad); color: #2a0606; }
.btn.sm { padding: .45rem .75rem; font-size: .9rem; min-height: 36px; }
.btn.block { width: 100%; }
.msg { padding: .7rem .9rem; border-radius: 10px; margin: .75rem 0; background: var(--panel2); border: 1px solid var(--line); }
.msg.err { border-color: var(--bad); color: #ffb4b4; } .msg.okk { border-color: var(--ok); color: #b6f2d6; }

/* Lista */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .7rem 0; border-bottom: 1px solid var(--line); display: flex; gap: .75rem; align-items: center; justify-content: space-between; }
.list li:last-child { border: 0; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--line); font-size: .92rem; }
th { color: var(--mut); font-weight: 600; }
.tablewrap { overflow-x: auto; }

video { max-width: 100%; border-radius: 10px; margin: .5rem 0; }
img, audio { max-width: 100%; }
.qrtext { font-family: ui-monospace, monospace; font-size: .85rem; resize: vertical; }
.card img { border-radius: 10px; width: 100%; height: auto; margin-top: .5rem; }
a.card { color: inherit; text-decoration: none; display: block; }
a.card:hover { border-color: var(--brand); }

/* Login */
.auth { max-width: 420px; margin: 8vh auto; padding: 0 1rem; }

/* Mapa de localização (tiles próprios) */
.map { position: relative; height: 340px; background: #0a1822; border-radius: var(--r); overflow: hidden; touch-action: none; cursor: grab; user-select: none; }
.map .tile { position: absolute; width: 256px; height: 256px; max-width: none; pointer-events: none; }
.map .pin { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; background: var(--brand); border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(63,193,201,.3); }
.map .trail { position: absolute; inset: 0; pointer-events: none; }
.map .zoom { position: absolute; right: .5rem; top: .5rem; display: grid; gap: .3rem; z-index: 2; }
.map .attr { position: absolute; left: .4rem; bottom: .2rem; font-size: .65rem; color: #fff; background: rgba(0,0,0,.5); padding: 0 .3rem; border-radius: 4px; z-index: 2; }

/* Planta da casa */
.plan { position: relative; width: 100%; background: #0a1822; border-radius: var(--r); overflow: hidden; border: 1px dashed var(--line); touch-action: none; }
.plan img { display: block; width: 100%; height: auto; pointer-events: none; user-select: none; }
.plan .empty { padding: 3rem 1rem; text-align: center; color: var(--mut); }
.sensor { position: absolute; transform: translate(-50%, -50%); width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: .62rem; font-weight: 800; color: #04222a; background: var(--ok); border: 3px solid #fff; cursor: grab; touch-action: none; }
.sensor.warn { background: var(--warn); } .sensor.bad { background: var(--bad); color: #fff; animation: pulse 1.2s infinite; } .sensor.off { background: var(--mut); }

/* Linha do tempo */
.bars { display: flex; align-items: flex-end; gap: 2px; height: 70px; }
.bars span { flex: 1; background: var(--brand); border-radius: 2px 2px 0 0; min-height: 2px; }
.spark { width: 100%; height: 90px; }

/* Matriz de preferências */
.prefs td, .prefs th { text-align: center; } .prefs td:first-child, .prefs th:first-child { text-align: left; }

/* Navegação inferior em celular */
.bottom { padding: .5rem 1rem calc(.5rem + var(--safe-b)); text-align: center; color: var(--mut); font-size: .75rem; }
.toast { position: fixed; left: 50%; bottom: calc(1rem + var(--safe-b)); transform: translateX(-50%); z-index: 50; max-width: 92vw; }
.sosbar { background: var(--bad); color: #fff; padding: .8rem 1rem; font-weight: 700; display: flex; gap: .75rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
