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

body {
    font-family: 'Microsoft YaHei', Arial, sans-serif;
    background: #f5f5f5;
    padding: 10px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e0e0e0;
    flex-wrap: wrap;
    gap: 10px;
}

h1 {
    color: #333;
    margin: 0;
    font-size: 20px;
}

.store-name {
    color: #2196F3;
    font-size: 14px;
    margin-top: 5px;
}

.header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-secondary {
    padding: 6px 12px;
    background: #757575;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.btn-secondary:hover {
    background: #616161;
}

h2 {
    color: #555;
    margin-bottom: 15px;
    font-size: 18px;
}

.tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-btn {
    padding: 10px 15px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    color: #666;
    transition: all 0.3s;
    white-space: nowrap;
    flex-shrink: 0;
}

.tab-btn.active {
    color: #2196F3;
    border-bottom: 3px solid #2196F3;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.form-group {
    margin-bottom: 15px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 5px;
}

.form-group input, .form-group select {
    padding: 10px;
    margin: 5px 5px 5px 0;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    width: 100%;
    max-width: 200px;
}

.form-group button {
    padding: 10px 20px;
    background: #2196F3;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    margin-top: 5px;
    width: 100%;
}

.form-group button:hover {
    background: #1976D2;
}

/* 表格容器 - 支持横向滚动 */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 15px;
    position: relative;
    background: white;
}

table {
    width: 100%;
    min-width: 600px;
    border-collapse: collapse;
}

th, td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
    font-size: 13px;
}

th {
    background: #f5f5f5;
    font-weight: bold;
    color: #555;
    position: sticky;
    top: 0;
    z-index: 10;
}

tr:hover {
    background: #f9f9f9;
}

.btn-edit, .btn-delete {
    padding: 5px 10px;
    margin: 2px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    display: inline-block;
}

.btn-edit {
    background: #4CAF50;
    color: white;
}

.btn-delete {
    background: #f44336;
    color: white;
}

.formula-container {
    margin: 15px 0;
    padding: 10px;
    background: #fff;
    border: 1px dashed #ddd;
    border-radius: 5px;
    min-height: 50px;
}

.formula-item {
    display: flex;
    align-items: center;
    margin: 8px 0;
    gap: 8px;
    padding: 8px;
    background: #f9f9f9;
    border-radius: 4px;
    flex-wrap: wrap; /* 允许换行 */
}

.formula-item select {
    flex: 2;
    min-width: 120px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.formula-item input {
    flex: 1;
    min-width: 80px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.unit-text {
    color: #666;
    font-size: 13px;
    white-space: nowrap;
}

.btn-remove {
    padding: 6px 12px;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
}

.btn-add-formula {
    padding: 8px 16px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    width: 100%;
}

.profit-positive {
    color: #4CAF50;
    font-weight: bold;
}

.profit-negative {
    color: #f44336;
    font-weight: bold;
}

#price-chart {
    max-height: 300px;
    margin: 15px 0;
}

#history-records {
    margin-top: 15px;
}

.history-record {
    padding: 10px;
    margin: 5px 0;
    background: #f9f9f9;
    border-left: 3px solid #2196F3;
    border-radius: 3px;
    font-size: 13px;
}

.add-formula-btn {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 3px;
    cursor: pointer;
    margin-top: 5px;
    font-size: 12px;
}

.remove-formula-btn {
    background: #f44336;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
}

.cost-change-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}

.cost-change-content {
    background: white;
    padding: 20px;
    border-radius: 10px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    width: 100%;
}

.cost-change-item {
    padding: 10px;
    margin: 10px 0;
    background: #f9f9f9;
    border-radius: 5px;
    font-size: 13px;
}

.cost-increase {
    color: #f44336;
}

.cost-decrease {
    color: #4CAF50;
}

.footer {
    text-align: center;
    padding: 20px;
    margin-top: 30px;
    border-top: 1px solid #e0e0e0;
    background: #f9f9f9;
    font-size: 12px;
    color: #666;
}

.footer p {
    margin: 5px 0;
}

