/* 基础样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    overflow-x: hidden;
}

/* 主容器 */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
}

/* 顶部导航 */
.header {
    background-color: #4a90e2;
    color: white;
    padding: 15px 0;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

/* 主内容区域 */
.main-content {
    padding: 20px 0;
}

/* 按钮样式 */
.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
    touch-action: manipulation;
    user-select: none;
}

.btn-primary {
    background-color: #4a90e2;
    color: white;
}

.btn-primary:hover {
    background-color: #357abd;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(74, 144, 226, 0.3);
}

.btn-secondary {
    background-color: #e0e0e0;
    color: #333;
}

.btn-secondary:hover {
    background-color: #bdbdbd;
    transform: translateY(-1px);
}

/* 添加设备区域 */
.add-device-section {
    margin-bottom: 20px;
    text-align: center;
}

#addDeviceBtn {
    width: 100%;
    max-width: 300px;
    font-size: 1.1rem;
    padding: 15px;
}

/* 设备卡片容器 */
.device-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

/* 设备卡片样式 */
.device-card {
    background-color: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.device-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.device-card h3 {
    font-size: 1.25rem;
    margin-bottom: 10px;
    color: #4a90e2;
}

.device-info {
    margin-bottom: 15px;
    font-size: 0.95rem;
    color: #666;
}

.device-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 10px;
    background-color: #f8f9fa;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.device-stats:hover {
    background-color: #e9ecef;
}

.sn-count {
    font-weight: 600;
    color: #4a90e2;
    cursor: pointer;
    transition: color 0.2s ease;
}

.sn-count:hover {
    color: #357abd;
}

/* 卡片内展开按钮 */
.expand-card-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    color: #666;
    padding: 5px;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 25px;
    height: 25px;
}

.expand-card-btn:hover {
    background-color: #e0e0e0;
    color: #333;
}

.expand-card-icon {
    transition: transform 0.3s ease;
    font-size: 0.7rem;
}

/* 设备SN码详情区域 */
.device-sn-detail {
    background-color: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    max-height: 300px;
    overflow-y: auto;
    transition: max-height 0.3s ease, opacity 0.3s ease, margin-bottom 0.3s ease;
}

.device-sn-detail.collapsed {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    margin-bottom: 0;
    padding: 0 15px;
}

/* 设备SN码列表 */
.device-sn-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* 设备SN码项 */
.device-sn-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: white;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: background-color 0.2s ease;
}

.device-sn-item:hover {
    background-color: #f0f8ff;
}

/* 空SN码状态 */
.empty-sn {
    text-align: center;
    color: #666;
    font-style: italic;
    padding: 20px 0;
}

/* SN码时间 */
.sn-time {
    font-size: 0.8rem;
    color: #999;
    white-space: nowrap;
}

/* 卡片操作按钮 */
.card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.card-actions .btn {
    padding: 10px;
    font-size: 0.9rem;
}

/* 历史记录区域 */
.history-section {
    text-align: center;
    margin-top: 30px;
}

/* 模态框样式 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
    animation: fadeIn 0.3s ease;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideIn 0.3s ease;
    position: relative;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.close-btn:hover {
    background-color: #f0f0f0;
    color: #333;
}

.modal-body {
    padding: 20px;
}

/* 表单样式 */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #333;
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-group input:focus {
    outline: none;
    border-color: #4a90e2;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 25px;
}

.form-actions .btn {
    flex: 1;
    padding: 12px;
}

/* 扫码模态框样式 */
.scanner-modal {
    background-color: rgba(0, 0, 0, 0.9);
}

.scanner-content {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border-radius: 0;
    background-color: transparent;
    color: white;
}

.scanner-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    z-index: 10;
    background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
}

.scanner-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: white;
}

.close-scanner {
    color: white;
    background-color: rgba(255, 255, 255, 0.2);
}

.close-scanner:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.scanner-body {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* 扫描容器 */
.scanner-container {
    position: relative;
    width: 100%;
    max-width: 500px;
    aspect-ratio: 1;
    margin-bottom: 20px;
    overflow: hidden;
    border-radius: 12px;
}

.scanner-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scanner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.7) 0%,
        rgba(0, 0, 0, 0) 25%,
        rgba(0, 0, 0, 0) 75%,
        rgba(0, 0, 0, 0.7) 100%
    );
}

.scanner-frame {
    position: absolute;
    top: 25%;
    left: 25%;
    width: 50%;
    height: 50%;
    border: 2px solid #4a90e2;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    animation: pulse 2s infinite;
}

