/**
 * Search Bar MD3 Beautification & Structural Refactoring
 * 实现了统一的“胶囊型”搜索框，集成了模块选择器、输入区域和圆形按钮。
 */

/* 核心变量与重置 (MD3 Tokens) */
:root {
    --md3-search-height: 48px;
    --md3-search-radius: 24px;
    --md3-search-bg: var(--md-sys-color-surface-container-high, #ece6f0);
    --md3-search-on-bg: var(--md-sys-color-on-surface, #1d1b20);
    --md3-search-outline: var(--md-sys-color-outline-variant, #cac4d0);
    --md3-search-primary: var(--md-sys-color-primary, #6750a4);
}

/* 1. 胶囊型搜索框容器 (Main Form) */
.md3-search-bar {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 720px;
    height: var(--md3-search-height);
    background-color: var(--md3-search-bg);
    border: 1px solid var(--md3-search-outline);
    border-radius: var(--md3-search-radius);
    padding: 0 4px 0 0; /* 右侧留空给圆形按钮 */
    box-sizing: border-box;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: visible !important; /* 确保下拉菜单不被裁剪 */
}

.md3-search-bar:hover {
    background-color: var(--md-sys-color-surface-container-highest, #e6e0e9);
    box-shadow: var(--md-sys-elevation-level1);
}

/* 焦点状态：整个容器获得 2px 边框和外发光 */
.md3-search-bar:focus-within {
    background-color: var(--md-sys-color-surface-container-high);
    border-color: var(--md3-search-primary);
    box-shadow: 0 0 0 1px var(--md3-search-primary);
}

/* 2. 模块选择器 (MD3 Select Integration) */
.md3-search-bar__module-select {
    flex-shrink: 0;
}

/* 移动端：顶栏搜索框内隐藏模块选择，仅在展开后显示 */
@media screen and (max-width: 767px) {
    #destoon-search .md3-search-bar__module-select {
        display: none !important;
    }
    #destoon-search .md3-search-bar__input {
        padding-left: 16px; /* 补偿隐藏后的左间距 */
    }
}

.custom-md3-select {
    position: relative;
    display: flex;
    align-items: center;
    height: 100%;
}

/* 顶栏 PC 搜索：频道触发器样式由 header-search-module-select.css 接管 */
#destoon-search .custom-md3-select__trigger {
    padding: 0;
    height: auto;
    margin: 0;
    border-right: none;
    opacity: 1;
}

#destoon-search .custom-md3-select__trigger:hover {
    opacity: 1;
}

.custom-md3-select__selected-text {
    font-family: var(--md-sys-typescale-body-large-font);
    font-size: 14px;
    font-weight: 500;
    color: var(--md3-search-on-bg);
    white-space: nowrap;
}

.custom-md3-select__arrow {
    font-size: 20px !important;
    color: var(--md-sys-color-on-surface-variant);
    margin-left: 2px;
    transition: transform 0.2s;
}

.custom-md3-select--open .custom-md3-select__arrow {
    transform: rotate(180deg);
}

/* 下拉选项菜单 (Surface Container) */
.custom-md3-select__options {
    position: absolute !important;
    top: calc(100% + 2px) !important;
    left: 2px !important;
    min-width: 140px;
    max-height: 400px;
    overflow-y: auto !important;
    background-color: var(--md-sys-color-surface-container);
    border-radius: 12px;
    box-shadow: var(--md-sys-elevation-level3);
    list-style: none !important;
    padding: 8px 0 !important;
    margin: 0 !important;
    z-index: 9999 !important;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s cubic-bezier(0, 0, 0.2, 1);
}

.custom-md3-select--open .custom-md3-select__options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.custom-md3-select__option {
    padding: 10px 16px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.1s;
    color: var(--md3-search-on-bg);
}

.custom-md3-select__option:hover {
    background-color: var(--md-sys-color-surface-container-highest);
}

.custom-md3-select__option--selected {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    font-weight: 600;
}

/* 3. 输入区域 (Input Field) */
.md3-search-bar__input-wrapper {
    flex-grow: 1;
    display: flex;
    align-items: center;
    position: relative;
    height: 100%;
}

.md3-search-bar__input {
    width: 100%;
    height: 100%;
    border: none !important;
    background: transparent !important;
    outline: none !important;
    padding: 0 12px;
    font-size: 16px;
    color: var(--md3-search-on-bg);
    font-family: inherit;
}

.md3-search-bar__input::placeholder {
    color: var(--md-sys-color-on-surface-variant);
    opacity: 0.7;
}

.md3-search-bar__clear {
    margin: 0 8px;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    display: flex;
    align-items: center;
}

.md3-search-bar__clear:hover {
    color: var(--md-sys-color-on-surface);
}

/* 4. 搜索提交按钮 (Circular Icon Button) */
.md3-search-bar__submit {
    width: 40px;
    height: 40px;
    border-radius: 20px;
    border: none;
    background-color: var(--md3-search-primary);
    color: var(--md-sys-color-on-primary, #ffffff);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s;
    flex-shrink: 0;
}

.md3-search-bar__submit:hover {
    background-color: var(--md-sys-color-primary-fixed-dim, #4f378b);
    transform: scale(1.05);
}

.md3-search-bar__submit:active {
    transform: scale(0.95);
}

.md3-search-bar__submit .material-symbols-outlined {
    font-size: 24px;
}

/* 5. 移动端搜索下拉内的模块选择器 */
.mdc-search-dropdown {
    /* 修正移动端抽屉的溢出问题 */
    overflow: visible !important;
}

/* 为 content 层立个定位上下文，让关闭按钮可以绝对定位 */
.mdc-search-dropdown__content {
    position: relative;
}

/* 将关闭按钮从 flex 流移出，不占据宽度 */
.mdc-search-dropdown .mdc-search-dropdown__close-btn {
    position: absolute !important;
    right: 6px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 10;
}

/* 隐藏 toolbar 部分的默认关闭按钮（换用绝对定位的版本） */

.mdc-search-dropdown__content {
    /* 允许弹出的下拉菜单溢出可见，避免被裁剪 */
    overflow: visible !important;
    padding: 6px 12px !important;
}

.mdc-search-dropdown__module-wrapper {
    /* 直接承担水平滚动，避免父元素 overflow:hidden 拦截触摸事件 */
    display: flex;
    align-items: center;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    scrollbar-width: none;
    padding: 0 16px;
    box-sizing: border-box;
    margin-bottom: 0;
}

.mdc-search-dropdown__module-wrapper::-webkit-scrollbar {
    display: none;
}

/* 内层轨道：内容小时中对齐，内容大时自然扩张可滑 */
.mdc-search-dropdown__scroll-row {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    flex-wrap: nowrap;
    min-width: 100%; /* 内容少时至少占满容器，中对齐有效 */
    justify-content: center;
}

/* 两个子项均不得被压缩 */
.mdc-search-dropdown__scroll-row .md3-search-bar__module-select,
.mdc-search-dropdown__scroll-row .mdc-search-dropdown__inline-btn {
    flex-shrink: 0;
}

.mdc-search-dropdown__inline-btn {
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    border-radius: 12px;
    background-color: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-primary, #6750a4);
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
    flex-shrink: 0;
    border: 1px solid var(--md3-search-outline);
    transition: background-color 0.2s;
}

.mdc-search-dropdown__inline-btn:hover {
    background-color: var(--md-sys-color-surface-container-highest);
}

.mdc-search-dropdown__module-wrapper .custom-md3-select__trigger {
    background-color: var(--md-sys-color-surface-container-high);
    border: 1px solid var(--md3-search-outline);
    border-radius: 12px;
    padding: 0 16px;
    height: 48px;
    margin: 0;
    justify-content: space-between;
    width: 100%;
    box-sizing: border-box;
}

.mdc-search-dropdown__module-wrapper .custom-md3-select__selected-text {
    font-size: 16px;
}

/* PC 端专有调节 */
@media screen and (min-width: 768px) {
    .mdc-search-section {
        flex: 1;
        justify-content: center;
        padding: 0 24px;
    }
}

/* 6. 深色模式适配 (Dark Mode) */
:root[data-theme="dark"], :root.theme-dark {
    --md3-search-bg: var(--md-sys-color-surface-container-high, #2b2930);
    --md3-search-on-bg: var(--md-sys-color-on-surface, #e6e1e5);
    --md3-search-outline: var(--md-sys-color-outline-variant, #49454f);
}
