/* =========================================
   1. 全局与基础设置
   ========================================= */
:root {
    --primary-color: #0d6efd;       /* 主色调：科技蓝 */
    --primary-hover: #0b5ed7;
    --secondary-color: #6c757d;     /* 次要色：灰 */
    --success-color: #198754;       /* 成功绿 */
    --danger-color: #dc3545;        /* 危险红 */
    --warning-color: #ffc107;       /* 警告黄 */
    --info-color: #0dcaf0;          /* 信息蓝 */
    --bg-color: #f5f7fa;            /* 背景灰 */
    --card-bg: #ffffff;             /* 卡片白 */
    --text-main: #2c3e50;           /* 主文本 */
    --text-muted: #6c757d;          /* 弱文本 */
    --border-color: #e9ecef;
    --radius-md: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.05);
    --shadow-md: 0 5px 15px rgba(0,0,0,0.08);
}

body {
    background-color: var(--bg-color);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text-main);
    line-height: 1.6;
}

/* 主容器 */
.camera-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* =========================================
   2. 头部样式 (.camera-header)
   ========================================= */
.camera-header {
    margin-bottom: 30px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 20px;
}

.camera-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.camera-header p {
    color: var(--text-muted);
    margin: 0;
    font-size: 0.95rem;
}

/* =========================================
   3. 布局容器 (.container-wrapper)
   ========================================= */
/* 使用 Flex 布局让表单和状态在宽屏并排 */
.container-wrapper {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap; /* 允许换行以适应移动端 */
}

/* 通用卡片样式 (.my-container) */
.my-container {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 25px;
    border: 1px solid var(--border-color);
    transition: box-shadow 0.3s ease;
}

.my-container:hover {
    box-shadow: var(--shadow-md);
}

/* 布局分配：左侧表单占 60%，右侧状态占 40% */
.container-wrapper .my-container:first-child {
    flex: 3; /* 对应表单区域 */
    min-width: 300px;
}

.container-wrapper .my-container:nth-child(2) {
    flex: 2; /* 对应状态区域 */
    min-width: 250px;
    height: fit-content; /* 高度自适应内容 */
}

.my-container h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 0;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* =========================================
   4. 表单样式 (.bind-form)
   ========================================= */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 0.95rem;
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ced4da;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    /* 保持 input 不会溢出父容器 */
    box-sizing: border-box;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.code-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* 提示信息区域 */
.credential-tips {
    background-color: #e7f1ff;
    border-left: 4px solid var(--primary-color);
    padding: 15px;
    border-radius: 4px;
    margin: 20px 0;
    font-size: 0.9rem;
    color: #495057;
}

.credential-tips p {
    margin-bottom: 5px;
}

.credential-tips p:last-child {
    margin-bottom: 0;
}

/* 按钮组 */
.button-group {
    display: flex;
    gap: 15px;
    margin-top: 25px;
}

button {
    padding: 10px 24px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.clear-btn {
    background-color: #f8f9fa;
    color: var(--text-main);
    border: 1px solid #ced4da;
}

.clear-btn:hover {
    background-color: #e2e6ea;
}

.analyze-btn {
    background-color: var(--primary-color);
    color: white;
    flex-grow: 1; /* 主按钮占据剩余空间 */
}

.analyze-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

/* =========================================
   5. 状态与结果 (.result-container)
   ========================================= */
.status-indicator-box {
    display: flex;
    align-items: center;
    background: #f8f9fa;
    padding: 15px;
    border-radius: var(--radius-sm);
}

/* 状态圆点 */
.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 12px;
    flex-shrink: 0;
}

/* 圆点颜色状态 (配合 JS 切换类名) */
.status-dot.info { background-color: var(--info-color); box-shadow: 0 0 0 3px rgba(13, 202, 240, 0.2); }
.status-dot.success { background-color: var(--success-color); box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.2); }
.status-dot.danger { background-color: var(--danger-color); box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.2); }
.status-dot.warning { background-color: var(--warning-color); box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.2); }

#status-text {
    font-weight: 500;
    font-size: 0.95rem;
}

/* 错误消息 */
.error-message {
    margin-top: 15px;
    padding: 12px;
    background-color: #f8d7da;
    color: #842029;
    border: 1px solid #f5c2c7;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

/* 加载动画 */
.loading {
    display: none; /* 默认隐藏 */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 20px;
    color: var(--primary-color);
}

.loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(13, 110, 253, 0.3);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 10px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* =========================================
   6. 设备列表 (.devices-grid)
   ========================================= */
.devices-grid {
    display: grid;
    /* 自动适应列宽，最小 280px，填满整行 */
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

/* 暂无设备状态 */
.no-devices {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    background-color: #f8f9fa;
    border: 2px dashed #dee2e6;
    border-radius: var(--radius-md);
    color: var(--text-muted);
}

/* --- JS 动态生成的卡片样式 (预判) --- */
.device-card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 15px;
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
}

.device-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-sm);
    border-color: #c5ccd3;
}

.device-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f0f0f0;
}

.device-card-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-main);
}

.device-card-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.status-badge {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 12px;
    background: #e9ecef;
    color: #495057;
}

.status-badge.success { background: #d1e7dd; color: #0f5132; }
.status-badge.danger { background: #f8d7da; color: #842029; }
.status-badge.warning { background: #fff3cd; color: #664d03; }

.device-info-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.info-label {
    color: var(--text-muted);
}

.info-value {
    font-weight: 500;
}

.font-mono {
    font-family: monospace;
    background: #f1f3f5;
    padding: 0 4px;
    border-radius: 3px;
}

.delete-btn {
    background: none;
    border: none;
    color: var(--danger-color);
    padding: 4px;
    cursor: pointer;
    opacity: 0.7;
}

.delete-btn:hover {
    opacity: 1;
    background: #ffebeb;
}

/* =========================================
   7. 移动端适配
   ========================================= */
@media (max-width: 768px) {
    .container-wrapper {
        flex-direction: column;
    }

    .my-container {
        width: 100%; /* 强制占满宽度 */
        box-sizing: border-box; /* 确保 padding 不会导致溢出 */
    }

    .button-group {
        flex-direction: column;
    }

    .camera-header h1 {
        font-size: 1.5rem;
    }
}