:root {
  --bg-main: #0b1220;
  --bg-card: #16233a;
  --bg-card-soft: #1b2d4a;
  --border-color: #2f5fa9;
  --text-primary: #d9ecff;
  --text-secondary: #aac7ea;
  --text-dim: #86abd8;
  --color-run: #33d7c3;
  --color-stop: #e46aa2;
  --color-sleep: #4b71d9;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  font-family: 'Montserrat', sans-serif;
  background: radial-gradient(circle at 20% 0%, #142a4e 0%, var(--bg-main) 55%);
  color: var(--text-primary);
  overflow: hidden;
}

.app-shell {
  width: min(100vw, 460px);
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  border-left: 1px solid #1f3f70;
  border-right: 1px solid #1f3f70;
}

.top-bar {
  flex: 0 0 126px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  background: linear-gradient(180deg, #173160 0%, #112649 100%);
}

.top-left {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.logo {
  font-size: 21px;
  letter-spacing: 1px;
  font-weight: 700;
}

.machine-block {
  display: flex;
  flex-direction: column;
}

.machine-no {
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.machine-status {
  font-size: 11px;
  color: #77ffa7;
  letter-spacing: 0.4px;
}

.top-center {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.nav-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: 12px;
  flex: 1;
  padding: 7px 6px;
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
  transition: all 0.2s;
}

.nav-btn:hover {
  background: #214074;
  color: var(--text-primary);
}

.nav-btn.active {
  background: #2f6fcb;
  color: #fff;
  border-color: #4f8feb;
}

.top-right {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.status-item-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}

.status-label {
  color: var(--text-dim);
  font-weight: 600;
}

.status-value {
  color: var(--text-primary);
  font-weight: 700;
}

.machine-nav {
  display: flex;
  gap: 4px;
}

.machine-btn {
  border: 1px solid var(--border-color);
  background: #1b3563;
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 700;
  border-radius: 7px;
  padding: 5px 7px;
  cursor: pointer;
}

.machine-btn-set {
  background: #2dbf84;
  color: #00180d;
}

.clock {
  font-size: 14px;
  font-weight: 700;
}

.content-main {
  flex: 1;
  min-height: 0;
  padding: 10px;
  overflow: hidden;
}

.screen {
  display: none;
  height: 100%;
  overflow: auto;
}

.screen.screen-active {
  display: block;
}

.op-title-block {
  background: linear-gradient(180deg, #1a3769 0%, #17305b 100%);
  border: 1px solid #4b7fcb;
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 10px;
}

.op-title-main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.op-title-machine {
  font-size: 15px;
  color: #a4c8f5;
  font-weight: 600;
}

.op-title-machine span {
  color: #e6f2ff;
  font-weight: 700;
}

.op-title-name {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.4px;
}

.op-title-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.op-chip {
  background: #102446;
  border: 1px solid #3566ab;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 10px;
  color: #9fc0ea;
}

.op-chip span {
  color: #e6f2ff;
  font-weight: 700;
}

.op-layout {
  display: grid;
  grid-template-columns: 148px 1fr;
  gap: 10px;
}

.status-panel {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 8px;
}

.box-header {
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 600;
}

.box-value {
  margin-top: 3px;
  font-size: 13px;
  font-weight: 700;
}

.gauge-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gauge-section {
  background: var(--bg-card-soft);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 8px;
}

.gauge-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.gauge-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.gauge-item {
  background: #13233e;
  border: 1px solid #2a507f;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
}

.arc-svg {
  width: 62px;
  height: 50px;
}

.arc-name {
  font-size: 9px;
  fill: #93b8ea;
}

.arc-val {
  font-size: 10px;
  font-weight: 700;
  fill: #dcecff;
}

.amb-grid {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 8px;
}

.amb-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10px;
}

.amb-name {
  font-weight: 700;
  color: var(--text-dim);
}

.vbar-wrap {
  width: 18px;
  height: 58px;
  background: #0d1c33;
  border: 1px solid #284977;
  border-radius: 3px;
}

.vbar-track {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column-reverse;
}

.vbar-fill {
  width: 100%;
  background: linear-gradient(180deg, #80ffc6, #2dbf84);
}

.air-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.air-item {
  display: grid;
  grid-template-columns: 92px 1fr 56px;
  align-items: center;
  gap: 6px;
  font-size: 10px;
}

.air-name {
  color: var(--text-dim);
  font-weight: 700;
}

.hbar-track {
  height: 10px;
  background: #0d1c33;
  border: 1px solid #284977;
  border-radius: 999px;
  overflow: hidden;
}

.hbar-fill {
  height: 100%;
  background: linear-gradient(90deg, #ffdb7a, #ff9e5a);
}

.air-val {
  text-align: right;
  font-weight: 700;
}

.ign-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.ign-enable-chip {
  background: #7b86ff;
  border-radius: 999px;
  color: #fff;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 700;
}

.ign-enable-chip.on {
  background: #2dbf84;
  color: #072314;
}

.ign-state {
  font-size: 10px;
  color: var(--text-secondary);
  font-weight: 700;
}

.ign-pill {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #223556;
}

.ign-temps {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ign-temp-row {
  display: grid;
  grid-template-columns: 22px 1fr 72px;
  gap: 6px;
  align-items: center;
  font-size: 10px;
}

.ign-temp-name {
  color: var(--text-dim);
  font-weight: 700;
}

.mini-bar-wrap {
  height: 8px;
  background: #0d1c33;
  border: 1px solid #284977;
  border-radius: 999px;
  overflow: hidden;
}

.mini-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #ffd27a, #ff7f52);
}

.ign-temp-val {
  text-align: right;
  font-size: 10px;
  font-weight: 700;
}

.ign-queue {
  margin-top: 6px;
  font-size: 10px;
  color: var(--text-secondary);
}

.status-badges {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  background: #1c3765;
  border: 1px solid #3465a7;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 10px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.stat-box,
.payload-section,
.parsed-section,
.setup-card,
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px;
}

.stat-label,
.payload-title,
.parsed-title,
.setup-card-title {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 700;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
}

.raw-json-view {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  font-size: 11px;
  background: #0f1a2f;
  border: 1px solid #2b4d7e;
  border-radius: 6px;
  padding: 8px;
  min-height: 44px;
  white-space: pre-wrap;
  word-break: break-word;
}

.parsed-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.parsed-item {
  background: #0f1a2f;
  border: 1px solid #2b4d7e;
  border-radius: 6px;
  padding: 5px;
  font-size: 10px;
}

.setup-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quick-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.quick-btn,
.action-btn {
  border: none;
  border-radius: 8px;
  background: #8fd8ff;
  color: #07243d;
  font-size: 11px;
  font-weight: 700;
  padding: 8px;
  cursor: pointer;
}

.json-textarea {
  width: 100%;
  min-height: 90px;
  resize: vertical;
  border: 1px solid #2b4d7e;
  border-radius: 8px;
  background: #0f1a2f;
  color: #dcecff;
  padding: 8px;
  font-size: 11px;
  margin-bottom: 6px;
}

.setup-actions,
.review-controls,
.popup-actions,
.helper-row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.table-wrap {
  overflow: auto;
  max-height: 360px;
}

.msg-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.msg-table th,
.msg-table td {
  padding: 8px;
  border-bottom: 1px solid #284977;
  text-align: left;
}

.payload-cell {
  max-width: 420px;
  word-break: break-word;
}

.bottom-command-bar {
  flex: 0 0 100px;
  border-top: 1px solid var(--border-color);
  background: linear-gradient(180deg, #12294d 0%, #0f203d 100%);
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  padding: 10px;
  align-items: stretch;
}

.btn-action {
  border: none;
  border-radius: 14px;
  color: #fff;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 18px;
  cursor: pointer;
}

.btn-icon {
  font-size: 18px;
}

.btn-text {
  font-size: 22px;
  letter-spacing: 0.5px;
}

.btn-run {
  background: var(--color-run);
  color: #04211a;
}

.btn-stop {
  background: var(--color-stop);
}

.btn-sleep {
  background: var(--color-sleep);
  font-size: 12px;
  min-width: 70px;
}

.publish-result {
  min-width: 0;
  border: 1px solid #2b4d7e;
  border-radius: 10px;
  background: #11294d;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 0 8px;
  grid-column: 1 / span 3;
  min-height: 30px;
}

.publish-result.err {
  color: #ff9bb8;
}

.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.popup-panel {
  width: min(96vw, 760px);
  background: linear-gradient(180deg, #1b3a72 0%, #17315f 100%);
  border: 2px solid #5e95e7;
  border-radius: 22px;
  padding: 24px;
}

.popup-small {
  width: min(92vw, 520px);
}

.popup-title {
  font-size: 36px;
  font-weight: 500;
  margin-bottom: 18px;
  text-align: center;
}

.recipe-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}

.recipe-btn {
  border: none;
  border-radius: 16px;
  padding: 24px 14px;
  font-size: 40px;
  font-weight: 500;
  color: #fff;
  cursor: pointer;
}

.popup-cancel-btn,
.popup-no-btn,
.popup-yes-stop {
  flex: 1;
  border: none;
  border-radius: 14px;
  padding: 16px 12px;
  font-size: 30px;
  font-weight: 500;
  cursor: pointer;
}

.popup-cancel-btn,
.popup-no-btn {
  background: #2f6fcb;
  color: #eaf4ff;
}

.popup-yes-stop {
  background: #d44b83;
  color: #fff;
}

@media (max-width: 760px) {
  .app-shell {
    width: 100vw;
    border: none;
  }

  .top-bar {
    flex: 0 0 134px;
  }

  .op-layout {
    grid-template-columns: 1fr;
  }

  .status-panel {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .bottom-command-bar {
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: 52px;
    flex: 0 0 auto;
  }

  .publish-result {
    grid-column: 1 / span 2;
    min-width: 0;
  }

  .btn-sleep {
    min-width: 0;
  }
}
