:root {
  color-scheme: light;
  --paper: #f4f2ed;
  --surface: #fffdf9;
  --ink: #22231f;
  --muted: #73736c;
  --line: #ddd9cf;
  --accent: #e06432;
  --accent-dark: #b94d24;
  --green: #387b5a;
  --red: #b44d4d;
  --shadow: 0 16px 42px rgba(50, 47, 38, 0.08);
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand, .connection, .panel-heading, .detail-heading, .section-heading,
.command-row, .recognition-form, .metric-strip { display: flex; align-items: center; }

.brand { gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: #fff;
  background: var(--accent);
  border-radius: 10px;
  font-weight: 800;
  letter-spacing: 0;
}
.brand-name { font-weight: 800; letter-spacing: .02em; }
.brand-subtitle, .muted, .panel-footnote { color: var(--muted); }
.brand-subtitle { margin-top: 2px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }

.connection { gap: 9px; color: var(--muted); font-size: 13px; }
.connection input { width: 180px; }

input, textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
input { min-width: 0; padding: 9px 10px; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224, 100, 50, .12); }

.button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.button:hover { border-color: #b9b3a6; background: #faf8f3; }
.button:active { transform: translateY(1px); }
.button.primary { border-color: var(--accent); color: #fff; background: var(--accent); }
.button.primary:hover { border-color: var(--accent-dark); background: var(--accent-dark); }
.button.subtle { color: var(--muted); background: transparent; }
.button.danger { border-color: #e0b5b5; color: var(--red); background: #fff8f8; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 99px;
  white-space: nowrap;
  font-size: 12px;
}
.status-pill::before { width: 7px; height: 7px; border-radius: 50%; background: currentColor; content: ""; }
.status-pill.online { color: var(--green); border-color: #bad5c4; background: #f2faf5; }
.status-pill.offline { color: var(--muted); background: #faf9f5; }

.workspace {
  display: grid;
  grid-template-columns: minmax(270px, 340px) minmax(0, 1fr);
  gap: 20px;
  max-width: 1480px;
  margin: 0 auto;
  padding: 24px 28px 36px;
}
.panel { min-width: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.device-panel { align-self: start; overflow: hidden; }
.detail-panel { min-height: calc(100vh - 112px); padding: 28px; }
.panel-heading, .detail-heading, .section-heading { justify-content: space-between; gap: 16px; }
.panel-heading { padding: 24px 22px 18px; }
.eyebrow { color: var(--accent-dark); font-size: 10px; font-weight: 800; letter-spacing: .16em; }
h1, h2, h3, p { margin: 0; }
h1 { margin-top: 5px; font-size: 24px; }
h2 { margin-top: 6px; font-size: 22px; }
h3 { margin-top: 5px; font-size: 15px; }

.device-list { display: grid; border-top: 1px solid var(--line); }
.device-entry {
  display: grid;
  gap: 9px;
  padding: 16px 22px;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  background: transparent;
}
.device-entry:hover, .device-entry.selected { background: #fff6f0; }
.device-entry-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.device-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.device-model { color: var(--muted); font-size: 12px; }
.device-entry-meta { color: var(--muted); font-size: 11px; }
.empty-state { padding: 32px 22px; color: var(--muted); font-size: 13px; }
.panel-footnote { padding: 13px 22px; border-top: 1px solid var(--line); font-size: 11px; }

.empty-detail { display: grid; place-items: center; min-height: 60vh; padding: 40px; text-align: center; color: var(--muted); }
.empty-symbol { margin-bottom: 14px; color: var(--accent); font-size: 54px; line-height: 1; }
.empty-detail h2 { color: var(--ink); font-size: 20px; }
.empty-detail p { max-width: 360px; margin-top: 8px; line-height: 1.7; }
.hidden { display: none !important; }
.detail-heading { padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.mono { font-family: Consolas, "SFMono-Regular", monospace; font-size: 12px; }
.metric-strip { align-items: stretch; gap: 1px; margin: 22px 0 28px; border: 1px solid var(--line); background: var(--line); }
.metric { flex: 1; min-width: 0; padding: 14px; background: #fff; }
.metric span { display: block; color: var(--muted); font-size: 11px; }
.metric strong { display: block; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.section-heading { margin-top: 25px; margin-bottom: 13px; }
.command-row { flex-wrap: wrap; gap: 9px; }
.recognition-form { flex-wrap: wrap; gap: 9px; margin-top: 14px; padding: 13px; border: 1px solid var(--line); background: #fbfaf6; }
.recognition-form label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.recognition-form input { width: 78px; padding: 7px 8px; }
.recognition-form label:first-child input { width: 92px; }
.recognition-form input[type="file"] { width: 210px; padding: 5px; }
.script-heading { margin-top: 30px; }
#script-editor { display: block; width: 100%; min-height: 230px; padding: 14px; resize: vertical; color: #30322d; background: #242522; border-color: #242522; font-family: Consolas, "SFMono-Regular", monospace; font-size: 12px; line-height: 1.6; }
.info-heading { margin-top: 30px; }
.json-viewer { max-height: 280px; margin: 0; padding: 14px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: #fbfaf6; color: #4b4b44; font: 12px/1.6 Consolas, "SFMono-Regular", monospace; white-space: pre-wrap; word-break: break-word; }
.log-heading { margin-top: 30px; }
.event-log { display: grid; gap: 7px; max-height: 230px; overflow: auto; padding: 12px; border: 1px solid var(--line); border-radius: 6px; background: #fbfaf6; }
.event { display: grid; grid-template-columns: 72px 1fr; gap: 10px; font: 12px/1.5 Consolas, "SFMono-Regular", monospace; }
.event-time { color: var(--muted); }
.event-message { white-space: pre-wrap; word-break: break-word; }

.script-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.script-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin: 14px 0;
}
.script-name-field { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.script-name-field input { width: min(320px, 48vw); padding: 8px 10px; }
.step-count { color: var(--muted); font-size: 12px; }
.validation { min-height: 18px; font-size: 12px; }
.validation.valid { color: var(--green); }
.validation.invalid { color: var(--red); }

.visual-script-editor {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  align-items: start;
  gap: 14px;
}
.action-palette {
  position: sticky;
  top: 14px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfaf6;
}
.palette-heading h4, .json-editor-heading h4 { margin: 5px 0 0; font-size: 14px; }
.palette-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-top: 14px; }
.action-tool {
  display: grid;
  place-items: center;
  gap: 5px;
  min-height: 66px;
  padding: 7px 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  font-size: 11px;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.action-tool:hover { border-color: var(--accent); background: #fff6f0; }
.action-tool:active { transform: translateY(1px); }
.action-icon { display: grid; place-items: center; width: 25px; height: 25px; color: var(--accent-dark); font-size: 19px; line-height: 1; }
.steps-workbench { min-width: 0; min-height: 180px; }
.script-steps { display: grid; gap: 10px; }
.script-empty {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 180px;
  padding: 25px;
  border: 1px dashed #c9c3b7;
  border-radius: 7px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}
.script-empty strong { color: var(--ink); font-size: 13px; }
.empty-symbol.small { margin: 0; font-size: 30px; }
.step-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.step-card:hover { border-color: #c3bcae; box-shadow: 0 5px 18px rgba(50, 47, 38, .06); }
.step-card.dragging { opacity: .45; border-color: var(--accent); }
.step-card.drop-target { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224, 100, 50, .12); }
.step-card-header { display: flex; align-items: center; gap: 9px; min-height: 48px; padding: 8px 11px; border-bottom: 1px solid var(--line); background: #fbfaf6; }
.drag-handle { color: #aaa69d; cursor: grab; font-size: 17px; user-select: none; }
.drag-handle:active { cursor: grabbing; }
.step-index { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 50%; color: #fff; background: var(--accent); font: 700 12px/1 Consolas, monospace; }
.step-title { min-width: 0; flex: 1; font-size: 13px; font-weight: 700; }
.step-action-name { margin-left: 7px; color: var(--muted); font-size: 11px; font-weight: 400; }
.step-action-select { width: 88px; min-width: 0; padding: 5px 6px; border: 1px solid var(--line); border-radius: 5px; color: var(--ink); background: #fff; font-size: 11px; }
.step-enabled { display: flex; align-items: center; gap: 4px; color: var(--muted); white-space: nowrap; font-size: 11px; }
.step-enabled input { width: 14px; height: 14px; accent-color: var(--accent); }
.step-actions { display: flex; align-items: center; gap: 3px; }
.icon-button { display: grid; place-items: center; width: 29px; height: 29px; padding: 0; border: 1px solid transparent; border-radius: 5px; color: var(--muted); background: transparent; font-size: 15px; }
.icon-button:hover { border-color: var(--line); color: var(--ink); background: #fff; }
.icon-button.delete:hover { border-color: #e0b5b5; color: var(--red); background: #fff8f8; }
.step-body { padding: 13px 14px 14px; }
.step-grid { display: grid; grid-template-columns: repeat(4, minmax(90px, 1fr)); gap: 10px; }
.step-grid.two { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
.step-grid.three { grid-template-columns: repeat(3, minmax(100px, 1fr)); }
.field { display: grid; gap: 5px; min-width: 0; }
.field > span, .field-label { color: var(--muted); font-size: 11px; }
.field input, .field select { width: 100%; min-width: 0; padding: 8px 9px; }
.field input[type="color"] { height: 36px; padding: 3px; cursor: pointer; }
.color-input-row { display: grid; grid-template-columns: minmax(0, 1fr) 37px; gap: 5px; }
.color-input-row input[type="color"] { width: 37px; }
.field input[type="file"] { padding: 6px; font-size: 11px; }
.field-note { grid-column: 1 / -1; color: var(--muted); font-size: 11px; line-height: 1.5; }
.region-block { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.region-heading { margin-bottom: 8px; color: var(--muted); font-size: 11px; font-weight: 700; }
.template-status { display: flex; align-items: center; gap: 8px; min-height: 30px; color: var(--muted); font-size: 11px; }
.template-status.ready { color: var(--green); }
.template-clear { padding: 3px 7px; min-height: 27px; font-size: 11px; }
.json-editor-panel { margin-top: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 7px; background: #fbfaf6; }
.json-editor-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 11px; }
#script-editor { min-height: 260px; }

.disabled-step { opacity: .5; }
.disabled-step .step-body { display: none; }

@media (max-width: 860px) {
  .script-actions { justify-content: flex-start; width: 100%; }
  .script-name-field { width: 100%; }
  .script-name-field input { flex: 1; width: auto; }
  .visual-script-editor { grid-template-columns: 1fr; }
  .action-palette { position: static; }
  .palette-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .action-tool { min-height: 58px; }
  .step-grid, .step-grid.three { grid-template-columns: repeat(2, minmax(110px, 1fr)); }
}

@media (max-width: 520px) {
  .palette-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .step-card-header { align-items: flex-start; }
  .step-actions { flex-wrap: wrap; }
  .step-grid, .step-grid.two, .step-grid.three { grid-template-columns: 1fr 1fr; }
  .json-editor-heading { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 860px) {
  .topbar { align-items: flex-start; flex-direction: column; padding: 16px; }
  .connection { flex-wrap: wrap; width: 100%; }
  .connection input { flex: 1; width: auto; }
  .workspace { grid-template-columns: 1fr; padding: 16px; }
  .detail-panel { min-height: 0; padding: 20px; }
  .metric-strip { display: grid; grid-template-columns: repeat(2, 1fr); }
  .metric { min-width: 0; }
}
