/* Trang /VirtualLeanbot-RC — bảng điều khiển tay cho Leanbot ảo.
   Trang tĩnh, đứng ngoài bundle Vue: CSS này không dùng chung với trang nào. */

:root {
  --rc-ink: #16202a;
  --rc-muted: #5d6b78;
  --rc-line: #d8e0e7;
  --rc-surface: #ffffff;
  --rc-ground: #eef2f5;
  --rc-accent: #2c5f85;
  --rc-signal: #c8352b;
  --rc-live: #1f9d55;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

.rc-page {
  position: relative;
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  background: var(--rc-ground);
  color: var(--rc-ink);
  font-family: Arial, Helvetica, sans-serif;
  overflow: hidden;
}

.rc-panel-right {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  min-width: 0;
  background: var(--rc-ground);
  overflow: hidden;
}

/* ------------------------------------------------------------------ header */

.rc-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: var(--rc-surface);
  border-bottom: 1px solid var(--rc-line);
  flex: 0 0 auto;
}

.rc-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 16px;
}

.rc-title-sub {
  color: var(--rc-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.rc-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  font-size: 13px;
  color: var(--rc-muted);
}

.rc-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--rc-muted);
}

.rc-status.is-live {
  color: var(--rc-live);
  font-weight: bold;
}

/* Trang tự khởi động nên phải nhìn ra ngay là đang bận hay đã điều khiển được:
   chấm vàng nhấp nháy = đang nạp, xanh = chạy, xám = dừng. */
.rc-status.is-loading {
  color: #d08b00;
}

.rc-status.is-loading .rc-status-dot {
  background: #d08b00;
  animation: rc-status-pulse 1s ease-in-out infinite;
}

@keyframes rc-status-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.25; }
}

.rc-status.is-live .rc-status-dot {
  background: var(--rc-live);
}

.rc-run-btn {
  min-width: 68px;
  height: 28px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: var(--rc-accent);
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 0.04em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease, background-color 0.15s ease;
}

.rc-run-btn:hover:not(:disabled) {
  filter: brightness(1.1);
}

.rc-run-btn.is-stop {
  background: var(--rc-signal);
}

.rc-run-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.rc-pause-btn {
  min-width: 72px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--rc-accent);
  border-radius: 4px;
  background: transparent;
  color: var(--rc-accent);
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 0.04em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.rc-pause-btn:hover:not(:disabled) {
  filter: brightness(1.1);
}

.rc-pause-btn.is-paused {
  background: var(--rc-accent);
  color: #fff;
}

.rc-pause-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* -------------------------------------------------------------------- twin */

/* Digital Twin 3D chiếm toàn bộ nửa màn hình bên trái */
.rc-twin {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  background: var(--rc-surface);
  border-right: 1px solid var(--rc-line);
  overflow: hidden;
}

.rc-twin-notice {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background: var(--rc-surface);
}

.rc-twin-notice[hidden] {
  display: none;
}

.rc-twin-notice-text {
  max-width: 46ch;
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--rc-muted);
}

.rc-twin-login {
  padding: 8px 18px;
  border-radius: 4px;
  background: var(--rc-accent);
  color: #fff;
  font-size: 13px;
  text-decoration: none;
}

.rc-twin-login:hover {
  filter: brightness(1.1);
}

.rc-twin-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* --------------------------------------------------------------------- tabs */

.rc-tabs-bar {
  display: flex;
  background: var(--rc-surface);
  border-bottom: 1px solid var(--rc-line);
  padding: 0 12px;
  gap: 4px;
  flex: 0 0 auto;
}

.rc-tab {
  position: relative;
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--rc-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
  white-space: nowrap;
}

.rc-tab:hover {
  color: var(--rc-ink);
  background: rgba(0, 0, 0, 0.02);
}

.rc-tab.is-active {
  color: var(--rc-accent);
  border-bottom-color: var(--rc-accent);
}

.rc-tab.has-unread::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #d08b00;
}

/* ---------------------------------------------------------------- tab panels */

.rc-tab-panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--rc-surface);
  overflow: hidden;
}

.rc-tab-panel[hidden] {
  display: none !important;
}

.rc-controls {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 24px 16px;
  background: var(--rc-surface);
  overflow-y: auto;
}

.rc-drive {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 260px;
  min-width: 0;
}

/* -------------------------------------------------------------------- dpad */

.rc-dpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  /* Chặn trên để D-pad không phình thành ba nút khổng lồ trên màn rộng. */
  max-width: 240px;
}

.rc-pad-btn {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  position: relative;
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: 50%;
  background: var(--rc-signal);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: background-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}

