:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4d;
  --text: #e7edf4;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --danger: #f85149;
  --ok: #3fb950;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  background: radial-gradient(1200px 600px at 10% -10%, #1c2a3f 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.top {
  padding: 0.55rem 0.9rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.top h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.toolbar label {
  font-size: 0.9rem;
  color: var(--muted);
}

select,
input[type="text"],
textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  font-size: 0.95rem;
}

select:focus,
input:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button,
.btn-link {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
  display: inline-block;
  transition:
    transform 0.07s ease,
    filter 0.12s ease,
    box-shadow 0.12s ease,
    opacity 0.12s ease;
}

button:hover,
.btn-link:hover {
  filter: brightness(1.08);
}

button:active,
.btn-link:active {
  transform: scale(0.97);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.35);
}

button:disabled,
.btn-link:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button.mes-btn-busy,
.btn-link.mes-btn-busy {
  opacity: 0.75;
  cursor: wait;
  animation: mes-btn-pulse 0.9s ease-in-out infinite;
}

@keyframes mes-btn-pulse {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.15);
  }
}

body.mes-request-pending {
  cursor: wait;
}

body.mes-request-pending .tabs button:not(:disabled),
body.mes-request-pending .toolbar button:not(:disabled) {
  pointer-events: none;
  opacity: 0.88;
}

button.secondary {
  background: var(--border);
  color: var(--text);
}

button.danger {
  background: var(--danger);
}

.msg {
  margin: 0.35rem 0.9rem;
  min-height: 1.1rem;
  font-size: 0.82rem;
}

.msg.err {
  color: var(--danger);
}

.msg.ok {
  color: var(--ok);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0 0.9rem 0.4rem;
  border-bottom: 1px solid var(--border);
  align-items: flex-end;
}

.tabs button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.tabs button.active {
  background: var(--surface);
  color: var(--text);
  border-color: var(--accent);
}

.panel {
  display: none;
  padding: 0.75rem 1rem;
  max-width: 100%;
  width: 100%;
}

.panel.active {
  display: block;
}

/* 10 工位：统一扫码入口（服务端归类后对位到各框） */
input.mes-st10-scan-funnel {
  font-size: 1.05rem;
  padding: 0.55rem 0.65rem;
  border: 2px solid #2563eb;
  border-radius: 8px;
  width: 100%;
  max-width: 48rem;
}

section.panel[data-panel="10"] .mes-st10-scan-funnel:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.35);
}

/* Excel 布局 sort_order：工位面板内控件纵向排序 */
section.panel.active:not(.bootstrap-fail) {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

section.panel.active:not(.bootstrap-fail) > .mes-gui-row,
section.panel.active:not(.bootstrap-fail) > .field.mes-gui-row {
  flex: 0 0 auto;
}

section.panel.active:not(.bootstrap-fail) > .mes-st10-triplet {
  flex: 0 0 auto;
}

.mes-st10-triplet {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  background: rgba(255, 255, 255, 0.03);
}

.mes-st10-triplet-fields {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.mes-st10-triplet-fields .mes-gui-row {
  margin: 0;
}

.mes-st10-h3 {
  margin: 0 0 0.65rem 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.mes-st10-intro.hint.mes-gui-row {
  border-left: 3px solid var(--accent);
  padding-left: 0.65rem;
}

.mes-st10-resolve.mes-st10-resolved {
  color: #9bd49b;
}

a.btn-link.secondary {
  background: var(--border);
  color: var(--text);
}

/* —— 单工位终端 / 大屏（隐藏 Tab，仅一块面板） —— */
body.mes-terminal-page nav.tabs {
  display: none !important;
}

body.mes-terminal-page main#panels .panel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  margin-left: auto;
  margin-right: auto;
}

body.mes-terminal-page main#panels .panel.dash-panel {
  max-width: 92rem;
}

body.mes-terminal-page main#panels .panel:not(.dash-panel) {
  max-width: 100%;
}

.panel h2 {
  margin: 0 0 0.45rem;
  font-size: 0.96rem;
  font-weight: 600;
}

.panel.bootstrap-fail {
  max-width: 42rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(26, 35, 50, 0.85);
}

.panel.bootstrap-fail .btn-link {
  margin-top: 0.85rem;
}

.panel.bootstrap-fail p {
  margin: 0.65rem 0 0;
  line-height: 1.55;
}

.field {
  margin-bottom: 0.5rem;
}

.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.radio-row label {
  display: inline;
  margin-right: 1rem;
  color: var(--text);
}

.hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

/* 10工位：双栏卡片 + 关键件网格，避免右侧大面积空白 */
section.panel[data-panel="10"].active {
  display: flex !important;
  flex-direction: column;
  gap: 0.45rem;
}

