/* 全局样式 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: #f5f7fa;
    color: #333;
    font-size: 14px;
}

/* 布局 */
.layout {
    display: flex;
    min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
    width: 200px;
    background: #1a237e;
    color: white;
    flex-shrink: 0;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.logo {
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo h2 {
    font-size: 20px;
    margin-bottom: 5px;
}

.logo p {
    font-size: 12px;
    opacity: 0.8;
}

.menu a {
    display: block;
    padding: 14px 20px;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.menu a:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.menu a.active {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border-left-color: #ff6f00;
}

/* 主内容区 */
.main-content {
    flex: 1;
    margin-left: 200px;
    min-height: 100vh;
}

.topbar {
    background: white;
    padding: 15px 25px;
    border-bottom: 1px solid #e8e8e8;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar h1 {
    font-size: 18px;
    font-weight: 500;
}

.user {
    color: #666;
}

.page-content {
    padding: 25px;
}

/* 登录页 */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a237e 0%, #3949ab 100%);
}

.login-box {
    background: white;
    padding: 32px;
    border-radius: 8px;
    width: 360px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.login-box .logo {
    border-bottom: none;
    padding: 0;
    color: #1a237e;
}

.login-box .logo p {
    opacity: 1;
    color: #666;
}

/* 卡片 */
.card {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.card-title {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f0f0f0;
}

/* 工具栏 */
.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar input,
.toolbar select {
    padding: 8px 12px;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    font-size: 14px;
}

.toolbar input:focus,
.toolbar select:focus {
    outline: none;
    border-color: #1a237e;
}

/* 按钮 */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-primary {
    background: #1a237e;
    color: white;
}

.btn-primary:hover {
    background: #283593;
}

.btn-success {
    background: #2e7d32;
    color: white;
}

.btn-success:hover {
    background: #388e3c;
}

.btn-danger {
    background: #c62828;
    color: white;
}

.btn-danger:hover {
    background: #d32f2f;
}

.btn-secondary {
    background: #f5f5f5;
    color: #333;
    border: 1px solid #d9d9d9;
}

.btn-secondary:hover {
    background: #eeeeee;
}

.btn-small {
    padding: 4px 10px;
    font-size: 12px;
}

/* Tab 切换 */
.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e8e8e8;
    padding-bottom: 10px;
}

.tab-btn {
    padding: 8px 20px;
    border: 1px solid #d9d9d9;
    background: #f5f5f5;
    color: #666;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.tab-btn:hover {
    background: #e8e8e8;
    color: #333;
}

.tab-btn.active {
    background: #1a237e;
    color: white;
    border-color: #1a237e;
    font-weight: 500;
    box-shadow: 0 2px 4px rgba(26, 35, 126, 0.2);
}

/* 状态标签 */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success {
    background: #e8f5e9;
    color: #2e7d32;
}

.badge-warning {
    background: #fff3e0;
    color: #ef6c00;
}

/* 表格 */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.data-table th,
.data-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #f0f0f0;
}

.data-table th {
    background: #fafafa;
    font-weight: 500;
    color: #666;
    font-size: 13px;
}

.data-table tr:hover {
    background: #fafafa;
}

.data-table .actions {
    white-space: nowrap;
}

/* 表单 */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: #555;
    font-size: 13px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    font-size: 14px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

/* 模态框 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #f0f0f0;
    text-align: right;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.close-btn {
    font-size: 24px;
    cursor: pointer;
    color: #999;
    background: none;
    border: none;
}

.close-btn:hover {
    color: #333;
}

/* 统计卡片 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.stat-card .label {
    color: #888;
    font-size: 13px;
    margin-bottom: 8px;
}

.stat-card .value {
    font-size: 24px;
    font-weight: 600;
    color: #1a237e;
}

.stat-card .value.danger {
    color: #c62828;
}

.stat-card .value.success {
    color: #2e7d32;
}

/* 历史记录弹窗 */
.history-modal .modal {
    max-width: 900px;
}

.history-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.history-tabs button {
    padding: 8px 16px;
    border: 1px solid #d9d9d9;
    background: white;
    cursor: pointer;
    border-radius: 4px;
}

.history-tabs button.active {
    background: #1a237e;
    color: white;
    border-color: #1a237e;
}

/* 开单项列表 */
.item-list {
    border: 1px solid #e8e8e8;
    border-radius: 4px;
    padding: 15px;
    margin-bottom: 15px;
}

.item-header {
    display: grid;
    grid-template-columns: 2fr 1.6fr 0.7fr 0.9fr 0.9fr 0.9fr 0.7fr 0.5fr 60px 60px 60px;
    gap: 10px;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 2px solid #e0e0e0;
    font-weight: bold;
    font-size: 13px;
    color: #333;
}

.item-header span {
    text-align: center;
}

.item-row {
    display: grid;
    grid-template-columns: 2fr 1.6fr 0.7fr 0.9fr 0.9fr 0.9fr 0.7fr 0.5fr 60px 60px 60px;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f0f0f0;
}

.item-row.purchase-row {
    grid-template-columns: 2fr 1.6fr 0.7fr 1fr 1fr 0.5fr 0.7fr 70px 70px;
}

.part-image-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
}

.has-image {
    color: #2e7d32;
    font-size: 12px;
    cursor: pointer;
    padding: 4px 6px;
    border: 1px solid #2e7d32;
    border-radius: 4px;
    display: inline-block;
    background: #e8f5e9;
}

.has-image:hover {
    background: #c8e6c9;
}

.no-image {
    color: #999;
    font-size: 12px;
    cursor: pointer;
    padding: 4px 6px;
    border: 1px dashed #d9d9d9;
    border-radius: 4px;
    display: inline-block;
}

.no-image:hover {
    color: #1890ff;
    border-color: #1890ff;
}

.image-share-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border: 1px solid #f0f0f0;
    border-radius: 4px;
    background: #fafafa;
}

