/* BME Field PWA — Top Bar Styles
 * Marker: PWA-TOPBAR-CSS-V1-20260518 (PWA Refactor P2)
 *
 * Dark background (#0b0b0b), white text, magenta/blue accents.
 * Matches existing BME visual style from grade.html tiers + lookup.html.
 *
 * Include AFTER existing page CSS. All selectors are prefixed bme-topbar/
 * bme-chip/bme-drawer/bme-popover/bme-mode-* to avoid collisions.
 */

/* ── Top bar container ─────────────────────────────────────────── */
.bme-topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0 12px;
  margin-bottom: 10px;
  border-bottom: 1px solid #222;
  /* Prevent wrapping on narrow C72 screens */
  flex-wrap: nowrap;
  min-height: 44px;
}

.bme-topbar-back {
  color: #8cf;
  text-decoration: none;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
  padding: 4px 6px;
  border-radius: 6px;
  /* Hit target >= 44px via parent flex */
}
.bme-topbar-back:active { background: #1a2a3a; }

.bme-topbar-title {
  font-size: 17px;
  margin: 0;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #fff;
}

/* ── Chips (power + pair) ──────────────────────────────────────── */
.bme-chip {
  appearance: none;
  -webkit-appearance: none;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid #333;
  border-radius: 20px;
  background: #1a1a1a;
  color: #ddd;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.2;
  margin: 0;
}
.bme-chip:active { background: #252525; }

.bme-chip-power {
  border-color: #2a3a4a;
  color: #9cf;
}
.bme-chip-power.power-active {
  background: #0f2040;
  border-color: #2a6a9a;
  color: #9cf;
}

.bme-chip-pair {
  border-color: #2a2a3a;
  color: #c8aff0;
}
.bme-chip-pair.pair-paired {
  background: #1a0f2a;
  border-color: #5a3f8a;
  color: #c8aff0;
}
.bme-chip-pair.pair-unpaired {
  color: #789;
}

/* ── Mode segmented control ────────────────────────────────────── */
.bme-mode-seg {
  display: flex;
  gap: 0;
  border: 1px solid #333;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}
.bme-mode-btn {
  appearance: none;
  -webkit-appearance: none;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  background: #1a1a1a;
  color: #aaa;
  border: 0;
  cursor: pointer;
  line-height: 1.2;
  margin: 0;
  white-space: nowrap;
}
.bme-mode-btn + .bme-mode-btn {
  border-left: 1px solid #333;
}
.bme-mode-btn.active {
  background: #1a4fa0;
  color: #fff;
}
.bme-mode-btn:active { filter: brightness(1.2); }

/* ── Power popover ─────────────────────────────────────────────── */
.bme-popover {
  position: relative;
  background: #181818;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  z-index: 50;
}
.bme-popover[hidden] { display: none; }
.bme-popover-title {
  font-size: 11px;
  color: #8cf;
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-bottom: 8px;
  font-weight: 600;
}
.bme-popover-hint {
  font-size: 11px;
  color: #789;
  text-align: center;
  margin-top: 6px;
}

/* ── Pair drawer ───────────────────────────────────────────────── */
.bme-drawer {
  background: #111;
  border: 1px solid #2a2a3a;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}
.bme-drawer[hidden] { display: none; }
.bme-drawer-title {
  font-size: 13px;
  font-weight: 700;
  color: #c8aff0;
  margin-bottom: 10px;
}
.bme-pair-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.bme-pair-label {
  font-size: 11px;
  color: #789;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.bme-pair-code {
  font-family: ui-monospace, monospace;
  font-weight: 700;
  font-size: 22px;
  color: #c8aff0;
  letter-spacing: 3px;
}
.bme-sse-status {
  font-size: 12px;
  color: #999;
}
.bme-sse-status.live    { color: #9f9; }
.bme-sse-status.connecting { color: #fc9; }
.bme-sse-status.disconnected { color: #f99; }
.bme-drawer-close {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  padding: 10px;
  font-size: 13px;
  font-weight: 600;
  background: #222;
  color: #aaa;
  border: 1px solid #333;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 8px;
}

/* ── Helper banner ─────────────────────────────────────────────── */
.bme-banner-warn {
  background: #3d1f0a;
  border: 1px solid #6a3a1a;
  border-radius: 8px;
  color: #fc9;
  font-size: 12px;
  padding: 8px 12px;
  margin-bottom: 8px;
}
.bme-banner-warn[hidden] { display: none; }

/* ── Exception banner (tag-issue P3) ───────────────────────────── */
.bme-banner-exception {
  background: #3d2a0a;
  border: 1px solid #8a5a1a;
  border-radius: 8px;
  color: #fca;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 12px;
  margin-bottom: 10px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.bme-banner-exception[hidden] { display: none; }
.bme-banner-exception .exc-icon { flex-shrink: 0; }
.bme-banner-exception .exc-msg  { flex: 1; }


/* === PWA-FIX-TOPBAR-POWER-MODE-20260518 === Bug1: narrow-screen safety + power-chip polish */
.bme-topbar {
  overflow-x: visible;
}
.bme-topbar-title {
  /* Title is least important on narrow screens — let it shrink to 0 if needed */
  min-width: 0;
  flex-shrink: 1;
}
.bme-chip-power {
  /* Slightly tighter to leave room for mode seg + pair chip on 320px screens */
  padding: 5px 8px;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bme-chip-power #topbarPowerLabel {
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  vertical-align: middle;
}
@media (max-width: 380px) {
  .bme-topbar-title {
    /* Hide title text on narrow screens; keep document.title for tab label */
    display: none;
  }
  .bme-chip, .bme-mode-btn {
    padding: 5px 7px;
    font-size: 11px;
  }
}
/* === end PWA-FIX-TOPBAR-POWER-MODE-20260518 === */


/* === PWA-FIX-TOPBAR-OVERFLOW-V2-20260518 === Bug2: hard overflow protection for C72 ~360px viewport */
.bme-topbar {
  gap: 6px;
}
.bme-chip-power {
  max-width: 100px;
}
.bme-chip-power #topbarPowerLabel {
  max-width: 50px;
}
@media (max-width: 480px) {
  /* C72 + most narrow phones land here */
  .bme-topbar-title {
    display: none;
  }
  .bme-topbar {
    gap: 4px;
  }
  .bme-chip {
    padding: 4px 6px;
    font-size: 11px;
  }
  .bme-chip-power #topbarPowerLabel {
    max-width: 44px;
  }
  .bme-mode-btn {
    padding: 4px 8px;
    font-size: 11px;
  }
  /* Collapse pair chip to icon-only — full code still in drawer */
  #topbarPairLabel {
    display: none;
  }
  .bme-chip-pair {
    padding: 4px 7px;
  }
}
@media (max-width: 360px) {
  .bme-chip-power #topbarPowerLabel {
    /* Drop label entirely; bolt icon-only ⚡ */
    display: none;
  }
  .bme-chip-power {
    max-width: 50px;
  }
}
/* === end PWA-FIX-TOPBAR-OVERFLOW-V2-20260518 === */


/* === PWA-FIX-BUGS-3456-20260518 === Bug3a: pair chip must not stretch */
.bme-chip-pair {
  flex: 0 0 auto;
  max-width: 130px;
  width: auto;
}
@media (max-width: 480px) {
  /* When label is hidden, lock pair chip to icon-only width */
  .bme-chip-pair {
    width: 36px;
    min-width: 36px;
    max-width: 36px;
    padding: 4px 0;
    justify-content: center;
  }
}
/* === end PWA-FIX-BUGS-3456-20260518 === */

/* ── Sync chip (SPEC-033 v3 — topbar integration 2026-05-21) ───── */
.bme-chip-sync {
  border-color: #2a3a2a;
  color: #9c9;
  gap: 6px;
  padding: 5px 8px;
}
.bme-chip-sync[data-state="ok"] {
  border-color: #2a4a2a;
  background: #0f1a0f;
  color: #9c9;
}
.bme-chip-sync[data-state="ok"] .bme-ss-dot { color: #4caf50; }
.bme-chip-sync[data-state="queued"] {
  border-color: #4a3a1a;
  background: #1a1408;
  color: #ffb300;
}
.bme-chip-sync[data-state="queued"] .bme-ss-dot { color: #ffb300; }
.bme-chip-sync[data-state="offline"] {
  border-color: #6a2020;
  background: #2a0a0a;
  color: #ff8a8a;
}
.bme-chip-sync[data-state="offline"] .bme-ss-dot { color: #e53935; }
.bme-chip-sync .bme-ss-dot {
  font-size: 13px;
  line-height: 1;
}
.bme-chip-sync .bme-ss-text {
  font-size: 11px;
  letter-spacing: 0.01em;
}
.bme-chip-sync .bme-ss-btn {
  appearance: none;
  -webkit-appearance: none;
  margin-left: 4px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 600;
  border: 1px solid #555;
  background: #222;
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
  min-height: 18px;
}
.bme-chip-sync .bme-ss-btn:active { background: #3a3a3a; }
.bme-chip-sync .bme-ss-btn:disabled { opacity: 0.4; cursor: default; }
