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

:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --radius: 8px;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.5;
}

/* ========== 登录页 ========== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-card {
    background: #fff;
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 400px;
}

.login-card h1 {
    text-align: center;
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--gray-800);
}

.login-card .subtitle {
    text-align: center;
    color: var(--gray-500);
    margin-bottom: 32px;
}

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-700);
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-700);
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-control::placeholder {
    color: var(--gray-400);
}

/* ========== 按钮 ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    gap: 6px;
}

.btn-block {
    width: 100%;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover {
    background: #16a34a;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ========== 布局 ========== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
    width: 240px;
    background: #fff;
    border-right: 1px solid var(--gray-200);
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--gray-200);
    position: relative;
}

.sidebar-title {
    font-size: 18px;
    color: var(--primary);
    margin: 0;
}

.sidebar-close {
    display: none;
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    font-size: 24px;
    color: var(--gray-400);
    cursor: pointer;
    border-radius: var(--radius);
}

.sidebar-close:hover {
    background: var(--gray-100);
    color: var(--gray-600);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--gray-600);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-icon {
    margin-right: 10px;
    font-size: 16px;
}

.nav-item:hover {
    background: var(--gray-50);
    color: var(--primary);
}

.nav-item.active {
    background: rgba(79, 70, 229, 0.05);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 500;
}

/* 主内容区 */
.main-content {
    flex: 1;
    margin-left: 240px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* 顶部栏 */
.topbar {
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--gray-800);
}

.search-box {
    display: flex;
    gap: 8px;
}

.search-box .form-control {
    width: 280px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: var(--radius);
    transition: background 0.2s;
}

.user-menu:hover {
    background: var(--gray-100);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 500;
}

.user-name {
    font-size: 14px;
    color: var(--gray-700);
}

/* 页面内容 */
.page-content {
    flex: 1;
    padding: 24px;
}

.content-area {
    flex: 1;
    padding: 24px;
}

/* ========== 卡片 ========== */
.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-800);
    margin: 0;
}

.card-body {
    padding: 20px;
}

.card-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
}

/* ========== 统计卡片 ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.stat-card .stat-label {
    font-size: 14px;
    color: var(--gray-500);
    margin-bottom: 8px;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
}

.stat-card.primary .stat-value { color: var(--primary); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.warning .stat-value { color: var(--warning); }

/* ========== 表格 ========== */
.table-wrapper {
    overflow-x: auto;
}

.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

.table th {
    background: var(--gray-50);
    font-weight: 600;
    font-size: 13px;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table tr:hover {
    background: var(--gray-50);
}

.table td {
    font-size: 14px;
    color: var(--gray-700);
}

/* ========== 标签 ========== */
.tag {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 500;
}

.tag-success {
    background: #dcfce7;
    color: #166534;
}

.tag-danger {
    background: #fee2e2;
    color: #991b1b;
}

.tag-warning {
    background: #fef3c7;
    color: #92400e;
}

.tag-primary {
    background: #e0e7ff;
    color: #3730a3;
}

.tag-gray {
    background: var(--gray-200);
    color: var(--gray-600);
}

/* ========== 工具栏 ========== */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.toolbar .form-control {
    width: auto;
    min-width: 150px;
}

/* ========== 输入组 ========== */
.input-group {
    display: flex;
    gap: 8px;
}

.input-group .form-control {
    flex: 1;
}

/* ========== 商品信息框 ========== */
.product-info-box {
    background: var(--gray-50);
    padding: 16px;
    border-radius: var(--radius);
    margin-top: 16px;
}

.scan-actions {
    margin-top: 16px;
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.scan-actions .form-group {
    margin-bottom: 0;
}

/* ========== 二维码容器 ========== */
.qrcode-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    background: var(--gray-50);
    border-radius: var(--radius);
    min-width: 100px;
}

.qrcode-container canvas {
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    background: #ffffff;
}

.qrcode-container .btn {
    margin-top: 8px;
    font-size: 11px;
    padding: 4px 8px;
    width: 100%;
    text-align: center;
}

.qrcode-container .btn:hover {
    background: var(--gray-300);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

/* ========== 分页 ========== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

.pagination-info {
    font-size: 14px;
    color: var(--gray-500);
}

.pagination-btn {
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    background: #fff;
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--gray-50);
    border-color: var(--gray-400);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========== 模态框 ========== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: #fff;
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    font-size: 24px;
    color: var(--gray-400);
    cursor: pointer;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: var(--gray-100);
    color: var(--gray-600);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ========== 表单行 ========== */
.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

/* ========== 警告提示 ========== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-warning {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    color: #92400e;
}

.alert-success {
    background: #dcfce7;
    border: 1px solid #86efac;
    color: #166534;
}

.alert-danger {
    background: #fee2e2;
    border: 1px solid #fca5a5;
    color: #991b1b;
}

/* ========== 空状态 ========== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-500);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state-text {
    font-size: 14px;
}

/* ========== 移动端菜单按钮 ========== */
.menu-toggle {
    display: none;
    padding: 8px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: var(--radius);
}

.menu-toggle:hover {
    background: var(--gray-100);
}

.menu-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--gray-600);
    margin: 5px 0;
    transition: 0.3s;
}