.image-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.item-row:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.item-row input,
.item-row select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
}

.item-row input[readonly] {
    background: #f5f5f5;
}

.item-row input:focus,
.item-row select:focus {
    outline: none;
    border-color: #1890ff;
    box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}

.add-part-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(24, 144, 255, 0.4);
}

.image-upload-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.image-upload-controls input[type="file"] {
    display: none;
}

.image-preview-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
}

.selected-count {
    color: #666;
    font-size: 14px;
}

/* Toast */
.toast {
    position: fixed;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 12px 20px;
    border-radius: 4px;
    color: white;
    z-index: 2000;
    animation: fadeIn 0.3s ease;
}

.toast.success {
    background: #2e7d32;
}

.toast.error {
    background: #c62828;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -60%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 40px;
    color: #999;
}

/* 分页 */
.pagination {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin-top: 15px;
}

.pagination button {
    padding: 6px 12px;
    border: 1px solid #d9d9d9;
    background: white;
    cursor: pointer;
    border-radius: 4px;
}

.pagination button.active {
    background: #1a237e;
    color: white;
    border-color: #1a237e;
}

.pagination button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* Tab 标签页 */
.tab-nav {
    display: flex;
    border-bottom: 2px solid #e8e8e8;
    margin-bottom: 16px;
    background: #fff;
    padding: 0 4px;
}

.tab-nav-item {
    padding: 12px 20px;
    cursor: pointer;
    color: #666;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-size: 14px;
    transition: all 0.2s;
}

.tab-nav-item:hover {
    color: #1890ff;
}

.tab-nav-item.active {
    color: #1890ff;
    border-bottom-color: #1890ff;
    font-weight: 500;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* 响应式 */
@media (max-width: 768px) {
    .sidebar {
        width: 60px;
    }
    .logo h2,
    .logo p {
        display: none;
    }
    .menu a {
        padding: 15px;
        text-align: center;
        font-size: 12px;
    }
    .main-content {
        margin-left: 60px;
    }
    .item-row {
        grid-template-columns: 1fr;
    }
}

/* 可搜索下拉框高亮样式 */
.searchable-select .dropdown > div:hover,
.searchable-select .dropdown > div.active-option {
    background: #1890ff;
    color: #fff;
}

/* 配件搜索弹窗高亮行 */
.part-search-modal .data-table tbody tr.active-row,
.part-search-modal .data-table tbody tr:hover {
    background: #1890ff;
    color: #fff;
}
.part-search-modal .data-table tbody tr.active-row td[style*="sticky"],
.part-search-modal .data-table tbody tr:hover td[style*="sticky"] {
    background: #1890ff;
    color: #fff;
}

/* 配件搜索弹窗表格区域 */
.part-search-table-wrap {
    flex: 1;
    overflow: auto;
    margin-top: 12px;
    position: relative;
    max-height: 320px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
}
.part-search-table-wrap::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
.part-search-table-wrap::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 5px;
}
.part-search-table-wrap::-webkit-scrollbar-track {
    background: #f1f1f1;
}
.part-search-table-wrap table {
    border-collapse: collapse;
    min-width: 700px;
    width: 100%;
}
.part-search-table-wrap thead th {
    position: sticky;
    top: 0;
    background: #f3f4f6;
    z-index: 3;
    white-space: nowrap;
}
.part-search-table-wrap thead th:first-child {
    left: 0;
    z-index: 5;
}
.part-search-table-wrap tbody td:first-child {
    position: sticky;
    left: 0;
    background: #fff;
    z-index: 1;
}
.part-search-table-wrap tbody tr.active-row td:first-child,
.part-search-table-wrap tbody tr:hover td:first-child {
    background: #1890ff;
}
/* 历史购买过的配件行标记 */
.part-search-table-wrap tbody tr.history-row {
    background: #fff7e6;
}
.part-search-table-wrap tbody tr.history-row:hover,
.part-search-table-wrap tbody tr.history-row.active-row {
    background: #1890ff;
}
.part-search-table-wrap tbody tr.history-row td:first-child {
    background: #fff7e6;
}
.part-search-table-wrap tbody tr.history-row.active-row td:first-child,
.part-search-table-wrap tbody tr.history-row:hover td:first-child {
    background: #1890ff;
}
.history-badge {
    display: inline-block;
    background: #fa8c16;
    color: #fff;
    font-size: 11px;
    padding: 1px 5px;
    border-radius: 3px;
    white-space: nowrap;
}
.sug-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #d1d5db;
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 999;
    max-height: 220px;
    overflow-y: auto;
}
.search-btn-wrap {
    position: relative;
    z-index: 1000;
}
.sug-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    color: #374151;
    border-bottom: 1px solid #f3f4f6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sug-item:last-child { border-bottom: none; }
