/**
 * SearchableSelect 通用搜索下拉框样式
 * 参照码单中购方单位搜索框设计
 */

.ss-wrapper {
    position: relative;
    width: 100%;
}

.ss-input {
    width: 100%;
    padding: 8px 32px 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    background-color: #fff;
    transition: all 0.2s;
    outline: none;
    box-sizing: border-box;
}

.ss-input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.ss-input:disabled {
    background-color: #f3f4f6;
    cursor: not-allowed;
}

.ss-clear-btn {
    position: absolute;
    right: 32px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    line-height: 16px;
    text-align: center;
    border-radius: 50%;
    background: #d1d5db;
    color: white;
    font-size: 12px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
    z-index: 1;
}

.ss-clear-btn:hover {
    background: #9ca3af;
}

.ss-arrow {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    font-size: 12px;
    pointer-events: none;
    transition: transform 0.2s;
}

.ss-wrapper.open .ss-arrow {
    transform: translateY(-50%) rotate(180deg);
}

.ss-value {
    display: none;
}

.ss-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    max-height: 320px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.ss-loading {
    padding: 12px;
    text-align: center;
    color: #6b7280;
    font-size: 13px;
    display: none;
    flex-shrink: 0;
}

.ss-list {
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

.ss-add-container {
    flex-shrink: 0;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    padding: 4px;
}

.ss-list::-webkit-scrollbar {
    width: 6px;
}

.ss-list::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.ss-list::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

.ss-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.15s ease;
    border-bottom: 1px solid #f9fafb;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.ss-item:hover,
.ss-item.ss-highlight {
    background-color: #a5c8ff !important;
}

.ss-item.ss-selected {
    background-color: #a5c8ff !important;
    color: #2c3e50;
    border-left: 3px solid #4a6fa5;
}

.ss-item-label {
    color: #1f2937;
}

.ss-item.ss-selected .ss-item-label {
    color: #2c3e50;
    font-weight: 500;
}

.ss-empty,
.ss-error {
    padding: 16px;
    text-align: center;
    color: #9ca3af;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.ss-error {
    color: #ef4444;
}

.ss-add-item {
    padding: 8px;
}

.ss-add-btn {
    width: 100%;
    padding: 8px 12px;
    border: 1px dashed #2563eb;
    background: white;
    color: #2563eb;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.ss-add-btn:hover {
    background: rgba(22, 93, 255, 0.08);
    border-color: #1d4ed8;
}

/* 标签样式 */
.ss-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    background: rgba(22, 93, 255, 0.15);
    color: #1e40af;
    border-radius: 12px;
    font-size: 12px;
    margin-right: 4px;
}

.ss-tag-close {
    margin-left: 4px;
    cursor: pointer;
    opacity: 0.6;
}

.ss-tag-close:hover {
    opacity: 1;
}

/* 设为默认按钮 */
.ss-set-default {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    background: transparent;
    color: #1e40af;
    border: 1px solid rgba(22, 93, 255, 0.3);
    border-radius: 12px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
    margin-left: 6px;
}

.ss-set-default:hover {
    background: rgba(22, 93, 255, 0.15);
}