.scanner-line {
    position: absolute;
    top: 25%;
    left: 25%;
    width: 50%;
    height: 2px;
    background-color: #4a90e2;
    box-shadow: 0 0 10px #4a90e2;
    animation: scanLine 2s linear infinite;
}

/* 扫描结果 */
.scan-result {
    background-color: white;
    color: #333;
    padding: 20px;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    animation: fadeIn 0.3s ease;
}

.scan-result h3 {
    color: #2ecc71;
    margin-bottom: 15px;
    font-size: 1.25rem;
}

.sn-code {
    font-size: 1.1rem;
    font-weight: 600;
    background-color: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    word-break: break-all;
}

.scan-actions {
    display: flex;
    gap: 10px;
}

.scan-actions .btn {
    flex: 1;
    padding: 12px;
}

/* 扫描提示 */
.scan-hint {
    text-align: center;
    color: white;
    font-size: 1rem;
    margin-top: 20px;
}

/* 历史记录样式 */
.history-content {
    max-height: 95vh;
}

.history-list {
    max-height: 70vh;
    overflow-y: auto;
}

.history-item {
    margin-bottom: 20px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
}

.history-item h4 {
    color: #4a90e2;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.history-sn-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 500px;
    overflow-y: auto;
    transition: max-height 0.3s ease, opacity 0.3s ease;
}

.history-sn-list.collapsed {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 10px 0;
    transition: background-color 0.2s ease;
}

.history-item-header:hover {
    background-color: rgba(74, 144, 226, 0.1);
    border-radius: 8px;
}

.history-header-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.history-item h4 {
    margin: 0;
    font-size: 1.1rem;
    color: #4a90e2;
}

.expand-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    color: #666;
    padding: 5px;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 25px;
    height: 25px;
}

.expand-btn:hover {
    background-color: #f0f0f0;
    color: #333;
}

.expand-icon {
    transition: transform 0.3s ease;
    font-size: 0.7rem;
}

.sn-count {
    font-weight: 600;
    color: #666;
    font-size: 0.9rem;
}

.history-sn-item {
    padding: 8px 12px;
    background-color: white;
    border-radius: 6px;
    font-size: 0.95rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.sn-timestamp {
    font-size: 0.85rem;
    color: #999;
}

/* 加载中样式 */
.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(255, 255, 255, 0.95);
    padding: 20px 30px;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    text-align: center;
    z-index: 2000;
    animation: fadeIn 0.3s ease;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f0f0f0;
    border-top: 4px solid #4a90e2;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

/* 消息提示样式 */
.message {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    padding: 15px 25px;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    z-index: 2000;
    animation: slideDown 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.message.success {
    background-color: #2ecc71;
}

.message.error {
    background-color: #e74c3c;
}

.message.info {
    background-color: #3498db;
}

/* 隐藏类 */
.hidden {
    display: none !important;
}

/* 动画 */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translate(-50%, -20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

@keyframes scanLine {
    0% {
        transform: translateY(0);
    }
    100% {
        transform: translateY(100%);
    }
}

/* 响应式设计 */
@media (max-width: 768px) {
    .device-cards {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .header h1 {
        font-size: 1.3rem;
    }
    
    .btn {
        padding: 10px 16px;
        font-size: 0.95rem;
    }
    
    .modal-content {
        width: 95%;
        margin: 10px;
    }
    
    .scanner-container {
        width: 100%;
        max-width: none;
    }
    
    .scan-actions {
        flex-direction: column;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .card-actions {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 10px;
    }
    
    .header {
        padding: 12px 0;
    }
    
    .header h1 {
        font-size: 1.15rem;
    }
    
    .device-card {
        padding: 15px;
    }
    
    .modal-header,
    .modal-body {
        padding: 15px;
    }
    
    .scanner-header {
        padding: 15px;
    }
    
    .scanner-body {
        padding: 15px;
    }
}

/* 横屏模式优化 */
@media (orientation: landscape) and (max-height: 500px) {
    .scanner-container {
        max-width: 400px;
    }
    
    .scanner-body {
        flex-direction: row;
        justify-content: space-around;
    }
    
    .scan-result {
        margin-left: 20px;
    }
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* 手动输入界面样式 */
.manual-input-section {
    background-color: white;
    color: #333;
    padding: 20px;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    animation: fadeIn 0.3s ease;
}

.manual-input-section h3 {
    color: #4a90e2;
    margin-bottom: 20px;
    font-size: 1.25rem;
}

.manual-input-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.manual-input {
    width: 100%;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.manual-input:focus {
    outline: none;
    border-color: #4a90e2;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.manual-actions {
    display: flex;
    gap: 10px;
}

.manual-actions .btn {
    flex: 1;
    padding: 12px;
}

/* 禁用文本选择 */
.no-select {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}