:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel2: #1c222c;
  --border: #2b323d;
  --text: #e6edf3;
  --muted: #9aa7b4;
  --accent: #4aa3ff;
  --green: #2ecc40;
  --amber: #f0ad4e;
  --red: #e74c3c;
  --blue: #5dade2;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 20px;
  background: linear-gradient(180deg, #1a212c, #11161d);
  border-bottom: 1px solid var(--border);
}

.brand h1 { margin: 0; font-size: 20px; }
.brand .accent { color: var(--accent); }
.subtitle { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

.btn {
  background: var(--accent);
  color: #06121f;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn-sec { background: var(--panel2); color: var(--text); border: 1px solid var(--border); }
.btn-sec.active { background: var(--amber); color: #1a1207; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.dropzone {
  margin: 14px 20px;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel);
  font-size: 13px;
}
.dropzone.drag { border-color: var(--accent); color: var(--text); }
.dropzone code { color: var(--accent); }

.status { margin: 0 20px 10px; color: var(--muted); font-size: 13px; }

.panel {
  margin: 12px 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.panel h2 { margin: 0 0 10px; font-size: 15px; color: var(--text); }

.dev-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.dev-row.dev-row-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .dev-row { grid-template-columns: 1fr; } }

.device {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}
.device.tx { border-top: 3px solid var(--amber); }
.device.rx { border-top: 3px solid var(--green); }

.device-head { display: flex; align-items: center; justify-content: space-between; }
.device-title { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.dev-sub { color: var(--muted); font-size: 11px; margin: 4px 0; word-break: break-word; }
.dev-sub.small { font-size: 10px; }
.dev-empty { color: var(--muted); font-style: italic; padding: 14px 4px; }

.mod-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 5px; font-weight: 700; font-size: 12px;
  background: #2a3542; color: var(--text);
}
.mod-A { background: #355c7d; }
.mod-B { background: #6c5b7b; }
.mod-C { background: #2a6f5a; }

.conn-led {
  width: 12px; height: 12px; border-radius: 50%;
  background: #444; border: 1px solid #222;
}
.conn-led.on { background: var(--green); box-shadow: 0 0 6px var(--green); }

.power {
  display: block; width: 100%; margin: 6px 0; background: var(--panel);
  color: var(--text); border: 1px solid var(--border);
}
.power.on { background: var(--green); color: #06210b; border-color: var(--green); }

.rf-label { font-weight: 600; font-size: 13px; margin: 4px 0; color: var(--blue); }

.device.rx.jammed { border-top-color: var(--red); }
.rx-jam {
  margin: 4px 0; padding: 6px 8px; border-radius: 6px;
  background: rgba(231, 76, 60, 0.15); border: 1px solid var(--red);
  color: var(--red); font-weight: 600; font-size: 12px; line-height: 1.3;
}
.rx-jam.active { animation: jamBlink 0.8s ease-in-out infinite; }
.rx-jam.warn {
  background: rgba(243, 156, 18, 0.15); border-color: var(--orange, #f39c12);
  color: var(--orange, #f39c12);
}
.rx-jam.warn.active { animation: warnBlink 1.2s ease-in-out infinite; }

.roles-panel-details { margin: 0; }
.roles-panel-details summary { cursor: pointer; font-weight: 600; }
.role-map-hint { font-size: 12px; color: var(--muted, #888); margin: 6px 0; line-height: 1.35; }
.role-map-block { margin: 6px 0; font-size: 12px; }
.role-map-block summary { cursor: pointer; font-weight: 600; color: var(--blue); }
.role-map-tbl { width: 100%; border-collapse: collapse; margin-top: 4px; font-size: 12px; }
.role-map-tbl th, .role-map-tbl td { border: 1px solid var(--border); padding: 3px 5px; text-align: left; }
.role-map-tbl th { background: var(--panel); }
.role-map-inp { width: 5.5em; padding: 2px 4px; border-radius: 4px; border: 1px solid var(--border); background: var(--panel); color: var(--text); }
.role-map-tab { color: var(--muted, #888); }
.role-num-row { display: flex; align-items: center; gap: 6px; margin: 3px 0; font-size: 13px; }
.role-num-nr { font-weight: 600; min-width: 4.5em; }
@keyframes jamBlink {
  0%, 100% { background: rgba(231, 76, 60, 0.15); }
  50% { background: rgba(231, 76, 60, 0.35); }
}
@keyframes warnBlink {
  0%, 100% { background: rgba(243, 156, 18, 0.12); }
  50% { background: rgba(243, 156, 18, 0.28); }
}

.rotary { display: flex; align-items: center; gap: 6px; margin: 6px 0; flex-wrap: wrap; }
.rotary.num-sel-row .ns-offset-lbl { font-size: 12px; color: var(--muted, #888); margin-left: 4px; }
.rotary .ns-offset-inp {
  width: 3.2em; padding: 4px 6px; border-radius: 5px;
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
}
.rotary select {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 4px 6px;
}
.rotary select.rotary-select-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}
.rotary-dial-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  margin: 0;
}
.rotary-dial-outer {
  position: relative; width: 158px; height: 158px; flex-shrink: 0;
}
.rotary-dial-outer.disabled { opacity: 0.55; pointer-events: none; filter: grayscale(0.35);
}
.rotary-dial-svg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 0;
}
.rotary-leader {
  stroke: #6a7380; stroke-width: 0.55; vector-effect: non-scaling-stroke;
}
.rotary-leader.active { stroke: #1a1a1a; stroke-width: 0.85; }
.rotary-dial {
  position: absolute; left: 50%; top: 50%;
  width: 76px; height: 76px; margin: -38px 0 0 -38px;
  border-radius: 50%;
  background: #b8bcc6;
  border: 2px solid #1a1a1a;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
  cursor: grab; touch-action: none; user-select: none; z-index: 2;
}
.rotary-dial.dragging { cursor: grabbing; }
.rotary-dial.disabled { pointer-events: none; cursor: not-allowed; }
.rotary-dial:focus { outline: 2px solid var(--accent); outline-offset: 3px; }
.rotary-dial-handle {
  position: absolute; left: 50%; top: 50%;
  width: 32px; height: 9px; margin: -4.5px 0 0 -3px;
  transform-origin: 4px 50%;
  background: #eceef2;
  border: 2px solid #111;
  border-radius: 5px;
  transition: transform 0.12s ease-out;
  pointer-events: none; z-index: 3;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.rotary-dial-notch {
  position: absolute; right: 3px; top: 50%; width: 5px; height: 5px;
  margin-top: -2.5px; border: 1.5px solid #111; border-radius: 1px;
  background: transparent; box-sizing: border-box;
}
.rotary-pos-hit {
  position: absolute; width: 36px; height: 18px; padding: 0; border: none;
  background: transparent; transform: translate(-50%, -50%);
  cursor: pointer; z-index: 4; border-radius: 4px;
}
.rotary-pos-hit:hover + .rotary-pos-lbl,
.rotary-pos-lbl:hover { color: #fff; }
.rotary-pos-lbl {
  position: absolute; font-size: 10px; font-weight: 700; color: #d8dee6;
  transform: translate(-50%, -50%);
  pointer-events: none; white-space: nowrap; text-align: center;
  font-family: Consolas, "Segoe UI", sans-serif;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  z-index: 5; letter-spacing: 0.02em;
}
.rotary-pos-lbl.active {
  color: #111; font-size: 11px;
  background: #eceef2; padding: 1px 5px; border-radius: 3px;
  border: 1.5px solid #111;
  text-shadow: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
.rotary-dial-caption {
  font-size: 10px; font-weight: 600; color: var(--muted); text-align: center;
  max-width: 150px; line-height: 1.2;
}
.rotary-dial-caption.active { color: var(--text); }

.tx-control-row {
  display: flex; align-items: flex-start; gap: 10px; margin: 8px 0;
}
.tx-dial-col { flex: 0 0 auto; min-width: 0; }
.tx-dial-label {
  font-size: 11px; color: var(--muted); text-align: center; margin-bottom: 2px;
}
.tx-offset-row {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  margin-top: 2px; font-size: 11px;
}
.tx-offset-row .ns-offset-inp { width: 2.8em; padding: 2px 4px; }
.tx-btn-col {
  display: flex; flex-direction: column; gap: 4px; flex: 1 1 auto; min-width: 72px;
}
.tx-btn-col-solo { max-width: 120px; margin: 8px 0; }
.tx-mbtn {
  width: 100%; min-width: 0; padding: 6px 8px; font-size: 11px;
}

.rotary.num-sel-row { align-items: flex-start; }
.rotary.num-sel-row > label:first-child { margin-top: 88px; }

.btn-stop {
  display: block; width: 100%; margin: 6px 0;
  background: #5a2230; color: #ffd7df; border: 1px solid #7a2b3c;
}
.btn-stop.active { background: var(--red); color: #2a0508; }

.btn-bar { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.mbtn {
  flex: 1 1 auto; min-width: 56px; padding: 8px 6px;
  background: #243042; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; cursor: pointer; user-select: none; font-size: 12px;
}
.mbtn:active { background: var(--accent); color: #06121f; }

.io-block { margin-top: 8px; }
.io-details { margin-top: 8px; }
.io-details > summary { cursor: pointer; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.io-details-body { margin-top: 4px; }
.rx-editor-host { margin-top: 8px; }
.io-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }

.lamp-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.lamp-cell { display: flex; flex-direction: column; align-items: center; gap: 2px; max-width: 52px; }
.lamp {
  width: 20px; height: 20px; border-radius: 50%;
  background: #3a3a3a; border: 1px solid #222;
}
.lamp.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
.lamp-name { font-size: 8px; color: var(--muted); text-align: center; line-height: 1.15; word-break: break-word; }

.vbit-grid { display: grid; grid-template-columns: repeat(22, 1fr); gap: 2px; }
.vbit {
  width: 100%; aspect-ratio: 1 / 1; min-width: 7px;
  background: #333; border: 1px solid #444; border-radius: 2px;
}
.vbit.on { background: var(--blue); border-color: var(--blue); }

.frame-wrap { margin-top: 8px; }
.frame-bits { display: grid; grid-template-columns: repeat(16, 1fr); gap: 2px; }
.frame-bit {
  font-size: 8px; text-align: center; padding: 3px 0;
  background: #2a2f38; border: 1px solid var(--border); border-radius: 3px; color: var(--muted);
}
.frame-bit.on { background: var(--amber); color: #1a1207; border-color: var(--amber); font-weight: 700; }

.rx-frame {
  margin-top: 8px; font-family: Consolas, monospace; font-size: 11px;
  color: var(--muted); word-break: break-all;
}

/* Edytor konfiguracji RX */
.rx-cfg-editor {
  margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border);
}
.rx-cfg-tabs { display: flex; gap: 4px; margin-bottom: 4px; }
.rx-cfg-tab {
  padding: 4px 10px; font-size: 11px; cursor: pointer;
  background: var(--panel); color: var(--muted); border: 1px solid var(--border);
  border-radius: 5px 5px 0 0;
}
.rx-cfg-tab.active { background: var(--panel2); color: var(--text); border-bottom-color: var(--panel2); }
.rx-cfg-src {
  width: 100%; min-height: 140px; max-height: 280px; resize: vertical;
  font-family: Consolas, "Courier New", monospace; font-size: 11px; line-height: 1.35;
  background: #0d1117; color: #c9d1d9; border: 1px solid var(--border); border-radius: 0 5px 5px 5px;
  padding: 8px; tab-size: 4;
}
.rx-cfg-src.hidden { display: none; }
.rx-cfg-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.rx-cfg-btns .btn { font-size: 12px; padding: 6px 10px; }
.rx-cfg-msg { font-size: 11px; margin-top: 4px; min-height: 1.2em; color: var(--muted); }
.rx-cfg-msg.ok { color: var(--green); }
.rx-cfg-msg.err { color: var(--red); }

.tx-quick-actions {
  display: flex; flex-direction: column; gap: 6px; margin: 8px 0;
}
.tx-quick-actions .rfid-btn,
.tx-quick-actions .btn-stop {
  display: block; width: 100%; margin: 0;
}
.tx-quick-actions .rfid-status { font-size: 11px; color: var(--muted); margin-top: -2px; }
.tx-quick-actions .rfid-status.ok { color: var(--blue); font-weight: 600; }

.rx-pwr-btn { margin-top: 10px; width: 100%; }

.rfid-block {
  margin: 8px 0; padding: 8px; border-radius: 6px;
  background: rgba(93, 173, 226, 0.08); border: 1px solid rgba(93, 173, 226, 0.35);
}
.rfid-btn {
  display: block; width: 100%; margin: 4px 0;
  background: #243042; color: var(--text); border: 1px solid var(--border);
}
.rfid-btn.on { background: #2a5a8a; border-color: var(--blue); color: #e8f4ff; }
.rfid-status { font-size: 11px; color: var(--muted); }
.rfid-status.ok { color: var(--blue); font-weight: 600; }

.foot {
  margin: 16px 20px; padding-top: 10px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: 12px;
}
