/* ==================== 基础变量 ==================== */
:root {
    --primary: #1677ff;
    --primary-light: #e6f4ff;
    --success: #52c41a;
    --warning: #faad14;
    --danger: #ff4d4f;
    --bg: #f5f5f5;
    --card-bg: #ffffff;
    --text: #1f1f1f;
    --text-secondary: #666666;
    --border: #e8e8e8;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --radius: 12px;
    --radius-sm: 8px;
}

/* ==================== 重置样式 ==================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 
                 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==================== 头部 ==================== */
.header {
    background: linear-gradient(135deg, var(--primary), #4096ff);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.header .status {
    font-size: 0.75rem;
    opacity: 0.9;
    padding: 4px 10px;
    background: rgba(255,255,255,0.2);
    border-radius: 20px;
}

.header .status.connected {
    background: rgba(82, 196, 26, 0.3);
}

/* ==================== 主内容区 ==================== */
.main {
    flex: 1;
    padding: 12px;
    padding-bottom: 100px;
}

.desktop-order-layout {
    display: block;
}

.desktop-order-sidebar,
.desktop-order-main {
    display: block;
}

/* ==================== 卡片 ==================== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}

.card label {
    display: block;
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 0.9rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-header label {
    margin-bottom: 0;
}

.desktop-card-toggle {
    display: none;
    width: 100%;
    background: transparent;
    border: none;
    padding: 0;
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 600;
    text-align: left;
    align-items: center;
    justify-content: space-between;
}

.desktop-collapsible-content {
    display: block;
}

/* ==================== 输入框 ==================== */
input[type="text"],
input[type="number"],
input[type="tel"],
select,
textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="tel"]:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

textarea {
    resize: vertical;
    min-height: 60px;
}

/* ==================== 下拉列表 ==================== */
.dropdown-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    max-height: 200px;
    overflow-y: auto;
    z-index: 50;
}

.dropdown-list .item {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.dropdown-list .item:last-child {
    border-bottom: none;
}

.dropdown-list .item:active {
    background: var(--primary-light);
}

.dropdown-list .item .name {
    font-weight: 500;
}

.dropdown-list .item .sub {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.customer-selector {
    position: relative;
}

.customer-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.customer-header-row label {
    margin-bottom: 0;
}

.btn-add-customer {
    padding: 8px 12px;
    font-size: 0.85rem;
    white-space: nowrap;
}

.selected-item {
    margin-top: 10px;
    padding: 12px;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.selected-item .clear-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
}

/* ==================== 按钮 ==================== */
button {
    cursor: pointer;
    font-size: 0.9rem;
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:active {
    background: #0958d9;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:active {
    background: #389e0d;
}

.btn-secondary {
    background: var(--primary-light);
    color: var(--primary);
}

.btn-secondary:active {
    background: #cce7ff;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-outline:active {
    background: var(--bg);
}

/* ==================== 最近购买 ==================== */
.recent-list {
    margin-top: 12px;
}

.recent-list .hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.material-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.material-chip {
    background: #fafafa;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 0.85rem;
    cursor: pointer;
}

.material-chip:active {
    background: var(--primary-light);
    border-color: var(--primary);
}

/* ==================== 订单明细 ==================== */
.order-items {
    min-height: 60px;
}

.empty-hint {
    color: var(--text-secondary);
    text-align: center;
    padding: 20px;
    font-size: 0.9rem;
}

.order-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    margin-bottom: 6px;
}

.order-item .item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 6px;
}

.order-item .item-name {
    font-weight: 500;
    font-size: 0.95rem;
}

.order-item .item-spec {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.order-item .item-inputs {
    /* display: grid;  Remove grid to allow flex-direction: column in JS to work */
    /* grid-template-columns: 1fr 1fr 1fr; */
    /* gap: 8px; */
    display: block;
}

.order-item .input-group {
    display: flex;
    flex-direction: column;
}

.order-item .input-group label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 2px;
    font-weight: normal;
}

.order-item .input-group input {
    padding: 6px 8px;
    font-size: 0.85rem;
    text-align: right;
}

.order-item .input-group input.short-input {
    width: 100px;
    flex: none;
}

.order-item .item-amount {
    text-align: right;
    margin-top: 8px;
    font-weight: 600;
    color: var(--danger);
}

.order-item .delete-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    padding: 0;
    width: 24px;
    height: 24px;
}

