/* 顶部工具栏 */
.top-toolbar {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    z-index: 1000;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    pointer-events: none;
}

.top-toolbar > * {
    pointer-events: auto;
}

/* 左下角工具栏 */
.bottom-left-toolbar {
    position: absolute;
    bottom: calc(var(--bottom-menu-height) + var(--info-bar-height) + 8px);
    left: 10px;
    z-index: 1000;
    display: flex;
    gap: 8px;
    pointer-events: none;
}

.bottom-left-toolbar > * {
    pointer-events: auto;
}

/* 工具栏按钮组 */
.toolbar-group {
    display: flex;
    gap: 8px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(10px);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.location-search-form {
    align-items: center;
}

.location-search-form input {
    width: min(240px, 32vw);
    height: 44px;
    box-sizing: border-box;
    padding: 0 10px;
    border: 1px solid #bbb;
    border-radius: 6px;
    font-size: 14px;
}

.location-search-form button {
    min-width: 64px;
    height: 44px;
    padding: 0 12px;
    border: 1px solid #1976D2;
    border-radius: 6px;
    background: #1976D2;
    color: white;
    cursor: pointer;
}

.location-search-form button:disabled {
    opacity: 0.65;
    cursor: wait;
}

.location-search-attribution {
    color: #555;
    font-size: 10px;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
}

.location-search-attribution:hover {
    text-decoration: underline;
}

/* 工具栏按钮 */
.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 44px;
    padding: 0 12px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    color: #333;
    white-space: nowrap;
    user-select: none;
}

.toolbar-btn:hover {
    background: #f5f5f5;
    border-color: #999;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.toolbar-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.toolbar-btn.active {
    background: #2196F3;
    color: white;
    border-color: #2196F3;
}

.toolbar-btn.primary {
    background: #4CAF50;
    color: white;
    border-color: #4CAF50;
}

.toolbar-btn.primary:hover {
    background: #45a049;
    border-color: #45a049;
}

.toolbar-btn.warning {
    background: #FF9800;
    color: white;
    border-color: #FF9800;
}

.toolbar-btn.warning:hover {
    background: #f57c00;
    border-color: #f57c00;
}

.toolbar-btn.danger {
    background: #f44336;
    color: white;
    border-color: #f44336;
}

.toolbar-btn.danger:hover {
    background: #d32f2f;
    border-color: #d32f2f;
}

/* 图标按钮 */
.toolbar-btn i {
    font-size: 18px;
}

.toolbar-btn.icon-only {
    min-width: 44px;
    padding: 0;
}

.toolbar-btn .btn-text {
    margin-left: 6px;
}

.toolbar-btn.icon-only .btn-text {
    display: none;
}

/* 资源选择器按钮 */
.resource-selector-wrap {
    position: relative;
}

.resource-selector-btn {
    position: relative;
    min-width: 120px;
    padding: 0 12px;
}

.resource-selector-btn .resource-icon {
    width: 32px;
    height: 32px;
    background-size: cover;
    border-radius: 4px;
    margin-right: 8px;
}

.resource-selector-btn .resource-name {
    flex: 1;
    text-align: left;
    font-size: 13px;
}

.resource-selector-btn .dropdown-icon {
    margin-left: 8px;
    font-size: 12px;
}

/* 底部按钮栏 - 保持原有设计但优化 */
#bottom_menu {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.9);
    height: var(--bottom-menu-height);
    width: 100%;
    bottom: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
    box-sizing: border-box;
}

#place_btn {
    height: 56px;
    min-width: 120px;
    padding: 0 18px;
    border: 0;
    border-radius: 8px;
    background: #1976D2;
    color: white;
    font: bold 14px Arial;
    cursor: pointer;
}

#place_btn:disabled {
    background: #555;
    color: #aaa;
    cursor: not-allowed;
}

#scan_btn {
    flex: 1;
    height: 64px;
    margin: 0 8px;
    background: linear-gradient(to top, #335500, #338800);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    max-width: 400px;
}

#scan_btn:hover {
    background: linear-gradient(to top, #446600, #449900);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

#scan_btn:active {
    transform: translateY(0);
}

#scan_btn a {
    vertical-align: middle;
    font: bold 14px Arial;
    color: white;
    text-align: center;
    line-height: 1.4;
}

#scan_btn a span {
    font-size: 11px;
    font-weight: normal;
    opacity: 0.85;
}

#save_text {
    width: 100%;
    min-height: 150px;
    box-sizing: border-box;
    resize: vertical;
    padding: 10px;
    font-family: Consolas, monospace;
    font-size: 12px;
}

.dialog-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.dialog-actions button {
    min-height: 40px;
    padding: 0 14px;
}

.dialog-actions .primary-action {
    background: #2e7d32;
    color: white;
}

.resource-config-row,
.offline-config-row {
    display: grid;
    align-items: center;
    gap: 8px;
    padding: 10px 8px;
    border-bottom: 1px solid #ddd;
    font-size: 13px;
}

.resource-config-row {
    grid-template-columns: auto 20px 24px minmax(80px, 1fr) minmax(100px, 150px) 48px;
}

.offline-config-row {
    grid-template-columns: 20px minmax(80px, 1fr) minmax(100px, 150px) 48px;
}

.resource-color-swatch {
    width: 18px;
    height: 18px;
    border: 1px solid #000;
    box-sizing: border-box;
}

.resource-config-row input[type="range"],
.offline-config-row input[type="range"] {
    width: 100%;
    min-width: 0;
}