.rc-pad-btn:hover {
  filter: brightness(1.12);
}

.rc-pad-btn:active {
  transform: translateY(1px);
}

.rc-pad-btn.is-active {
  background: var(--rc-live);
  color: #ffffff;
  transform: scale(1.06);
  box-shadow: 0 0 0 3px #ffffff, 0 0 0 6px var(--rc-live), 0 4px 12px rgba(31, 157, 85, 0.5);
  filter: brightness(1.08);
  z-index: 2;
}

.rc-pad-btn.is-active:hover {
  filter: brightness(1.15);
}

.rc-pad-stop {
  background: #17a2b8;
  font-size: 18px;
}

.rc-pad-btn.is-pressed:not(.is-active) {
  transform: scale(0.94);
  filter: brightness(1.15);
}

.rc-pad-stop.is-active,
.rc-pad-stop.is-pressed {
  background: #c8352b !important;
  color: #ffffff;
  transform: scale(1.06);
  box-shadow: 0 0 0 3px #ffffff, 0 0 0 6px #c8352b, 0 4px 12px rgba(200, 53, 43, 0.5);
  filter: brightness(1.1);
  z-index: 2;
}

/* Mũi tên tam giác D-pad chuẩn vector, xoay theo hướng lệnh */
.rc-arrow {
  width: 24px;
  height: 24px;
  display: block;
  pointer-events: none;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 0.8;
  stroke-linejoin: round;
  transform-origin: 50% 50%;
  transition: transform 0.12s ease;
}

.rc-pad-btn[data-cmd="F"] .rc-arrow { transform: rotate(0deg); }
.rc-pad-btn[data-cmd="I"] .rc-arrow { transform: rotate(45deg); }
.rc-pad-btn[data-cmd="R"] .rc-arrow { transform: rotate(90deg); }
.rc-pad-btn[data-cmd="J"] .rc-arrow { transform: rotate(135deg); }
.rc-pad-btn[data-cmd="B"] .rc-arrow { transform: rotate(180deg); }
.rc-pad-btn[data-cmd="H"] .rc-arrow { transform: rotate(225deg); }
.rc-pad-btn[data-cmd="L"] .rc-arrow { transform: rotate(270deg); }
.rc-pad-btn[data-cmd="G"] .rc-arrow { transform: rotate(315deg); }

/* Mã byte thật sự gửi xuống Serial — để đối chiếu với sketch Arduino. */
.rc-byte {
  position: absolute;
  right: 7px;
  bottom: 5px;
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  opacity: 0.85;
  pointer-events: none;
}

/* Nút D-pad hình tròn nên dịch byte vào trong để không bị cong viền che khuất */
.rc-pad-btn .rc-byte {
  right: 14px;
  bottom: 10px;
  font-size: 14px;
  font-weight: 700;
  opacity: 1;
}

.rc-byte-inline {
  position: static;
  min-width: 10px;
  color: var(--rc-muted);
  opacity: 1;
}

.rc-byte-inline[hidden] {
  display: none;
}

/* ------------------------------------------------------------------- speed */

.rc-speed {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 280px;
  font-size: 13px;
}

.rc-speed label {
  color: var(--rc-muted);
}

.rc-speed input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
}

.rc-speed-value {
  min-width: 20px;
  text-align: right;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------------- actions */

.rc-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: center;
  gap: 8px;
  width: 100%;
  max-width: 320px;
  margin: 0;
}

.rc-action {
  position: relative;
  padding: 10px 38px 10px 22px;
  border: 1px solid var(--rc-line);
  border-radius: 6px;
  background: #f7f9fb;
  color: var(--rc-ink);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

.rc-action:hover:not(:disabled) {
  border-color: var(--rc-accent);
  background: #f0f4f8;
}

.rc-action::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #cfd8dc;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.rc-action:disabled::before {
  display: none;
}

.rc-action.is-active {
  background: #eaf3fa;
  border-color: #2c5f85;
  color: #143750;
  font-weight: 600;
  box-shadow: 0 0 0 2px rgba(44, 95, 133, 0.25);
}

.rc-action.is-active::before {
  background: #1f9d55;
  box-shadow: 0 0 6px rgba(31, 157, 85, 0.8);
}

.rc-action.is-pressed {
  transform: scale(0.96);
  background: #d6eaf8;
  border-color: #1976d2;
  box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.35);
}

.rc-action .rc-byte {
  position: absolute;
  right: 7px;
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
  padding: 2px 7px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.08);
  font-family: "Courier New", Courier, monospace;
  font-size: 14px;
  font-weight: 700;
  color: var(--rc-ink);
}