.footer a {
    color: #2196F3;
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* 移动端优化 */
@media (max-width: 768px) {
    body {
        padding: 5px;
    }
    
    .container {
        padding: 10px;
        border-radius: 5px;
    }
    
    h1 {
        font-size: 18px;
    }
    
    h2 {
        font-size: 16px;
    }
    
    .header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .header-actions {
        width: 100%;
    }
    
    .btn-secondary {
        flex: 1;
        text-align: center;
        font-size: 12px;
        padding: 8px 10px;
    }
    
    .tabs {
        gap: 2px;
        padding-bottom: 2px;
    }
    
    .tab-btn {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .form-group {
        padding: 10px;
    }
    
    .form-group input, .form-group select, .form-group textarea {
        max-width: 100%;
        margin: 3px 0;
        font-size: 16px; /* 防止iOS自动缩放 */
    }
    
    .form-group button {
        font-size: 14px;
        padding: 12px 20px;
        margin-top: 8px;
    }
    
    /* 配方项移动端优化 */
    .formula-item {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px;
    }
    
    .formula-item select, 
    .formula-item input,
    .searchable-select-wrapper,
    .material-select-wrapper {
        width: 100% !important;
        min-width: auto !important;
        flex: none !important;
        margin: 3px 0;
    }
    
    .formula-item input[type="number"] {
        width: calc(100% - 30px) !important;
        display: inline-block;
    }
    
    .unit-text {
        display: inline-block;
        margin-left: 5px;
    }
    
    .formula-item button {
        width: 100%;
        margin-top: 5px;
    }
    
    .btn-add-formula {
        padding: 12px 16px;
        font-size: 14px;
        margin-top: 8px;
    }
    
    /* 表格移动端优化 */
    .table-container {
        margin-top: 10px;
        border-radius: 5px;
        overflow-x: auto;
        background: white;
    }
    
    .table-container::after {
        display: none; /* 移动端不显示渐变提示 */
    }
    
    table {
        min-width: 600px;
        font-size: 12px;
        background: white;
    }
    
    th, td {
        padding: 8px 6px;
        font-size: 12px;
        background: white;
    }
    
    th {
        font-size: 12px;
        white-space: nowrap;
        background: #f5f5f5;
    }
    
    td {
        background: white;
    }
    
    .btn-edit, .btn-delete {
        padding: 6px 10px;
        font-size: 11px;
        display: inline-block;
        margin: 2px;
        white-space: nowrap;
    }
    
    /* 搜索下拉框移动端优化 */
    .material-search-input {
        font-size: 16px !important; /* 防止iOS自动缩放 */
        padding: 10px !important;
        padding-right: 60px !important; /* 与JavaScript设置保持一致 */
    }
    
    .material-dropdown {
        max-height: 180px;
        font-size: 14px;
    }
    
    .dropdown-item {
        padding: 12px 10px;
        font-size: 14px;
    }
    
    .dropdown-toggle-btn {
        font-size: 14px;
        padding: 8px;
    }
    
    /* 文字识别输入框 */
    textarea {
        font-size: 16px !important; /* 防止iOS自动缩放 */
        min-height: 100px;
    }
    
    #price-chart {
        max-height: 250px;
    }
    
    .footer {
        padding: 15px 10px;
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 3px;
    }
    
    .container {
        padding: 8px;
    }
    
    h1 {
        font-size: 16px;
    }
    
    h2 {
        font-size: 15px;
        margin-bottom: 10px;
    }
    
    .store-name {
        font-size: 13px;
    }
    
    .header {
        padding-bottom: 10px;
        margin-bottom: 15px;
    }
    
    .header-actions {
        gap: 5px;
    }
    
    .btn-secondary {
        font-size: 11px;
        padding: 6px 8px;
    }
    
    .tab-btn {
        padding: 8px 10px;
        font-size: 12px;
    }
    
    .form-group {
        padding: 8px;
        margin-bottom: 10px;
    }
    
    .form-group h3 {
        font-size: 14px;
        margin-bottom: 8px;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 10px 8px;
        font-size: 16px;
    }
    
    .form-group button {
        padding: 12px 16px;
        font-size: 14px;
    }
    
    .formula-item {
        padding: 8px;
        gap: 6px;
    }
    
    .btn-remove {
        padding: 10px;
        font-size: 13px;
    }
    
    table {
        min-width: 500px;
        font-size: 11px;
    }
    
    th, td {
        padding: 6px 4px;
        font-size: 11px;
    }
    
    .btn-edit, .btn-delete {
        padding: 5px 8px;
        font-size: 10px;
    }
    
    .material-dropdown {
        max-height: 150px;
    }
    
    .dropdown-item {
        padding: 10px 8px;
        font-size: 13px;
    }
    
    #price-chart {
        max-height: 200px;
    }
    
    .history-record {
        padding: 8px;
        font-size: 12px;
    }
    
    .footer {
        padding: 12px 8px;
        font-size: 10px;
    }
}

/* 横屏模式优化 */
@media (max-width: 768px) and (orientation: landscape) {
    .material-dropdown {
        max-height: 120px;
    }
    
    .formula-container {
        max-height: 200px;
        overflow-y: auto;
    }
}