.threshold-value {
    text-align: right;
    white-space: nowrap;
}

/* 资源选择菜单：锚定在触发按钮正下方。 */
#res_selector_bar {
    position: absolute;
    left: 0;
    top: calc(100% + 8px);
    right: auto;
    bottom: auto;
    max-height: calc(100vh - 90px);
    width: 80px;
    background-color: rgba(0, 0, 0, 0.95);
    overflow-y: auto;
    overflow-x: hidden;
    border-radius: 8px;
    z-index: 1001;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
}

#res_selector_bar::-webkit-scrollbar {
    width: 4px;
}

#res_selector_bar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

#res_selector_bar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

#res_selector_bar .button_box {
    margin: 2px;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .top-toolbar {
        top: 8px;
        left: 8px;
        right: 8px;
        gap: 6px;
    }

    .bottom-left-toolbar {
        bottom: calc(var(--bottom-menu-height) + var(--info-bar-height) + 6px);
        left: 8px;
        gap: 6px;
    }

    .toolbar-group {
        padding: 6px;
        gap: 6px;
    }

    .toolbar-btn {
        min-width: 40px;
        height: 40px;
        padding: 0 10px;
        font-size: 13px;
    }

    .toolbar-btn i {
        font-size: 16px;
    }

    /* 移动端隐藏文字，只显示图标 */
    .toolbar-btn .btn-text {
        display: none;
    }

    .toolbar-btn.icon-only {
        min-width: 40px;
    }

    .resource-selector-btn {
        min-width: 100px;
        padding: 0 8px;
    }

    .resource-selector-btn .resource-icon {
        width: 28px;
        height: 28px;
        margin-right: 6px;
    }

    .resource-selector-btn .resource-name {
        font-size: 12px;
    }

    .location-search-form input {
        width: min(210px, 34vw);
        height: 40px;
    }

    .location-search-form button {
        min-width: 40px;
        height: 40px;
        padding: 0 10px;
    }

    .location-search-form .btn-text {
        display: none;
    }

    #bottom_menu {
        height: var(--bottom-menu-height);
        padding: 0 6px;
    }

    #scan_btn {
        height: 56px;
        margin: 0 6px;
        border-radius: 6px;
    }

    #res_selector_bar {
        max-height: calc(100vh - 78px);
    }
}

@media (max-width: 480px) {
    .top-toolbar {
        top: 6px;
        left: 6px;
        right: 6px;
        gap: 4px;
    }

    .bottom-left-toolbar {
        bottom: calc(var(--bottom-menu-height) + var(--info-bar-height) + 6px);
        left: 6px;
        gap: 4px;
    }

    .toolbar-group {
        padding: 4px;
        gap: 4px;
    }

    .toolbar-btn {
        min-width: 36px;
        height: 36px;
        padding: 0 8px;
        font-size: 12px;
    }

    .toolbar-btn i {
        font-size: 14px;
    }

    .resource-selector-btn {
        min-width: 80px;
        padding: 0 6px;
    }

    .resource-selector-btn .resource-icon {
        width: 24px;
        height: 24px;
        margin-right: 4px;
    }

    .resource-selector-btn .resource-name {
        font-size: 11px;
    }

    .location-search-form {
        order: 3;
        width: 100%;
        box-sizing: border-box;
    }

    .location-search-form input {
        flex: 1;
        width: auto;
        min-width: 0;
        height: 36px;
    }

    .location-search-form button {
        height: 36px;
        min-width: 36px;
        padding: 0 8px;
    }

    #bottom_menu {
        height: var(--bottom-menu-height);
        padding: 0 4px;
    }

    #scan_btn {
        height: 48px;
        margin: 0 4px;
        border-radius: 4px;
    }

    #scan_btn a {
        font-size: 12px;
    }

    #place_btn {
        min-width: 92px;
        height: 48px;
        padding: 0 10px;
        font-size: 12px;
    }

    #res_selector_bar {
        max-height: calc(100vh - 70px);
        width: 68px;
    }

    #res_selector_bar .button_box {
        width: 64px;
        height: 64px;
    }

    .resource-config-row {
        grid-template-columns: auto 18px 24px minmax(70px, 1fr) 44px;
    }

    .resource-config-row input[type="range"] {
        grid-column: 2 / -1;
    }

    .resource-config-row .threshold-value {
        grid-column: 5;
        grid-row: 1;
    }

    .offline-config-row {
        grid-template-columns: 18px minmax(70px, 1fr) 44px;
    }

    .offline-config-row input[type="range"] {
        grid-column: 1 / -1;
    }
}

/* 横屏模式优化 */
@media (max-height: 500px) and (orientation: landscape) {
    :root {
        --bottom-menu-height: 50px;
        --info-bar-height: 50px;
    }

    .top-toolbar {
        top: 4px;
        gap: 4px;
    }

    .bottom-left-toolbar {
        bottom: calc(var(--bottom-menu-height) + var(--info-bar-height) + 4px);
        gap: 4px;
    }

    .toolbar-group {
        padding: 4px;
    }

    .toolbar-btn {
        height: 32px;
        min-width: 32px;
        padding: 0 6px;
    }

    #bottom_menu {
        height: var(--bottom-menu-height);
    }

    #scan_btn {
        height: 40px;
    }

    #res_selector_bar {
        top: calc(100% + 6px);
        max-height: calc(100vh - 58px);
    }
}