/* ==================== 批量操作 ==================== */
.batch-actions {
    display: flex;
    gap: 6px;
    margin-top: 12px;
    flex-wrap: nowrap;
    padding: 8px 10px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
    align-items: center;
    justify-content: flex-start;
}

/* 税点输入控件 */
.tax-rate-group {
    display: flex;
    align-items: center;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 20px;
    overflow: hidden;
    height: 30px;
}

.tax-rate-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #475569;
    padding: 0 6px;
    white-space: nowrap;
    line-height: 1;
}

.tax-rate-group input {
    width: 40px;
    border: none;
    border-left: 1px solid #cbd5e1;
    padding: 0 6px;
    font-size: 0.85rem;
    font-weight: 700;
    text-align: center;
    color: #1e293b;
    background: transparent;
    outline: none;
    height: 100%;
}

.tax-rate-group input:focus {
    background: #f8fafc;
}

/* 更多下拉菜单 */
.more-dropdown {
    position: relative;
    display: inline-block;
}

.more-dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 100;
    min-width: 140px;
    margin-top: 6px;
    overflow: hidden;
}

.more-dropdown-content.show {
    display: block;
}

.more-dropdown-content button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 14px;
    border: none;
    background: none;
    font-size: 0.85rem;
    color: #334155;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

.more-dropdown-content button:hover {
    background: #f1f5f9;
}

.more-dropdown-content button:not(:last-child) {
    border-bottom: 1px solid #f1f5f9;
}

/* 强调按钮（切换不含税） */
#batchActions .btn-emphasis {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 1px solid #f59e0b;
    color: #92400e;
    border-radius: 20px;
    padding: 6px 10px;
    font-size: 0.8rem;
    font-weight: 700;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(245, 158, 11, 0.15);
    cursor: pointer;
    white-space: nowrap;
    height: 30px;
    line-height: 1.2;
}

#batchActions .btn-emphasis:hover {
    background: linear-gradient(135deg, #fde68a 0%, #fcd34d 100%);
    border-color: #d97706;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(245, 158, 11, 0.25);
}

#batchActions .btn-emphasis:active {
    background: #fcd34d;
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(245, 158, 11, 0.15);
}

/* 更多按钮 */
#batchActions .more-dropdown .btn-outline {
    padding: 6px 10px;
    font-size: 0.8rem;
    height: 30px;
    line-height: 1.2;
}

/* ==================== 汇总 ==================== */
.summary {
    background: linear-gradient(135deg, #fff7e6, #fff1e0);
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.total-amount {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--danger);
}

/* ==================== 底部 ==================== */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    padding: 12px 16px;
    display: flex;
    gap: 12px;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
    z-index: 100;
}

.footer button {
    flex: 1;
    padding: 14px;
    font-size: 1rem;
}

