/* HR Core-MK · escala de cinza, mobile-first, adaptativo portrait/landscape */

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #000;
  --fg: #fff;
  --mid: #1a1a1a;
  --line: #333;
  --muted: #888;
  --accent: #fff;
  --r: 10px;
}
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  font-feature-settings: "tnum";
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* TOP BAR */
.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: max(env(safe-area-inset-top), .4rem) .6rem .35rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  gap: .5rem;
}
.top-l { justify-self: start; }
.top-c { justify-self: center; min-width: 0; }
.top-r { justify-self: end; display: flex; gap: .5rem; align-items: center; }
.clock { font-size: 1.05rem; font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.meta { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.badge {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: .15rem .55rem;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.live { color: var(--fg); border-color: var(--fg); }
.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg);
  width: 36px; height: 36px;
  border-radius: 8px;
  font-size: 1.05rem;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--mid); }

/* MAIN SCREEN */
.screen {
  height: calc(100vh - 50px);
  height: calc(100dvh - 50px);
  display: grid;
  grid-template-rows: 1fr auto auto auto auto;
  gap: .4rem;
  padding: .5rem .6rem max(env(safe-area-inset-bottom), .5rem);
  overflow: hidden;
}

/* FC GIGANTE */
.fc-display {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  min-height: 0;
}
.fc-num {
  font-size: clamp(8rem, 38vmin, 22rem);
  font-weight: 900;
  line-height: .92;
  letter-spacing: -4px;
  font-variant-numeric: tabular-nums;
}
.fc-unit {
  font-size: 1rem;
  color: var(--muted);
  letter-spacing: 6px;
  text-transform: uppercase;
  margin-top: .2rem;
}
.fc-status {
  margin-top: .8rem;
  font-size: .85rem;
  color: var(--muted);
  min-height: 1.2em;
}

/* ZONAS — barras horizontais */
.zones {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .3rem;
}
.zone {
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  padding: .35rem .25rem;
  text-align: center;
  background: transparent;
  transition: background .12s, border-color .12s;
}
.zone .zlbl { display: block; font-weight: 800; font-size: 1rem; letter-spacing: 1px; }
.zone .zrng { display: block; font-size: .68rem; color: var(--muted); margin-top: .15rem; font-variant-numeric: tabular-nums; }
.zone.active {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
.zone.active .zrng { color: var(--bg); }

/* STATS */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .3rem;
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: .45rem .3rem;
}
.stat { text-align: center; }
.stat .lbl { display: block; font-size: .65rem; color: var(--muted); letter-spacing: 1.2px; }
.stat .val { display: block; font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: .1rem; }

/* PSE — botões grandes */
.pse {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: .3rem;
  min-height: 56px;
}
.pse button {
  background: transparent;
  border: 1.5px solid var(--line);
  color: var(--fg);
  border-radius: var(--r);
  font-size: 1.15rem;
  font-weight: 700;
  min-height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: .25rem;
}
.pse button .pse-lbl {
  font-size: .58rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: .5px;
  text-transform: uppercase;
  margin-top: .1rem;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pse button:active, .pse button.flash { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.pse button:active .pse-lbl, .pse button.flash .pse-lbl { color: var(--bg); }

/* CONTROLES */
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .3rem;
}
.controls .ctl {
  background: transparent;
  border: 1.5px solid var(--line);
  color: var(--fg);
  padding: .75rem .5rem;
  border-radius: var(--r);
  font-size: .92rem;
  font-weight: 600;
  min-height: 50px;
}
.controls .ctl:disabled { opacity: .35; }
.controls .ctl:active:not(:disabled) { background: var(--mid); }
.controls .ctl-conn { grid-column: 1 / -1; border-color: var(--fg); }
.controls .ctl-conn.connected { background: var(--fg); color: var(--bg); }
.controls .ctl-mod { grid-column: 1 / -1; }
.controls .ctl-start { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.controls .ctl-start.recording { background: transparent; color: var(--fg); }

/* LANDSCAPE: layout 3 colunas */
@media (orientation: landscape) and (min-width: 700px) {
  .screen {
    grid-template-rows: 1fr auto auto;
    grid-template-columns: minmax(180px, 1fr) 2.4fr minmax(180px, 1fr);
    grid-template-areas:
      "pse fc zones"
      "stats stats stats"
      "controls controls controls";
    gap: .55rem;
    padding: .6rem .8rem;
  }
  .fc-display { grid-area: fc; }
  .zones { grid-area: zones; grid-template-columns: 1fr; grid-auto-rows: 1fr; align-content: stretch; }
  .zone { display: flex; flex-direction: column; justify-content: center; padding: .4rem; }
  .pse { grid-area: pse; grid-auto-flow: row; grid-auto-rows: 1fr; }
  .stats { grid-area: stats; }
  .controls { grid-area: controls; grid-template-columns: repeat(6, 1fr); }
  .controls .ctl-conn, .controls .ctl-mod { grid-column: span 1; }
  .fc-num { font-size: clamp(8rem, 28vmin, 18rem); }
}

/* ============ MODAIS ============ */
.modal-back {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.85);
  z-index: 100;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 1rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-back.hide { display: none; }
.modal {
  background: #0a0a0a;
  border: 1px solid var(--line);
  border-radius: 14px;
  width: 100%;
  max-width: 720px;
  margin-top: max(env(safe-area-inset-top), .5rem);
  margin-bottom: 2rem;
  display: flex; flex-direction: column;
}
.modal.modal-sm { max-width: 440px; }
.m-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--line);
}
.m-head h2 { font-size: 1.05rem; font-weight: 700; letter-spacing: .3px; }
.m-head .x {
  background: transparent; border: none; color: var(--muted);
  font-size: 1.2rem; padding: .3rem .5rem; border-radius: 6px;
}
.m-body { padding: 1rem; display: flex; flex-direction: column; gap: .85rem; }
.m-foot {
  display: flex; gap: .5rem; justify-content: flex-end;
  padding: .75rem 1rem;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.m-foot .btn-pri,
.m-foot .btn-sec {
  padding: .65rem 1.1rem;
  border-radius: 8px;
  font-size: .9rem; font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--line);
  background: transparent;
  color: var(--fg);
}
.m-foot .btn-pri { background: var(--fg); color: var(--bg); border-color: var(--fg); }

