/* 搜索面板相关样式 */
.search-panel {
    position: absolute;
    z-index: 10;
    background-color: var(--secondary-bg, #dbc8c8);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
    width: 300px;
    display: flex;
    flex-direction: column;
    top: -10000px;
    left: -10000px;
    transition: box-shadow 0.2s ease, opacity 0.15s ease-in-out;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    opacity: 0.97;
}

/* --- Header --- */
.search-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
}

/* 拖动句柄样式 */
.search-panel-drag-handle {
    width: 18px;
    height: 18px;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.5;
    transition: opacity 0.2s ease;
}

.search-panel-drag-handle:hover {
    opacity: 1;
}

.search-panel-drag-handle svg {
    display: block;
    width: 9px;
    height: 14px;
}

/* 关闭按钮样式 */
.search-panel-close {
    border: none;
    background: transparent;
    font-size: 18px;
    line-height: 1;
    color: var(--text-color);
    cursor: pointer;
    padding: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* --- Main Content --- */
.search-panel-main-content {
    padding: 0 12px 2px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.search-panel-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.search-panel-input-container {
    flex: 1;
    width: 100%;
    min-width: 0;
    position: relative;
    display: flex;
    align-items: center;
    padding-left: 30px;
}

.search-input-container::before {
    content: "";
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 0.6;
    z-index: 1;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='16' height='16' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E");
}

.replace-input-container::before {
    content: "";
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 0.6;
    z-index: 1;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='16' height='16' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6'%3E%3C/path%3E%3Cpolyline points='15 3 21 3 21 9'%3E%3C/polyline%3E%3Cline x1='10' y1='14' x2='21' y2='3'%3E%3C/line%3E%3C/svg%3E");
}

.dark-theme .search-input-container::before,
.dark-theme .replace-input-container::before {
    filter: invert(1) brightness(2);
}

.search-panel-label {
    margin-bottom: 0;
    font-size: 12px;
    color: var(--text-color);
    font-weight: 500;
    white-space: nowrap;
    margin-right: 4px;
    flex-shrink: 0;
    width: auto;
    text-align: left;
    line-height: 1;
}

.search-panel-input {
    flex: 1;
    padding: 6px 8px 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--secondary-bg, #ffffff);
    color: var(--text-color);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
    min-width: 0;
}

.dark-theme .search-panel-input {
    background-color: rgba(30, 30, 30, 0.8);
    border-color: rgba(255, 255, 255, 0.2);
}

.search-panel-input:focus {
    outline: none;
    border-color: #ced4da;
    box-shadow: 0 0 0 2px rgba(233, 236, 239, 0.4);
}

.search-panel-button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
}

.search-panel-button {
    padding: 5px 10px;
    background-color: var(--button-bg-color, var(--bg-color));
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-color);
    cursor: pointer;
    font-size: 13px;
    text-align: center;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
    box-sizing: border-box;
    flex-grow: 1;
    flex-shrink: 1;
    flex-basis: calc(50% - 4px);
}

/* 主要操作按钮样式 - 改为类选择器 */
.search-panel-button.search-panel-button-primary {
    background-color: #E9ECEF; /* New light gray */
    color: var(--text-color); /* Dark text color */
    border-color: #E9ECEF;    /* New light gray */
}

.search-panel-button.search-panel-button-primary:hover {
    background-color: #ced4da; /* Darker gray for hover */
    border-color: #ced4da;    /* Darker gray for hover */
    color: var(--text-color); /* Ensure text color remains dark on hover */
}

.dark-theme .search-panel-button.search-panel-button-primary {
    background-color: #58a6ff; /* A brighter blue for dark theme primary buttons */
    color: #ffffff; /* White text color */
    border-color: #58a6ff;
}

.dark-theme .search-panel-button.search-panel-button-primary:hover {
    background-color: #458dd4; /* A slightly darker blue for hover */
    border-color: #458dd4;
    color: #ffffff;
}

.search-panel-button:focus {
    outline: none;
    border-color: #ced4da;
    box-shadow: 0 0 0 2px rgba(233, 236, 239, 0.4);
}

.search-panel-button:active {
    background-color: var(--button-active-bg-color, var(--active-color));
    transform: translateY(1px);
}

.dark-theme .search-panel-button {
    background-color: rgba(40, 40, 40, 0.8);
    border-color: rgba(255, 255, 255, 0.15);
}

.dark-theme .search-panel-button:hover {
    background-color: rgba(60, 60, 60, 0.8);
    border-color: rgba(255, 255, 255, 0.25);
}

.search-panel-close:hover {
    background-color: var(--hover-color);
    color: var(--text-color);
}

.search-panel-close:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(233, 236, 239, 0.4);
}

.search-panel-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    width: 100%;
    max-height: 300px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease, padding-top 0.3s ease, margin-top 0.3s ease;
}

.search-panel-options.collapsed {
    max-height: 0;
    padding-top: 0;
    margin-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    border-top-color: transparent;
    pointer-events: none;
    opacity: 0;
    overflow: hidden;
}

.dark-theme .search-panel-options {
    border-top-color: rgba(255, 255, 255, 0.15);
}

.dark-theme .search-panel-options.collapsed {
    border-top-color: transparent;
}

.search-panel-option {
    display: flex;
    align-items: center;
    font-size: 12px;
    cursor: pointer;
    user-select: none;
    width: calc((100% - 10px) / 2);
    box-sizing: border-box;
    padding: 2px 0;
}