/* ========== 徽章 ========== */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
}

.badge-danger {
    background: var(--danger);
    color: #fff;
}

.badge-success {
    background: var(--success);
    color: #fff;
}

.badge-warning {
    background: var(--warning);
    color: #fff;
}

.badge-primary {
    background: var(--primary);
    color: #fff;
}

/* ========== 响应式 ========== */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .menu-toggle {
        display: block;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .main-content {
        margin-left: 0;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .topbar {
        padding: 12px 16px;
    }

    .search-box .form-control {
        width: 180px;
    }

    .page-content {
        padding: 16px;
    }

    .content-area {
        padding: 16px;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .toolbar {
        width: 100%;
    }

    .toolbar .form-control {
        flex: 1;
        min-width: 0;
    }

    .table th,
    .table td {
        padding: 10px 12px;
        font-size: 13px;
    }

    .user-name {
        display: none;
    }
}

@media (max-width: 480px) {
    .login-card {
        padding: 24px;
    }

    .login-card h1 {
        font-size: 20px;
    }

    .search-box {
        display: none;
    }

    .stat-card .stat-value {
        font-size: 24px;
    }
}

/* ========== 扫码容器样式 ========== */
.scanner-container {
    margin: 20px 0;
    padding: 20px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    background: #f9f9f9;
}

.scanner-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.scanner-header h4 {
    margin: 0;
    color: var(--gray-800);
}

.btn-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray-400);
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
}

.btn-close:hover {
    background: var(--gray-100);
    color: var(--gray-600);
}

.scanner-video {
    position: relative;
    width: 100%;
    max-width: 400px;
    margin: 0 auto 20px;
}

.scanner-video video {
    width: 100%;
    height: auto;
    border-radius: var(--radius);
    background: #000;
}

.scanner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.scanner-frame {
    width: 250px;
    height: 250px;
    border: 2px solid #4CAF50;
    border-radius: 8px;
    animation: pulse 2s infinite;
}

.scanner-overlay p {
    margin-top: 15px;
    color: var(--gray-800);
    font-size: 14px;
    background: rgba(255, 255, 255, 0.8);
    padding: 5px 10px;
    border-radius: 4px;
}

.scanner-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(76, 175, 80, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
    }
}

/* ========== 打印样式 ========== */
@media print {
    .sidebar,
    .topbar,
    .btn,
    .pagination,
    .scanner-container {
        display: none !important;
    }

    .main-content {
        margin-left: 0;
    }

    .card {
        box-shadow: none;
        border: 1px solid var(--gray-300);
    }
}