.sug-item:hover { background: #1890ff; color: #fff; }
.sug-item-active { background: #1890ff !important; color: #fff !important; }

/* 可清除输入框 */
.clearable-input {
    position: relative;
    display: flex;
    align-items: center;
}
.clearable-input input {
    width: 100%;
    padding-right: 24px;
    box-sizing: border-box;
}
.clear-btn {
    position: absolute;
    right: 6px;
    color: #aaa;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: none;
    user-select: none;
}
.clearable-input:hover .clear-btn,
.clearable-input input:focus ~ .clear-btn {
    display: block;
}
.clear-btn:hover { color: #555; }

/* 隐藏 number 输入框的上下箭头 */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type=number] {
    -moz-appearance: textfield;
}
.searchable-select .dropdown > div:hover .detail,
.searchable-select .dropdown > div.active-option .detail {
    color: rgba(255,255,255,0.85);
}

/* AI 助手页面 */
.ai-agent-page {
    height: calc(100vh - 80px);
    padding: 20px;
}

.ai-agent-page .chat-card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    height: 100%;
    display: flex;
    flex-direction: column;
    max-width: 900px;
    margin: 0 auto;
}

.ai-agent-page .chat-header {
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-agent-page .chat-header h3 {
    margin: 0;
    font-size: 18px;
}

.ai-agent-page .chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
}

.ai-agent-page .chat-message {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
}

.ai-agent-page .chat-message.user {
    align-items: flex-end;
}

.ai-agent-page .chat-message.assistant {
    align-items: flex-start;
}

.ai-agent-page .chat-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.6;
    font-size: 14px;
}

.ai-agent-page .chat-message.user .chat-bubble {
    background: #1a73e8;
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-agent-page .chat-message.assistant .chat-bubble {
    background: white;
    color: #333;
    border: 1px solid #e8e8e8;
    border-bottom-left-radius: 4px;
}

.ai-agent-page .chat-time {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
}

.ai-agent-page .chat-footer {
    padding: 16px 20px;
    border-top: 1px solid #eee;
    background: white;
    border-radius: 0 0 10px 10px;
}

.ai-agent-page .quick-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.ai-agent-page .chat-input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.ai-agent-page .chat-input-row textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    min-height: 42px;
    max-height: 120px;
}

.ai-agent-page .chat-input-row textarea:focus {
    outline: none;
    border-color: #1a73e8;
}

.ai-agent-page .btn-record {
    background: #f0f0f0;
    color: #333;
    border: 1px solid #ddd;
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
}

.ai-agent-page .btn-record.recording {
    background: #ff4444;
    color: white;
    border-color: #ff4444;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}

.ai-agent-page .confirm-actions {
    display: flex;
    gap: 10px;
}

/* ===== 打印预览弹窗表格样式 ===== */
.preview-sheet {
    background: #fff;
    padding: 20px 24px;
    border-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,.12);
    font-family: "Microsoft YaHei", SimSun, sans-serif;
    font-size: 13px;
    color: #000;
}
.preview-title {
    text-align: center;
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 12px;
    letter-spacing: 2px;
}
.preview-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0 20px;
    font-size: 12px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #333;
}
.preview-meta span { line-height: 1.9; }
table.preview-items {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
}
table.preview-items th,
table.preview-items td {
    border: 1px solid #333;
    padding: 5px 6px;
    text-align: center;
    font-size: 12px;
    word-break: break-all;
    vertical-align: middle;
}
table.preview-items th {
    background: #f0f0f0;
    font-weight: bold;
}
table.preview-items td.left { text-align: left; }
table.preview-items .total-row {
    font-weight: bold;
    background: #fafafa;
}
.preview-bottom {
    display: flex;
    flex-wrap: wrap;
    gap: 0 20px;
    font-size: 12px;
    padding: 6px 0;
    border-top: 1px solid #333;
    border-bottom: 1px solid #333;
    margin-bottom: 8px;
}
.preview-bottom span { line-height: 1.9; }
.preview-address,
.preview-slogan,
.preview-remark {
    font-size: 12px;
    margin-top: 5px;
}
