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

:root {
    --bg-0: #f7fbfb;
    --bg-1: #eef8f5;
    --bg-2: #edf5ff;
    --panel: rgba(255, 255, 255, 0.86);
    --panel-strong: rgba(255, 255, 255, 0.95);
    --border: rgba(143, 191, 184, 0.25);
    --line: rgba(109, 148, 171, 0.12);
    --text-0: #20323d;
    --text-1: #48616f;
    --text-2: #7d919f;
    --mint: #50bfa5;
    --mint-strong: #1f9d86;
    --sky: #5da8ff;
    --sky-soft: #e8f3ff;
    --sun: #f4c55a;
    --danger: #da6a73;
    --danger-soft: #fff1f2;
    --shadow-lg: 0 20px 40px rgba(80, 145, 158, 0.12);
    --shadow-sm: 0 10px 22px rgba(106, 159, 170, 0.08);
    --radius-xl: 22px;
    --radius-lg: 18px;
    --radius-md: 14px;
    --radius-sm: 10px;
}

body {
    min-height: 100vh;
    font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
    font-size: 13px;
    color: var(--text-0);
    background:
        radial-gradient(circle at top left, rgba(168, 235, 218, 0.42), transparent 30%),
        radial-gradient(circle at top right, rgba(166, 207, 255, 0.28), transparent 30%),
        linear-gradient(160deg, var(--bg-0), var(--bg-1) 46%, var(--bg-2));
    overflow-y: auto;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.top-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    margin: 14px 14px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.88), rgba(244, 251, 255, 0.78));
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow-sm);
}

.top-bar .title {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #234253;
}

.top-bar .status {
    display: flex;
    gap: 12px;
    margin-left: auto;
    align-items: center;
}

.status-badge,
.info-badge,
.hero-badge,
.mini-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
}

.status-badge.running {
    background: rgba(80, 191, 165, 0.16);
    color: var(--mint-strong);
}

.status-badge.stopped {
    background: rgba(218, 106, 115, 0.14);
    color: #be4d57;
}

.info-badge {
    background: rgba(93, 168, 255, 0.14);
    color: #2f74be;
}

.btn {
    border: none;
    border-radius: 999px;
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease, background-color .18s ease;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(80, 145, 158, 0.12);
}

.btn:disabled {
    opacity: .45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-start {
    color: #fff;
    background: linear-gradient(135deg, #43c1a0, #2ca883);
}

.btn-stop {
    color: #fff;
    background: linear-gradient(135deg, #f08b93, #db6771);
}

.btn-send,
.btn-write {
    color: #fff;
    background: linear-gradient(135deg, #5da8ff, #3b86eb);
}

.btn-sm {
    padding: 7px 12px;
}

.btn-read {
    color: #fff;
    background: linear-gradient(135deg, #4fc8a0, #27aa82);
}

.btn-xs {
    padding: 5px 10px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--text-1);
    border: 1px solid rgba(95, 150, 171, 0.18);
    box-shadow: none;
}

.main-body {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: 14px;
    padding: 14px;
    overflow: visible;
}

.sidebar,
.panel {
    border: 1px solid var(--border);
    background: var(--panel);
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow-sm);
}

.sidebar {
    width: 256px;
    border-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header,
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

.sidebar-header h3,
.panel-header h3 {
    font-size: 15px;
    color: #234253;
}

.sidebar-top-action {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

.sidebar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.connection-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    padding: 8px;
}

.connection-list li {
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.72);
    transition: transform .18s ease, border-color .18s ease, background-color .18s ease;
}

.connection-list li:hover {
    transform: translateY(-1px);
    border-color: rgba(93, 168, 255, 0.28);
    background: rgba(240, 248, 255, 0.95);
}

.connection-list li.selected {
    border-color: rgba(80, 191, 165, 0.34);
    background: linear-gradient(135deg, rgba(227, 248, 242, 0.95), rgba(238, 246, 255, 0.95));
}

.connection-list li.empty-hint {
    cursor: default;
}

.conn-id {
    font-weight: 700;
    color: var(--text-0);
}

.conn-addr {
    margin-top: 6px;
    color: var(--mint-strong);
    font-size: 14px;
    font-weight: 700;
}

.conn-remote {
    margin-top: 4px;
    color: var(--text-2);
    font-size: 12px;
    word-break: break-all;
}

.content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow: visible;
}

.panel {
    border-radius: var(--radius-xl);
    overflow: hidden;
}

.panel-tools {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-1);
    font-size: 12px;
}

.hint {
    color: var(--text-2);
    font-size: 12px;
}

.table-wrap {
    overflow: auto;
    max-height: min(62vh, 720px);
}

.frame-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.frame-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 10px 8px;
    text-align: left;
    white-space: nowrap;
    color: var(--text-1);
    background: rgba(244, 250, 252, 0.96);
    border-bottom: 1px solid var(--line);
}

