/* ========================================
   串口助手页面专用样式
   柔和亮色主题，与主体风格一致
   ======================================== */

/* ========== 工作区布局 ========== */
.serial-workspace {
    display: flex;
    height: calc(100vh - 7rem);
    margin: 0 auto;
    max-width: 1400px;
}

/* 左侧边栏 */
.serial-sidebar {
    width: 240px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e2e8f0;
    overflow-y: auto;
}

/* 右侧主区域 */
.serial-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 0 12px 12px 12px;
    overflow: hidden;
}

/* ========== 参数配置组 ========== */
.param-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.param-label {
    font-size: 12px;
    font-weight: 500;
    color: #64748b;
    letter-spacing: 0.02em;
}

.param-select {
    width: 100%;
    padding: 8px 10px;
    border-radius: 8px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    font-size: 13px;
    font-weight: 500;
    color: #334155;
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpolyline points='M6 9l6 6m-3-3v6'%3E/polyline%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

.param-select:focus {
    outline: none;
    border-color: #a5b4fc;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* ========== 连接按钮 ========== */
.btn-connect {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    white-space: nowrap;
}

.btn-connect:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary-full { background: #635bff; color: white; }
.btn-primary-full:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(99, 91, 255, 0.3); }
.btn-success-full { background: linear-gradient(135deg, #22c55e, #16a34a); color: white; }
.btn-success-full:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(34, 197, 94, 0.25); }
.btn-danger-full { background: linear-gradient(135deg, #ef4444, #dc2626); color: white; }
.btn-danger-full:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(239, 68, 68, 0.25); }

/* 隐藏辅助类 */
.hidden { display: none !important; }

/* ========== 控制栏 ========== */
.control-bar {
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.85);
}

/* 格式标签按钮 */
.format-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    background: transparent;
}

.format-badge-active {
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    color: #2563eb;
    border-color: #93c5fd;
}

.format-badge:hover {
    background: #f1f5f9;
    border-color: #e2e8f0;
}

.format-badge-error {
    color: #ef4444;
}
.format-badge-error:hover {
    background: #fef2f2;
    border-color: #fecaca;
}

/* 工具栏小按钮 */
.tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: transparent;
    border: 1px solid #e2e8f0;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s ease;
}
.tool-btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #334155;
}

/* 校验位选择 */
.check-select {
    padding: 6px 28px 6px 10px;
    border-radius: 8px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    font-size: 12px;
    font-weight: 500;
    color: #334155;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpolyline points='M6 9l6 6m-3-3v6'%3E/polyline%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

/* ========== 自动发送 ========== */
.auto-send-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
}

.auto-interval {
    width: 70px;
    padding: 4px 6px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background: #fff;
    font-size: 12px;
    text-align: center;
    color: #334155;
    outline: none;
    /* 隐藏数字输入框箭头 */
    -moz-appearance: textfield;
}

.auto-interval:focus {
    border-color: #a5b4fc;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.auto-send-btn {
    padding: 5px 14px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #64748b;
    white-space: nowrap;
}
.auto-send-btn.active {
    background: linear-gradient(135deg, #fef08a, #f59e0b);
    border-color: #fde047;
    color: #92400e;
}
.auto-send-btn:hover {
    transform: translateY(-1px);
}

/* 发送按钮 */
.btn-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 20px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    background: #635bff;
    color: white;
    white-space: nowrap;
}
.btn-send:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(99, 91, 255, 0.3);
}
.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.send-toolbar {
    flex-shrink: 0;
}

/* ========== 接收区域 ========== */
.receive-area {
    font-family: 'Consolas', 'Courier New', 'SF Mono', monospace;
    background: #fafbfb;
    word-break: break-all;
}

/* 接收/发送消息气泡 */
.record-msg {
    padding: 8px 14px;
    border-radius: 10px;
    max-width: 90%;
    animation: fadeInUp 0.2s ease forwards;
    line-height: 1.5;
}

