:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --text: #14213d;
  --muted: #64748b;
  --border: #dbe3ee;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --ok: #15803d;
  --ok-soft: #f0fdf4;
  --log-bg: #0b1220;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.05);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 500px at 10% -10%, #e0ecff 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  min-height: 100vh;
}

h1, h2, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.topbar {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 20px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #2563eb, #7c3aed);
  color: #fff; font-weight: 800; letter-spacing: 0.5px; font-size: 13px;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28);
}
h1 { font-size: 20px; font-weight: 700; letter-spacing: 0.2px; }
.subtitle { color: var(--muted); font-size: 12px; margin-top: 2px; }
.version {
  margin-left: 4px; padding: 2px 8px; border-radius: 999px;
  background: #e8eefb; color: #3557a6; font-size: 11px; font-weight: 600;
}

.pill {
  padding: 7px 13px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap;
}
.pill-idle { background: #eef2f7; color: #52627a; border-color: #dbe3ee; }
.pill-busy { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.pill-ready { background: #ecfdf5; color: #15803d; border-color: #bbf7d0; }
.pill-error { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.pill-warn { background: #fffbeb; color: #b45309; border-color: #fde68a; }

.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 20px 0;
  display: grid;
  grid-template-columns: minmax(300px, 0.86fr) minmax(0, 1.4fr);
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
h2 { font-size: 15px; font-weight: 700; letter-spacing: 0.2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #f8fafc; border-color: #c6d2e3; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.primary:disabled { background: #93b4f5; border-color: #93b4f5; }
.btn.small { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn.big { width: 100%; padding: 12px; font-size: 15px; margin-top: 4px; }
.btn.danger { background: #fff; color: var(--danger); border-color: #fecaca; }

.field { margin-bottom: 12px; }
.field label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; font-weight: 600; }
select, input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  padding: 9px 10px;
  outline: none;
}
select:focus, input[type="text"]:focus, input[type="checkbox"]:focus-visible, button:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 1px;
}
select:disabled, input:disabled { background: #f8fafc; color: #94a3b8; }

.check { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px; font-weight: 600; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
.hint.warn-text { color: var(--warn); }
.danger-text { color: var(--danger); }
.advanced { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 10px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 12px; font-weight: 600; }

.kv {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 6px 10px;
  margin: 0 0 16px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid #e8eef7;
  border-radius: 10px;
}
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }

.mode { display: flex; gap: 12px; font-size: 13px; }
.mode label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.mode input { accent-color: var(--accent); }

.fw-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.fw-status { color: var(--muted); font-size: 11px; white-space: nowrap; }
.panel-head + .hint { margin: 0 0 12px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
thead th {
  text-align: left; font-size: 11px; letter-spacing: 0.4px; text-transform: uppercase;
  color: var(--muted); background: #f8fafc; padding: 9px 10px; border-bottom: 1px solid var(--border);
}
tbody td { padding: 8px 10px; border-bottom: 1px solid #eef2f7; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.invalid { background: #fff7f7; }
tbody td select { min-width: 180px; }
tbody td input[type="text"] { width: 110px; font-family: ui-monospace, Consolas, monospace; }
.cell-size { color: var(--muted); font-size: 12px; white-space: nowrap; }
.icon-btn {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  cursor: pointer; border-radius: 8px; padding: 4px 8px; line-height: 1;
}
.icon-btn:hover { background: #fef2f2; color: var(--danger); }
.row-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; }
.total { color: var(--muted); font-size: 12px; }
.total strong { color: var(--text); font-size: 13px; }

.errors {
  margin: 8px 0 12px; padding: 10px 12px; border-radius: 10px;
  background: var(--danger-soft); border: 1px solid #fecaca; color: #991b1b; font-size: 12px;
}
.errors ul { margin: 0; padding-left: 18px; }
.errors li + li { margin-top: 4px; }
.errors.warn { background: var(--warn-soft); border-color: #fde68a; color: #92400e; }

.banner {
  max-width: 1140px;
  margin: 0 auto 8px;
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 13px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1e40af;
}
.banner-error { border-color: #fecaca; background: #fef2f2; color: #991b1b; }
.banner-warn { border-color: #fde68a; background: #fffbeb; color: #92400e; }
.banner-ok { border-color: #bbf7d0; background: #f0fdf4; color: #166534; }

.progress-panel { max-width: 1140px; margin: 16px auto 0; }
.progress-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.progress {
  height: 12px; border-radius: 999px; background: #e8eef7; overflow: hidden;
  border: 1px solid #dbe3ee;
}
#progress-bar {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, #2563eb, #7c3aed);
  transition: width 0.15s linear;
}
.progress-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 6px; }

.console-panel { max-width: 1140px; margin: 16px auto 0; }
.log {
  height: 220px; overflow: auto; background: var(--log-bg); color: #d7e2f4;
  border-radius: 10px; padding: 10px 12px;
  font: 12px/1.6 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.log-line { display: block; }
.log-time { color: #64748b; margin-right: 8px; }
.log-info { color: #cbd5e1; }
.log-success { color: #86efac; }
.log-warn { color: #fcd34d; }
.log-error { color: #fca5a5; }

.result {
  max-width: 1140px; margin: 16px auto 0; padding: 16px 18px;
  border-radius: var(--radius); border: 1px solid var(--border); background: #fff;
  box-shadow: var(--shadow);
}
.result h3 { margin: 0 0 6px; font-size: 15px; }
.result p { color: var(--muted); font-size: 13px; }
.result.result-ok { border-color: #bbf7d0; background: var(--ok-soft); }
.result.result-ok h3 { color: var(--ok); }
.result.result-warn { border-color: #fde68a; background: var(--warn-soft); }
.result.result-warn h3 { color: var(--warn); }
.result.result-error { border-color: #fecaca; background: var(--danger-soft); }
.result.result-error h3 { color: #b91c1c; }

.footer {
  max-width: 1140px; margin: 22px auto 36px; padding: 0 20px;
  color: var(--muted); font-size: 12px;
}
.footer p + p { margin-top: 5px; }

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

.tabs {
  max-width: 1180px;
  margin: 0 auto;
  padding: 2px 20px 10px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.tab {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 18px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.tab:hover { color: var(--text); border-color: #c6d2e3; }
.tab.tab-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tab.tab-active:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }

/* --------------------------------------------------------- serial monitor */

.monitor-panel { max-width: 1140px; margin: 6px auto 0; }

.monitor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: flex-end;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid #e8eef7;
  border-radius: 10px;
}
.field.compact { margin-bottom: 0; min-width: 148px; }
.field.compact label { margin-bottom: 5px; }
.field.compact select, .field.compact input[type="text"] { padding: 7px 9px; }
.monitor-toggles { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; padding-bottom: 3px; }
.check.compact { margin: 0; font-weight: 500; font-size: 12px; gap: 6px; }
.check.compact input { width: 15px; height: 15px; }

.monitor-status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 12px;
  margin: 12px 0 8px;
}
.monitor-stats {
  color: var(--muted);
  font: 12px ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}
.monitor-actions { margin-left: auto; display: flex; gap: 8px; }

.monitor-notice {
  margin: 4px 0 10px;
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 12px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1e40af;
}
.monitor-notice-ok { border-color: #bbf7d0; background: #f0fdf4; color: #166534; }
.monitor-notice-warn { border-color: #fde68a; background: #fffbeb; color: #92400e; }
.monitor-notice-error { border-color: #fecaca; background: #fef2f2; color: #991b1b; }

.monitor-output {
  height: 380px;
  overflow: auto;
  background: var(--log-bg);
  color: #d7e2f4;
  border: 1px solid #1e293b;
  border-radius: 10px;
  padding: 10px 12px;
  font: 12px/1.6 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.monitor-output:focus-visible { outline: 2px solid #93c5fd; outline-offset: 1px; }
.monitor-line { display: block; }
.monitor-rx { color: #d7e2f4; }
.monitor-sent { color: #93c5fd; }
.monitor-hex { color: #a7f3d0; }
.monitor-info { color: #94a3b8; font-style: italic; }

.monitor-send { display: flex; gap: 8px; margin-top: 10px; }
.monitor-send input {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}
.monitor-send .btn { flex: none; padding-left: 22px; padding-right: 22px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .topbar { padding: 16px 14px 8px; }
  .layout, .progress-panel, .console-panel, .footer, .banner, .tabs, .monitor-panel {
    margin-left: 12px; margin-right: 12px; padding-left: 0; padding-right: 0;
  }
  .layout { padding-left: 0; padding-right: 0; }
  .tabs { padding-left: 0; padding-right: 0; }
  .panel { padding: 15px; }
  .monitor-panel { padding: 15px; }
  table { min-width: 540px; }
  .monitor-output { height: 300px; }
}