.frame-table td {
    padding: 9px 8px;
    border-bottom: 1px solid rgba(128, 155, 173, 0.08);
    vertical-align: top;
}

.frame-table tr:hover {
    background: rgba(240, 248, 255, 0.72);
}

.col-time { width: 96px; }
.col-dir { width: 52px; text-align: center; }
.col-conn { width: 78px; }
.col-addr { width: 120px; }
.col-fc { width: 96px; }
.col-di { width: 66px; }
.col-name { width: 120px; }
.col-parsed { max-width: 320px; }
.col-hex {
    max-width: 240px;
    color: #557083;
    font-family: Consolas, monospace;
    font-size: 11px;
}
.col-valid { width: 50px; text-align: center; }

.dir-rx {
    color: #d9596b;
    font-weight: 700;
}

.dir-tx {
    color: #2f85df;
    font-weight: 700;
}

.valid-ok { color: var(--mint-strong); }
.valid-err { color: #cb5563; font-weight: 700; }

.row-error {
    background: var(--danger-soft) !important;
}

.row-report {
    background: rgba(229, 251, 245, 0.88) !important;
}

.row-report:hover {
    background: rgba(214, 247, 238, 0.95) !important;
}

.row-report .col-fc {
    color: var(--mint-strong);
    font-weight: 700;
}

.parsed-cell,
.hex-cell {
    word-break: break-all;
}

.hex-cell {
    cursor: pointer;
}

.hex-cell:hover {
    color: #2f85df;
}

.send-panel {
    padding-bottom: 16px;
}

.form-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    margin-top: 12px;
}

.form-row label {
    width: 168px;
    color: var(--text-1);
    font-weight: 600;
}

.form-row input,
.form-row select,
.form-row textarea,
.workbench-search input,
.field-inline input,
.field-inline select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid rgba(109, 148, 171, 0.18);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.95);
    color: var(--text-0);
    font-size: 13px;
    font-family: Consolas, "Microsoft YaHei", monospace;
    transition: border-color .18s ease, box-shadow .18s ease;
}

.form-row textarea {
    min-height: 92px;
    resize: vertical;
}

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus,
.workbench-search input:focus,
.field-inline input:focus,
.field-inline select:focus {
    outline: none;
    border-color: rgba(93, 168, 255, 0.5);
    box-shadow: 0 0 0 4px rgba(93, 168, 255, 0.12);
}

.hero-badge {
    background: rgba(255, 255, 255, 0.78);
    color: #2d6e90;
    border: 1px solid rgba(93, 168, 255, 0.16);
}

.tabs {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
}

.main-tabs {
    margin-bottom: 12px;
}

.tab-btn {
    border: none;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.6);
    color: var(--text-1);
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .18s ease, color .18s ease, transform .18s ease;
}

.tab-btn:hover {
    transform: translateY(-1px);
}

.tab-btn.active {
    background: linear-gradient(135deg, rgba(84, 193, 166, 0.95), rgba(81, 161, 255, 0.9));
    color: #fff;
    box-shadow: 0 10px 22px rgba(80, 145, 158, 0.14);
}

.tab-count {
    margin-left: 4px;
    opacity: .72;
    font-size: 11px;
}

.tab-content {
    display: none;
    padding: 0 16px;
}

.tab-content.active {
    display: block;
}

.workbench-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 14px;
}

.workbench-group-meta {
    padding: 16px 18px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.74);
    border: 1px solid rgba(109, 148, 171, 0.12);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.group-label {
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-2);
}

.group-title {
    margin-top: 6px;
    font-size: 18px;
    font-weight: 700;
    color: #214153;
}

.group-desc {
    margin-top: 8px;
    color: var(--text-1);
    line-height: 1.7;
}

.workbench-search {
    min-width: 280px;
}

.workbench-search label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-1);
    font-size: 12px;
    font-weight: 700;
}

.sub-tabs {
    flex-wrap: wrap;
    gap: 10px;
    padding: 0 0 6px;
}

.workbench-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 16px;
    padding: 10px 0 4px;
}

.cmd-card {
    border: 1px solid rgba(109, 148, 171, 0.14);
    border-radius: 22px;
    background: var(--panel-strong);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    container-type: inline-size;
}

