/* ========================================================================
   SONOLINK — modem.css
   Modem console: RX/TX panels, spectrum, signal bar, packet cards
   ======================================================================== */

.modem {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

.modem__panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 14px 16px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modem__panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modem__title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.modem__rate {
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  padding: 4px 8px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* ---- Status pill ---- */
.modem__status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-dim);
}

.modem__status .pill__dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-faint);
  transition: background 200ms ease, box-shadow 200ms ease;
}

.modem__status[data-state="preamble"] .pill__dot,
.modem__status[data-state="sync"] .pill__dot,
.modem__status[data-state="rx_len"] .pill__dot,
.modem__status[data-state="rx_payload"] .pill__dot,
.modem__status[data-state="rx_crc"] .pill__dot {
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  animation: pulse-dot 1s ease-in-out infinite;
}

.modem__status .pill__snr {
  color: var(--text-faint);
  padding-left: 6px;
  border-right: 1px solid var(--border);
  padding-right: 6px;
}

/* ---- Controls row ---- */
.modem__controls {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 8px;
}

/* ---- Calibration banner ---- */
.modem__calib-banner {
  font-size: 0.8125rem;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  line-height: 1.5;
}

.modem__calib-banner .dim { color: var(--text-faint); }

.modem__calib-banner.is-loading { opacity: 0.75; }

.modem__calib-banner.sev-good {
  border-color: rgba(91, 227, 198, 0.5);
  background: rgba(91, 227, 198, 0.08);
}
.modem__calib-banner.sev-ok {
  border-color: rgba(255, 209, 102, 0.4);
  background: rgba(255, 209, 102, 0.06);
}
.modem__calib-banner.sev-warn {
  border-color: rgba(255, 107, 107, 0.4);
  background: rgba(255, 107, 107, 0.06);
}

/* ---- Spectrum ---- */
.modem__spectrum {
  position: relative;
  height: 120px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

#mc-spectrum {
  width: 100%;
  height: 100%;
  display: block;
}

.modem__signal-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(255,255,255,0.06);
}

.modem__signal-bar::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--lvl, 0%);
  background: linear-gradient(90deg, transparent, var(--accent));
  transition: width 120ms ease-out;
  box-shadow: 0 0 8px var(--accent);
}

/* ---- Legend ---- */
.modem__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 0.7rem;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
}

.modem__legend i.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-left: 6px;
  vertical-align: middle;
}

/* ---- Received messages list ---- */
.modem__rx-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  padding-top: 4px;
}

.modem__rx-list:empty::before {
  content: 'لم تصل أي packets بعد. ابدأ الاستماع ثم أرسل من جهاز قريب.';
  display: block;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-faint);
  padding: 18px 12px;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.pkt {
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.875rem;
  animation: card-enter 320ms ease backwards;
}

.pkt--crc { border-color: rgba(255, 107, 107, 0.4); }
.pkt--err { border-color: rgba(255, 209, 102, 0.4); }

.pkt__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 0.7rem;
  color: var(--text-dim);
}

.pkt__badge {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  font-size: 0.65rem;
}

.pkt--crc .pkt__badge {
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.1);
  border-color: rgba(255, 107, 107, 0.4);
}

.pkt__time, .pkt__snr {
  font-size: 0.7rem;
}

.pkt__snr {
  margin-right: auto;
  color: var(--text-faint);
}

.pkt__body {
  color: var(--text);
  line-height: 1.55;
  word-break: break-word;
}

.pkt__body em.dim { color: var(--text-faint); font-style: italic; }

.pkt__hex {
  font-size: 0.65rem;
  color: var(--text-faint);
  margin-top: 6px;
  padding: 6px 8px;
  background: rgba(0,0,0,0.3);
  border-radius: 6px;
  word-break: break-all;
}

/* ---- TX section ---- */
.modem__input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  resize: vertical;
  min-height: 60px;
  line-height: 1.5;
  outline: none;
  transition: border-color 200ms ease;
}

.modem__input:focus { border-color: var(--accent); }
.modem__input::placeholder { color: var(--text-faint); }

.modem__tx-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-dim);
}

.modem__tx-progress {
  position: relative;
  height: 8px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 4px;
}

.modem__tx-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 10px var(--accent-glow);
  transition: width 100ms linear;
}

.modem__tx-progress-label {
  position: absolute;
  top: -22px;
  right: 0;
  font-size: 0.7rem;
  color: var(--accent);
  letter-spacing: 0.1em;
}

/* ---- Tips ---- */
.modem__tips {
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.6;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed var(--border);
}

.modem__tips strong { color: var(--text); }

/* Override the app-placeholder area to allow our scrolling layout */
#screen-app .app-placeholder { display: none; }