/* ==================== 弹窗 ==================== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    align-items: flex-end;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.1rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    padding: 0;
    width: 32px;
    height: 32px;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.modal-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-footer #cartCount {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.create-customer-tip {
    margin-bottom: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: #f6f8fb;
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.5;
}

.create-customer-form {
    display: grid;
    gap: 12px;
}

.create-contact-form {
    display: grid;
    gap: 12px;
}

.create-contact-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.create-customer-field label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.88rem;
    font-weight: 600;
}

.create-customer-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.create-customer-inline input {
    flex: 1;
}

.create-customer-inline .btn-outline {
    flex-shrink: 0;
    padding: 10px 12px;
    white-space: nowrap;
}

.contact-project-select {
    align-items: stretch;
}

.contact-project-select select {
    flex: 1;
}

.create-project-fields {
    display: grid;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fafcff;
}

.selected-project-hint {
    margin-top: 6px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.tax-code-picker-content {
    max-width: 520px;
    max-height: 78vh;
    display: flex;
    flex-direction: column;
}

.tax-code-picker-status {
    padding: 10px 16px 4px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.tax-code-candidate-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.tax-code-candidate-item:last-child {
    border-bottom: none;
}

.tax-code-candidate-item .candidate-main {
    flex: 1;
    min-width: 0;
}

.tax-code-candidate-item .candidate-title {
    font-size: 0.98rem;
    font-weight: 700;
    color: var(--text);
    word-break: break-all;
}

.tax-code-candidate-item .candidate-row,
.tax-code-candidate-item .candidate-meta {
    margin-top: 4px;
    font-size: 0.84rem;
    color: var(--text-secondary);
    word-break: break-all;
}

.tax-code-candidate-item .candidate-tax-code {
    margin-top: 6px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
    word-break: break-all;
}

.tax-code-candidate-item .candidate-action {
    flex-shrink: 0;
    min-width: 72px;
    padding: 10px 12px;
}

.ton-price-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.ton-price-item label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.ton-price-tip {
    margin-top: 12px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.ton-highlight {
    border-color: var(--warning);
    box-shadow: 0 0 0 3px rgba(250, 173, 20, 0.2);
}

/* ==================== 搜索栏 ==================== */
.search-bar {
    margin-bottom: 12px;
}

.search-bar input {
    background: var(--bg);
    border: none;
}

/* ==================== 筛选标签 ==================== */
.filter-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 12px;
}

.filter-tabs .tab {
    flex-shrink: 0;
    padding: 6px 14px;
    background: #fafafa;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
}

.filter-tabs .tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.quick-group-btn {
    padding: 6px 10px;
    margin: 4px;
    border: 1px solid var(--border);
    background: white;
    border-radius: 16px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

/* ==================== 物料列表 ==================== */
.material-list {
    max-height: 400px;
    overflow-y: auto;
}

.material-list .loading {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

.quick-groups-modal {
    display: flex;
    flex-wrap: wrap;
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
    background: #fafafa;
    gap: 8px;
}

.material-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    gap: 8px;
}

.material-item:active {
    background: var(--bg);
}

.material-item .check-icon {
    width: 24px;
    height: 24px;
    border: 2px solid #ddd;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: white;
    flex-shrink: 0;
}

.material-item.selected .check-icon {
    background: var(--primary);
    border-color: var(--primary);
}

.material-item .info {
    flex: 1;
    min-width: 0;
}

.material-item .name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
    transition: font-size 0.2s ease;
}

.material-item .spec {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.material-item .meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.material-item.selected {
    background: var(--primary-light);
}

/* 已选预览面板 */
.selected-preview {
    background: #f5f5f5;
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    max-height: 120px;
    overflow-y: auto;
}

.selected-preview .preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 8px;
}

.selected-preview .clear-all {
    color: var(--danger);
    cursor: pointer;
    font-weight: normal;
    font-size: 0.8rem;
}

.selected-preview .preview-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.selected-preview .preview-item {
    display: flex;
    align-items: center;
    background: white;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.8rem;
    gap: 6px;
}