.cmd-card-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px 14px;
    border-bottom: 1px solid rgba(109, 148, 171, 0.1);
    background: linear-gradient(135deg, rgba(246, 251, 250, 0.94), rgba(244, 248, 255, 0.92));
}

.cmd-heading {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.cmd-code {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 62px;
    padding: 6px 10px;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(37, 67, 84, 0.96), rgba(52, 94, 117, 0.96));
    color: #bff8ea;
    font-family: Consolas, monospace;
    font-size: 12px;
    font-weight: 700;
}

.cmd-title-wrap {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.cmd-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-0);
}

.cmd-format {
    color: var(--text-2);
    line-height: 1.5;
}

.cmd-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.mini-tag {
    font-size: 11px;
    border: 1px solid transparent;
}

.tag-read {
    color: var(--mint-strong);
    background: rgba(80, 191, 165, 0.14);
}

.tag-write {
    color: #2f85df;
    background: rgba(93, 168, 255, 0.14);
}

.tag-danger {
    color: #c75662;
    background: rgba(218, 106, 115, 0.12);
}

.cmd-card-body {
    padding: 18px;
}

.cmd-note {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(255, 247, 222, 0.9), rgba(255, 251, 238, 0.95));
    border: 1px solid rgba(244, 197, 90, 0.3);
    color: #7b5b12;
    line-height: 1.7;
    font-size: 12px;
}

.cmd-actions {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 14px;
    align-items: flex-start;
    min-width: 0;
}

.cmd-write-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.read-only-tip {
    color: var(--text-2);
    padding-top: 10px;
}

.write-control-row {
    display: grid;
    grid-template-columns: 108px 1fr;
    gap: 12px;
    align-items: flex-start;
}

.write-control-row label {
    padding-top: 10px;
    color: var(--text-1);
    font-weight: 700;
}

.field-stack {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 0;
}

.field-inline {
    display: flex;
    gap: 10px;
    align-items: center;
    min-width: 0;
}

.field-inline > * {
    min-width: 0;
}

.split-inline {
    flex-wrap: wrap;
}

.split-inline > * {
    flex: 1 1 180px;
}

@container (max-width: 440px) {
    .cmd-card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .cmd-tags {
        justify-content: flex-start;
    }

    .cmd-actions {
        grid-template-columns: 1fr;
    }

    .cmd-actions > .btn {
        width: 100%;
    }
}

@container (max-width: 360px) {
    .write-control-row {
        grid-template-columns: 1fr;
    }

    .write-control-row label {
        padding-top: 0;
    }

    .split-inline > * {
        flex-basis: 100%;
    }
}

.field-hint {
    color: var(--text-2);
    line-height: 1.6;
}

.cmd-example-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.cmd-preview {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px;
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(240, 248, 255, 0.88), rgba(238, 251, 247, 0.9));
    border: 1px solid rgba(93, 168, 255, 0.12);
}

.preview-label {
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-2);
}

.hex-preview {
    color: #2f74be;
    font-family: Consolas, monospace;
    word-break: break-all;
}

.hex-preview.is-error {
    color: #c75662;
}

.detail-hex {
    padding: 12px 14px;
    margin: 12px;
    border-radius: 14px;
    color: #1d6d61;
    background: linear-gradient(135deg, rgba(229, 251, 245, 0.95), rgba(237, 247, 255, 0.95));
    font-family: Consolas, monospace;
    font-size: 13px;
    word-break: break-all;
}

#detailContent {
    max-height: 70vh;
    overflow: auto;
    padding-bottom: 12px;
}

.detail-table {
    width: calc(100% - 24px);
    margin: 0 12px 12px;
    border-collapse: collapse;
    font-size: 12px;
}

.detail-table th,
.detail-table td {
    padding: 10px 12px;
    border: 1px solid rgba(109, 148, 171, 0.12);
    text-align: left;
}

.detail-table th {
    width: 120px;
    background: rgba(244, 250, 252, 0.96);
    color: var(--text-1);
}

.empty-hint {
    padding: 24px;
    color: var(--text-2);
    text-align: center;
}

@media (max-width: 1180px) {
    .main-body {
        flex-direction: column;
        overflow: visible;
    }

    .sidebar {
        width: 100%;
        max-height: 260px;
    }

    .workbench-toolbar,
    .workbench-hero {
        flex-direction: column;
    }

    .cmd-actions {
        grid-template-columns: 1fr;
    }

    .workbench-search {
        width: 100%;
        min-width: 0;
    }
}

