/* o atributo hidden sempre vence regras de display */
[hidden] { display: none !important; }

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --border: #e1e5eb;
  --text: #18202b;
  --muted: #667085;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --on: #f59e0b;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1f2430;
    --border: #2a3140;
    --text: #e6e9ef;
    --muted: #8b95a7;
    --accent: #4f8cff;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--err); }
button.small { padding: 2px 8px; font-size: 12px; }
input, select {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 10px;
  min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.top {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--accent); }
.brand span { color: var(--text); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px;
  background: var(--surface-2); font-size: 12px; color: var(--muted);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--err); }
.live { color: var(--muted); font-size: 12px; }
.live.on { color: var(--ok); }

.tabs { display: flex; gap: 4px; padding: 8px 20px 0; border-bottom: 1px solid var(--border); background: var(--surface); overflow-x: auto; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; color: var(--muted); white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 200px; }
.toolbar p { flex: 1; margin: 0; }
.check { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }
.muted { color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px;
}
.card h3 { margin: 0; font-size: 15px; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head h3 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); padding: 1px 8px; border-radius: 6px; }
.offline { opacity: .55; }

.ent { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--border); }
.ent:first-of-type { border-top: none; }
.ent .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: text; }
.ent .name:hover { text-decoration: underline dotted; }
.ent .val { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.ent .sub { font-size: 12px; color: var(--muted); }
.link-ic { font-size: 11px; color: var(--accent); }
.more { margin-top: 6px; font-size: 12px; }

.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: .15s; cursor: pointer;
}
.switch span::after {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.switch input:checked + span { background: var(--on); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:disabled + span { cursor: not-allowed; opacity: .5; }
.switch.pending span { opacity: .6; }

.members { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.member { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.member .src { font-size: 10px; color: var(--accent); text-transform: uppercase; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.row-actions .spacer { flex: 1; }

.int-card { margin-bottom: 14px; }
.int-card .fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin: 10px 0; }
.int-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.int-card label.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.tbl-wrap { overflow-x: auto; margin: 8px 0; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 4px 8px; border-bottom: 1px solid var(--border); }
.table td input, .table td select { width: 100%; min-width: 90px; padding: 4px 6px; }
.disc { margin-top: 8px; font-size: 13px; }
.disc li { margin: 4px 0; }
.import { display: flex; gap: 16px; align-items: center; margin-bottom: 14px; }
.import > div { flex: 1; }
.import p { margin: 4px 0 0; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); width: min(640px, calc(100vw - 32px)); padding: 0; }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
dialog h3 { margin: 0 0 4px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px;
  transition: transform .2s; max-width: calc(100vw - 32px); z-index: 20;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--err); color: #fff; }
.empty { color: var(--muted); padding: 30px; text-align: center; grid-column: 1 / -1; }

@media (max-width: 640px) {
  .top { padding: 10px 16px; flex-wrap: wrap; }
  .chips { order: 3; flex-basis: 100%; }
  .tabs { padding: 4px 8px 0; }
  main { padding: 16px; }
  .grid { grid-template-columns: 1fr; }
  .import { flex-direction: column; align-items: stretch; }
}
details { margin: 4px 0 8px; }
details summary { cursor: pointer; font-size: 13px; }
.int-card h4 { margin: 14px 0 4px; font-size: 13px; }

/* ---------------- construtor de vínculos */
dialog.builder { width: min(1000px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog.builder form { gap: 14px; }
.builder-top { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.builder-top h3 { margin: 0; }
.builder-top input { flex: 1; min-width: 200px; font-size: 15px; }
.builder-body { display: grid; grid-template-columns: 280px 1fr; gap: 14px; min-height: 380px; }
.palette-wrap { display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); border-radius: 10px; padding: 10px; min-height: 0; border: 2px dashed transparent; }
.palette-wrap.over { border-color: var(--err); }
.palette { overflow: auto; flex: 1; max-height: 52vh; display: flex; flex-direction: column; gap: 10px; }
.pal-head { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; display: flex; gap: 6px; align-items: center; }
.pal-item, .node {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; margin-bottom: 4px; cursor: grab; user-select: none; touch-action: none;
  transition: border-color .12s, transform .12s, box-shadow .12s;
}
.pal-item:hover, .node:hover { border-color: var(--accent); }
.pal-item:focus-visible, .node:focus-visible { outline: 2px solid var(--accent); }
.dragging { opacity: .35; }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }
.grip { color: var(--muted); font-size: 12px; }
.pal-tip { font-size: 12px; margin: 0; }
.pal-empty { padding: 10px; }

.stage { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.flow { position: relative; display: flex; align-items: center; gap: 56px; flex: 1; padding: 16px; border-radius: 10px; background: radial-gradient(circle, var(--border) 1px, transparent 1px) 0 0 / 18px 18px; }
.wires { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.wire { fill: none; stroke: var(--accent); stroke-width: 2; opacity: .75; }
.arrow { fill: var(--accent); }
.slot { position: relative; z-index: 1; flex: 1; min-width: 0; min-height: 70px; display: flex; flex-direction: column; justify-content: center; gap: 4px; border: 2px dashed var(--border); border-radius: 10px; padding: 8px; transition: border-color .12s, background .12s; }
.slot.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.slot .node { margin: 0; background: var(--surface); }
.slot.is-origin .node.origin { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
#slot-origin { flex: 0 1 240px; }
.node-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.node-text b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-text small { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { border: none; background: none; color: var(--muted); padding: 2px 4px; font-size: 13px; }
.icon-btn:hover { color: var(--accent); }
.placeholder { color: var(--muted); font-size: 13px; text-align: center; padding: 10px; pointer-events: none; }
.slot .node + .placeholder { padding: 4px; font-size: 12px; }

.mode-col { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.mode-btn {
  width: 56px; height: 56px; border-radius: 50%; font-size: 26px; line-height: 1;
  display: grid; place-items: center; padding: 0;
  background: var(--surface); border: 2px solid var(--accent); color: var(--accent);
  box-shadow: var(--shadow); transition: transform .25s, background .15s;
}
.mode-btn:hover { background: var(--accent); color: var(--accent-text); transform: scale(1.06); }
.mode-btn.follow { border-style: solid; color: var(--warn); border-color: var(--warn); }
.mode-btn.follow:hover { background: var(--warn); color: #fff; }
.mode-btn.spin { animation: flip .35s ease; }
@keyframes flip { from { transform: rotateY(180deg); } to { transform: rotateY(0); } }
.mode-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface); padding: 0 6px; border-radius: 4px; }
.mode-hint { margin: 0; color: var(--muted); font-size: 13px; text-align: center; }
.ghost { position: fixed; left: 0; top: 0; z-index: 100; pointer-events: none; background: var(--accent); color: var(--accent-text); padding: 6px 12px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 18px rgba(0,0,0,.25); white-space: nowrap; }

/* mini diagrama nos cartões */
.mini-flow { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; margin: 10px 0; }
.mini-col { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.mini-node { display: flex; align-items: center; gap: 6px; font-size: 12.5px; background: var(--surface-2); border-radius: 6px; padding: 4px 8px; min-width: 0; }
.mini-node span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mode-btn.small-mode { width: 36px; height: 36px; font-size: 18px; border-width: 1.5px; }

@media (max-width: 760px) {
  .builder-body { grid-template-columns: 1fr; }
  .palette { max-height: 30vh; }
  .flow { flex-direction: column; gap: 40px; }
  #slot-origin { flex: none; width: 100%; }
  .slot { width: 100%; }
  .mode-btn { transform: rotate(90deg); }
  .mode-btn:hover { transform: rotate(90deg) scale(1.06); }
}

/* ajustes de proporção / overflow */
.builder-body > * { min-width: 0; }
dialog.builder form { min-width: 0; }
.flow { gap: 44px; }
#slot-origin { flex: 1 1 0; }
.slot.targets { flex: 1.25 1 0; }
.pal-head { flex-wrap: wrap; }
@media (max-width: 760px) {
  dialog.builder { width: calc(100vw - 16px); max-width: calc(100vw - 16px); }
  dialog.builder form { padding: 14px; }
  .builder-top input { min-width: 0; width: 100%; }
  #slot-origin, .slot.targets { flex: none; }
}

/* =====================================================================
   PWA / painel inicial
   ===================================================================== */
:root { --tile: var(--surface); --tile-on: color-mix(in srgb, #fbbf24 14%, var(--surface)); --icon: #9aa3b2; --icon-on: #f5b301; --cool: #4f8cff; }
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318; --surface: #1b1d23; --surface-2: #23262e; --border: #2b2f39; --tile: #1c1f26;
    --tile-on: #2a2619; --icon: #8e97a8; --icon-on: #fcd34d;
  }
}
html { -webkit-text-size-adjust: 100%; }
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.top { padding-top: max(12px, env(safe-area-inset-top)); }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:disabled { cursor: default; }
.tabs button { display: inline-flex; align-items: center; gap: 6px; }
.tabs svg { width: 16px; height: 16px; fill: currentColor; flex: none; }
.primary-soft { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); border-color: transparent; color: var(--accent); font-weight: 600; }
.empty.small { padding: 14px; font-size: 13px; }

/* barra do painel */
.dash-bar { display: flex; align-items: center; gap: 12px; margin: 0 2px 16px; flex-wrap: wrap; }
.dash-hello { flex: 1; min-width: 180px; display: flex; flex-direction: column; }
.dash-hello b { font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.dash-hello span { font-size: 13px; }
.dash-actions { display: flex; gap: 8px; }
.hidden-view { display: none; }
#tab-home.editing .hidden-view { display: inline-flex; }

/* seções em colunas (masonry) */
.dash { columns: 340px auto; column-gap: 18px; }
.dsec { break-inside: avoid; margin: 0 0 22px; display: block; }
.dsec h2 { font-size: 20px; font-weight: 500; margin: 2px 4px 10px; letter-spacing: -.01em; }
.dash > .empty { column-span: all; }

/* cartões */
.cell { display: flex; min-width: 0; }
.cell > .tile { flex: 1; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; grid-auto-flow: dense; }
.tile {
  position: relative; min-height: 96px; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px;
  background: var(--tile); border: 1px solid var(--border); border-radius: 16px;
  padding: 12px 6px; text-align: center; color: var(--text); user-select: none; -webkit-user-select: none;
  transition: background .15s, border-color .15s, transform .08s;
}
button.tile:active:not(:disabled) { transform: scale(.96); }
.tile .ic { width: 28px; height: 28px; fill: var(--icon); flex: none; transition: fill .15s; }
.ic.sm { width: 18px; height: 18px; }
.tile.on { background: var(--tile-on); border-color: color-mix(in srgb, var(--icon-on) 35%, var(--border)); }
.tile.on > .ic { fill: var(--icon-on); filter: drop-shadow(0 0 6px color-mix(in srgb, var(--icon-on) 45%, transparent)); }
.t-label { font-size: 13.5px; line-height: 1.2; max-width: 100%; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.t-sub { font-size: 11.5px; color: var(--muted); }
.tile.na { opacity: .5; }
.tile.pend { animation: pulse .9s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.tile:hover:not(:disabled) { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

.tile.sensor { align-items: flex-start; justify-content: space-between; text-align: left; padding: 12px; }
.t-row { display: flex; align-items: center; gap: 6px; color: var(--muted); max-width: 100%; }
.t-row .t-label { font-size: 12.5px; }
.t-value { font-size: 22px; font-variant-numeric: tabular-nums; }
.t-value small { font-size: 12px; color: var(--muted); margin-left: 3px; }

/* ar-condicionado */
.tile.climate { justify-content: space-between; padding: 10px 12px 12px; gap: 4px; }
.c-head { display: flex; align-items: center; gap: 8px; width: 100%; }
.c-head .t-label { flex: 1; text-align: left; font-weight: 500; }
.c-power { width: 34px; height: 34px; border-radius: 50%; padding: 0; display: grid; place-items: center; background: var(--surface-2); border: none; }
.c-power .ic { fill: var(--muted); }
.c-power.on { background: color-mix(in srgb, var(--cool) 22%, var(--surface)); }
.c-power.on .ic { fill: var(--cool); }
.c-gauge { position: relative; width: 128px; height: 112px; }
.gauge { width: 128px; height: 128px; position: absolute; top: -4px; left: 0; }
.g-track { fill: none; stroke: var(--surface-2); stroke-width: 7; stroke-linecap: round; }
.g-fill { fill: none; stroke: var(--muted); stroke-width: 7; stroke-linecap: round; opacity: .6; }
.gauge.active .g-fill { stroke: var(--cool); opacity: 1; }
.g-knob { fill: var(--text); }
.c-val { position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px; font-weight: 300; font-variant-numeric: tabular-nums; padding-top: 8px; }
.c-val sup { font-size: 12px; color: var(--muted); margin-left: 2px; vertical-align: top; position: relative; top: 8px; }
.c-ctrl { display: flex; align-items: center; gap: 6px; width: 100%; }
.c-ctrl .t-sub { flex: 1; text-align: center; line-height: 1.2; }
.c-ctrl button { width: 38px; height: 38px; border-radius: 50%; padding: 0; font-size: 20px; line-height: 1; background: var(--surface-2); border: none; flex: none; }
.c-ctrl button:active:not(:disabled) { background: color-mix(in srgb, var(--cool) 25%, var(--surface)); }

/* solar */
.dsec.solar { background: none; }
.solar-sum { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--tile); border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px; margin-bottom: 8px; }
.ss-main { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 180px; }
.ss-main > div { display: flex; flex-direction: column; }
.ic.sun { width: 34px; height: 34px; fill: #f5b301; }
.ss-big { font-size: 24px; font-weight: 500; font-variant-numeric: tabular-nums; }
.ss-kpis { display: flex; gap: 18px; }
.ss-kpis div { display: flex; flex-direction: column; align-items: flex-end; }
.ss-kpis b { font-size: 18px; font-weight: 500; font-variant-numeric: tabular-nums; }
.ss-kpis span { font-size: 11.5px; color: var(--muted); }
.pv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; }
.pv { background: var(--tile); border: 1px solid var(--border); border-radius: 14px; padding: 10px 8px; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.pv-bar { width: 34px; height: 64px; border-radius: 6px; background: var(--surface-2); position: relative; overflow: hidden;
  background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(90deg, var(--border) 1px, transparent 1px); background-size: 100% 25%, 50% 100%; }
.pv-bar span { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(#fcd34d, #f59e0b); transition: height .4s; }
.pv-val { font-size: 12.5px; font-variant-numeric: tabular-nums; }
.pv-lbl { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.pv.na { opacity: .55; }

/* edição do painel */
.sec-edit { display: flex; gap: 6px; align-items: center; margin: 0 0 10px; }
.sec-edit input { flex: 1; font-size: 16px; font-weight: 500; }
.icon-btn.danger { color: var(--err); }
.tile-wrap { position: relative; }
.tile-wrap > .tile { pointer-events: none; }
.sec-cols { display: flex !important; flex-direction: row !important; align-items: center; gap: 4px !important; color: var(--muted); font-size: 14px !important; }
.sec-cols select { padding: 4px 6px; font-size: 13px; }
.small-hint { font-size: 12px; margin: -4px 0 0; }
.tile-tools { position: absolute; left: 4px; right: 4px; bottom: 4px; display: flex; justify-content: space-between; gap: 2px; }
.tile-tools button { flex: 1; padding: 3px 0; font-size: 11px; border-radius: 7px; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(4px); }
.tile-tools button.danger { color: var(--err); }
#tab-home.editing .tiles .tile-wrap > .tile { border-style: dashed; padding-bottom: 30px; }
.tile.add { border-style: dashed; color: var(--muted); font-size: 26px; background: none; }

/* diálogo de seleção */
.pick-list { max-height: 55vh; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.pick-item { display: flex !important; flex-direction: row !important; align-items: center; gap: 10px !important; padding: 8px 6px; border-radius: 8px; color: var(--text) !important; font-size: 14px !important; cursor: pointer; }
.pick-item:hover { background: var(--surface-2); }
.pick-item span { flex: 1; }
.pick-item small { color: var(--muted); font-size: 11px; }
.pick-item .ic { fill: var(--icon); }
#pick-dialog input[type=search] { width: 100%; }

/* ---------------- celular: navegação inferior estilo app */
@media (max-width: 640px) {
  .top { padding: max(10px, env(safe-area-inset-top)) 16px 10px; gap: 10px; }
  .chips { display: none; }
  .brand { flex: 1; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    justify-content: space-around; gap: 0; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border); border-bottom: none;
    background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  }
  .tabs button { flex-direction: column; gap: 3px; font-size: 10.5px; padding: 4px 2px; border-bottom: none; flex: 1; min-width: 0; }
  .tabs button.active { border-bottom: none; color: var(--accent); }
  .tabs svg { width: 24px; height: 24px; }
  main { padding: 14px 12px calc(84px + env(safe-area-inset-bottom)); }
  .dash { columns: 1; }
  .dsec h2 { font-size: 19px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
  .tile { min-height: 88px; border-radius: 14px; }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
  dialog { max-height: calc(100dvh - 32px); }
}
@media (max-width: 360px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
}
.toast:not(.show) { visibility: hidden; }
.c-val { display: flex; align-items: center; justify-content: center; }
.c-val sup { top: -10px; }

/* câmera */
.tile.camera { min-height: 150px; padding: 0; overflow: hidden; justify-content: space-between; align-items: stretch;
  background: radial-gradient(120% 90% at 30% 20%, #2a2f3a, #0b0d11); color: #e8ebf0; }
.cam-bg { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding-top: 14px; }
.cam-bg .t-sub { color: #aab2c0; }
.ic.cam-ic { width: 34px; height: 34px; fill: #8e97a8; }
.cam-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; background: linear-gradient(transparent, rgba(0,0,0,.55)); }
.cam-foot .t-label { text-align: left; }
.cam-live { font-size: 12px; color: #aab2c0; white-space: nowrap; }
dialog.cam-dialog { width: min(960px, calc(100vw - 16px)); background: #000; border-color: #222; color: #e8ebf0; padding: 0; overflow: hidden; }
.cam-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #111; }
.cam-head b { font-weight: 600; }
.cam-head .muted { flex: 1; font-size: 12.5px; }
.cam-head .icon-btn { color: #e8ebf0; font-size: 18px; }
#cam-video { display: block; width: 100%; max-height: 78vh; aspect-ratio: 16 / 9; background: #000; object-fit: contain; }
@media (max-width: 640px) { dialog.cam-dialog { width: 100vw; max-width: 100vw; margin: auto 0; border-radius: 0; border: none; } }

/* arrastar cartões */
.drag-handle { position: absolute; top: 4px; left: 4px; z-index: 2; width: 30px; height: 30px; padding: 0; border-radius: 8px; font-size: 16px; line-height: 1;
  display: grid; place-items: center; cursor: grab; touch-action: none; -webkit-user-select: none; user-select: none;
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(4px); color: var(--muted); }
.cell.dragging { opacity: .3; }
.drag-ghost { position: fixed; z-index: 100; pointer-events: none; opacity: .9; box-shadow: 0 12px 30px rgba(0,0,0,.35); border-radius: 16px; }
.drag-ghost .drag-handle, .drag-ghost .tile-tools { display: none; }
.cell.drop-before::before, .cell.drop-after::after { content: ""; position: absolute; top: 4px; bottom: 4px; width: 4px; border-radius: 2px; background: var(--accent); z-index: 3; }
.cell.drop-before::before { left: -6px; }
.cell.drop-after::after { right: -6px; }
.dsec.drop-sec .tiles { outline: 2px dashed color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 5px; border-radius: 12px; }

/* última detecção no cartão da câmera */
.tile.camera.has-snap { aspect-ratio: 16 / 9; min-height: 120px; }
.cam-snap { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.tile.camera .cam-foot, .tile.camera .cam-bg { position: relative; z-index: 1; }
.tile.camera.has-snap .cam-foot { margin-top: auto; }
.cam-badge { position: absolute; top: 8px; right: 8px; z-index: 1; font-size: 11px; padding: 3px 8px; border-radius: 999px; background: rgba(0,0,0,.5); color: #fff; backdrop-filter: blur(4px); }

/* acessos (passkeys) */
.access-btn { display: grid; place-items: center; padding: 6px; border-radius: 8px; }
.access-btn:hover { color: var(--text); }
dialog.access-dialog { width: min(560px, calc(100vw - 24px)); }
.acc-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.acc-head b { font-size: 17px; }
.access-dialog h4 { margin: 14px 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.acc-list { display: flex; flex-direction: column; gap: 8px; }
.acc-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; }
.acc-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.acc-info small { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.acc-tag { font-size: 11px; font-weight: 500; color: var(--accent); margin-left: 4px; }
.acc-item .danger { color: var(--err); flex: none; }
.acc-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.acc-qr { margin-top: 14px; padding: 14px; border: 1px dashed var(--border); border-radius: 12px; text-align: center; }
.qr-img { display: inline-block; background: #fff; padding: 8px; border-radius: 10px; line-height: 0; color: #000; }
.qr-img svg { width: 220px; height: 220px; }
.acc-url { display: flex; gap: 6px; }
.acc-url input { flex: 1; min-width: 0; font-size: 12px; }

/* página de login */
body.login-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px 24px; display: flex; flex-direction: column; gap: 12px; max-width: none; margin: 0; }
.login-brand { display: flex; align-items: center; gap: 10px; color: var(--accent); font-weight: 600; font-size: 18px; }
.login-brand span { color: var(--text); }
.login-card h1 { margin: 8px 0 0; font-size: 24px; font-weight: 600; letter-spacing: -.01em; }
.lg-name { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.lg-name input { font-size: 16px; }
.lg-btn { padding: 12px 16px; font-size: 16px; border-radius: 12px; }
.lg-msg { min-height: 1.2em; margin: 0; font-size: 14px; }
.lg-msg.err { color: var(--err); }
.lg-link { color: var(--accent); font-size: 14px; }