/* form rows */
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; }
.row label { display: flex; flex-direction: column; gap: .25rem; font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.row label.span2 { grid-column: 1 / -1; }
.row label em { color: var(--muted); font-style: italic; text-transform: none; letter-spacing: 0; font-size: .68rem; }
.row input, .row select {
  background: var(--mid);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .55rem .65rem;
  font-size: .95rem;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}
.row input:focus, .row select:focus { outline: 1px solid var(--fg); outline-offset: 1px; }
.row input[readonly] { background: #050505; color: var(--muted); }
.card { border: 1px solid var(--line); border-radius: var(--r); padding: .8rem; }
.card h3 { font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; margin-bottom: .15rem; }
.card .hint { font-size: .78rem; color: var(--muted); margin-bottom: .55rem; line-height: 1.4; }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: .45rem; margin-top: .55rem; }
.kpis-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 540px) { .kpis-4 { grid-template-columns: repeat(2, 1fr); } }
.kpi { border: 1px solid var(--line); border-radius: 8px; padding: .55rem; text-align: center; }
.kpi .lbl { display: block; font-size: .62rem; color: var(--muted); letter-spacing: .8px; }
.kpi .val { display: block; font-size: 1rem; font-weight: 700; margin-top: .1rem; font-variant-numeric: tabular-nums; }

/* modality grid */
.modality-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: .5rem; }
.modality-grid button {
  background: var(--mid); color: var(--fg);
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  padding: 1rem .5rem;
  font-size: 1rem;
}
.modality-grid button:active, .modality-grid button.sel { background: var(--fg); color: var(--bg); border-color: var(--fg); }

/* histórico */
.hist-list { display: flex; flex-direction: column; gap: .4rem; max-height: 60vh; overflow-y: auto; }
.hist-item {
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: .65rem .75rem;
  cursor: pointer;
  display: flex; flex-direction: column; gap: .15rem;
}
.hist-item:active { background: var(--mid); }
.hist-item .h-top { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.hist-item .h-date { font-weight: 700; font-size: .92rem; }
.hist-item .h-mod { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.hist-item .h-meta { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); font-size: .85rem; }

/* resumo */
.sum-class { font-size: .9rem; color: var(--fg); padding: .6rem .8rem; border: 1px dashed var(--line); border-radius: var(--r); }
.sum-zones { display: flex; flex-direction: column; gap: .35rem; }
.sum-zone-row { display: grid; grid-template-columns: 40px 1fr 70px; gap: .5rem; align-items: center; font-size: .82rem; }
.sum-zone-row .bar { background: var(--mid); height: 16px; border-radius: 4px; position: relative; overflow: hidden; }
.sum-zone-row .bar > span { display: block; height: 100%; background: var(--fg); }
.sum-zone-row .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.sum-zone-row .zk { font-weight: 700; }

.banner { padding: .7rem .9rem; border: 1px solid var(--fg); border-radius: var(--r); font-size: .9rem; }

.chart { width: 100%; height: 180px; background: var(--mid); border-radius: 6px; }

/* TOAST */
.toast {
  position: fixed; bottom: max(env(safe-area-inset-bottom), 1.5rem);
  left: 50%; transform: translateX(-50%);
  background: var(--fg); color: var(--bg);
  padding: .7rem 1.1rem;
  border-radius: 999px;
  font-size: .9rem; font-weight: 600;
  z-index: 200;
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}
.toast.hide { opacity: 0; transform: translate(-50%, 12px); transition: all .2s; pointer-events: none; }
.toast.show { opacity: 1; transition: all .2s; }

.hide { display: none !important; }