.record-read {
    background: linear-gradient(135deg, #eff6ff, #f0fdf4);
    border-left: 3px solid #22c55e;
    align-self: flex-start;
    color: #166534;
}

.record-write {
    background: linear-gradient(135deg, #f5f3ff, #ede9fe);
    border-right: 3px solid #635bff;
    align-self: flex-end;
    color: #4c46d6;
}

.record-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    opacity: 0.55;
    margin-bottom: 2px;
}

.record-time { font-family: 'Inter', sans-serif; }
.record-type-tag { font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }

.record-body { font-family: 'Consolas', 'Courier New', monospace; word-break: break-all; }

/* 复制提示 */
.copy-hint {
    position: absolute;
    top: 4px;
    right: 4px;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
    font-size: 10px;
    color: #22c55e;
    font-weight: 600;
    background: white;
    padding: 2px 6px;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.record-msg:hover .copy-hint { opacity: 1; }

/* 空状态提示 */
.empty-hint { color: #94a3b8; }

/* 日志记录样式 */
.record-msg {
    padding: 6px 12px;
    border-radius: 8px;
    max-width: 100%;
    animation: fadeInUp 0.15s ease forwards;
    line-height: 1.5;
    word-break: break-all;
}

.record-read {
    background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
    border-left: 3px solid #22c55e;
    color: #166534;
}

.record-write {
    background: linear-gradient(135deg, #f5f3ff, #ede9fe);
    border-right: 3px solid #635bff;
    color: #4c46d6;
}

.record-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    opacity: 0.55;
    margin-bottom: 2px;
    font-family: 'Inter', -apple-system, sans-serif;
}

.record-time { font-family: 'Inter', monospace; }
.record-type-tag { font-weight: 700; letter-spacing: 0.05em; }

.record-body {
    font-family: 'Consolas', 'Courier New', 'SF Mono', monospace;
    word-break: break-all;
    font-size: 13px;
}

/* 警告/错误消息 */
.record-msg[class*="error"] {
    background: linear-gradient(135deg, #fef2f2, #fff1f2);
    border-left: 3px solid #ef4444;
    color: #991b1b;
}

/* warning */
.record-warning {
    background: linear-gradient(135deg, #fffbeb, #fefce8);
    border-left: 3px solid #f59e0b;
    color: #92400e;
}

/* ========== 调整手柄（分隔线） ========== */
.resize-handle {
    height: 5px;
    background: #e2e8f0;
    cursor: ns-resize;
    position: relative;
    z-index: 10;
}
.resize-handle::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 3px;
    background: #cbd5e1;
    border-radius: 2px;
    opacity: 0;
    transition: opacity 0.2s;
}
.resize-handle:hover::after { opacity: 1; }

/* ========== 发送区域 ========== */
.send-area textarea {
    resize: none;
}

/* ========== 底部状态栏 ========== */
.status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    font-size: 12px;
    color: #64748b;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.status-idle { background: #93a5ed; }
.status-connecting { background: #fbbf24; animation: pulse-dot 1s infinite; }
.status-connected { background: #22c55e; }
.status-error { background: #ef4444; }

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.status-text { font-weight: 500; }

/* ========== 动画 ========== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========== 响应式适配 ========== */

@media (max-width: 768px) {
    .serial-workspace {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .serial-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
        max-height: 40vh;
    }

    .serial-main {
        border-radius: 12px 12px 0 0;
        min-height: 60vh;
    }

    .control-bar {
        flex-wrap: wrap;
        gap: 8px;
    }

    .control-bar > div:last-child {
        width: 100%;
        justify-content: space-around;
    }

    .send-toolbar {
        flex-wrap: wrap;
        gap: 6px;
    }

    /* 移动端隐藏部分工具栏元素以节省空间 */
    #btn-scroll-lock,
    #btn-export { display: none; }
}

/* ========== 浏览器兼容性提示增强 ========== */
.api-unsupported {
    animation: shake 0.4s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}