/* 触摸优化 */
@media (hover: none) and (pointer: coarse) {
    /* 增大可点击区域 */
    .btn-edit, .btn-delete, .btn-remove, .dropdown-item {
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .tab-btn {
        min-height: 44px;
    }
    
    .dropdown-toggle-btn {
        min-width: 44px;
        min-height: 44px;
    }
}

/* 搜索下拉框样式 */
.material-search-input,
.formula-item input.material-search-input {
    width: 100% !important;
    padding: 8px 60px 8px 8px !important;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box !important;
    flex: none !important;
    min-width: 200px !important; /* 确保最小宽度 */
    white-space: nowrap; /* 不换行 */
    overflow: hidden; /* 隐藏溢出 */
    text-overflow: ellipsis; /* 显示省略号 */
}

.material-search-input:focus {
    outline: none;
    border-color: #2196F3;
}

.dropdown-toggle-btn {
    transition: transform 0.2s;
}

.dropdown-toggle-btn:hover {
    color: #2196F3;
}

.dropdown-toggle-btn:active {
    transform: scale(0.9);
}

.material-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    min-width: 300px; /* 确保最小宽度 */
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.dropdown-item {
    padding: 10px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid #f0f0f0;
    white-space: normal; /* 允许换行 */
    word-wrap: break-word; /* 长单词换行 */
    line-height: 1.4;
}

.dropdown-item:hover {
    background: #f5f5f5;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.material-select-wrapper {
    position: relative;
    flex: 1;
}

.searchable-select-wrapper {
    position: relative;
    flex: 1;
    min-width: 200px; /* 确保有足够宽度显示长名称 */
}

.formula-item .searchable-select-wrapper {
    flex: 2; /* 在配方项中占更多空间 */
    min-width: 250px;
}

/* 移动端优化 */
@media (max-width: 768px) {
    .material-dropdown {
        max-height: 150px;
    }
    
    .dropdown-item {
        padding: 8px;
        font-size: 13px;
    }
}


/* 防止iOS输入框自动缩放 */
input, select, textarea, button {
    font-size: 16px;
}

/* 移动端滚动优化 */
.table-container,
.material-dropdown,
.formula-container {
    -webkit-overflow-scrolling: touch;
}

/* 移动端按钮点击反馈 */
button, .btn-edit, .btn-delete, .btn-remove, .dropdown-item, .tab-btn {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    tap-highlight-color: rgba(0, 0, 0, 0.1);
}

/* 移动端输入框优化 */
input:focus, select:focus, textarea:focus {
    font-size: 16px; /* 防止iOS自动缩放 */
}

/* 移动端表格滚动提示 */
@media (max-width: 768px) {
    .table-container {
        position: relative;
    }
    
    .table-container::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 20px;
        background: linear-gradient(to left, rgba(255,255,255,0.9), transparent);
        pointer-events: none;
        z-index: 1;
    }
}

/* 移动端长按选择优化 */
@media (max-width: 768px) {
    * {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    input, textarea, .material-search-input {
        -webkit-user-select: text;
        user-select: text;
        -webkit-touch-callout: default;
    }
}

/* 移动端横屏提示 */
@media (max-width: 768px) and (orientation: landscape) {
    .container {
        max-height: 100vh;
        overflow-y: auto;
    }
}


/* 清空按钮样式 */
.input-clear-btn {
    transition: color 0.2s;
}

.input-clear-btn:hover {
    color: #f44336 !important;
}

.input-clear-btn:active {
    transform: scale(0.9);
}


/* 移动端优化 */
@media (max-width: 768px) {
    body {
        padding: 5px;
    }
    
    .container {
        padding: 10px;
    }
    
    h1 {
        font-size: 18px;
    }
    
    h2 {
        font-size: 16px;
    }
    
    .header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .header-actions {
        width: 100%;
    }
    
    .btn-secondary {
        flex: 1;
        font-size: 12px;
        padding: 8px 10px;
    }
    
    .tabs {
        gap: 3px;
    }
    
    .tab-btn {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    /* 表格优化 */
    table {
        min-width: 100%;
        font-size: 12px;
    }
    
    th, td {
        padding: 8px 5px;
        font-size: 12px;
    }
    
    /* 按钮组优化 */
    .action-buttons {
        display: flex;
        flex-direction: column;
        gap: 3px;
    }
    
    .btn-edit, .btn-delete {
        padding: 6px 8px;
        font-size: 11px;
        width: 100%;
    }
    
    /* 表单优化 */
    .form-group input, .form-group select {
        max-width: 100%;
        font-size: 13px;
    }
    
    .formula-item {
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .formula-item select,
    .formula-item input {
        min-width: 100px;
        font-size: 13px;
    }
}

/* 搜索框样式 */
.search-box {
    margin-bottom: 10px;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 5px;
}

.search-box input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.search-box input:focus {
    outline: none;
    border-color: #2196F3;
}