.search-panel-option input[type="checkbox"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--border-color);
    border-radius: 3px;
    margin-right: 6px;
    position: relative;
    cursor: pointer;
    vertical-align: middle;
    background-color: var(--bg-color);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.dark-theme .search-panel-option input[type="checkbox"] {
    border-color: rgba(255, 255, 255, 0.4);
    background-color: rgba(50, 50, 50, 0.7);
}

.search-panel-option input[type="checkbox"]:checked {
    background-color: #E9ECEF;
    border-color: #E9ECEF;
}

.dark-theme .search-panel-option input[type="checkbox"]:checked {
    background-color: #58a6ff;
    border-color: #58a6ff;
}

.search-panel-option input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 5px;
    width: 4px;
    height: 8px;
    border: solid var(--text-color);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    display: block;
}

.dark-theme .search-panel-option input[type="checkbox"]:checked::after {
    border-color: #ffffff;
}

.search-panel-option input[type="checkbox"]:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(233, 236, 239, 0.4);
}

.search-panel-option:hover input[type="checkbox"]:not(:checked) {
    border-color: #ced4da;
    background-color: rgba(233, 236, 239, 0.2);
}

.dark-theme .search-panel-option:hover input[type="checkbox"]:not(:checked) {
    border-color: rgba(255, 255, 255, 0.6);
    background-color: rgba(70, 70, 70, 0.7);
}

.search-panel-option label {
    color: var(--text-color);
    font-weight: normal;
    transition: color 0.2s ease;
    line-height: 1.2;
    display: inline-block;
    vertical-align: middle;
    white-space: nowrap;
}

.search-panel-option input[type="checkbox"]:checked + label {
    color: var(--text-color);
    font-weight: 500;
}

.search-panel-status {
    font-size: 12px;
    color: var(--secondary-text-color);
    min-height: 20px;
    margin-top: 6px;
    padding: 4px 8px;
    transition: color 0.2s ease, background-color 0.2s ease;
    border-radius: 3px;
    text-align: center;
    background-color: rgba(0, 0, 0, 0.03);
    margin-bottom: 2px;
}

.dark-theme .search-panel-status {
    background-color: rgba(255, 255, 255, 0.05);
}

.search-panel-status.error {
    color: var(--error-color, #e53935);
    font-weight: 500;
    background-color: rgba(229, 57, 53, 0.07);
}

.dark-theme .search-panel-status.error {
    background-color: rgba(229, 57, 53, 0.15);
}

.search-panel-status.success {
    color: var(--success-color, #43a047);
    background-color: rgba(67, 160, 71, 0.07);
}

.dark-theme .search-panel-status.success {
    background-color: rgba(67, 160, 71, 0.15);
}

.cm-search-match-highlight {
    background-color: rgba(255, 213, 79, 0.4);
    border-radius: 2px;
}

.dark-theme .cm-search-match-highlight {
    background-color: rgba(255, 213, 79, 0.3);
}

.cm-search-match-current {
    background-color: rgba(255, 152, 0, 0.6);
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(255, 152, 0, 0.8);
    position: relative;
    animation: pulse-highlight 1.5s infinite;
}

@keyframes pulse-highlight {
    0%, 100% { background-color: rgba(255, 152, 0, 0.6); }
    50% { background-color: rgba(255, 152, 0, 0.8); }
}

.dark-theme .cm-search-match-current {
    background-color: rgba(255, 152, 0, 0.5);
    box-shadow: 0 0 0 1px rgba(255, 152, 0, 0.7);
}

.search-input-error {
    border-color: var(--error-color, #e53935) !important;
    animation: search-error-flash 0.8s ease;
}

@keyframes search-error-flash {
    0%, 100% { background-color: var(--input-bg-color, var(--bg-color)); }
    50% { background-color: rgba(229, 57, 53, 0.1); }
}

@media (max-width: 576px) {
    .search-panel {
        width: calc(100% - 40px);
        left: 20px !important;
        right: 20px !important;
    }
    
    .search-panel-button-group {
        justify-content: space-between;
    }
    
    .search-panel-button {
        min-width: calc(50% - 4px);
    }
}

/* --- Footer --- */
.search-panel-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0px 8px 4px 8px;
}

/* 更多设置按钮样式 */
.search-panel-more-settings {
    width: 20px;
    height: 20px;
    padding: 0;
    background-color: transparent;
    border: none;
    border-radius: 50%;
    color: var(--secondary-text-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, color 0.2s ease;
    opacity: 0.7;
}

.search-panel-more-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.search-panel-more-settings:hover {
    background-color: rgba(0, 0, 0, 0.08);
    color: var(--text-color);
    opacity: 1;
}

.search-panel-more-settings:focus {
    outline: none;
    background-color: rgba(0, 0, 0, 0.1);
    opacity: 1;
}

.search-panel-more-settings[aria-expanded="true"] {
    color: var(--text-color);
    opacity: 1;
}

.dark-theme .search-panel-more-settings {
    color: rgba(255, 255, 255, 0.7);
}

.dark-theme .search-panel-more-settings:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    opacity: 1;
}

.dark-theme .search-panel-more-settings:focus {
    outline: none;
    background-color: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    opacity: 1;
}

.dark-theme .search-panel-more-settings[aria-expanded="true"] {
    color: rgba(255, 255, 255, 0.9);
    opacity: 1;
}