.mes-st10-content {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(0, 0.82fr);
  gap: 0.7rem;
  align-items: start;
}

.mes-st10-col {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  background: rgba(255, 255, 255, 0.02);
}

.mes-st10-col .field {
  margin-bottom: 0.38rem;
}

.mes-st10-parts-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem 0.55rem;
}

.mes-st10-part-cell {
  margin-bottom: 0;
}

.mes-st10-bind-status {
  margin: 0.2rem 0 0;
}

.mes-st10-bind-status.mes-st10-bind-ok {
  color: #9bd49b;
}

.mes-st10-bind-status.mes-st10-bind-err {
  color: #ff8b8b;
}

section.panel[data-panel="10"] input[type="text"],
section.panel[data-panel="10"] textarea,
section.panel[data-panel="10"] select {
  padding: 0.32rem 0.45rem;
  font-size: 0.85rem;
}

section.panel[data-panel="10"] button {
  padding: 0.38rem 0.65rem;
  font-size: 0.82rem;
}

@media (max-width: 1500px) {
  .mes-st10-parts-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1200px) {
  .mes-st10-content {
    grid-template-columns: 1fr;
  }

  .mes-st10-parts-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .mes-st10-parts-grid {
    grid-template-columns: 1fr;
  }
}

textarea {
  width: 100%;
  min-height: 4rem;
  resize: vertical;
}

/* —— 看板 Dashboard —— */
.panel.dash-panel {
  max-width: 86rem;
}

.dash-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 48%);
  gap: 1.35rem;
  align-items: start;
}

.dash-top-main {
  min-width: 0;
}

.dash-top-aside {
  position: sticky;
  top: 0.75rem;
}

@media (max-width: 960px) {
  .dash-top {
    grid-template-columns: 1fr;
  }

  .dash-top-main {
    order: 1;
  }

  .dash-top-aside {
    order: 2;
    position: static;
  }
}

.dash-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 1rem;
}

.dash-top-aside .dash-hero {
  margin-bottom: 0;
  padding: 0.85rem;
}

.dash-top-aside .dash-hero-img {
  max-height: min(88vh, 820px);
}

.dash-top-aside .dash-hero-caption {
  margin-top: 0.7rem;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
  opacity: 0.92;
}

.dash-hero {
  margin: 0 0 1.35rem;
  padding: 0.65rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: linear-gradient(155deg, rgba(61, 139, 253, 0.08) 0%, var(--surface) 42%, #141c28 100%);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

.dash-hero-frame {
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  line-height: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.dash-hero-img {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(46vh, 340px);
  object-fit: contain;
  object-position: center center;
}

.dash-hero-caption {
  margin: 0.55rem 0 0;
  padding: 0 0.15rem;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
  letter-spacing: 0.03em;
}

.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.dash-card {
  background: linear-gradient(145deg, #1e2a3d 0%, #151d2b 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.dash-card-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.dash-card-value {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.dash-section-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 1.25rem 0 0.5rem;
  color: var(--muted);
}

section.panel.mes-simple-muted {
  opacity: 0.72;
  pointer-events: none;
}

body.mes-simple-flow button[data-simple-flow-disable]:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.dash-bars {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.dash-bar-row {
  display: grid;
  grid-template-columns: 5rem 1fr 2.5rem;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.dash-bar-label {
  color: var(--muted);
}

.dash-bar-track {
  height: 8px;
  background: #0d1218;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.dash-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, #238636, #3d8bfd);
  min-width: 4px;
  transition: width 0.35s ease;
}

.dash-bar-count {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.dash-recent {
  margin: 0 0 1rem;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.dash-recent li {
  margin-bottom: 0.25rem;
}

/* —— 10 工位错料声光报警 —— */
.alarm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: alarm-fade-in 0.2s ease-out;
}

@keyframes alarm-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.alarm-dialog {
  background: linear-gradient(180deg, #2a1f1f 0%, #1a1518 100%);
  border: 2px solid var(--danger);
  border-radius: 14px;
  max-width: 28rem;
  width: 100%;
  padding: 1.25rem 1.35rem;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(248, 81, 73, 0.35);
}

.alarm-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--danger);
  margin-bottom: 0.75rem;
  letter-spacing: 0.02em;
}

.alarm-body {
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--text);
  margin-bottom: 1.1rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.alarm-confirm {
  width: 100%;
  padding: 0.65rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  background: var(--danger);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
}

.alarm-confirm:hover {
  filter: brightness(1.08);
}

@keyframes alarm-pulse {
  0%,
  100% {
    box-shadow: inset 0 0 0 0 transparent;
  }
  50% {
    box-shadow: inset 0 0 0 5px rgba(248, 81, 73, 0.35);
  }
}

body.alarm-active {
  animation: alarm-pulse 0.85s ease-in-out 3;
}
