:root {
    --primary: #667eea;
    --primary-dark: #5a6fd6;
    --secondary: #764ba2;
    --success: #11998e;
    --danger: #eb3349;
    --warning: #f093fb;
    --bg: #f5f7fa;
    --card-bg: #ffffff;
    --text: #333333;
    --text-muted: #999999;
    --border: #e0e0e0;
    --sidebar-bg: #2c3e50;
    --sidebar-text: #ecf0f1;
    --header-height: 60px;
    --radius: 10px;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    font-family: 'Microsoft YaHei', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--header-height);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.header h1 {
    font-size: 18px;
    flex: 1;
    text-align: center;
    font-weight: 500;
}

.main-content {
    padding: 80px 20px 20px;
    min-height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
}

.section {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 25px;
    margin-bottom: 20px;
    transition: box-shadow 0.3s;
}

.section:hover {
    box-shadow: var(--shadow-hover);
}

.section h3 {
    margin-bottom: 20px;
    color: #2c3e50;
    font-size: 16px;
    border-bottom: 2px solid #ecf0f1;
    padding-bottom: 10px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    margin-bottom: 8px;
    color: #555;
    font-weight: 500;
    font-size: 14px;
}

.form-group input,
.form-group select {
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    transition: border-color 0.3s, box-shadow 0.3s;
    width: 100%;
    min-height: 52px;
    touch-action: manipulation;
    background: white;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.form-group input:focus-visible,
.form-group select:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-group.full-width {
    grid-column: span 2;
}

.btn {
    padding: 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.3s, transform 0.1s, box-shadow 0.2s;
    width: 100%;
    min-height: 52px;
    touch-action: manipulation;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn:active {
    transform: scale(0.99);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3);
}

.btn-primary:hover {
    opacity: 0.92;
    box-shadow: 0 6px 14px rgba(102, 126, 234, 0.35);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    opacity: 0.92;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 可搜索下拉框 */
.searchable-select {
    position: relative;
}

.searchable-select-trigger {
    width: 100%;
    min-height: 52px;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 15px;
    transition: border-color 0.3s;
}

.searchable-select-trigger:hover {
    border-color: #d0d0d0;
}

.searchable-select-trigger::after {
    content: '▼';
    font-size: 10px;
    color: var(--text-muted);
    margin-left: 10px;
}

.searchable-select.open .searchable-select-trigger {
    border-color: var(--primary);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.searchable-select.open .searchable-select-trigger::after {
    content: '▲';
}

.searchable-select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    border: 2px solid var(--primary);
    border-top: none;
    border-bottom-left-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
    background: white;
    max-height: 320px;
    overflow-y: auto;
    display: none;
    z-index: 101;
    box-shadow: var(--shadow-hover);
}

.searchable-select.open .searchable-select-dropdown {
    display: block;
}

.searchable-select-search {
    padding: 10px;
    border-bottom: 1px solid #eee;
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
}

.searchable-select-search input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.searchable-select-search input:focus {
    outline: none;
    border-color: var(--primary);
}

.searchable-select-options {
    max-height: 260px;
    overflow-y: auto;
}

.searchable-select-option {
    padding: 12px 14px;
    cursor: pointer;
    border-bottom: 1px solid #f5f5f5;
    transition: background 0.2s;
}

.searchable-select-option:hover,
.searchable-select-option.keyboard-active {
    background: #f0f4ff;
}

.searchable-select-option .material-name {
    font-size: 14px;
    color: var(--text);
    font-weight: 500;
}

.searchable-select-option .material-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.stock-badge {
    background: #fff3cd;
    color: #856404;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
}

.stock-badge.no-stock {
    background: #f8d7da;
    color: #721c24;
}

.location-badge {
    background: #e8f4fd;
    color: #0c5460;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
}

.searchable-select-no-results {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.searchable-select-loading {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* 表格 */
.table-container {
    overflow-x: auto;
    margin-top: 20px;
    border-radius: var(--radius);
    border: 1px solid #f0f0f0;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

table th {
    background: #f5f7fa;
    padding: 12px 10px;
    text-align: left;
    color: #555;
    font-weight: 600;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

table td {
    padding: 12px 10px;
    border-bottom: 1px solid #f0f0f0;
    color: var(--text);
}

table tbody tr:hover {
    background: #f9f9f9;
}

table tbody tr:nth-child(even) {
    background: #fafbfc;
}

table tbody tr:nth-child(even):hover {
    background: #f2f4f6;
}

.empty-result {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 14px;
}

.preview-image {
    max-width: 60px;
    max-height: 60px;
    object-fit: contain;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid #eee;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.preview-image:hover {
    border-color: var(--primary);
    box-shadow: 0 0 8px rgba(102, 126, 234, 0.3);
}

.download-link {
    display: inline-block;
    padding: 6px 12px;
    background: var(--primary);
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-size: 12px;
    transition: background 0.2s;
}

.download-link:hover {
    background: var(--primary-dark);
}

/* 统计卡片 */
.summary-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.summary-card {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    padding: 20px;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: var(--shadow);
    transition: transform 0.2s;
}

.summary-card:hover {
    transform: translateY(-2px);
}

.summary-card .label {
    font-size: 13px;
    opacity: 0.9;
    margin-bottom: 8px;
}

.summary-card .value {
    font-size: 24px;
    font-weight: bold;
}

.summary-card.in {
    background: linear-gradient(135deg, var(--success) 0%, #38ef7d 100%);
}

.summary-card.out {
    background: linear-gradient(135deg, var(--danger) 0%, #f45c43 100%);
}

.summary-card.remaining {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
}

.summary-card.records {
    background: linear-gradient(135deg, var(--warning) 0%, #f5576c 100%);
}

.summary-card.location {
    background: linear-gradient(135deg, #36d1dc 0%, #5b86e5 100%);
}

/* 分页 */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.pagination button {
    padding: 8px 14px;
    border: 1px solid var(--border);
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.pagination button:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

.pagination button.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-info {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 10px;
}

/* 加载与骨架屏 */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    border-radius: 4px;
    animation: skeleton-loading 1.2s infinite;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.7);
    z-index: 200;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(2px);
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(102, 126, 234, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Toast 提示 */
.toast-container {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 12px 18px;
    border-radius: var(--radius);
    color: white;
    font-size: 14px;
    box-shadow: var(--shadow-hover);
    animation: slideIn 0.3s ease;
    max-width: 320px;
    word-break: break-word;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* 响应式 */
@media (max-width: 768px) {
    .main-content {
        padding: 75px 12px 20px;
    }

    .section {
        padding: 18px;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .form-group.full-width {
        grid-column: span 1;
    }

    .summary-info {
        grid-template-columns: repeat(2, 1fr);
    }

    .summary-card .value {
        font-size: 20px;
    }

    table {
        font-size: 12px;
    }

    table th, table td {
        padding: 8px 6px;
    }

    .btn {
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 16px;
    }

    .summary-info {
        grid-template-columns: 1fr;
    }
}

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 打印优化 */
@media print {
    .header,
    .form-actions,
    .pagination,
    .toast-container {
        display: none !important;
    }

    .main-content {
        padding: 0;
    }

    .section {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}