.rc-action.is-active .rc-byte {
  background: rgba(44, 95, 133, 0.12);
  border-color: rgba(44, 95, 133, 0.3);
  color: #143750;
  font-weight: 700;
}

/* Nút tạm khoá: xám hẳn đi để khỏi nhầm với nút mờ do chương trình chưa chạy
   (cụm .is-disabled chỉ giảm opacity cả mảng). */
.rc-action:disabled {
  background: #eceff2;
  color: #9aa8b4;
  cursor: not-allowed;
  border-color: var(--rc-line);
}

.rc-action-wide {
  grid-column: span 2;
}

.rc-dpad.is-disabled,
.rc-actions.is-disabled {
  opacity: 0.45;
}

/* Line Tracking là trạng thái ĐANG CHẠY, không phải toggle bật/tắt như đèn hay
   kẹp — nên nó dùng đúng ngôn ngữ highlight của D-pad (nền xanh live + chữ
   trắng + vòng sáng) thay vì kiểu nhấn nhẹ của các nút action còn lại. Vòng
   sáng để 4px thôi vì khe lưới .rc-actions chỉ 8px, 6px như D-pad sẽ đè lên
   nút phía trên. */
.rc-action[data-cmd="T"].is-active {
  background: var(--rc-live);
  border-color: var(--rc-live);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px var(--rc-live), 0 4px 12px rgba(31, 157, 85, 0.5);
  filter: brightness(1.05);
  z-index: 2;
}

/* Giữ phản hồi hover giống D-pad: đang active mà rê chuột thì sáng lên, không
   bị rule hover chung kéo về nền nhạt. */
.rc-action[data-cmd="T"].is-active:hover:not(:disabled) {
  background: var(--rc-live);
  border-color: var(--rc-live);
  filter: brightness(1.12);
}

/* Chấm trạng thái và ô mã byte phải đổi màu theo, không thì chìm vào nền xanh. */
.rc-action[data-cmd="T"].is-active::before {
  background: #ffffff;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.9);
}

.rc-action[data-cmd="T"].is-active .rc-byte {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
  color: #ffffff;
  font-weight: 700;
}

/* ----------------------------------------------------------------- console */

.rc-pane-serial,
.rc-pane-log {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  background: var(--rc-surface);
  overflow: hidden;
}

.rc-log-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--rc-muted);
}

.rc-console-head {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  flex: 0 0 auto;
}

.rc-console-legend {
  display: flex;
  gap: 10px;
  color: var(--rc-muted);
}

.rc-legend::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 4px;
  border-radius: 2px;
}

.rc-legend-tx::before {
  background: var(--rc-accent);
}

.rc-legend-rx::before {
  background: var(--rc-live);
}

.rc-console-clear {
  margin-left: auto;
  padding: 3px 10px;
  border: 1px solid var(--rc-line);
  border-radius: 4px;
  background: #f7f9fb;
  font-size: 11px;
  cursor: pointer;
}

/* Copy + Clear đứng cạnh nhau: chỉ nút đầu tiên đẩy cả nhóm sang phải. */
.rc-console-clear + .rc-console-clear {
  margin-left: 0;
}

.rc-console-output {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 6px 8px;
  background: #10161c;
  border-radius: 4px;
  color: #d7e2ec;
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  line-height: 1.45;
  /* Giữ newline gốc; dòng dài cuộn ngang, không tự xuống dòng. */
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}

.rc-console-line {
  display: inline;
}

.rc-console-err {
  color: #ff8a7a;
}

.rc-console-tx {
  color: #7fc2ff;
}

.rc-console-rx {
  color: #7ee2a8;
}

.rc-console-sys {
  color: #9aa8b4;
}

.rc-console-input {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rc-console-input input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--rc-line);
  border-radius: 4px;
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
}

.rc-newline-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--rc-muted);
  white-space: nowrap;
}

.rc-send-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 4px;
  background: var(--rc-accent);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
}

.rc-send-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Runner Brython: chạy ngầm, không chiếm chỗ nhưng KHÔNG display:none — iframe
   ẩn hẳn có thể bị trình duyệt hoãn việc chạy script. */
.rc-runner-frame {
  position: absolute;
  width: 0;
  height: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

/* ------------------------------------------------------------------ narrow */

@media (max-width: 800px) {
  .rc-page {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 45vh 55vh;
  }

  .rc-twin {
    border-right: none;
    border-bottom: 1px solid var(--rc-line);
  }
}

.rc-ide-link { color: var(--rc-accent); font-size: 12px; white-space: nowrap; text-decoration: none; }
.rc-ide-link:hover { text-decoration: underline; }