@media (max-width: 860px) {
    .top-bar {
        flex-wrap: wrap;
    }

    .top-bar .status {
        margin-left: 0;
    }

    .form-row,
    .write-control-row {
        grid-template-columns: 1fr;
        display: grid;
    }

    .form-row label,
    .write-control-row label {
        width: auto;
        text-align: left;
    }

    .workbench-content {
        grid-template-columns: 1fr;
    }
}

/* 新增的设备管理相关样式 */
.btn-register {
    width: 100%;
    color: #fff;
    background: linear-gradient(135deg, #5da8ff, #3b86eb);
}

.btn-danger {
    color: #fff;
    background: linear-gradient(135deg, #f08b93, #db6771);
}

.main-tab-content {
    display: none;
}

.main-tab-content.active {
    display: block;
}

.simple-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.simple-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 10px 8px;
    text-align: left;
    white-space: nowrap;
    color: var(--text-1);
    background: rgba(244, 250, 252, 0.96);
    border-bottom: 1px solid var(--line);
}

.simple-table td {
    padding: 9px 8px;
    border-bottom: 1px solid rgba(128, 155, 173, 0.08);
    vertical-align: middle;
}

.simple-table tr:hover {
    background: rgba(240, 248, 255, 0.72);
}

.simple-table td button {
    margin-right: 6px;
}

/* 设备升级页 */
.upgrade-panel { padding: 16px; }
.upgrade-section { margin-bottom: 24px; }
.upgrade-section h4 { margin: 0 0 12px; font-size: 14px; color: #2c3e50; }
.upgrade-section-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 12px;
}
.upgrade-section-header h4 { margin: 0; }
.upgrade-file-info {
    margin: 8px 0; padding: 8px 12px;
    background: #f5f7fa; border-radius: 4px;
    font-size: 13px; color: #606266;
}
.upgrade-progress-wrap {
    margin: 12px 0; padding: 12px;
    background: #f5f7fa; border-radius: 6px;
}
.progress-bar {
    height: 20px; background: #ebeef5; border-radius: 10px; overflow: hidden;
}
.progress-bar-inner {
    height: 100%; width: 0;
    background: linear-gradient(90deg, #1b8f72, #27ae60);
    transition: width 0.2s;
}
.progress-bar-inner.error { background: #c0392b; }
.progress-bar-inner.done { background: #27ae60; }
.progress-text {
    margin-top: 6px; display: flex; justify-content: space-between;
    font-size: 13px; color: #606266;
}
.progress-meta {
    margin-top: 4px; font-size: 12px; color: #909399;
    display: flex; gap: 16px; flex-wrap: wrap;
}
.upgrade-log {
    max-height: 220px; overflow-y: auto;
    background: #1e1e1e; color: #d4d4d4;
    padding: 8px 12px; border-radius: 4px;
    font-family: Consolas, Monaco, monospace;
    font-size: 12px; line-height: 1.6;
}
.upgrade-log .log-line { white-space: pre-wrap; }
.upgrade-table {
    width: 100%; border-collapse: collapse;
    font-size: 13px;
}
.upgrade-table th, .upgrade-table td {
    padding: 8px 10px; border-bottom: 1px solid #ebeef5;
    text-align: left;
}
.upgrade-table th {
    background: #f5f7fa; color: #606266; font-weight: 600;
}

/* ========== 预置指令面板 ========== */
.preset-panel {
    margin-top: 10px;
    padding: 8px 10px;
    border-top: 1px solid var(--border, #ddd);
}

.preset-panel h3 {
    font-size: 12px;
    margin: 0 0 6px 0;
    color: var(--text-2, #666);
    text-transform: uppercase;
}

.preset-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 200px;
    overflow-y: auto;
}

.preset-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-radius: 3px;
    background: #fff8e1;
    margin-bottom: 3px;
    font-size: 12px;
}

.preset-item .preset-addr {
    font-weight: bold;
    color: #333;
}

.preset-item .preset-di {
    color: #1976d2;
}

.preset-item .preset-type {
    color: #666;
    font-size: 11px;
}

.preset-item .preset-cancel-btn {
    margin-left: auto;
    padding: 2px 8px;
    font-size: 11px;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

.preset-item .preset-cancel-btn:hover {
    background: #d32f2f;
}

/* 离线设备的连接信息样式 */
li[data-addr] .conn-remote {
    color: #999;
    font-style: italic;
}

/* 备案信息 */
.icp-footer {
    text-align: center;
    padding: 16px 20px;
    font-size: 12px;
    color: #606266;
}
.icp-footer a {
    color: #606266;
    text-decoration: none;
}
.icp-footer a:hover {
    color: #409EFF;
    text-decoration: underline;
}