.ss-item-content {
    flex-direction: row !important;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

/* 分组样式 */
.ss-group {
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
}

/* 自定义选项内容样式 */
.ss-item-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ss-item-main {
    font-size: 14px;
    color: #1f2937;
}

.ss-item-sub {
    font-size: 12px;
    color: #6b7280;
}

.ss-item-meta {
    font-size: 11px;
    color: #9ca3af;
}

/* 多选模式样式 */
.ss-multi-selected {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px 8px;
    min-height: 34px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background-color: #fff;
    cursor: text;
}

.ss-multi-selected:focus-within {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.ss-multi-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px 2px 8px;
    background: rgba(22, 93, 255, 0.15);
    color: #1e40af;
    border-radius: 4px;
    font-size: 12px;
    gap: 4px;
}

.ss-multi-tag-close {
    cursor: pointer;
    opacity: 0.6;
    font-size: 14px;
    line-height: 1;
}

.ss-multi-tag-close:hover {
    opacity: 1;
}

.ss-multi-input {
    flex: 1;
    min-width: 80px;
    border: none;
    outline: none;
    font-size: 14px;
    padding: 2px;
}

/* ==================== 函数式 API 样式 ==================== */

.searchable-select {
    position: relative;
    display: inline-block;
    min-width: 0;
}

.searchable-select input[type="text"] {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    background-color: #fff;
    transition: all 0.2s;
    outline: none;
    box-sizing: border-box;
    min-width: 0;
}

.searchable-select input[type="text"]:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.searchable-select .search-option {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.15s ease;
    border-bottom: 1px solid #f3f4f6;
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
}

.searchable-select .search-option:last-child {
    border-bottom: none;
}

.searchable-select .search-option:hover {
    background-color: #eff6ff;
}

.searchable-select .search-option.text-gray-400 {
    color: #9ca3af;
    font-style: italic;
}

/* ss-dropdown 样式 - 下拉框移动到 body 后仍能正常应用 */
.ss-dropdown {
    max-height: 320px !important;
    overflow: hidden !important; /* 保持 overflow: hidden，让 ss-list 内部滚动 */
    display: none;  /* 默认隐藏，由 JS open()/close() 通过 setProperty(!important) 控制显隐 */
    flex-direction: column !important;
    box-sizing: border-box;
}
.ss-dropdown.ss-open {
    display: flex;  /* 打开时由 JS 加 .ss-open class 或直接 setProperty */
}

.ss-dropdown::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.ss-dropdown::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.ss-dropdown::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
    border: 2px solid #f1f1f1;
}

.ss-dropdown::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.ss-dropdown::-webkit-scrollbar-thumb:active {
    background: #909090;
}

/* Firefox 滚动条 */
.ss-dropdown {
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 #f1f1f1;
}

/* 旧版样式保留兼容（下拉框未移动时） */
.searchable-select [id$="-dropdown"] {
    max-height: 200px;
    overflow-y: scroll !important;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* ==================== 去掉数字输入框微调按钮 ==================== */
.no-spin::-webkit-outer-spin-button,
.no-spin::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
    margin: 0 !important;
}

.no-spin {
    -moz-appearance: textfield !important;
    appearance: textfield !important;
}

/* 全局去掉数字输入框微调按钮（在选择商品弹窗筛选区） */
#product-select-modal .flex.flex-nowrap input[type="number"]::-webkit-outer-spin-button,
#product-select-modal .flex.flex-nowrap input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
    margin: 0 !important;
}

#product-select-modal .flex.flex-nowrap input[type="number"] {
    -moz-appearance: textfield !important;
    appearance: textfield !important;
}

/* 选择商品弹窗样式 */
.product-select-modal input[type="number"]::-webkit-outer-spin-button,
.product-select-modal input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
    margin: 0 !important;
}

.product-select-modal input[type="number"] {
    -moz-appearance: textfield !important;
    appearance: textfield !important;
}

/* ==================== 系统专用组件高亮（从上游订单继承的锁定字段） ==================== */
.ss-inherited-locked {
    position: relative;
    border-radius: 8px;
}
.ss-inherited-locked::before {
    content: '\f084';  /* fa-lock Font Awesome icon */
    font-family: 'FontAwesome';
    font-size: 11px;
    color: #6366f1;
    position: absolute;
    top: -8px;
    right: -4px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    z-index: 5;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.ss-inherited-locked .ss-input,
.ss-inherited-locked .searchable-select input[type="text"] {
    background-color: #f5f3ff !important;
    border-color: #a5b4fc !important;
    color: #3730a3 !important;
    cursor: default;
}
.ss-inherited-locked .ss-input:focus {
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15) !important;
}

/* 原生 input 组件的继承锁定高亮 */
.field-inherited-locked {
    background-color: #f5f3ff !important;
    border-color: #a5b4fc !important;
    color: #3730a3 !important;
    cursor: not-allowed;
    position: relative;
}
.field-inherited-locked::after {
    content: '\f084';
    font-family: 'FontAwesome';
    font-size: 11px;
    color: #6366f1;
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    pointer-events: none;
    opacity: 0.7;
}