.selected-preview .preview-name {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.selected-preview .preview-remove {
    color: #999;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
}

/* ==================== 隐藏 ==================== */
.hidden {
    display: none !important;
}

/* ==================== AI 输入 ==================== */
.ai-input-card {
    position: fixed;
    bottom: 80px;
    left: 12px;
    right: 12px;
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

/* ==================== 级联分组选择器 ==================== */
.picker-body {
    display: flex;
    padding: 0 !important;
    height: 75vh;
}

.picker-context {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: #fffbe6;
    color: #8c6d1f;
    font-size: 0.85rem;
    gap: 8px;
}

.picker-context span {
    flex: 1;
}

.group-sidebar {
    width: 120px;
    background: #fafafa;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 8px 10px;
    font-weight: 600;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
    background: white;
}

.group-list {
    flex: 1;
    overflow-y: auto;
}

.group-item {
    padding: 10px 8px;
    font-size: 0.8rem;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.group-item:active,
.group-item.active {
    background: white;
    color: var(--primary);
    font-weight: 500;
}

.group-item .arrow {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.group-item.has-children::after {
    content: '›';
    color: var(--text-secondary);
}

.material-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 8px;
}

/* 面包屑导航 */
.breadcrumb {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.breadcrumb .crumb {
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

.breadcrumb .crumb:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.breadcrumb .crumb.active {
    color: var(--primary);
    font-weight: 500;
}

.breadcrumb .separator {
    color: #ccc;
}

.material-area .search-bar {
    margin-bottom: 6px;
}

.material-area .material-list {
    flex: 1;
    overflow-y: auto;
    max-height: none;
}

/* ==================== Header Actions ==================== */
.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-sm {
    padding: 4px 8px;
    font-size: 0.75rem;
}

/* ==================== 联系人/驾驶员选择器 ==================== */
.extra-selectors {
    margin-top: 12px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.extra-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.extra-row label {
    font-weight: normal;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0;
}

.selector-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: #fafafa;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    min-width: 120px;
    justify-content: space-between;
}

.selector-btn:active {
    background: var(--primary-light);
}

.selector-btn .arrow {
    color: var(--text-secondary);
}

/* 联系人详情显示 */
.contact-details {
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: var(--radius-sm);
    margin: 8px 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
    position: relative;
}

.clear-contact-btn {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    margin-left: 8px;
    transition: color 0.2s;
}

.clear-contact-btn:hover {
    color: #ef4444;
}

.contact-card-clear {
    background: #f1f5f9;
    border: 1px dashed #cbd5e1;
}

.contact-card-clear .contact-name {
    color: #64748b;
    font-weight: 500;
}

/* 汇总表格 */
.summary-table {
    margin: 12px 0;
    overflow-x: auto;
}

.summary-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
}

.recent-sales-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.recent-sales-table .col-date {
    width: 24%;
    white-space: nowrap;
}

.recent-sales-table .col-customer {
    width: 20%;
    white-space: normal;
    word-break: break-all;
    overflow-wrap: anywhere;
}

.recent-sales-table .col-unit {
    width: 8%;
    white-space: nowrap;
    text-align: center;
}

.recent-sales-table .col-qty {
    width: 16%;
    white-space: nowrap;
    text-align: right;
}

.recent-sales-table .col-price {
    width: 32%;
    white-space: nowrap;
    text-align: right;
}

.summary-table th,
.summary-table td {
    padding: 6px 4px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.summary-table th {
    background: #f5f5f5;
    font-weight: 500;
    color: var(--text-secondary);
}

.summary-table td:first-child {
    max-width: 140px;
    white-space: normal;
    word-break: break-all;
    line-height: 1.3;
}

.summary-table td:nth-child(2),
.summary-table td:nth-child(3),
.summary-table td:nth-child(4) {
    text-align: right;
    white-space: nowrap;
}

.summary-table th:nth-child(2),
.summary-table th:nth-child(3),
.summary-table th:nth-child(4) {
    text-align: right;
}

.summary-table .recent-sales-table td.col-customer {
    white-space: normal;
    word-break: break-all;
    overflow-wrap: anywhere;
    text-align: left;
}

.summary-table .empty-cell {
    color: #f44336;
}

/* 选择器弹窗面板 */
.picker-panel {
    background: white;
    border-radius: var(--radius);
    width: 100%;
    max-width: 360px;
    max-height: 75vh;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.2s ease;
}

.picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.picker-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-add-contact {
    padding: 8px 10px;
}

.picker-list {
    flex: 1;
    overflow-y: auto;
    max-height: 50vh;
}

.picker-item {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
}

.picker-item:active {
    background: var(--primary-light);
}

.picker-item .item-name {
    font-weight: 500;
}

.picker-item .item-sub {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* 联系人卡片样式 */
.contact-card {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.15s;
}

.contact-card:active {
    background: var(--primary-light);
}

.contact-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.contact-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text);
}

.contact-mobile {
    font-size: 0.9rem;
    color: var(--primary);
    font-weight: 500;
}

.contact-address,
.contact-project {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
    line-height: 1.4;
}

.contact-project {
    color: #999;
}

/* ==================== 历史购买列表项 ==================== */
.recent-item {
    display: flex;
    align-items: flex-start;
    padding: 8px 12px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    gap: 8px;
    transition: background 0.15s;
}

.recent-item:active,
.recent-item.selected {
    background: var(--primary-light);
}

.recent-item .check-icon {
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: white;
    flex-shrink: 0;
    margin-top: 1px;
}

.recent-item.selected .check-icon {
    background: var(--primary);
    border-color: var(--primary);
}

.recent-info {
    flex: 1;
    min-width: 0;
}

.recent-title {
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 2px;
    line-height: 1.2;
}

.recent-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 1px;
}

.recent-address {
    font-size: 0.7rem;
    color: #999;
    line-height: 1.2;
}

/* header按钮组 */
.header-btns {
    display: flex;
    gap: 8px;
}

/* 快速定位分组 */
.quick-groups {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.quick-group-btn {
    padding: 8px 14px;
    background: linear-gradient(135deg, var(--primary) 0%, #1565c0 100%);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    transition: transform 0.15s, box-shadow 0.15s;
}

.quick-group-btn:active {
    transform: scale(0.95);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* 弹窗内快速分组 */
.quick-groups-modal {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 10px 16px;
    background: #f8f9fa;
    border-bottom: 1px solid var(--border);
}

/* ==================== 已选物料弹窗 ==================== */
.sub-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.sub-modal.hidden {
    display: none;
}

.selected-modal-content {
    background: white;
    border-radius: var(--radius);
    width: 100%;
    max-width: 360px;
    max-height: 60vh;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.selected-modal-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.selected-modal-header .clear-all-btn {
    color: var(--danger);
    font-size: 0.85rem;
    font-weight: normal;
    cursor: pointer;
}

.selected-modal-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.selected-modal-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid #f0f0f0;
}

.selected-modal-item .item-info {
    flex: 1;
    min-width: 0;
}

.selected-modal-item .item-name {
    font-weight: 500;
    margin-bottom: 2px;
}

.selected-modal-item .item-spec {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.selected-modal-item .item-remove {
    color: var(--danger);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 8px;
}

/* ==================== 客户风险 ==================== */
.risk-section {
    margin-top: 12px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.risk-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    font-weight: 500;
}

.risk-header-main {
    display: flex;
    align-items: center;
    gap: 8px;
}

.risk-level {
    font-weight: 600;
}
.risk-level.level-极高 { color: #ff4d4f; }
.risk-level.level-高 { color: #fa8c16; }
.risk-level.level-中 { color: #faad14; }
.risk-level.level-低 { color: #52c41a; }
.risk-level.level-无 { color: #52c41a; }

.risk-toggle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.risk-toggle.expanded {
    transform: rotate(180deg);
}

.risk-summary-grid {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}

.risk-metric-grid {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}

.risk-summary-grid-inner,
.risk-metric-grid-inner,
.risk-detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.risk-summary-grid-inner.compact-desktop {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.risk-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.risk-section-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text);
}

.risk-section-count {
    flex-shrink: 0;
    padding: 2px 8px;
    border-radius: 999px;
    background: #eef4ff;
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 600;
}

.risk-stat-card {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fafcff;
}

.risk-stat-card.tone-critical {
    background: #fff1f0;
    border-color: #ffccc7;
}

.risk-stat-card.tone-high {
    background: #fff7e6;
    border-color: #ffd591;
}

.risk-stat-card.tone-medium {
    background: #fffbe6;
    border-color: #ffe58f;
}

.risk-stat-card.tone-low {
    background: #f6ffed;
    border-color: #b7eb8f;
}

.risk-stat-card.tone-default {
    background: #f8fbff;
    border-color: #dbe7f5;
}

.risk-stat-label {
    display: block;
    font-size: 0.76rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.risk-stat-value {
    display: block;
    font-size: 0.9rem;
    color: var(--text);
    font-weight: 600;
    word-break: break-word;
}

.risk-detail-toggle {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--primary);
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    cursor: pointer;
}

.risk-content {
    padding: 8px 0;
    font-size: 0.85rem;
    line-height: 1.6;
}

.risk-content .risk-row {
    display: flex;
    padding: 4px 0;
}

.risk-content .risk-label {
    color: var(--text-secondary);
    min-width: 80px;
}

.risk-content .risk-value {
    flex: 1;
    word-break: break-all;
}

.risk-content .risk-block {
    padding: 8px;
    background: #f9f9f9;
    border-radius: 6px;
}

.risk-content .risk-block-compact {
    padding: 7px 8px;
}

.risk-content .risk-block-title {
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text);
    font-size: 0.76rem;
}

.risk-content .risk-block-text {
    color: var(--text-secondary);
    font-size: 0.76rem;
    white-space: pre-wrap;
    line-height: 1.45;
}

/* ==================== AI 智能开单 ==================== */
/* AI 按钮样式 */
.btn-ai {
    background: linear-gradient(135deg, #722ed1, #9254de);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 2px 6px rgba(114, 46, 209, 0.3);
    transition: transform 0.1s, box-shadow 0.2s;
}

.btn-ai:active {
    transform: scale(0.96);
    box-shadow: 0 1px 3px rgba(114, 46, 209, 0.3);
}

.ai-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #722ed1, #9254de);
    color: white;
    border-radius: var(--radius) var(--radius) 0 0;
    cursor: pointer;
    font-weight: 500;
}

.ai-toggle {
    font-size: 0.8rem;
}

.ai-body {
    padding: 12px;
}

.ai-body textarea {
    width: 100%;
    min-height: 60px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    resize: none;
    margin-bottom: 8px;
}

.ai-body .btn-primary {
    width: 100%;
}

/* AI 确认弹窗 */
.ai-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-item {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 12px;
    background: #f9f9f9;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.ai-item-info {
    flex: 1;
    min-width: 0;
}

.ai-item-name {
    font-weight: 500;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-item-spec {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.ai-item-qty {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-item-qty input {
    width: 60px;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    text-align: center;
}

.ai-item-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.ai-item-actions .btn-sm {
    white-space: nowrap;
}

.ai-confidence {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 500;
}

.ai-confidence.high {
    background: #d9f7be;
    color: #389e0d;
}

.ai-confidence.medium {
    background: #fff3cd;
    color: #d48806;
}

.ai-confidence.low {
    background: #ffeef0;
    color: #cf1322;
}

/* 二次匹配候选选择 */
.ai-secondary-item {
    padding: 10px 12px;
    background: #f0f5ff;
    border-radius: var(--radius-sm);
    border: 1px solid #adc6ff;
    margin-bottom: 8px;
}

.ai-secondary-desc {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 6px;
}

.ai-candidate-select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.9rem;
    background: white;
}

.ai-candidate-select:disabled {
    background: #f6ffed;
    border-color: #52c41a;
}

/* AI 加载遮罩 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

.loading-overlay p {
    color: var(--primary);
    font-size: 1.1rem;
    font-weight: 500;
}

@media (min-width: 1100px) {
    body {
        background:
            radial-gradient(circle at top left, rgba(22, 119, 255, 0.08), transparent 22%),
            linear-gradient(180deg, #eef4ff 0%, #f5f7fb 18%, #edf1f7 100%);
    }

    #app {
        max-width: 100%;
    }

    .header {
        padding: 18px 28px;
    }

    .header > div {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .main {
        width: min(1280px, 100%);
        margin: 0 auto;
        padding: 20px 16px 124px;
    }

    .desktop-order-layout {
        display: grid;
        grid-template-columns: 296px minmax(0, 944px);
        justify-content: center;
        gap: 16px;
        align-items: start;
    }

    .desktop-order-sidebar,
    .desktop-order-main {
        display: grid;
        gap: 12px;
        align-content: start;
    }

    .desktop-order-main {
        width: 100%;
        max-width: 944px;
    }

    .desktop-order-sidebar {
        position: sticky;
        top: 92px;
    }

    .desktop-order-sidebar .card,
    .desktop-order-main .card {
        margin-bottom: 0;
    }

    .card {
        border: 1px solid rgba(22, 119, 255, 0.08);
        box-shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
    }

    .desktop-card-toggle {
        display: flex;
        margin-bottom: 0;
    }

    .desktop-collapsible-card.is-collapsed .desktop-collapsible-content {
        display: none;
    }

    .desktop-collapsible-card:not(.is-collapsed) .desktop-card-toggle-text {
        color: var(--primary);
    }

    .desktop-collapsible-card.is-collapsed .desktop-card-toggle-text {
        color: var(--text-secondary);
    }

    #orderNoteCard textarea {
        min-height: 96px;
    }

    .order-items {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        min-height: 300px;
    }

    .order-item {
        padding: 10px 12px;
        margin-bottom: 0;
        height: 100%;
    }

    .order-item .item-header {
        margin-bottom: 8px;
    }

    .order-item .item-name {
        font-size: 1rem;
        line-height: 1.2;
    }

    .order-item .item-spec {
        line-height: 1.3;
    }

    .order-item .item-inputs {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .desktop-order-item-grid {
        display: grid !important;
        grid-template-columns: minmax(0, 1.25fr) repeat(3, minmax(0, 0.9fr));
        gap: 8px;
        width: 100%;
        margin-bottom: 0 !important;
        align-items: end;
    }

    .desktop-order-item-grid .input-group,
    .desktop-order-item-actions .input-group {
        min-width: 0;
    }

    .desktop-order-item-grid .input-group label,
    .desktop-order-item-actions .input-group label {
        font-size: 0.72rem;
        margin-bottom: 3px;
        white-space: nowrap;
    }

    .desktop-order-item-grid .input-group input,
    .desktop-order-item-actions .input-group input,
    .desktop-order-item-actions .input-group select {
        min-height: 36px;
        padding: 6px 8px;
        font-size: 0.88rem;
    }

    .desktop-order-item-actions {
        display: flex !important;
        flex-wrap: wrap;
        gap: 8px 10px;
        align-items: end;
    }

    .desktop-order-item-actions .input-group {
        flex: 0 0 auto;
    }

    .desktop-order-item-actions .btn-sm {
        padding: 6px 10px;
    }

    .summary-table table {
        font-size: 0.82rem;
    }

    .footer {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        bottom: 24px;
        width: min(944px, calc(100vw - 48px));
        padding: 10px 12px;
        border-radius: 18px;
        box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
        justify-content: center;
    }

    .footer button {
        flex: none;
        min-width: 200px;
    }

    .risk-section {
        margin-top: 10px;
        padding-top: 10px;
    }

    .risk-header {
        padding: 4px 0;
    }

    .risk-summary-grid-inner.compact-desktop {
        gap: 6px;
    }

    .risk-summary-grid-inner.compact-desktop .risk-stat-card {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 6px 10px;
    }

    .risk-summary-grid-inner.compact-desktop .risk-stat-label {
        margin-bottom: 0;
        white-space: nowrap;
        font-size: 0.74rem;
    }

    .risk-summary-grid-inner.compact-desktop .risk-stat-value {
        text-align: right;
        font-size: 0.86rem;
    }

    .modal {
        align-items: center;
        padding: 24px;
    }

    .modal-content {
        width: min(1200px, 92vw);
        height: min(90vh, 920px);
        max-height: 90vh;
        border-radius: 20px;
    }

    .picker-body {
        height: calc(min(90vh, 920px) - 170px);
    }

    .selected-modal-content,
    .picker-panel {
        max-width: 520px;
    }

    /* 桌面端批量操作优化 */
    #batchActions {
        padding: 12px 18px;
        gap: 12px;
    }

    #batchActions .btn-outline,
    #batchActions #toggleNoTaxBtn {
        padding: 9px 18px;
        font-size: 0.88rem;
    }

    #batchActions label[for='taxRateInput'] {
        padding: 9px 14px;
    }

    #batchActions #taxRateInput {
        width: 64px;
        padding: 9px 12px;
    }
}

@media (min-width: 1500px) {
    .order-items {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
